1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
#include <iostream>
#include <iomanip>
using namespace std;
// stucture function
struct Division // changed from Corp Data to Division
{
string div; // divisions name.... changed from Division to name
double annualSales; // annual sales, now holds the total
double avg; // average of quarter sales
double firstqtr, secondqtr, thirdqtr, fourthqtr; // quater sales for first, second, third and fourth.
//double total // do not need this anymore
};
// Function prototypes
void GetDivisionSales(Division& div);
void FindTotalandAvgSales(Division& div);
void DisplayCorpInfo(const Division& north, const Division& south, const Division& east, const Division& west);
int main()
{
Division north, south, east, west, div; // added to declare north, south, east, west and div
// Intro
cout << "Corporate Data Sales Program" << endl;
cout << "=============================\n" << endl;
GetDivisionSales(div);
FindTotalandAvgSales(div);
DisplayCorpInfo(north, south, east, west);
return 0;
}
// Function to get the Division sales
void GetDivisionSales(Division& div)
{
Division north, south, east, west;
// North Division
cout << "\nEnter the quarterly sales for the North Division:" << endl;
cout << "\t First quarter: ";
cin >> north.firstqtr;
cout << "\t Second quarter: ";
cin >> north.secondqtr;
cout << "\t Third quarter: ";
cin >> north.thirdqtr;
cout << "\t Fourth quarter: ";
cin >> north.fourthqtr;
// Validation
if (north.firstqtr < 0 || north.secondqtr < 0 || north.thirdqtr < 0 || north.fourthqtr < 0)
{
cout << "You have entered in the a wrong number, please try something greater than 0" << endl;
cin >> north.firstqtr;
cin >> north.secondqtr;
cin >> north.thirdqtr;
cin >> north.fourthqtr;
}
// South Division
cout << "\nEnter the quarterly sales for the South Division:" << endl;
cout << "\t First quarter: ";
cin >> south.firstqtr;
cout << "\t Second quarter: ";
cin >> south.secondqtr;
cout << "\t Third quarter: ";
cin >> south.thirdqtr;
cout << "\t Fourth quarter: ";
cin >> south.fourthqtr;
// Validation
if (north.firstqtr < 0 || north.secondqtr < 0 || north.thirdqtr < 0 || north.fourthqtr < 0)
{
cout << "You have entered in the a wrong number, please try something greater than 0" << endl;
cin >> south.firstqtr;
cin >> south.secondqtr;
cin >> south.thirdqtr;
cin >> south.fourthqtr;
}
// East Division
cout << "\nEnter the quarterly sales for the East Division:" << endl;
cout << "\t First quarter: ";
cin >> east.firstqtr;
cout << "\t Second quarter: ";
cin >> east.secondqtr;
cout << "\t Third quarter: ";
cin >> east.thirdqtr;
cout << "\t Fourth quarter: ";
cin >> east.fourthqtr;
// Validation
if (east.firstqtr < 0 || east.secondqtr < 0 || east.thirdqtr < 0 || east.fourthqtr < 0)
{
cout << "You have entered in the a wrong number, please try something greater than 0" << endl;
cin >> east.firstqtr;
cin >> east.secondqtr;
cin >> east.thirdqtr;
cin >> east.fourthqtr;
}
// West Division
cout << "\nEnter the quarterly sales for the West Division:" << endl;
cout << "\t First quarter: ";
cin >> west.firstqtr;
cout << "\t Second quarter: ";
cin >> west.secondqtr;
cout << "\t Third quarter: ";
cin >> west.thirdqtr;
cout << "\t Fourth quarter: ";
cin >> west.fourthqtr;
// Validation
if (west.firstqtr < 0 || west.secondqtr < 0 || west.thirdqtr < 0 || west.fourthqtr < 0)
{
cout << "You have entered in the a wrong number, please try something greater than 0" << endl;
cin >> west.firstqtr;
cin >> west.secondqtr;
cin >> west.thirdqtr;
cin >> west.fourthqtr;
}
}
// Function to find Total and Average sales
void FindTotalandAvgSales(Division& div)
{
Division north, south, east, west;
// Calculates Totals
north.annualSales = (north.firstqtr + north.secondqtr + north.thirdqtr + north.fourthqtr);
south.annualSales = (south.firstqtr + south.secondqtr + south.thirdqtr + south.fourthqtr);
east.annualSales = (east.firstqtr + east.secondqtr + east.thirdqtr + east.fourthqtr);
west.annualSales = (west.firstqtr + west.secondqtr + west.thirdqtr + west.fourthqtr);
// Calculates Average
north.avg = (north.annualSales / 4);
south.avg = (south.annualSales / 4);
east.avg = (east.annualSales / 4);
west.avg = (west.annualSales / 4);
}
void DisplayCorpInfo(const Division& north, const Division& south, const Division& east, const Division& west)
{
Division north, south, east, west;
// Display total sales
cout << "\nTotal Annual Sales:" << endl;
cout << "\t North Division: " << north.annualSales << endl;
cout << "\t South Division: " << south.annualSales << endl;
cout << "\t East Division: " << east.annualSales << endl;
cout << "\t West Division: " << west.annualSales << endl;
// Displays Average Sales
cout << "\n Average Quarter Sales:" << endl;
cout << "\t North Division: " << north.avg << endl;
cout << "\t South Division: " << south.avg << endl;
cout << "\t East Division: " << east.avg << endl;
cout << "\t West Division: " << west.avg << endl;
}
|