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.
Your 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. Print out a daily report listing sales for each burrito type and total number of all burritos sold.
So far, this sounds very similar to a previous exercise! This difference this time is that you 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.
SAMPLE OUTPUT:
Enter the number of different types sold: 4
Enter the name of the burrito 1: chicken
Enter the number of burritos sold of this type: 4
Enter the name of the burrito 2: pork
Enter the number of burritos sold of this type: 3
Enter the name of the burrito 3: shrimp
Enter the number of burritos sold of this type: 7
Enter the name of the burrito 4: california
Enter the number of burritos sold of this type: 9
Burrito Name Burrito Count
------------------------------------------
chicken 4
pork 3
shrimp 7
california 9
The total number of burritos sold for 4 types: 23
#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;
}
Screenshot of the code:
Screenshot of the output:
I have done the code as per your requirement. If you have any query, please comment down below.