Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Monkey Business(C++) A local zoo wants to keep track of how many pounds of food

ID: 3859652 • Letter: M

Question

Monkey Business(C++)

A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 7 array, where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers 1, 2, and 3; the weekdays are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday". The program should first prompt the user to input the data for each monkey, starting with "Sunday" for monkey #1, then monkeys #2 and #3, followed by "Monday" for monkey #1, then monkeys #2 and #3 and so on, through "Saturday". The program then creates a report that includes the following information, each properly labeled (see below):

Average amount of food eaten per day by the whole family of monkeys.

The least amount of food eaten during the week by any one monke

The greatest amount of food eaten during the week by any one monkey.

Input Validation: Do not accept negative numbers for pounds of food eaten. When a negative value is entered, the program outputs "invalid (negative) food quantity -- re-enter" and attempts to reread the value.

NOTE: Decimal values should be displayed using default precision, i.e. do not specify precision

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
int quantity[3][7];
string days[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
for(int i=0;i<3;i++) {
for(int j=0;j<7;j++) {
cout<<days[i]<<" for monkey #"<<(i+1)<<": ";
cin >> quantity[i][j];
if(quantity[i][j] < 0) {
cout<<"invalid (negative) food quantity -- re-enter: ";
j--;
}
}
}
int totalQuantity = 0;
for(int j=0;j<7;j++) {
cout<<"Average amount of food eaten per "<<days[j]<<" by the whole family of monkeys: "<<(quantity[0][j]+quantity[1][j]+quantity[2][j])/(double)3<<endl;
}
int minQuantity = quantity[0][0], maxQuantity = quantity[0][0];
for(int i=0;i<3;i++) {
for(int j=0;j<7;j++) {
if(minQuantity > quantity[i][j]) {
minQuantity = quantity[i][j];
}
if(maxQuantity < quantity[i][j]) {
maxQuantity = quantity[i][j];
}
}
}
cout<<"The least amount of food eaten during the week by any one monkey: "<<minQuantity<<endl;
cout<<"The greatest amount of food eaten during the week by any one monkey: "<<maxQuantity<<endl;

return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                             

sh-4.2$ main                                                                                                                                                                                          

Sunday for monkey #1: 1                                                                                                                                                                               

Sunday for monkey #1: 2                                                                                                                                                                               

Sunday for monkey #1: 3                                                                                                                                                                               

Sunday for monkey #1: 4                                                                                                                                                                               

Sunday for monkey #1: 5                                                                                                                                                                               

Sunday for monkey #1: 6                                                                                                                                                                               

Sunday for monkey #1: 7                                                                                                                                                                               

Monday for monkey #2: 8                                                                                                                                                                               

Monday for monkey #2: 9                                                                                                                                                                               

Monday for monkey #2: 10                                                                                                                                                                              

Monday for monkey #2: 11                                                                                                                                                                              

Monday for monkey #2: 12                                                                                                                                                                              

Monday for monkey #2: 13                                                                                                                                                                              

Monday for monkey #2: 14                                                                                                                                                                              

Tuesday for monkey #3: 15                                                                                                                                                                             

Tuesday for monkey #3: 16                                                                                                                                                                             

Tuesday for monkey #3: 17                                                                                                                                                                             

Tuesday for monkey #3: 18                                                                                                                                                                             

Tuesday for monkey #3: 19                                                                                                                                                                             

Tuesday for monkey #3: 20                                                                                                                                                                             

Tuesday for monkey #3: 21                                                                                                                                                                             

Average amount of food eaten per Sunday by the whole family of monkeys: 8                                                                                                                             

Average amount of food eaten per Monday by the whole family of monkeys: 9                                                                                                                             

Average amount of food eaten per Tuesday by the whole family of monkeys: 10                                                                                                                           

Average amount of food eaten per Wednesday by the whole family of monkeys: 11                                                                                                                         

Average amount of food eaten per Thursday by the whole family of monkeys: 12                                                                                                                          

Average amount of food eaten per Friday by the whole family of monkeys: 13                                                                                                                            

Average amount of food eaten per Saturday by the whole family of monkeys: 14                                                                                                                          

The least amount of food eaten during the week by any one monkey: 1                                                                                                                                   

The greatest amount of food eaten during the week by any one monkey: 21

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote