Question
This lab will test your ability to create and use base classes and derived classes. There will be 8 files. This program records purchases from
This lab will test your ability to create and use base classes and derived classes.There will be 8 files.
This program records purchases from Amazon and calculates the cost. There are three types of items that a user can purchase - a book, a DVD, or a digital music download. For each item there is a title, a list of authors, and a price. For each item you need to get information and you need to calculate the costs. You will create four classes as follows:
The Generic Item
This contains everything that is common to all types of purchases.
By default generic item will create an object with the title set to an empty string, the list of authors to a nullptr, the number of authors to 0, and the price to $0.00.
The generic item can also be created with the following data - the title, the number of authors, and the price. The constructor will prompt the user for the authors. Since the number of authors is not known before runtime, dynamic memory allocation will have to be used to get the list of authors.
When asked to calculate the cost, generic item will simply return the price.
When asked to get information, generic item will stream out the title, a list of authors, and the price to 2 decimal places.
Be sure to cleanup on object destruction.
Book.
This contains information specific to a book purchase.
When asked to calculate the cost, the book will add a 10% penalty to the price for using paper and 13% of the price for the harmonized sales tax.
When asked to get information, book will stream out information from the generic item that it is derived from. It will also stream out one line specifying: "There is a 10% penalty for using paper."
DVD.
This contains information specific to a DVD purchase.
When asked to calculate the cost, the DVD will add a 5% penalty to the price for using plastic and 13% of the price for the harmonized sales tax.
When asked to get information, the DVD will stream out information from the generic item that it is derived from. It will also stream out one line specifying: "There is a 5% penalty for using plastic."
Digital Music Download.
This contains information specific to the purchase of digital music download.
When asked to calculate the cost, the digital music download will add 13% of the price for the harmonized sales tax.
When asked to get information, the DVD will stream out information from the generic item that it is derived from.
Sample Run
You have been given the main test program: AmazonMain.cpp. You have to create the header and CPP files for all the four classes.
A sample run is as follows:
For testing purchases, please order one book, one DVD, and one digital download. FOR THE BOOK Enter the title: The Book Enter the price: 11.66 Enter the number of authors: 3 Enter the name of author 1 : Book Author1 Enter the name of author 2 : Book Author2 Enter the name of author 3 : Book Author3 FOR THE DVD Enter the title: The DVD Enter the price: 34.99 Enter the number of authors: 2 Enter the name of author 1 : DVD Author1 Enter the name of author 2 : DVD Author2 FOR THE DIGITAL MUSIC DOWNLOAD Enter the title: Best Hits of Smoopey Enter the price: 21.49 Enter the number of authors: 2 Enter the name of author 1 : Smoopey1 Enter the name of author 2 : Smoopey2 Title: The Book Authors: Book Author1, Book Author2, Book Author3. Price: $11.66 There is a 10% penalty for using paper. The real cost is $14.34 Title: The DVD Authors: DVD Author1, DVD Author2. Price: $34.99 There is a 5% penalty for using plastic. The real cost is $41.29 Title: Best Hits of Smoopey Authors: Smoopey1, Smoopey2. Price: $21.49 The real cost is $24.28 The total cost is $79.91
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started