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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#include <iostream>
#include <string>
using namespace std;
class profit{
public:
int first;
int second;
int third;
int fourth;
int total;
double average;
string name;
};
void readin(profit[], int);
void printArray(profit[], int);
void total(profit[], int);
void average(profit[], int);
void profitHigh(profit[], int);
void profit(profit[], int);
void lostprofit(profit[], int);
void even(profit[], int);
int main()
{
int n;
profit company[30];
cout << "Enter amount of items to be analyzed" << endl;
cin >> n;
readin(company,n);
printArray(company,n);
total(company,n);
average(company,n);
profitHigh(company,n);
profit(company,n);
lostprofit(company,n);
even(company,n);
return 0;
}
void readin(profit arr[],int size)
{
cout << "Enter the Item Name and the Profit for that quarter" << endl;
for(j = 0; j < size; j++)
cin >> arr[j].name >> arr[j].first >> arr[j].second >> arr[j].third >> arr[j].fourth;
}
void printArray(profit arr[],int size)
{
cout << "Table of Data from item and quarterly sales" << endl;
for(k = 0; k < size; k++)
cout << arr[k].name << arr[k].first << arr[k].second << arr[k].third << arr[k].fourth;
}
void total(profit arr[],int size)
{
for(int l = 0; l < size; l++)
{
arr[l].total = arr[l].first + arr[l].second + arr[l].third + arr[l].fourth
}
}
void average(profit arr[],int size)
{
for(a = 0; a < size; a++)
{
arr[a].average = arr[m].total / 4;
}
for(m = 0; m < size; m++)
{
cout << arr[m].name << " made $" << arr[m].total << " this year and averaged $" << arr[m].average << endl;
}
}
void profitHigh(profit arr[],int size)
{
string id;
int temp;
string quarter;
for(n = 0; n < size; n++)
{
if(arr[n].first > temp)
{
temp = arr[n].first;
id = arr[n].name;
}
else if(arr[n].second > temp)
{
temp = arr[n].second;
id = arr[n].name;
}
else if(arr[n].third > temp)
{
temp = arr[n].third;
id = arr[n].name;
}
else if(arr[n[.fourth > temp;
{
temp = arr[n].fourth;
id = arr[n].name;
}
}
for(p = 0; p < size; p++)
{
if(temp == arr[p].first)
quarter = "1st";
else if(temp == arr[p].second)
quarter = "2nd";
else if(temp == arr[p].third)
quarter = "3rd";
else if(temp == arr[p].fourth)
quarter = "4th";
}
cout << id << " had the greatest profit of $" << temp << " of the " << quarter << " quarter sales" << endl;
}
void profit(profit arr[],int size)
{
int quart1;
int quart2;
int quart3;
int quart4;
for(q = 0; q < size; q++)
{
if(arr[q].first > 0)
quart1++;
if(arr[q].second > 0)
quart2++;
if(arr[q].third > 0)
quart3++;
if(arr[q].fourth > 0)
quart4++;
}
cout << "Quarter One had " << quart1 << " profitable gains." << endl;
cout << "Quarter Two had " << quart2 << " profitable gains." << endl;
cout << "Quarter Three had " << quart3 << " profitable gains." << endl;
cout << "Quarter Four had " << quart4 << " profitable gains." << endl;
cout << "/n/n" << endl;
}
void lostprofit(profit arr[],int size)
{
int quart1;
int quart2;
int quart3;
int quart4;
for(w = 0; w < size; w++)
{
if(arr[w].first < 0)
quart1++;
if(arr[w].second < 0)
quart2++;
if(arr[w].third < 0)
quart3++;
if(arr[w].fourth < 0)
quart4++;
}
cout << "Quarter One had " << quart1 << " losses." << endl;
cout << "Quarter Two had " << quart2 << " losses." << endl;
cout << "Quarter Three had " << quart3 << " losses." << endl;
cout << "Quarter Four had " << quart4 << " losses." << endl;
cout << "/n/n" << endl;
}
void even(profit arr[],int size)
{
int quart1;
int quart2;
int quart3;
int quart4;
for(x = 0; x < size; x++)
{
if(arr[x].first < 0)
quart1++;
if(arr[x].second < 0)
quart2++;
if(arr[x].third < 0)
quart3++;
if(arr[x].fourth < 0)
quart4++;
}
cout << "Quarter One had " << quart1 << " items that broke even." << endl;
cout << "Quarter Two had " << quart2 << " items that broke even." << endl;
cout << "Quarter Three had " << quart3 << " items that broke even." << endl;
cout << "Quarter Four had " << quart4 << " items that broke even." << endl;
cout << "/n/n" << endl;
}
|