Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C++ create a class named Order that performs order processing of a single

ID: 3770233 • Letter: U

Question

Using C++ create a class named Order that performs order processing of a single item. The class has the following five fields:

Customer name
Customer number
Quantity ordered
Unit price
Total price

Include set and get methods for each field except the total price field. The set methods prompt the user for values for each field. This class also needs a method to compute the total price (quantity times unit price) and a method to display the field values.

Create a subclass named ShippedOrder that overrides computePrice() by adding a shipping and handling charge of $4.00. Write an application named UseOrder that instantiates an object of each of these classes. Prompt the user for data for the Order object, and display the results, then prompt the user for data for the ShippedOrder object, and display the results.

Explanation / Answer

#include <iostream>
#include <string>

#define MAX 1000

using namespace std;

class Order
{
protected:
string name;
string number;
int quantity;
float unit_price;
float total_price;

public:
void set_name()
{
cout<<"Enter the name of the customer::";
cin>>name;
}

void set_num()
{
cout<<"Enter the number of the customer::";
cin>>number;
}

void set_quantity()
{
cout<<"Enter quantity::";
cin>>quantity;
}
void set_unitprice()
{
cout<<"Enter unit price::";
cin>>unit_price;
}


string get_name(){ return name; }
string get_num(){ return number;}
int get_quantity(){ return quantity; }
float get_unitprice(){ return unit_price; }
float computePrice(){ return unit_price*quantity; }

};

class ShippedOrder: public Order{

public:
float computePrice() { return unit_price*quantity+4; }
};


int main() {

Order obj1;
obj1.set_name();
obj1.set_num();
obj1.set_quantity();
obj1.set_unitprice();
cout<<"Total price is "<<obj1.computePrice()<<endl<<endl;

ShippedOrder obj2;
obj2.set_name();
obj2.set_num();
obj2.set_quantity();
obj2.set_unitprice();
cout<<"Total price is "<<obj2.computePrice()<<endl;

return 1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote