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

Note: use functionsto do this. (least and greatest amounts are for a monkey for

ID: 3578589 • Letter: N

Question

 Note: use functionsto do this.       (least and greatest amounts are for a monkey for the entire week, not just a single day.) 
  Description: 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 × 5 array, where each row represents a different monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey. Then it should create a report that includes the following information: • 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 monkey. • 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 

Explanation / Answer

Here is the C++ code for you:

#include <iostream>
#include <iomanip>
using namespace std;
double avgPerDay(double foodConsumed[][5], int day)
{
double avg = 0.0;
for(int i = 0; i < 3; i++)
avg += foodConsumed[i][day];
return avg / 3;
}
int leastFood(double foodConsumed[][5])
{
int lowRow = 0, lowCol = 0;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 5; j++)
if(foodConsumed[i][j] < foodConsumed[lowRow][lowCol])
{
lowRow = i;
lowCol = j;
}
return lowRow;   
}
int maxFood(double foodConsumed[][5])
{
int maxRow = 0, maxCol = 0;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 5; j++)
if(foodConsumed[i][j] > foodConsumed[maxRow][maxCol])
{
maxRow = i;
maxCol = j;
}
return maxRow;   
}
int main()
{
//Stores this information in a two-dimensional 3 × 5 array, where each row represents a
//different monkey and each column represents a different day of the week.
double foodConsumed[3][5];
//The program should first have the user input the data for each monkey.
for(int i = 0; i < 3; i++)
for(int j = 0; j < 5; j++)
{
cout<<"Enter the food consumed by monkey #"<<i+1<<", for week #"<<j+1<<": ";
cin>>foodConsumed[i][j];
//Input Validation: Do not accept negative numbers for pounds of food eaten
while(foodConsumed[i][j] < 0)
{
cout<<"Negative values are not allowed to enter."<<endl;
cout<<"Enter the food consumed by monkey #"<<i+1<<", for week #"<<j+1<<": ";
cin>>foodConsumed[i][j];
}
}
//Average amount of food eaten per day by the whole family of monkeys.
for(int i = 0; i < 5; i++)
cout<<"Average food eaten for day #"<<i+1<<": "<<fixed<<setprecision(1)<<avgPerDay(foodConsumed, i)<<endl;
//The least amount of food eaten during the week by any one monkey.
cout<<"The least amount of food eaten during the week is by monkey #"<<leastFood(foodConsumed)<<endl;
//The greatest amount of food eaten during the week by any one monkey.
cout<<"The greatest amount of food eaten during the week is by monkey #"<<maxFood(foodConsumed)<<endl;
}

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