Write a program that uses a structure named CorpData to store the following info
ID: 3539135 • Letter: W
Question
Write a program that uses a structure named CorpData to store the following information
on a company division:
Division name (such as East, West, North, or South)
First quarter sales
Second quarter sales
Third quarter sales
Fourth quarter sales
Include a constructor that allows the division name and four quarterly sales amounts to be speci%uFB01ed at the time a CorpData variable is created.
The program should create four CorpData variables, each representing one of the following corporate divisions: East, West, North, and South. These variables should be passed one at a time, as constant references, to a function that computes the division%u2019s annual sales total and quarterly average, and displays these along with the division name.
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
struct CorpData
{
double f_q,s_q,t_q,fo_q;
string div;
CorpData()
{
div = "";
f_q = 0;
s_q = 0;
t_q = 0;
fo_q = 0;
}
CorpData(double f, double s, double t, double fo, string x)
{
div = x;
f_q = f;
s_q = s;
t_q = t;
fo_q = fo;
}
double annual_sales()
{
return f_q+s_q+t_q+fo_q;
}
double avg_quat_sales()
{
return (annual_sales()/4);
}
};
int main()
{
double f_q,s_q,t_q,fo_q;
string div;
struct CorpData cp[4];
for(int i=0;i<4;i++)
{
cout<<"enter quaterly sales "<<endl;
cin>>f_q>>s_q>>t_q>>fo_q;
cout<<"Enter division name (East, West, North, or South)"<endl<;
getline(cin,div);
cp[i] = CorpData(f_q,s_q,t_q,fo_q, div);
}
for(int i=0;i<4;i++)
{
cout<<cp[i].div;
cout<<"annual sales = "<<cp[i].annual_sales()<<endl;
cout<<"quaterly average sales = "<<cp[i].avg_quat_sales()<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.