1. Define a new C++class named “PurchaseOrder” that manages a purchase: number of items(integer), cost per item(double), and the description of the purchase(string). Please note that the total can be derived from multiplying the quantity with the cost per item and should not be a data member. The class must provide at least the following two methods: •toString methods that return the string containing all the information about the purchase order in the following format: Description() Quantity() Total() For example, here is a specific purchase order: Description(A box of candy) Quantity(100) CostPerItem($1.25) Total($125.00) •compareTotal method that compares the information between the 2 PurchaseOrderobjects and returns -1 if the total of the first purchase is less, 0 if they both have the same total, and 1 if greater. Please make use of the fact that there must be an object to call this method with. Note: you can add as many other methods as you need. Show how this class is being used and tested. 2. Write a function named “createPurchaseOrder” that accepts the quantity (integer), the cost per item(double), and the description(string). It will return a newly created PurchaseOrderobject holding that information if they are valid: quantity and cost per item cannot be negative and the description can not be empty or blank(s). When it is invalid, it will return NULL to indicate that it cannot create such PurchaseOrderobject.
1. Define a new C++class named “PurchaseOrder” that manages a purchase: number of items(integer), cost per item(double), and the description of the purchase(string).
Please note that the total can be derived from multiplying the quantity with the cost per item and should not be a data member.
The class must provide at least the following two methods:
•toString methods that return the string containing all the information about the purchase order in the following format:
Description(<purchase-descripton>) Quantity(<number-of-items) Cost(<cost-per-item>) Total(<total-cost-of-this-purchase>)
For example, here is a specific purchase order: Description(A box of candy) Quantity(100) CostPerItem($1.25) Total($125.00)
•compareTotal method that compares the information between the 2 PurchaseOrderobjects and returns -1 if the total of the first purchase is less, 0 if they both have the same total, and 1 if greater. Please make use of the fact that there must be an object to call this method with.
Note: you can add as many other methods as you need. Show how this class is being used and tested.
2. Write a function named “createPurchaseOrder” that accepts the quantity (integer), the cost per item(double), and the description(string). It will return a newly created PurchaseOrderobject holding that information if they are valid: quantity and cost per item cannot be negative and the description can not be empty or blank(s). When it is invalid, it will return NULL to indicate that it cannot create such PurchaseOrderobject.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps