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
|
#include <iostream>
#include <string>
using namespace std;
struct CorpData
{
string name;
double first, second, third, fourth, total, avg;
CorpData(string n = "", double f = 0, double s = 0, double t = 0, double h = 0)
{
name = n;
first = f;
second = s;
third = t;
fourth = h;
}
void showinfo(CorpData part)
{
cout << "Branch: " << part.name << endl;
cout << "Total Sales : " << part.total << endl;
cout << "Average Sales : " << part.avg << endl;
}
void calculate(CorpData calc)
{
calc.total = calc.first + calc.second + calc.third + calc.fourth;
calc.avg = (calc.total) / 4;
}
};
void showinfo(CorpData);
void calculate(CorpData);
int main()
{
CorpData data1("East", 10000, 80000, 20000, 30000);
CorpData data2("West", 20000, 70000, 10000, 40000);
CorpData data3("North", 30000, 60000, 20000, 30000);
CorpData data4("South", 40000, 50000, 10000, 40000);
const int Branch = 4;
CorpData data[Branch] = { data1, data2, data3, data4 };
for (int i = 0; i < Branch; i++)
{
calculate(CorpData);
showinfo(CorpData);
}
return 0;
}
|