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
|
#include <iostream>
#include <string>
using namespace std;
string Individuals [] = {"Anne", "Bob", "Ralph", "Tim", "Barbara", "Jane", "Steve", "Tom", "Mike", "Shirley", "Pam", "Frank"};
int Weight [12] = {30, 150, 305, 225, 135, 160, 80, 200, 165, 90, 100, 120};
int SizeOfArray = 12;
void printIndividualsWeight ()
{
for (int i = 0; i < SizeOfArray; ++i)
cout << Individuals[i] <<"\t"<<"\t"<< Weight[i] << endl;
}
void IndividualsInElevator ()
{
int MaximumWeight = 0;
int i = 0;
cout <<"The People That Entered The Elevator Are : "<< endl;
MaximumWeight += Weight[i];
while (MaximumWeight <= 1100)
i++;
MaximumWeight += Weight[i];
cout << Individuals[i-1] <<" "<< Weight[i-1] << "Pounds" << endl;
MaximumWeight -= Weight[i];
cout <<"Maximum Weight In The Elevator Was"<< MaximumWeight << "lb and"<< i <<"Individuals Entered into the Elevator"<< endl;
}
int IndivInElev ()
{
int MaximumWeight1 = 0;
int i = 0;
MaximumWeight1 += Weight[i];
while (MaximumWeight1 <= 1100)
{
i++;
MaximumWeight1 += Weight[i];
}
MaximumWeight1 -= Weight[i];
i;
cout << endl;
return i;
}
int count1 ()
{
int count11;
count11 = IndivInElev();
return count11;
}
void SortDescend ()
{
int HoldWeight = -1;
string HoldIndividuals = " ";
for (int i=0; i < SizeOfArray; ++i)
for (int j = i+1; j < SizeOfArray; ++j)
if (Weight[i] < Weight[j])
{
HoldWeight = Weight[i];
HoldIndividuals = Individuals[i];
Weight[i] = Weight [j];
Individuals[j] = Individuals[j];
Weight[j] = HoldWeight;
Individuals[j] = HoldIndividuals;
}
}
int count2 ()
{
int count22;
count22 = IndivInElev();
return count22;
}
void SortAscend ()
{
int i, j, tempWeight;
string tempIndividuals = " ";
for (i = 0; i < SizeOfArray; i++)
for (int j = i+1; j < SizeOfArray; j++)
if (Weight[i] > Weight[j])
{
tempWeight = Weight[i];
tempIndividuals = Individuals[i];
Weight[i] = Weight [j];
Individuals[i] = Individuals[j];
Weight[j] = tempWeight;
Individuals[j] = tempIndividuals;
}
}
int count3 ()
{
int count33;
count33 = IndivInElev();
return count33;
}
void IndividualsHigh ()
{
int count1R, count2R, count3R;
count1R = count1();
count2R = count2();
count3R = count3();
if (count1R > count2R && count2R > count3R)
cout <<"Count I (Default) Allowed The Most Individuals Onto The Elevator"<< endl;
else if (count2R > count1R && count1R > count3R)
cout <<"Count II (Descending) Allowed The Most Individuals Onto The Elevator"<< endl;
else
cout <<"Count III (Ascending) Allowed The Most Individuals Onto The Elevator"<< endl;
}
int main ()
{
printIndividualsWeight ();
IndividualsInElevator ();
SortDescend ();
printIndividualsWeight ();
IndividualsInElevator ();
SortAscend ();
printIndividualsWeight ();
IndividualsInElevator ();
IndividualsHigh ();
cout << "coded by Lionel Messi" << endl;
system("PAUSE");
return 0;
}
|