In: Computer Science
The local taqueria wants you to write a program which tracks the number of burritos they sell each day and help them analyze their business.
The C++ program should ask the user for the number of different burrito types sold, then get the names of the types and the number of burritos sold of each type of that day. It asks to print out a daily report listing sales for each burrito type and total number of all burritos sold.
It must use a struct called SalesRecord which has two fields -- a string containing the name of the burrito, and an int containing the number of burritos sold of this type. You must have one dynamically allocated array of SalesRecord structs.
PROGRAM :
#include<iostream>
using namespace std;
struct SalesRecord{ //created structure named SalesRecord as
given in question
string name; //string variable name for storing the names of the
burritos
int num; //int variable num for storing the number of sold burritos
of this type
};
int main(){
int n,i,sum = 0; //variable n for different types of burritos, i
for for loop, sum for storing the total number of burritos
sold
cout<<"Enter the number of different types sold: ";
cin>>n; //asking for different types of burritos
SalesRecord sr[n]; //creating array of struct SalesRecord
for(i = 0;i<n;i++){
cout<<"Enter the name of the burrito "<<(i+1)<<":
";
cin>>sr[i].name; //Asking for name of each type of
burritos
cout<<"Enter the number of burritos sold of this type:
";
cin>>sr[i].num; //asking for number of burritos sold for each
type
sum+=sr[i].num; //adding number of burritos for each type
}
cout<<"Burrito_Name Burrito_Count"<<endl;
cout<<"------------------------------------------"<<endl;
for(i = 0;i<n;i++){
cout<<sr[i].name<<" "<<sr[i].num<<endl;
//printing each type of burritos with numbers sold
}
cout<<"The total number of burritos sold for
"<<n<<" types: "<<sum<<endl; //printing
total number of burritos sold
return 0;
}
OUTPUT :