In C++ Provide one application for a business store that sale 2 models of one pr
ID: 3572732 • Letter: I
Question
In C++
Provide one application for a business store that sale 2 models of one product, model A and model B. The application first provides the menu to allow users can select one of the following tasks per time and when they finish one task, they can continue to using the application to select other task from the menu until they choose exit. All the output on the screen and in files should be exact as requested, and show the pseudo code.
MENU
1. Sale Product
2. Ending day sale report
3. Ending month sale report
4. Ending year sale report
0. Exit
Part 1: Sale Product: For each sale transaction, after entering the sale transaction number (string), number of Model A units sold (int), price of model A unit (double), the number of model B (int), the price of model B unit (double), the amound paid of customer (double) from the keyboard, the application should print the receipt on the screen and write one line to the file name SaleInDay_yyyy_mm_dd.txt.
The receipt is in the following format (the first transaction in the below example:
Date: 06/27/2016
Sale Transaction: 2611
12 Model A (1.99 per unit): 23.88
10 Model B (2.19 per unit): 21.90
Subtotal: 43.78
Tax: 3.78
Total: 49.56
Amount paid: 50.00
Balance: -0.44
* Write one line to output file:
For example, on day 06/26/2016, each sale transaction will be written on one line in the file named SaleInDay_2016_06_26.txt. Each line includes 5 information separated by a tab ” ”
-The first column: transaction number
-The second column is number of model A units sold,
-The third column is the price of model A unit
-The fourth column is number of model B units sold,
-The last column is the price of model B unit
2601 12 1.99 10 2.19
2602 8 1.99 12 2.19
2603 14 1.99 14 2.19
2604 9 1.99 11 2.19
2605 13 1.99 16 2.19
2606 11 1.99 10 2.19
2607 7 1.99 12 2.19
2608 8 1.99 16 2.19
2609 12 1.99 15 2.19
2610 15 1.99 18 2.19
Part 2: Ending day sale report: -At the end of the day, users will run task 2 to calculate subtotal of sale during the day.
* open and read the file Sale_yyyy_mm_dd.txt that is created from the task 1.
* For each line: calculate the money of model A sold and the money of model B sold on each sale transaction, then add up to have sum of number model A units sold, sum of money model A sold, sum of number model B units sold, sum of money model B sold and total money sold both model sold during the day
* display the report of the day on the screen and write one line to the output file to file SaleInMonth_yyyy_mm.txt
For example: on the day 06/26/2016, there are 10 sale transaction in above file Sale_2016_06_26.txt
The output of the Day Sale Report on the screen a below:
Sale Report in: 06/27/2016
Model A: 109 216.91
Model B: 134 293.46
Total: 510.37
216.91 (total money sold model A whole day)
= moneyA of transaction1 + moneyA of transaction 2+ …. +monye of transaction 10
293.46 (total money sold model B whole day)
= moneyB of transaction1 + moneyB of transaction 2+ …. +money of transaction 10
moneyA of each transaction = number of modelA units (2nd column) * price of unit A (3rd column)
moneyB of each transaction = number of modelB units (4th column) * price of unit B (5th column)
109 (total A units sold in whole day) = sum of 2nd column
234 (total B units sold in whole day) = sum of 4th column
510.37 (total money sold in the day)
= total money sold model A whole day + total money sold model B whole day
These above information of each day sold will be saved on one line in the file SaleInMonth_2016_06.txt with 5 information that are separated by a tab “ ” as below
*The 1st column is the day of the month
*The 2nd column is the number of model A sold on each day
*The 3rd column is the money sold model A on each day
*The 4th column is the number of model B sold on each day
*The last column is the money sold model B on each day
1 72 143.28 98 214.62
2 85 169.15 106 232.14
3 91 181.09 97 212.43
4 78 170.82 92 210.68
5 87 190.53 105 240.45
6 88 192.72 110 251.90
7 93 175.77 98 204.82
8 85 160.65 96 200.64
9 90 170.1 93 194.37
10 88 175.12 101 221.19
11 76 151.24 105 229.95
12 94 187.06 120 262.80
13 89 177.11 115 251.85
14 96 191.04 103 225.57
15 87 173.13 118 258.42
16 79 157.21 112 245.28
17 94 187.06 103 225.57
18 84 167.16 105 229.95
19 76 151.24 122 267.18
20 94 187.06 107 234.33
21 89 177.11 113 247.47
22 92 183.08 108 236.52
23 93 185.07 104 227.76
24 88 175.12 102 223.38
25 94 187.06 116 254.04
26 109 216.91 134 293.46
27 90 179.10 108 236.52
28 88 175.12 114 249.66
29 96 191.04 104 227.76
30 86 171.14 110 240.90
-----------------------------------------------------------------------------------
This is what I have so far:
#include <iostream>
#include <iomanip>
using namespace std
Int main ()
{
String tno;
int nA;
int nB;
double Aprice;
double Bprice;
double amt;
int ch;
while(true)
{
cout << "Menu";
cout << “1. Sale Product";
cout << "2. Ending day sale report";
cout << "3. Ending month sale report";
cout << "4. Ending year sale report";
cout << "0.Exit";
cout << "Enter your choice: ";
cin >> choice;
cout << endl;
switch(choice)
}
{
BufferedWriter b=new BufferedWriter(new FileWriter(new File("Sale_2016_07_20.txt")));
cout << "Sale report";
{
case 1: cout << "Enter transaction number";
cin >> tno;
cout << "Enter number of Model A units sold: ";
cin >> nA;
cout << "Enter the price of model A unit: ";
cin >> Aprice;
cout << "Enter number of Model B units sold: ";
cin >> nB;
cout << "Enter the price of model B unit: ";
cin >> Bprice
cout << "Enter the amount paid of customer: ";
cin >>amt
cout << tno+nA+Aprice+nB+Bprice+amt;
b.write(tno+" "+nA+" "+Aprice+" "+nB+" "+Bprice+" ");
cout << "Do you want to enter another transaction details? (1-exit/0-continue)”;
cin >> flag
}
not sure where to go from here?
Explanation / Answer
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
string day,month,year;
string sale_product()
{
ofstream out;
string tno;
int nA;
int nB;
double Aprice;
double Bprice;
double amt;
double tax =3.78;
cout << "Enter the day : ";
cin.ignore();
getline(cin,day);
cout << "Enter the month : ";
getline(cin,month);
cout << "Enter the year : ";
getline(cin,year);
string filename="SaleInDay_"+year+"_"+month+"_"+day+".txt";
cout<<filename;
out.open(filename,ofstream::out|ofstream::app);
cout << "Enter the transaction number : ";
getline(cin,tno);
cout << "Enter number of Model A units sold: ";
cin >> nA;
cout << "Enter the price of model A unit: ";
cin >> Aprice;
cout << "Enter number of Model B units sold: ";
cin >> nB;
cout << "Enter the price of model B unit: ";
cin >> Bprice;
cout << "Enter the amount paid of customer: ";
cin >>amt;
cout<<endl;
cout<<"Date: "<<month<<"/"<<day<<"/"<<year<<endl;
cout<<"Sale Transaction: "<<tno<<endl;
cout<<nA<<" Model A("<<Aprice<<" per unit): "<<nA*Aprice<<endl;
cout<<nB<<" Model B("<<Bprice<<" per unit): "<<nB*Bprice<<endl;
cout<<"Subtotal: "<<(nA*Aprice)+(nB*Bprice)<<endl;
cout<<"Tax: "<<tax<<endl;
cout<<"Total: "<<(nA*Aprice)+(nB*Bprice)+tax<<endl;
cout<<"Amount paid: "<<amt<<endl;
cout<<"Balance: "<<amt-((nA*Aprice)+(nB*Bprice)+tax)<<endl;
out<<tno<<" "<<nA<<" "<<Aprice<<" "<<nB<<" "<<Bprice<<endl;
out.close();
return filename;
}
void day_sale_product(string filename)
{
ifstream in;
in.open("filename");
string line;
double Aprice;
double Bprice;
int nA;
int nB;
string tno;
int totalnA=0;
int totalnB=0;
double totalAprice=0;
double totalBprice=0;
while(getline(in,line,' '))
{
istringstream is(line);
is>>tno;
is>>nA;
is>>Aprice;
is>>nB;
is>>Bprice;
totalnA=totalnA+nA;
totalnB=totalnB+nB;
totalAprice=totalAprice+Aprice;
totalBprice=totalBprice+Bprice;
}
cout<<"Sale Report in :"<<month<<"/"<<day<<"/"<<year<<endl;
cout<<"Model A : "<<totalnA<<" "<<totalAprice<<endl;
cout<<"Model B : "<<totalnB<<" "<<totalBprice<<endl;
string f="SaleInMonth_"+year+"_"+month+".txt";
ofstream o;
o.open(f,ofstream::out|ofstream::app);
o<<day<<" "<<totalnA<<" "<<totalAprice<<" "<<totalnB<<" "<<totalBprice<<endl;
o.close();
in.close();
}
void month_sale_product()
{}
void year_sale_product()
{}
int main ()
{
int ch;
string f="";
do
{
cout << "Menu"<<endl;
cout << "1. Sale Product"<<endl;
cout << "2. Ending day sale report"<<endl;
cout << "3. Ending month sale report"<<endl;
cout << "4. Ending year sale report"<<endl;
cout << "0.Exit"<<endl;
cout << "Enter your choice: "<<endl;
cin >> ch;
switch(ch)
{
case 0: break;
case 1:f=sale_product();
break;
case 2: day_sale_product(f);
break;
case 3:month_sale_product();
break;
case 4:year_sale_product();
break;
}
} while(ch!=0);
system("pause");
return 0;
}
Output:
Menu
1. Sale Product
2. Ending day sale report
3. Ending month sale report
4. Ending year sale report
0.Exit
Enter your choice:
1
Enter the day : 06
Enter the month : 12
Enter the year : 2016
SaleInDay_2016_12_06.txtEnter the transaction number : 2612
Enter number of Model A units sold: 10
Enter the price of model A unit: 2
Enter number of Model B units sold: 10
Enter the price of model B unit: 4
Enter the amount paid of customer: 100
Date: 12/06/2016
Sale Transaction: 2612
10 Model A(2 per unit): 20
10 Model B(4 per unit): 40
Subtotal: 60
Tax: 3.78
Total: 63.78
Amount paid: 100
Balance: 36.22
Menu
1. Sale Product
2. Ending day sale report
3. Ending month sale report
4. Ending year sale report
0.Exit
Enter your choice: