A10-Storing Information

On This Page


Overview

There are three parts to this assignment:

  1. Review Exercises:

    First make sure you have completed and turned in the exercises from lesson 10. Then complete the exercises in CodeLab 10. These exercises will help prepare you for the problem-solving program and should be completed first. You can look at solutions if you miss your first attempt.

  2. Problem Solving Program:

    Complete the programming project following the Program Specifications listed below. You may make extra credit additions to this program as outlined in the section on Extra Credit.

Program Specifications

Note that you must complete this program either by yourself or by working with one other student of this class following the rules of Pair Programming for Homework Assignments.

  1. Using your store.cpp source code from the last assignment, update your application that manages a store of products to load and save the product data of your store.

    Keep the Product class without adding any new variables or removing any of the required functions from the last two assignments.

  2. Add a second read() member function to your Product class that reads data from an input stream and loads the data into the member variables of the Product object in the following order:
    1. name
    2. price
    3. quantity

    Use the following function prototype exactly for this function:

    /**
        Loads information about this Product from the file stream.
    
        @param fin An input stream connected to the files with the
        data to load.
    */
    void read(ifstream& fin);
    
  3. Add a write() member function to your Product class that writes the member variables to an output stream in the following order, each on a new line:
    1. name
    2. price
    3. quantity
    Use the following function prototype exactly for this function:
    /**
        Writes information about this Product to the file stream.
    
        @param fout An output stream connected to the file in
        which to save the data.
    */
    void write(ofstream& fout);
    
  4. Add a loadData() non-member function to your program that loads product data from a file and returns the loaded data in a vector of Product objects.

    Use the following prototype exactly for this function:

    /**
        Loads the Product data from the specified file name and
        returns the data in a vector of Product objects.
    
        @param fileName The name of the file from which to read.
    */
    vector<Product> loadData(string fileName);
    
  5. Call the loadData() function with an argument of "products.txt" when the store program starts so that it loads the file automatically without any user input.
  6. The products.txt must follow the format of this file: products.txt.

    Note that product names may have spaces.

  7. Add a saveData() non-member function to your program that stores a vector of Product data into a file. Use the following prototype exactly for this function:
    /**
        Writes store data to an output file.
    
        @param store The vector of Product objects.
        @param fileName The name of the file to which to write.
    */
    void saveData(vector<Product> store, string fileName);
    
  8. Call the saveData() function when the store program exits so that all the current store data is saved to a file named store.txt automatically without any user input.

    The output of the saveData() function must follow the same format as the product.txt input file.

  9. The name of the source code file must be store2.cpp and all your code must be in this file.

    Be careful of the spelling, including capitalization, as you will lose points for a misspelled name.

  10. Your updated program must stll operate like the specifications for assignment 9 with the exception the product data are not hard coded at start-up, but are loaded instead from a file.
  11. Make sure that every function declaration (prototype) has a function comment block. In addition, remember to include a file comment block and follow all the other style rules we have covered.
  12. Submit your files to Blackboard as explained in the section of this document: What to Turn In.

Example Program

You can see an example of how the program operates by downloading and running the executable file: store2.exe. To run the program, you will need to save the products.txt file into the same directory as the store2.exe file.

Hints:

  1. Remember that Windows text files end in "\r\n" (see lesson 10.1.3) and that getline() stops reading when it sees a '\n' (see lesson 10.2.5). Thus, if you use Windows, I recommend that you save your products.txt file using TextPad with a UNIX file format.
  2. For an example of reading file data into a vector of objects, see lesson lesson 10.3.5.
  3. Do not forget about using: fin.ignore(1000, '\n') or cin >> ws to clear whitespace from the input buffer.
  4. Manipulators may be useful for formatting the output (see lesson 10.4.2).

Extra Credit

The following are worth extra credit points:

  1. Complete the assignment using pair programming. (1 point)
  2. Write a non-member function using the following prototype: (3 points)
    /**
        Writes a report to a file named report.txt.
    
        @param store The vector of Product objects.
        @param fileName The name of the file to which to write.
    */
    void writeReport(vector<Product> store, string fileName);
    

    Call the function from main() to produce text like the following in a file named report.txt when menu item 6 is selected:

    Report for my store:
    # Name               Price   Qty     Value
    1 Baseball caps       7.99    50    399.50
    2 Traditional mugs    5.99    15     89.85
    3 Large T-shirts     12.99    60    779.40
    
    Total inventory value: 1268.75
    

Make certain that your README.txt file describes any extra credit attempted.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.

Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the course information page.

Review Exercises

  • One point for each exercise from Lesson 10 that was attempted and turned in.
  • 0.64 points for each correctly answered question in CodeLab

Program Compilation

  • 4: Source code compiles with no errors or warnings
  • 2: Source code compiles with warnings
  • 0: Does not compile or wrong file turned in

Program Functionality

  • 10: Demonstrates mastery of the assignment
    • Applies concepts from the lessons appropriately
    • Meets all specifications (see above) with particularly elegant solutions
    • Runs to completion with no abnormal error conditions
    • Generates correct output given correct input
    • Behaves in a reasonable way in response to incorrect data
  • 8: Has all the functionality expected of the assignment
    • Demonstrates many techniques from the lesson
    • Attempts to meet all specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
  • 6: Has most of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Attempts to meet all but one of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
  • 4: Has some of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Attempts to meet at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have more than 3 minor errors
  • 2: Serious functional problems but shows some effort and understanding
    • Attempts to meet less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
  • 0: Does not execute

Program Style

  • 4: Code is well-documented including:
  • 3: Code has a minor documentation error
  • 2: Code has some documentation errors
  • 1: Code has many documentation errors
  • 0: No apparent attempt to follow documentation standards or write documentation comments

Program Style

  • 4: Code is well-documented as described in How To Document and Organize Your C++ Code
  • 3: Code has a minor documentation error
  • 2: Code has some (2-3) documentation errors
  • 1: Code has many (>3) documentation errors
  • 0: No apparent attempt to follow documentation standards or write documentation comments

README.txt File

  • 2: README.txt file submitted following the instructions
  • 1: README.txt file submitted but some information was missing
  • 0: No README.txt file submitted

Total possible: 40, plus extra credit

What to Turn In

Submit your assignment to Blackboard, in the assignment folder that matches the name of this assignment, following the instructions for submitting homework. Include the following items for grading:

  1. README.txt file
  2. All the exercise files from Lesson 10
  3. store2.cpp

You must submit all the files needed to complete your assignment. Do not assume that the instructors has any files. Your assignment must work as submitted.

Home | Blackboard | Announcements | Day Schedule | Eve Schedule
Course info | Help | FAQ's | HowTo's | Links
Last Updated: May 18 2008 @20:17:53