Starting from:

$29.99

CSE325 Project 5 Solution

Assignment Overview

This assignment focuses on multi-threaded programming in a Linux environment, and is the first milestone in a two-part project. You will design and implement the C++ program which simulates a simple producer-consumer system, as described below.


Assignment Deliverables

The deliverables for this assignment are the following files:

proj05.makefile – the makefile which produces proj05 proj05.student.cpp – the source code file for your solution


Assignment Specifications

A wholesale tree company maintains an inventory of tree seedlings and sells them to its customers (greenhouses, garden centers, etc). The customers can place purchase orders using several different methods (website, toll-free phone number, local phone number, etc) between the hours of 8:00 AM and 6:00 PM.

The simulation for this system will use the following files:

a) The file named "inventory.old" contains the inventory at the start of the day.

That file will contain zero or more lines, where each line contains four fields: the product ID number (field width of 6, unsigned integer), the price per seedling (field width of 5, dollars and cents), the quantity on hand (field width of 5, unsigned integer), and the product description (up to 30 characters). There is one space between fields. For example:

100492 2.50 360 Northern Red Oak
201005 10.17 62 Shagbark Hickory
100305 1.95 1043 Sugar Maple
100491 2.50 803 White Oak

b) The file named "orders" contains the set of all purchase orders received during the day, in temporal order.

That file will contain zero or more lines, where each line contains three fields: the customer ID number (field width of 7, unsigned integer), the product ID number being ordered (field width of 6, unsigned integer), and the number being ordered (field width of 5, unsigned integer). There is one space between fields. For example:

9981532 100305 65
9981532 100492 40
0003183 100305 100
9981532 100492 25
0003183 201005 5
0050600 100305 60

c) The file named "inventory.new" contains the inventory at the end of the day.

That file will have the same format as "inventory.old" (the inventory at the start of the day).
1. The program will input the contents of "inventory.old" and build a data structure representing the current inventory.

After building the current inventory, the program will create a separate thread: the producer thread.

After the producer thread halts, the program will create another separate thread: the consumer thread.

After the consumer thread halts, the program will create "inventory.new" and output the current inventory into it.

2. The producer thread will input the contents of "orders" and build a data structure representing the sequence of purchase orders (in the same order as they are in the file).

3. The consumer thread will create the output file named "log" and will then process the sequence of purchase orders in the data structure, from first to last.

The consumer thread will validate each purchase request. If there are enough seedlings on hand to fill the order, the current inventory will be updated. If the order cannot be filled for any reason, it will be rejected.

The consumer thread will track the results of processing each purchase order by sending one line to the "log" output file. Each line will be no more than 80 characters in length and will contain:

a) customer ID number
b) product ID number
c) product description
d) number ordered
e) transaction amount (number ordered x price per seedling)
f) result (filled or rejected)

The log entries will be appropriately formatted: items will be aligned in columns, and monetary values will be displayed as dollars and cents (for example, $50.00).

4. The program will include appropriate logic to handle exceptional cases and errors.

Assignment Notes

1. As stated above, your source code file will be named "proj05.student.cpp" and you must use "g++" to translate your source code file in the CSE Linux environment.


man 3 pthread_create man 3 pthread_join man 3 pthread_exit





7. Examples of the two input files are available in the "/user/cse325/Projects" directory. Note that those examples are intended to illustrate the format of the files and are inadequate to serve as non-trivial test cases. It will be necessary for you to develop a series of input files to test your solution.

More products