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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section: Chapter Questions
Problem 1PP
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning