A mail-order house sells five different products whose retail prices are as foll
ID: 3663941 • Letter: A
Question
A mail-order house sells five different products whose retail prices are as follows: product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows:
Product number
Quantity sold for one day
If the quantity sold for the product is over 10, then 10% off is applied to the sales. If the quantity sold for the product is over 20 then 25% off is applied to the sales. You must create a function named Calculate which has 2 parameters to calculate the sales and return the sales.
Your program must use a switch structure to help determine the retail price for each product. It should calculate and display the total retail value of each product sold last week. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results. You must create 3 separate files for this homework assignment. The Company.h file contains the definition of the class Company. The Company.cpp file contains the member-function definitions of the class Company. The lab3.cpp file contains the main function.
a) You must create 3 separate files as stated above.
b) Your program must produce the prompt and the output the same as given.
c) Your program should run correctly with the same inputs and outputs as given in the sample run.
d) Your program must use a switch structure to check the product number.
e) You must include the function Calculate that return a value.
f) The sales values should be displayed with currency.
Explanation / Answer
//Company.h
class Company {
public:
int product_no;
int quantity_sold;
float total_sell;
float calculate(int product, int quantity);
float totalSellWeek();
};
//Company.cpp
#include<iostream>
#include "Company.h"
using namespace std;
float Company :: calculate(int product, int quan) {
float sell = 0.0;
float sell_rate = 0.0;
switch(product) {
case 1:
sell_rate = 2.98;
break;
case 2:
sell_rate = 4.50;
break;
case 3:
sell_rate = 9.98;
break;
case 4:
sell_rate = 4.49;
break;
case 5:
sell_rate = 6.87;
break;
}
cout<<"sell rate choosen: "<<sell_rate<<endl;
sell = sell_rate * quan;
this->total_sell +=sell;
return sell;
}
float Company :: totalSellWeek() {
return this->total_sell;
}
//lab3.cpp
#include<iostream>
#include "Company.h"
using namespace std;
int main() {
Company x1,x2,x3,x4,x5;
x1.total_sell = 0;
x2.total_sell = 0;
x3.total_sell = 0;
x4.total_sell = 0;
x5.total_sell = 0;
while(true) {
int product = 0;
int quan = 0;
cout<<"Enter product number <1-5> < 0 to stop>: ";
cin>>product;
if(product == 0){
break;
}
cout<<"Enter quantity sold: ";
cin>>quan;
switch(product) {
case 1:
cout<<"The sales for this product 1 is: $"<<x1.calculate(1,quan)<<endl;
break;
case 2:
cout<<"The sales for this product 2 is: $"<<x2.calculate(2,quan)<<endl;
break;
case 3:
cout<<"The sales for this product 3 is: $"<<x3.calculate(3,quan)<<endl;
break;
case 4:
cout<<"The sales for this product 4 is: $"<<x4.calculate(4,quan)<<endl;
break;
case 5:
cout<<"The sales for this product 5 is: $"<<x5.calculate(5,quan)<<endl;
break;
}
}
cout<<"Total Sales for the week:"<<endl;
cout<<"------------------------------"<<endl;
cout<<"Product 1 $"<<x1.totalSellWeek()<<endl;
cout<<"Product 2 $"<<x2.totalSellWeek()<<endl;
cout<<"Product 3 $"<<x3.totalSellWeek()<<endl;
cout<<"Product 4 $"<<x4.totalSellWeek()<<endl;
cout<<"Product 5 $"<<x5.totalSellWeek()<<endl;
return 0;
}
Compile using : g++ lab3.cpp Company.cpp in linux
run: ./a.out
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.