Computer Science C++ Convert following program to use a loop and step through input the data for each division , also recive data from an input file that contains 4 row (for each division) and 4 column for each quarter sales //Name: //Date: //Problem statemnt: Corporate Sales Data Page 659 Gaddis #include #include #include using namespace std;
Computer Science
C++
Convert following program to use a loop and step through input the data for each division , also recive data from an input file that contains 4 row
(for each division) and 4 column for each quarter sales
//Name:
//Date:
//Problem statemnt: Corporate Sales Data Page 659 Gaddis
#include
#include
#include
using namespace std;
// Declaration of the Division structure.
struct Division
{
string name; // Division name
double quarter1; // First quarter sales
double quarter2; // Second quarter sales
double quarter3; // Third quarter sales
double quarter4; // Fourth quarter sales
double annualSales; // Annual sales
double averageQtrSales; // Average quarterly sales
};
int main()
{
//================= Create structure variables for each division. ===================
Division east, west, north, south;
//============= Store the names of the divisions. ===================================
east.name = "East";
west.name = "West";
north.name = "North";
south.name = "South";
//---------------------------------EAST DIVISION --------------------------------
//=================== Get sales data for East division ===============================
cout << "Enter the quarterly sales for the East Divison:\n";
cout << "First quarter: "< cin >> east.quarter1;
cout << "Second quarter: " << endl;
cin >> east.quarter2;
cout << "Third quarter: " << endl;
cin >> east.quarter3;
cout << "Fourth quarter: " << endl;
cin >> east.quarter4;
//====== Calculate the annual sales & average sales for the east division. ============
east.annualSales = east.quarter1 + east.quarter2 + east.quarter3 + east.quarter4;
east.averageQtrSales = east.annualSales / 4.0;
//-----------------------------------West DIVISION -------------------------------------------------
//================= Get sales data for West division =======================
cout << "Enter the quarterly sales for the West Divison:\n";
cout << "First quarter: " << endl;
cin >> west.quarter1;
cout << "Second quarter: " << endl;
cin >> west.quarter2;
cout << "Third quarter: " << endl;
cin >> west.quarter3;
cout << "Fourth quarter: " << endl;
cin >> west.quarter4;
//====== Calculate the annual sales & average sales for the West division. ============
west.annualSales = west.quarter1 + west.quarter2 + west.quarter3 + west.quarter4;
west.averageQtrSales = west.annualSales / 4;
//-----------------------------------North DIVISION -------------------------------------------------
//==================== Get sales data for North division ============================
cout << "Enter the quarterly sales for the North Divison:\n";
cout << "First quarter: " << endl;
cin >> north.quarter1;
cout << "Second quarter: " << endl;
cin >> north.quarter2;
cout << "Third quarter: " << endl;
cin >> north.quarter3;
cout << "Fourth quarter: " << endl;
cin >> north.quarter4;
//======= Calculate the annual sales & average for NORTH the division.
north.annualSales = north.quarter1 + north.quarter2 + north.quarter3 + north.quarter4;
north.averageQtrSales = north.annualSales / 4;
//-----------------------------------South DIVISION -------------------------------------------------
//==================== Get sales data for South division =============================
cout << "Enter the quarterly sales for the South Divison:\n";
cout << "First quarter: " << endl;
cin >> south.quarter1;
cout << "Second quarter: " << endl;
cin >> south.quarter2;
cout << "Third quarter: " << endl;
cin >> south.quarter3;
cout << "Fourth quarter: " << endl;
cin >> south.quarter4;
//==== Calculate the annual & average sales for SOUTH the division. ===
south.annualSales = south.quarter1 + south.quarter2 + south.quarter3 + south.quarter4;
south.averageQtrSales = south.annualSales / 4;
//============== Display Totals and Averages ====================
cout << setprecision(2) << fixed << showpoint;
cout << " Total Annual Sales: ===========> \n";
cout << "\tEast Division: $" << east.annualSales << endl;
cout << "\tWest Division: $" << west.annualSales << endl;
cout << "\tNorth Division: $" << north.annualSales << endl;
cout << "\tSouth Division: $" << south.annualSales << endl;
cout << " Average Quarterly Sales: ========> \n";
cout << "\tEast Division: $" << east.averageQtrSales << endl;
cout << "\tWest Division: $" << west.averageQtrSales << endl;
cout << "\tNorth Division: $" << north.averageQtrSales << endl;
cout << "\tSouth Division: $" << south.averageQtrSales << endl;
return 0;
}
Input file:
East West North South
Q1 90 85 78 89
Q2 95 75 88 90
Q3 78 98 65 89
Q4 99 88 90 88
Step by step
Solved in 2 steps with 1 images