On This Page
Overview
There are three parts to this assignment:
- Review Exercises:
First make sure you have completed and turned in the exercises from lesson 10. Then complete the exercises in CodeLab 10. The CodeLab exercises are more practice in how to use arrays and can be completed any time before the assignment is due.
- 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.
^ top
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.
- 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.
- 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.
- 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:
name
price
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);
Note that the function must be able to read product names that include single or multiple words with spaces between the words. This function is like the read() function you wrote in assignment 9, except you use fin rather than cin. For an example see lesson lesson 10.3.5.
- 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 store The list of products to display.
@param fileName The name of the file from which to read.
*/
void loadData(vector<Product>& store, string fileName);
The function must call the read(ifstream&) function from the previous step. For an example of reading file data into a vector of objects, see lesson lesson 10.3.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.
- The
products.txt must follow the format of this file: products.txt.
Note that product names may have spaces. Thus you must use getline() to read the product names.
- 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:
name
price
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);
- 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);
This function must call the write(ofstream&) function from the previous step.
- 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 save the data in the same format as the input file.
- Your updated program must still operate like the specifications for assignment 9 except that the product data are not hard coded at start-up, but are loaded instead from a file.
- Remember to follow all the style rules we have covered including:
- Class naming conventions (See: Class Names)
- Indentation in classes and placement of curly braces
- Every function declaration (prototype) in the class, including constructors, has a function comment block
- Every file has a file comment block
- No magic numbers (See: No Magic Numbers)
- 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:
- 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.
- For an example of reading file data into a vector of objects, see lesson lesson 10.3.5.
- Do not forget about using: fin >> ws to clear whitespace from the input buffer.
- Writing to a file is like reporting inventory. However, instead of writing to the screen you write to a file.
- Manipulators may be useful for formatting the output (see lesson 10.4.2).
^ top
Extra Credit
The following are worth extra credit points:
- Complete the assignment using pair programming. (1 point)
- 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.
^ top
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.
Lesson Exercises
- 2: All lesson exercises attempted and turned in
- 1: Some lesson exercises completed and turned in
- 0: No lesson exercises completed or turned in
Program Compilation
- 4: Source code compiles with no errors or warnings
- 3: Source code compiles with 1 warning
- 2: Source code compiles with 2 warnings
- 1: Source code compiles with 3+ 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
CodeLab and Other Tutorial Exercises
Number completed correctly / number exercises * 8 and rounded up to the nearest integer.
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: 30, plus extra credit
^ top
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:
README.txt file
- All the exercise files from Lesson 10
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.
^ top
Home
| Blackboard
| Day Schedule
| Eve Schedule
Syllabus
| Help
| FAQ's
| HowTo's
| Links
Last Updated: December 06 2009 @16:22:00
|