Computer Science

Computer Science

Santa Monica College CS 52 – C++ Programming

1

C++ Programming Programming Assignment 5

Instructions: 1. Read instructions carefully! 2. Use C++ syntax only, C syntax won’t be allowed. 3. Always use braces to define blocks. 4. Organize your code well with proper formatting and a single statement per line. 5. Always insert a space before and after each operator, e.g. a = b + c; not a=b+c; 6. Use meaningful variable names following conventions using camelCasing. 
 7. Comment your code to clarify your thoughts if needed but do NOT comment every single

line of code! 
 8. You may not use any library functions unless explicitly specified. 9. Name each program problem1.cpp, problem2.cpp, etc. and upload each file to Canvas. 10. Validate all input and re-prompt as long as an invalid value is entered! You don’t need to

validate the type.

Plagiarism: Plagiarism of any kind will not be tolerated! Plagiarized assignments will be reported to the Campus Disciplinarian. Problem 1 Shopping Cart 30 points Implement the class structure that represents a shopping cart for an online shop and items that can be put in the shopping cart. Create the following classes. Use appropriate access modifiers (member variables should be private!) and data types for each. Don’t forget to add getter and setter functions for each member variable.

• Item: This class has the member variables called title, description, and price. It has a pure virtual function called print (void print() = 0;) that prints the type and description of the current object to the console. This function is NOT implemented in this class but must be implemented/overridden in the three subclasses below.

o Book: This class inherits from Item. It has an instance variable called pageCount. o Movie: This class inherits from Item. It has an instance variable called length. o CD: This class inherits from Item. It has an instance variable called trackCount.

• ShoppingCart: This class keeps track of items that were bought. It has a single constructor which expects the maximum number of items that can be placed in the cart. It must have a dynamically allocated array of pointers to an item object (Item** array;) which is initialized in the constructor (array = new Item*[size]). The cart must have functions to add an item object to the cart and print the items currently in the cart to the console by calling each object’s print() function.

Finally, implement a main function that creates a shopping cart object. Then add one item of

Santa Monica College CS 52 – C++ Programming

2

each type to the shopping cart and finally list the items in the cart on the console.

Library: You need to include <string>

Order now and get 10% discount on all orders above $50 now!!The professional are ready and willing handle your assignment.

ORDER NOW »»