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 8. Then complete the exercises in CodeLab 8. 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.
- 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.
- Tutorial Exercises:
Complete the Tutorial Exercises in CodeLab 8 for this assignment before the specified due date. Refer to the assigned reading for the next lesson to help you understand the problems. Also, you can use the online lecture notes for more information as the notes become available.
^ 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.
- In a file named
product.cpp, write a declaration and a definition for a class named Product. The Product class represents an item you would find in a store and contains three private member variables: a string called name, a double called price and an int called quantity. You are NOT allowed to have any more member variables in the class than these three.
- Within this class, implement all the following functions:
- A default constructor that sets all the private variables to default values
- A three-parameter constructor that initializes all three member variables to the values passed to the parameter
- One "get" function for each private variable that returns the current value. The name of the function must follow the naming standards for "get" functions, which is the name of the variable with the prefix word "get".
- One "set" function for each private variable that sets a new value. The name of the function must follow the naming standards for "set" functions, which is the name of the variable with the prefix word "set". You must define the "set" functions outside the class declaration.
- Accessor function
getValue() that has no parameters and returns the price times the quantity.
- Accessor function
print() that has no parameters and returns no values, but displays the data of the class all on one line like this:
Milk 3.95 40 158.00
- All the accessor functions must include the keyword
const as discussed in lesson 8.2.4 and in the textbook on pages 219-220 under the section on, "const Correctness".
- In same
Product.cpp file, write a main() function that does the following:
- Constructs at least three
Product objects
- Sets values (name, price and quantity) for two objects using the three-argument constructor and for one object using the default constructor and "set" functions.
- Displays output for all 3 objects like that shown in the Sample Output section.
- Note that there is no user input for this assignment. Data for the program is hard-coded in main. Do NOT use any keyboard input streams, like
cin, in this assignment. If you have a cin statement in your program, you will get a low score.
- You must display at three different products. However, you may choose any name, price and quantity for the products as long as they are appropriate for a family-oriented store.
- Create the correct spacing for the output using the
setw() formatting function described on p. 68-69 of the textbook.
- You must use
string variables for this assignment and not char[] variables.
- Specify all numerical values as constants. Do not use any "magic numbers".
- Make sure that every function declaration (prototype) in the class declaration, including any constructors, has a function comment block. In addition, remember to include a file comment block and follow all the other style rules we have covered.
- Submit your file(s) to Blackboard as explained in the section of this document: What to Turn In.
Sample Output
When you run the program you see output like the following:
My products:
Name Price Qty Value
Milk 3.95 40 158.00
Bread 2.99 30 89.70
Cheese 4.98 20 99.60
Hints
- You can align text or numbers in a
setw() field using left or right. For example:
cout << setw(16) << left << name;
To use setw() you must include the iomanip library.
^ top
Extra Credit
The following are worth extra credit points:
- Complete the assignment using pair programming. (1 point)
- Add a function named
toString() that has no parameters and returns a string value containing all the data about the product. The function does NOT print any values and must NOT use cout. Instead, the function must return a string with one line of the output like that shown below. (2 points)
Milk 3.95 40 158.00
Note that this extra credit will require you to convert numbers to strings. For this you may want to research stringstreams.
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 8
product.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
| Announcements
| Day Schedule
| Eve Schedule
Course info
| Help
| FAQ's
| HowTo's
| Links
Last Updated: May 02 2009 @17:51:07
|