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
|
// MonkeyLab_Kingsbury
//
// Created by Caroline on 10/21/16.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
double average = 0;
void printContents(string monkeyNames[NUM_MONKEYS],int table[][NUM_DAYS]);
void rowSum(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS]);
void findLowest(int table[][NUM_DAYS]);
void findHighest(int table[][NUM_DAYS]);
//************************************************************//
// this function tracks the eating habits of 3 baby monkeys *
//************************************************************//
int main()
{
string monkeyNames[NUM_MONKEYS] = { "Curly", "Larry", "Moe" };
int table[NUM_MONKEYS][NUM_DAYS] = { { 45,33,55,66,77,88,100 },
{ 88,77,66,55,44,33,22 },
{ 44,55,11,66,77,88,99 }
};
printContents(monkeyNames,table);
rowSum(monkeyNames,table);
findLowest(table);
findHighest(table);
}
//************************************************************//
// this function prints the total food eaten by the monkeys *
//************************************************************//
void printContents(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS])
{
cout << "Name \t\tDay 1\tDay 2\tDay 3\tDay 4\tDay 5\tDay 6\tDay 7 " << endl;
cout << "________________________________________________________________\n";
for (int r = 0; r < NUM_MONKEYS; r++)
{
cout << monkeyNames[r];
for (int c = 0; c < NUM_DAYS; c++)
{
cout << "\t\t";
cout << table[r][c];
}
cout << endl;
}
cout << endl;
}
//*************************************************************//
// this function prints the sums of the rows for each monkey *
//*************************************************************//
void rowSum(string monkeyNames[NUM_MONKEYS], int table[][NUM_DAYS])
{
cout<<"Name \tAverage daily intake in pounds \n";
int totalRow=0;
for(int r=0;r<NUM_MONKEYS;r++)
{
for(int c=0;c<NUM_DAYS;c++)
totalRow=totalRow + table[r][c];
cout<< monkeyNames[r] <<"\t"<< setw (1)<<(totalRow/NUM_DAYS) <<endl;
}
totalRow = 0;
}
//*************************************************************//
// this function finds the lowest amount eaten by the monkeys *
//*************************************************************//
void findLowest(int table[][NUM_DAYS])
{
int leastFood;
int leastMonkey = 0;
int leastDay = 0;
int monkey = 0;
leastFood = table[leastMonkey][leastDay];
for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
for (int day = 0; day < NUM_DAYS; day++)
{
if (table[monkey][day] < leastFood)
{
leastFood = table[monkey][day];
leastDay = day;
leastMonkey = monkey;
}
}
cout<< "On day " << leastDay + 1 << " Monkey " << leastMonkey << " ate the least food, " << leastFood << " pounds.\n" ;
}
}
//*************************************************************//
// this function finds the highest amount eaten by the monkeys *
//*************************************************************//
void findHighest(int table[][NUM_DAYS])
{
int mostFood;
int mostMonkey = 0;
int mostDay = 0;
int monkey = 0;
mostFood = table[mostMonkey][mostDay];
for (monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
for (int day = 0; day < NUM_DAYS; day++)
{
if (table[monkey][day] > mostFood)
{
mostFood = table[monkey][day];
mostDay = day;
mostMonkey = monkey;
}
}
cout<< "\nOn day " << mostDay + 1 << ", Monkey " << mostMonkey << " ate the most food, " << mostFood << " pounds.\n" ;
}
}
|