Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10 pts] We would like you to self-test how much you retained from the lecture. Write the correct solution to the Mandatory Practice Problems. Debug your code until it runs correctly. Circle below how you wrote your code.
    1. (10 pts) I was able to write the code without referring to anything.
    2. (10 pts) I had to look at the notes, but still I was able to write the code without looking at the solution.
    3. (10 pts) I had to look at solutions to finish to code.
    4. (0 pts) I didn't do this.
    If you had to look at the solution, briefly describe what you missed but understand now.
    
    
    
    
  2. [90pts] Write a program hw.cpp that works as follows:

    1. It reads in a data file containing fruit name/price-per-pound pairs (e.g. fruit1.txt, fruit2.txt)
      Note: If the file can't be opened, the program should print the message File not found! and exit.
    2. It reads and executes the following commands:
      • add amount lbs name — which adds amount lbs of fruit name to the current order
        Note: if the name is not one of the ones read from the file, print the error message: Error! name not found!
      • price name — which prints the price of the fruit name formatted as in this example: blueberries are $1.59 per pound
        Note: if the name is not one of the ones read from the file, print the error message: Error! name not found!
      • checkout — which exits the program, printing out the total price of the order in the format: total is $num
    Assume the user always enters a valid command from the three above.

    Requirement: Use an array or arrays containing struct objects!

    Sample Runs
    ~/$ ./hw
    Filename: fruit1.txt
    command: add 3 lbs mango
    command: price asdf
    Error! asdf not found!
    command: price peaches
    Error! peaches not found!
    command: price blueberries
    blueberries are $1.59 per pound
    command: add 2.1 lbs blueberries
    command: checkout
    total is $5.469
    
    ~/$ ./hw
    Filename: fruit2.txt
    command: add 2.0 lbs oranges
    command: price kiwi
    kiwi are $1.07 per pound
    command: price starfruit
    Error! starfruit not found!
    command: add 1.5 lbs peas
    Error! peas not found!
    command: add 1.5 lbs plums
    command: checkout
    total is $2.505
    
    ~/$ ./hw
    Filename: foobar.txt
    File not found!
    

    Turn in