C++ program has an output using = Reading data from a file into arrays Processin
ID: 3694875 • Letter: C
Question
C++ program has an output using =
Reading data from a file into arrays
Processing parallel arrays
Writing array data to files
Passing arrays to functions
Processing arrays using various kinds of functions
Design using a hierarchy chart
Your command line output should be in the format shown below:
--------------------------------------------------------------------------------------------------
Grocery Shopping Program
Please enter the name of your grocery store file: g:\Minimart.txt
0)gallon-milk 1)ice-5lbs 2)barsoap-6pk 3) shampoo
4) lotion 5)cereal 6) bagels-6pk 7) muffins-2pk
8) muffins-3pk 9)eggs-dozen 10)bread 11)butter-1lb
12) cookingOil 13)sugar-1lb 14)detergent 15)bleach
16)orangeJuice 17)coffee-6oz 18)sugar-3lb 19)teabags50
Please place your order by entering the code for the item
You may choose the same item more than once
Enter -1 when finished:4
Lotion 4.99 taxable
You may choose the same item more than once
Enter -1 when finished: 1
Ice-51bs 0.99
You may choose the same item more than once
Enter -1 when finished:14
Detergent 4.99 taxable
You may choose the same item more than once
Enter -1 when finished: 16
Orangejuice 1.99
You may choose the same item more than once
Enter -1 when finished: -1
The total amount of the tax is $0.70
The total amount due is $15.96
Name of the output file where the receipt will be printed:g:\out.txt
Thank you for your online order
Press any key to continue….
---------------------------------------------------------------------------------
Your file output should be in the format shown below:
------------------------------------------------------------------------------------
Grocery output should be in the format shown below:
Ice-5lbs 0.99
Cereal 2.30
orangeJuice 1.99
lotion 4.99 taxable
detergent 4.99 taxable
The total amount of the tax is $0.70
The total amount due is $15.96
Thank you for your online order
tax is 7%
Explanation / Answer
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string line,file;
float tax=0.0,sum=0.0;
ifstream myf("Minicart.txt");
ofstream myo("out.txt");
cout<<"Please enter the name of your grocery store file:Minicart.txt";
if(myf.is_open())
{
while(!myf.eof())
{
getline (myf,line);
cout<<line;
}
}
cout<<"Please place your order by entering the code for the item"<<endl;
while(1)
{
cout<<"You may choose the same item more than once"<<endl;
cout<<"Enter - 1 when finished:";
cin>>option;
if(option==-1)
{
break;
}
else{
switch(option)
{
case 0: cout<<"gallon-milk 0.99";
sum=sum+0.99;myo<<"gallon-milk 0.99";
break;
case 1: cout<<"ice-5lbs 0.99";
sum=sum+0.99;myo<<"ice-5lb 0.99";
break;
case 2: cout<<"barsoap .4.99 taxable";
tax=tax+4.99;myo<<"barsoap 4.99";
break;
case 3: cout<<"Shampoo 4.99 taxable";
tax=tax+4.99;myo<<"Shampoo 4.99 taxable";
break;
case 4: cout<<"lotion 4.99 taxable";
tax=tax+4.99;myo<<"lotion 4.99 taxable;
break;
case 5: cout<<"cereal 0.99";
sum=sum+0.99;myo<<"cereal 0.99";
break;
case 6: cout<<"bagels-6pk 0.99";
sum=sum+0.99;myo<<"bagels-6pk 0.99";
break;
case 7: cout<<"muffins-2pk 4.99 taxable";
tax=tax+4.99;myo<<"muffins-2pk 4.99 taxable";
break;
case 8: cout<<"muffins-3pk 4.99 taxable";
tax=tax+4.99;myo<<"muffins-2pk 4.99 taxable"
break;
case 9: cout<<"eggs 0.99";
sum=sum+0.99;myo<<"eggs 0.99";
break;
case 10: cout<<"bread 0.99";
sum=sum+0.99;myo<<"bread 0.99";
break;
case 11: cout<<"butter-1lb 0.99";
sum=sum+0.99;myo<<"butter-1lb 0.99";
break;
case 12: cout<<"cookingOil 4.99 taxable";
tax=tax+4.99;myo<<"cookingOil 4.99";
break;
case 13: cout<<"sugar-1lb 4.99 taxable";
tax=tax+4.99;myo<<"sugar-1lb 4.99";
break;
case 14: cout<<"detergent 4.99 taxable";
tax=tax+4.99;myo<<"detergent 4.99";
break;
case 15: cout<<"bleach 4.99 taxable";
tax=tax+4.99;myo<<"bleach 4.99 taxable ";
break;
case 16: cout<<"orangeJuice 4.99 taxable";
tax=tax+4.99;myo<<orangeJuice 4.99 taxable";
break;
case 17: cout<<"coffee-6oz 0.99";
sum=sum+0.99;myo<<"coffee-6oz 0.99";
break;
case 18: cout<<"sugar-3lb 4.99 taxable";
tax=tax+4.99;myo<<"sugar-3lb 4.99 taxable";
break;
case 19: cout<<"teabags50 4.99 taxable";
tax=tax+4.99;myo<<"teabags50 4.99taxable";
break;
}}
}
cout<<"The total amount of the tax is $"<<tax<<endl;
cout<<"The total amount due is $"<<sum<<endl;
myo<<"The total amount of the tax is $"<<tax;
myo<<"The total amount due is $"<<sum;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.