CPS 6: Assignment #4

Fair Time

Due: Friday, Oct. 13, 8am

6 points

Change into your cps6 directory using the cd command and create another directory called assign4 using the mkdir command. Change into the assign4 directory.

In order to do this assignment, you need to copy some files using the following cp command (don't forget the trailing period, or dot): cp ~ola/cps6/assign4/* .

If you type ls you should see the following files: Makefile, fair.cc, glassware, and leather. To compile your program, just type: make fair

Problem:

It's the season for craft fairs. Your assignment is to help the crafters in determining which of their items are most profitable. Every crafter keeps a record of each item sold and the price it sold for. You are to write a generic program in which any crafter can find out specific information on a particular item.

Each crafter has a data file in which each line represents an item sold. The format of a line is the name of the item, the size of the item (small or large) and the price the item sold for. For example, in the data file below, 6 items were sold.

coat small 140.00
coat large 199.99
coat small 140.00
coat large 199.99
purse small 27.80
coat small 120.00

There are two data files you can use to test your program. The file leather contains the items coat, belt, wallet, and purse, all in small and large sizes. The file glassware contains the items mobile, platter, bowl, and mirror, all in small and large sizes.

Use standard I/O for the text shown in the sample runs, and use a file stream to read data stored in a craft data file.

Input:

Your program should ask the crafter for the name of a specific item, the size of the item (small or large), the cost to make the item and the name of the data file containing the list of items sold.

Output:

You should print the following information.

  1. identify the item
  2. print out the percentage for this item out of the total number of items sold
  3. print out the percentage for this item out of the total amount of money collected
  4. print the average selling price for this item
  5. print the total profit made on this item

Sample Runs:

> fair
Enter an inventory item: coat
Enter size of item (large or small): small
Enter cost of item: 61.50
Enter name of inventory file: leather
The small coat was 27.81 percent of the items sold
and 52.11 percent of the total amount of money collected.
Its average selling price was $131.90
Total profit on this item was $2957.00
> fair
Enter an inventory item: mirror
Enter size of item (large or small): large
Enter cost of item: 26.60
Enter name of inventory file: glassware
The large mirror was 14.05 percent of the items sold
and 24.90 percent of the total amount of money collected.
Its average selling price was $42.75
Total profit on this item was $274.55
>

Extra credit: (3 pts)

Once you have completed fair.cc, make a copy of it called fair2.cc. Modify fair2.cc in the following way. Each crafter makes exactly four items and you can assume that at least one of each of these items appears in a data file. If the user types in an item that is not made, inform the user that item is not made by this crafter and list the items that are made by this crafter. Your program must determine what the four items for this data file are and inform the user. The grader will test your program on a data file for another crafter, and you do not know what the four items for this crafter are.

Sample run for extra credit:

> fair2
Enter an inventory item: blouse
Enter size of item (large or small): large
Enter cost of item: 16.60
Enter name of inventory file: clothes
The item blouse is not made by this crafter. 
Items made include shirt, dress, pants and socks.
> 

Submission

When your program works correctly, create a README file containing your name, the date, and an estimate of how long you worked on the assignment. You must also include a list of names of all those people with whom you collaborated on the assignment.

To submit your programs electronically type

submit6  assign4  README  fair.cc 

You should receive a message telling you that the programs were submitted correctly. If it doesn't work try typing ~ola/bin/submit6 in place of submit6 above.

If you do the extra credit, you must also submit the file fair2.cc. Include it at the end of the submit6 command. That is, type

submit6  assign4  README  fair.cc  fair2.cc