In: Computer Science
Create a Class to contain a customer order
Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes.
Create a class constructor without parameters that initializes the attributes to default values.
Create a class constructor with parameters that initializes the attributes to the passed in parameter values.
Create a behavior of that class to generate a welcome message that includes the company name.
Create a Class to contain a customer order detail row
Create attributes of that class to store Product Name, Price and Amount. Create a public property for each of these attributes.
Create a constructor without parameters that set all the attributes to an empty string or zero.
Create a constructor with parameters that sets all the attributes to the passed in parameters.
Create a behavior that, when provided a sales tax value, returns the total price for a detail row including sales tax.
Create a behavior that, when provided a product name, price and quantity, returns a single line order detail.
Initialize a Customer order object instance.
For a custom order detail line, prompt the user to enter a product name, price and amount (each separately). Initialize a customer order detail object instance with the values provided.
Repeats this two more times for a total of three customer order details.
Using the behavior in Customer Order, display the header information in the console.
Using the behavior in Customer Order Detail, display the three order detail lines in the console (each on a separate line).
Pause the console for a final user input before.
Screenshot of the code:
Output:
Code to copy:
#include<iostream>
#include<string>
using namespace std;
//Define the class customer order
class customerOrder
{
//Define the public data members of the class.
public:
string Company_Name, Address;
double Sales_Tax;
double tt = 0;
//Define the default constuctor to set default values.
customerOrder()
{
Company_Name = "\0";
Address = "\0";
Sales_Tax = 0;
}
//Define the parametrized constuctor to set the values.
customerOrder(string const name, string const a, double t)
{
Company_Name = name;
Address = a;
Sales_Tax = t;
tt = t;
welcome();
}
//Define the function to display the headings.
void welcome()
{
cout << "\n\t<<< Welcome to the "
<< Company_Name << " >>>\n";
}
};
//Define the orderDetailed class.
class orderDetail : public customerOrder
{
//Define the public data members of the class.
public:
string product_Name[3];
double pprice[3], pamount[3], t;
//Define the default constuctor to set default values.
orderDetail()
{
for (int i = 0; i<3; i++)
{
product_Name[i] = "\0";
pprice[i] = 0;
pamount[i] = 0;
}
}
//Define the parametrized constuctor to set the values.
orderDetail(string *p_name, double *pr, double *amount)
{
for (int i = 0; i<3; i++)
{
product_Name[i] = p_name[i];
pprice[i] = pr[i];
pamount[i] = amount[i];
}
}
//Define the function to display the order details.
void Sdisplay(int *q)
{
// Display the order record in a row.
cout << "Simple order details :";
cout << "\nOrder Number\t| product Name"
<<"\t| quantity\t| price \n";
for (int iter = 0; iter<3; iter++)
{
cout << iter + 1 << "\t\t|" << product_Name[iter]
<< "\t\t|" << q[iter]
<< "\t\t|" << pprice[iter] << "\n";
}
cout << "------------------------------------------\n";
}
//Define the function to calculate the price as
//per the tax and quantity.
void Caldisplay(int *q, double tax)
{
// Display the order record in a row.
t = tax;
double tprice = 0;
cout << "Order detail with calculated "
<<"price including the salestax:";
cout << "\nOrder Number\t| product Name"
<<"\t| quantity\t| price \n";
for (int i = 0; i<3; i++)
{
double totalPrice = 0;
totalPrice = pprice[i] + (t*pprice[i]) / 100;
cout << i + 1 << "\t\t|" << product_Name[i]
<< "\t\t|" << q[i]
<< "\t\t|" << totalPrice*q[i] << "\n";
tprice = tprice + totalPrice*q[i];
}
cout << "------------------------------------------\n";
tprice = Calprice(q);
cout << "Total calculated price :\t\t " << tprice
<< "\n";
}
//Define the function to calculate the price.
double Calprice(int *q)
{
double tp = 0, e = 0;
for (int i = 0; i<3; i++)
{
tp = (pprice[i] + (t*pprice[i]) / 100)*q[i];
e = e + tp;
}
return e;
}
};
int main()
{
//Define the variables.
string cname, address, productname[3];
double t, price[3], amount[3];
int q[3];
//Accept the input for customerOrder class.
cout << "Enter the company name : ";
getline(cin, cname);
cout << "Enter the address : ";
getline(cin, address);
cout << "Enter the sales tax:";
cin >> t;
//Call the parametrized constuctor of the class
//customerOrder.
customerOrder coobj(cname, address, t);
//Accept the input for customerOrder class.
cout << "\n--- Provide the details for the order ---- \n";
for (int iter = 0; iter<3; iter++)
{
cout << iter + 1 << ".Enter the product name:";
cin >> productname[iter];
cout << " Enter the product price:";
cin >> price[iter];
cout << " Enter the amount : ";
cin >> amount[iter];
cout << " Enter the quantity : ";
cin >> q[iter];
}
//Call the parametrized constuctor of the class
//customerOrder.
orderDetail odobj(productname, price, amount);
//Call the function of the class orderDetail.
odobj.Sdisplay(q);
odobj.Caldisplay(q, t);
}