Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. The Invoice

C++

Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. The Invoice class should contain four private data members a part number (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type double). Your class should have 2 constructors. A default constructor to initialize data members to 0 or empty, and a parameterized constructor to initialize data members to the value passed as parameters. Provide a set and get (mutator and assessor) functions for each data member. The get functions should simply return the respective data, and the set functions should prompt and mutate the respective data. In addition, provide a member function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double. If the quantity is not positive, it should be set to zero. Finally, if a function only accesses the data without modifying it, it should adorn the const keyword where appropriate. Write a test program that demonstrates class Invoices capabilities, which means in client code call each public function of the class to thoroughly exercise all the classs code. Use multiple files for the project. You should have one header (.h) file for the class definition, one implementation (.cpp) file for the member function implementation. Finally, you should include one source file for testing code. NOTE: Because of the simplicity of this class and the ability to initialize member variables in the header file (since C++ 11) it would be entirely appropriate to implement all functions inside of the header file (.h). But for this exercise please implement all functions inside an implementation file (.cpp).

Example output: image text in transcribed

Beginning tests of the Invoice class... After instantiation without parameters... getPartNumber)- etPartDescription()- getQuanity() - getPricePerItem0 0 getInvoiontO $0.00 (formatting applied) After instantiation with parameters: PartNumber = 123, PartDescription Bolt, Quanity 5, PricePerItem = 0.50 getPartNumber 123 getPartDescription()- Bolt getQuanity)5 getPricePerItem()-.5 getInvoiceAmount $2.50 (formatting applied) After instantiation without parameters but set with mutator functions... setPartNumber("223") setPartDescription("chainsaw") setQuanity (-33) setPricePerItem(125.00).... getPartNumber() 123 getPartDescription)-chainsaw getQuanity()-o getPricePerItem) 125.00 getInvoiO $0.00 (formatting applied) After instantiation with parameters: PartNumber = 656, PartDescription-Hose, Quanity = 25, PricePerItem = 1.00 and setPartNumber( "778") setPartDescription("rocket launcher") setQuanity (2) setPricePerItem(15000.00).... getPartNumber() -778 getPartDescription)rocket launcher getQuanity2 getPricePerItem() 15000.00 getInvoiceAmountO $30000.00 (formatting applied) Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions