Write a program that uses a structure to store the following data on a company d
ID: 3703679 • Letter: W
Question
Write a program that uses a structure to store the following data on a company division: (name the structure Company) Division Name (such as East, West, North, or South) (string) //Make this member a string a call it dName. First-Quarter Sales //Make this meinber double and call itfirst?Sales Second-Quarter Sales//Make this member double and call it sndQSales Third-Quarter Sales /Make this member double and call it thirdQSales Fourth-Quarter Sales //Make this member double and call it fourthQSales Total Annual Sales//Make this member double and call it annualSales Average Quarterly Sales //Make this member double and call it avgQSales The program should keep a list of corporate sales data. It should ask the user how many divisions the corporate has. It should then dynamically allocate an array of Company structure. After the array has been dynamically allocated, the program should ask the user for: . Division name . First-Quarter Sales . Second-Quarter Sales . Third-Quarter Sales Fourth-Quarter Sales Each division's total and average sales should be calculated and stored in the appropriate member of each structure variable. These figures should then be displayed in the screeExplanation / Answer
#include <iostream>
using namespace std;
struct company
{
string dname;
double First_QuarterSale;
double Second_QuarterSale;
double Third_QuarterSale;
double Fourth_QuarterSale;
double Total_AnnualSale;
double Average_QuarterlySale;
};
void readCorpSales(company*,int);
void displaySalesData(company*,int);
void calculateAnnualSales(company&);
void calculateQuaterlyAvg(company&);
int main()
{
int corporatesize;
cout<<"How many divisions your corporate has: ";
cin>>corporatesize;
cin.ignore();
struct company* divisions=new company[corporatesize];
readCorpSales(divisions,corporatesize);
displaySalesData(divisions,corporatesize);
delete[] divisions;
return 0;
}
void readCorpSales(company *div,int s)
{
for( int i=0; i<s; ++i )
{
cout<<" Enter Division Name: ";
cin>>div[i].dname;
cout<<"Enter First Quarter Sale: ";
cin>>div[i].First_QuarterSale;
cout<<"Enter Second Quarter Sale: ";
cin>>div[i].Second_QuarterSale;
cout<<"Enter Third Quarter Sale: ";
cin>>div[i].Third_QuarterSale;
cout<<"Enter Fourth Quarter Sale: ";
cin>>div[i].Fourth_QuarterSale;
calculateAnnualSales(div[i]);
calculateQuaterlyAvg(div[i]);
}
}
void displaySalesData(company* div,int s)
{
cout<<" ===============================";
cout<<" Corporate Data Sales Report";
cout<<" ===============================";
cout<<" Division Name 1st Q($) 2nd Q($) 3rd Q($) 4th Q($) Annual Sale ($) Avg Q Sale($) ";
for( int i=0; i<s; ++i )
{
cout<<div[i].dname<<" "<<div[i].First_QuarterSale<<" "<<div[i].Second_QuarterSale<<" "<<div[i].Third_QuarterSale<<" "<<div[i].Fourth_QuarterSale<<" "<<div[i].Total_AnnualSale<<" "<<div[i].Average_QuarterlySale<<" ";
}
}
void calculateAnnualSales(company &div)
{
div.Total_AnnualSale=
div.First_QuarterSale+
div.Second_QuarterSale+
div.Third_QuarterSale+
div.Fourth_QuarterSale;
}
void calculateQuaterlyAvg(company &div)
{
div.Average_QuarterlySale=(div.Total_AnnualSale/4);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.