fork download
  1. //Roman Lara Delgado CSC5 Chapter 7, P.444, #4
  2. //
  3. /*******************************************************************************
  4. *
  5. * Track Monkeys' Food Consumption
  6. *_______________________________________________________________________________
  7. * This program tracks the daily food consumption of three monkeys at a local zoo
  8. * during a typical week. It calculates and generates a report including the
  9. * average amount of foodveaten per day by the whole family of monkeys, the least
  10. * amount of food eaten during the week by any one monkey, and the greatest
  11. * amount of food eaten during the week by any one monkey.
  12. * ______________________________________________________________________________
  13. * INPUT
  14. * pounds[][] : amount of food consumed by each monkey each day of the week
  15. *
  16. * OUTPUT
  17. * averagePounds : Avg. food amount eaten per monkey per day
  18. * highestAmount : highest amount of food consumed by a monkey in a day
  19. * lowestAmount : lowest amount of food consumed by a monkey in a day
  20. *
  21. *******************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. #include <string>
  25. using namespace std;
  26.  
  27. int main ()
  28. {
  29. /***************************************************************************
  30. * CONSTANTS
  31. * -------------------------------------------------------------------------
  32. * MONKEYS : number of monkeys
  33. * DAYS : number of days in a week
  34. * ************************************************************************/
  35. //Initialize Program Constants
  36. const int MONKEYS = 3; //CONSTANT - Number of monkeys
  37. const int DAYS = 7; //CONSTANT - Number of days.
  38.  
  39. float pounds[MONKEYS][DAYS]; /*INPUT - amount of food consumed by each
  40. monkey each day of the week */
  41.  
  42. //Name of the Days in a Week
  43. string nameDay[DAYS] = {"Sunday", "Monday", "Tuesday", "Wednesday",
  44. "Thursday", "Friday", "Saturday"};
  45. //Delcare Program Variables
  46. string highestDayName; //OUTPUT - day monkey consumed most food
  47. string lowestDayName; //OUTPUT - day monkey consumed least food
  48. float totalPounds; //CALC - tota amount of food consumed by monkeys
  49. float averagePounds; /*OUTPUT - Average food amount consumed
  50. per monkey per day */
  51. float highestAmount; /*OUTPUT - highest food amount consumed
  52. by monkey in a day */
  53. float lowestAmount; /*OUTPUT - lowest food amount consumed
  54. by monkey in a day */
  55.  
  56. //Input Pounds of Food Consumed Each Day
  57. for (int monkey = 0; monkey < MONKEYS; monkey++)
  58. {
  59. for (int day = 0; day < DAYS; day++)
  60. {
  61. cout << "Enter the amount of pounds of food eaten by monkey #";
  62. cout << monkey + 1 << " on " << nameDay[day] << ": ";
  63. cin >> pounds[monkey][day];
  64. cout << endl;
  65. }
  66. cout << endl;
  67. }
  68.  
  69. //Output Average Amount of Food Consumed Each Day by Each Monkey
  70. for (int day = 0; day < DAYS; day++)
  71. {
  72. totalPounds = 0;
  73.  
  74. for (int monkey = 0; monkey < MONKEYS; monkey++)
  75. {
  76. totalPounds += pounds[monkey][day];
  77. }
  78. averagePounds = totalPounds / MONKEYS;
  79.  
  80. cout << setprecision(2) << fixed;
  81. cout << "Average amount of food eaten on " << nameDay[day]
  82. << " is " << averagePounds << endl;
  83. }
  84.  
  85. highestDayName = nameDay[0];
  86. highestAmount = pounds[0][0];
  87.  
  88. //Determine Highest Amount of Food Consumed by Each Monkey
  89. for (int monkey = 1; monkey < MONKEYS; monkey++)
  90. {
  91. for (int day = 1; day < DAYS; day++)
  92. {
  93. if (pounds[monkey][day] > highestAmount)
  94. {
  95. highestAmount = pounds[monkey][day];
  96. highestDayName = nameDay[day];
  97. }
  98. }
  99. }
  100.  
  101. lowestDayName = nameDay[0];
  102. lowestAmount = pounds[0][0];
  103.  
  104. //Determine Lowest Amount of Food Consumed by Each Monkey
  105. for (int monkey = 1; monkey < MONKEYS; monkey++)
  106. {
  107. for (int day = 1; day < DAYS; day++)
  108. {
  109. if (pounds[monkey][day] < lowestAmount)
  110. {
  111. lowestAmount = pounds[monkey][day];
  112. lowestDayName = nameDay[day];
  113. }
  114. }
  115. }
  116.  
  117. //Output Highest and Lowest Amount of Food Consumed During the Week
  118. cout << endl;
  119. cout << "The highest amount of food eaten during the week was on ";
  120. cout << highestDayName << " with: " << highestAmount << " pounds.";
  121. cout << endl;
  122. cout << "The lowest amount of food eaten during the week was on ";
  123. cout << lowestDayName << " with: " << lowestAmount << " pounds.";
  124. cout << endl;
  125.  
  126. return 0;
  127. }
  128.  
  129.  
  130.  
Success #stdin #stdout 0.01s 5304KB
stdin
1
2
3
2
3
4
3
1
4
3
2
3
4
2
3
1
4
3
2
3
4
stdout
Enter the amount of pounds of food eaten by monkey #1 on Sunday: 
Enter the amount of pounds of food eaten by monkey #1 on Monday: 
Enter the amount of pounds of food eaten by monkey #1 on Tuesday: 
Enter the amount of pounds of food eaten by monkey #1 on Wednesday: 
Enter the amount of pounds of food eaten by monkey #1 on Thursday: 
Enter the amount of pounds of food eaten by monkey #1 on Friday: 
Enter the amount of pounds of food eaten by monkey #1 on Saturday: 

Enter the amount of pounds of food eaten by monkey #2 on Sunday: 
Enter the amount of pounds of food eaten by monkey #2 on Monday: 
Enter the amount of pounds of food eaten by monkey #2 on Tuesday: 
Enter the amount of pounds of food eaten by monkey #2 on Wednesday: 
Enter the amount of pounds of food eaten by monkey #2 on Thursday: 
Enter the amount of pounds of food eaten by monkey #2 on Friday: 
Enter the amount of pounds of food eaten by monkey #2 on Saturday: 

Enter the amount of pounds of food eaten by monkey #3 on Sunday: 
Enter the amount of pounds of food eaten by monkey #3 on Monday: 
Enter the amount of pounds of food eaten by monkey #3 on Tuesday: 
Enter the amount of pounds of food eaten by monkey #3 on Wednesday: 
Enter the amount of pounds of food eaten by monkey #3 on Thursday: 
Enter the amount of pounds of food eaten by monkey #3 on Friday: 
Enter the amount of pounds of food eaten by monkey #3 on Saturday: 

Average amount of food eaten on Sunday is 1.67
Average amount of food eaten on Monday is 2.33
Average amount of food eaten on Tuesday is 3.33
Average amount of food eaten on Wednesday is 2.33
Average amount of food eaten on Thursday is 2.67
Average amount of food eaten on Friday is 3.67
Average amount of food eaten on Saturday is 3.00

The highest amount of food eaten during the week was on Monday with: 4.00 pounds.
The lowest amount of food eaten during the week was on Sunday with: 1.00 pounds.