Create a C++ program Create a class named Order that performs order processing o
ID: 3768965 • Letter: C
Question
Create a C++ program
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.
Thanks.
Explanation / Answer
//header file order.h
#include <iostream.h>
#include <string.h>
using namespace std;
class Order // Class order and its attributes
{
public:
void setName(string myName);
string getName();
void setNumber(int ID);
int getNumber();
void setQuanity(int Quant);
int getQuanity();
void setPrice(double money);
double getPrice();
double calculateTotalPrice();
void printOrder();
double ship;
void SetShip(int yes);
private:
string name;
int number;
int quantity;
double price;
double total;
};
string Order::getName()
{
return name;
}
int Order::getNumber()
{
return number;
}
double Order::getPrice()
{
return price;
}
int Order::getQuanity()
{
return quantity;
}
double Order::calculateTotalPrice()
{
return price * quantity + ship;
}
void Order::setName(string myName)
{
myName = name;
}
void Order::setNumber(int ID)
{
ID = number;
}
void Order::setQuanity(int Quant)
{
Quant = quantity;
}
void Order::setPrice(double money)
{
money = price;
}
class ShippedOrder: public Order //Subclass of ShippedOrder
{
public:
void SetShip(int yes);
private:
double shipping;
};
void Order::SetShip(int yes)
{
cin >> yes;
switch (yes)
{
case 'y':
Order.ship = 4.00;
break;
case 'n':
Order.ship = 0.00;
default:
cout<< "please enter a (y) or (n)"<<endl;
}
//main program
#include <iostream>
#include <string>
#include "Order.h"
using namespace std;
int main()
{
string yourName;
int yourNumber;
int yourQuantity;
double yourPrice;
int Yes;
Order dress;
cout<< "Enter your First and last name: "<<endl;
cin>> yourName;
dress.setName(yourName);
cout<< "Enter your member ID number: "<<endl;
cin>> yourNumber;
dress.setNumber(yourNumber);
cout<< "Enter the quantity bought: "<<endl;
cin>> yourQuantity;
dress.setQuanity(yourQuantity);
cout<< "Enter the price per unit: "<<endl;
cin>> yourPrice;
dress.setPrice(yourPrice);
cout<< "Thank you! Your name is: " << yourName
<< " Your ID number is: "<< yourNumber
<< " The amount purchased is: " <<yourQuantity
<< " The price per unit is: " << yourPrice
<< " The total amount due before shipping is: "<< yourQuantity * yourPrice<<endl;
system("CLS");
cout<< " Would you like to ship this product? "<<endl;
cin >> Yes;
dress.SetShip(Yes);
system("pause");
return 0;
}