Write a program that uses a structure named CorpData to store the following info
ID: 3539131 • 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 <iomanip>
using namespace std;
//structure function
struct CorpData
{
string name; //stores division name
double firstQ, secondQ, thirdQ, fourthQ, totalA, average; //stores the data of each division
} north, south, west, east;
int main()
{
double northTotal, southTotal, eastTotal, westTotal,
aveNorth, aveSouth, aveEast, aveWest;
//North Division
cout << " North Division";
cout << " Enter first quarter sale : ";
cin >> north.firstQ;
cout << "Enter second quarter sale : ";
cin >> north.secondQ;
cout << "Enter third quarter sale : ";
cin >> north.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> north.fourthQ;
//South Division
cout << " South Division";
cout << " Enter first quarter sale : ";
cin >> south.firstQ;
cout << "Enter second quarter sale : ";
cin >> south.secondQ;
cout << "Enter third quarter sale : ";
cin >> south.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> south.fourthQ;
//East Division
cout << " East Division";
cout << " Enter first quarter sale : ";
cin >> east.firstQ;
cout << "Enter second quarter sale : ";
cin >> east.secondQ;
cout << "Enter third quarter sale : ";
cin >> east.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> east.fourthQ;
//West Division
cout << " West Division";
cout << " Enter first quarter sale : ";
cin >> west.firstQ;
cout << "Enter second quarter sale : ";
cin >> west.secondQ;
cout << "Enter third quarter sale : ";
cin >> west.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> west.fourthQ;
cout << " ";
//////////////////////////////////////////////////////////////////////////
// //
// Calculate the annual total each division //
// //
//////////////////////////////////////////////////////////////////////////
northTotal = (north.firstQ + north.secondQ + north.thirdQ + north.fourthQ);
southTotal = (south.firstQ + north.secondQ + north.thirdQ + north.fourthQ);
eastTotal = (east.firstQ + east.secondQ + east.thirdQ + east.fourthQ);
westTotal = (west.firstQ + west.secondQ + west.thirdQ + west.fourthQ);
//////////////////////////////////////////////////////////////////////////
// //
// Calculate the annual average each division //
// //
//////////////////////////////////////////////////////////////////////////
aveNorth = northTotal / 4;
aveSouth = southTotal / 4;
aveEast = eastTotal / 4;
aveWest = westTotal / 4;
//////////////////////////////////////////////////////////////////////////
// //
// Display the annual total and average of each division //
// //
//////////////////////////////////////////////////////////////////////////
cout << setw(10) << "Division" << setw(14) << " Annual Total" << setw(18) << " Annual Average ";
cout << setw(10) << " North " << setw(14) << northTotal << " " << setw(18) << aveNorth << endl;
cout << setw(10) << " South " << setw(14) << southTotal << " " << setw(18) << aveSouth << endl;
cout << setw(10) << " East " << setw(14) << eastTotal << " " << setw(18) << aveEast << endl;
cout << setw(10) << " West " << setw(14) << westTotal << " " << setw(18) << aveWest << endl ;
cout << endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.