Question

In C++ Rewrite Modularity section to clarify functions should be separate. Assignment 6 - Monkey Food...

In C++

Rewrite Modularity section to clarify functions should be separate.

Assignment 6 - Monkey Food

In the Gaddis textbook read Chapter 8 sections 8.1-8.9 before starting this assignment.

This assignment is Programming Challenge 4 from Chapter 8 of the textbook. 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 x 7 arrray, 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 from the keyboard. The number of pounds of food eaten by one monkey in one day should be a floating-point value.

Input Validation: Do not accept negative numbers.

Then your program should create a report that includes the following information:

  • A nicely-formatted table with a row for each monkey and a column for each day of the week showing the amount of food eaten by that monkey on that day. Be sure to include row and column labels. Format all the food amounts so that they print with the same number of decimal places. This makes the decimal points line up nicely. Note: you should write a separate function to print this table.
  • The average amount of food eaten per day by the whole group of monkeys. This is the total food eaten by all monkeys during the week divided by seven. Note: you should write a separate value-returning function to calculate this average.
  • The least amount of food eaten on any day during the week by any one monkey. Note: you should write a separate value-returning function to find the smallest amount of food.
  • The greatest amount of food eaten on any day during the week by any one monkey. Note: you should write a separate value-returning function to find the largest amount of food.

Your screen dialog might look similar to this (user input is shown in bold):

Enter pounds of food eaten by monkey 1 on Sun: 2.9
Enter pounds of food eaten by monkey 1 on Mon: 3.3
Enter pounds of food eaten by monkey 1 on Tue: 2.1
Enter pounds of food eaten by monkey 1 on Wed: 3.7
Enter pounds of food eaten by monkey 1 on Thu: 2.2
Enter pounds of food eaten by monkey 1 on Fri: 3.5
Enter pounds of food eaten by monkey 1 on Sat: 3.4

Enter pounds of food eaten by monkey 2 on Sun: 4.4
...

Your report might look similar to this:

Pounds of Food Eaten by Monkey and Day of Week

Monkey   Sun   Mon   Tue   Wed   Thu   Fri   Sat
     1   2.9   3.3   2.1   3.7   2.2   3.5   3.4
     2   4.4   4.8   4.1   3.2   5.1   2.9   2.6
     3   1.5   2.1   3.5   2.7   2.0   1.7   2.9

The average food eaten per day by all monkeys     :   9.2 pounds
The least amount of food eaten by any monkey      :   1.5 pounds
The largest amount of food eaten per by any monkey:   5.1 pounds

Modularity Your program must be a modular program. Your main function should not contain any loops. It should call one function to input the food amounts. It should call a separate function to print the table of food eaten. And it will call a separate value-returning function to find each of the following: average food eaten, least food eaten, and most food eaten (a total of 5 functions in addition to main()).

Additional Requirements:

  1. Do not use global variables in any assignment. A global variable is a variable that is declared outside any function. It is okay to use global constants.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

source 2.9 3.3 2.1 3.7 2.2 3.5 3.4 4.4 4.8 4.1 3.2 5.1 2.9 2.6 1.5 2.1 3.5 2.7 2.0 1.7 2.9-->input

As per the source data wrote the program as shown in below

#include <stdio.h>
float average(float a[3][7]);
float least(float a[3][7]);
float highest(float a[3][7]);
int main()
{          //starting of the instruction
float a[3][7];
food_amounts(a);
print_food_amounts(a);
printf("average food taken by all monkeys = %f\n",average(a));
printf("The least amount of food eaten by any monkey %f \n",least(a));
printf("The largest amount of food eaten per by any monkey: %f\n",highest(a));

}          //ending of the instruction
void food_amounts(float a[3][7])
{          //starting of the instruction
int i,j;
char day[][4] = {"Sun","Mon", "Tue", "Wed","Thu","Fri","Sat"};
for(i=0;i<3;i++)
{          //starting of the instruction
for(j=0;j<7;j++)
{
printf("Enter pounds of food eaten by monkey %d on %s: ",i+1,day[j]);
scanf("%f",&a[i][j]);
if(a[i][j]<0)
{          //starting of the instruction
printf("enter the positive amount\n");
j--;
}          //ending of the instruction
}
}          //ending of the instruction
}
void print_food_amounts(float a[3][7])
{
int i,j;
char day[8][7] = {"Monkey","Sun","Mon", "Tue", "Wed","Thu","Fri","Sat"};
printf("\n");
for(i=0;i<8;i++)
printf("%s\t",day[i]);
printf("\n");
for(i=0;i<3;i++)
{          //starting of the instruction
printf("%d\t",i+1);
for(j=0;j<7;j++)
printf("%.2f\t",a[i][j]);
printf("\n");
}          //ending of the instruction
  
}

float average(float a[3][7])
{          //starting of the instruction
float sum=0;
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<7;j++)
{          //starting of the instruction
sum+=a[i][j];
}          //ending of the instruction
}
return sum/3;
}
float least(float a[3][7])
{
float res=100;
int i,j;
for(i=0;i<3;i++)
{          //starting of the instruction
for(j=0;j<7;j++)
{
if(res>a[i][j])
res=a[i][j];
}          //ending of the instruction
}
return res;
}          //ending of the instruction
float highest(float a[3][7])
{
float res=0;
int i,j;
for(i=0;i<3;i++)
{          //starting of the instruction
for(j=0;j<7;j++)
{
if(res<a[i][j])
res=a[i][j];
}
}
return res;
}          //ending of the instruction

Add a comment
Know the answer?
Add Answer to:
In C++ Rewrite Modularity section to clarify functions should be separate. Assignment 6 - Monkey Food...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Rewrite Modularity section to clarify functions should be separate. Assignment 6 - Monkey Food...

    In C++ Rewrite Modularity section to clarify functions should be separate. Assignment 6 - Monkey Food In the Gaddis textbook read Chapter 8 sections 8.1-8.9 before starting this assignment. This assignment is Programming Challenge 4 from Chapter 8 of the textbook. 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 x 7 arrray,...

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

    C++ Monkey Business 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...

  • In java 1. Monkey Business (10 points) A local zoo wants to keep track of how...

    In java 1. Monkey Business (10 points) 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 x 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...

  • Pseudocode please Special Problem for Swap A local zoo wants to keep track of how many...

    Pseudocode please Special Problem for Swap 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 x 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"....

  • I need some help with finding the least amount for my third function.. //Libraries #include #include...

    I need some help with finding the least amount for my third function.. //Libraries #include #include #include using namespace std; // Global constants const int MONKEYS=3; const int DAYS=5; // Prototypes void getfoodeaten ( double[][DAYS]); void displayAvgDaily(double [][DAYS]); void displayLeastEaten(double [][DAYS]); int main () { double total; double average; double food[MONKEYS][DAYS]; cout<< "Please enter the number of pounds eaten for each monkey."< getfoodeaten(food); displayAvgDaily(food); displayLeastEaten(food); return 0; } // Function declarations void getfoodeaten ( double food[][DAYS]) {     for (int...

  • What are the 8 errors in this C++ program below: /* CSE 100 Professor Feng Learn...

    What are the 8 errors in this C++ program below: /* CSE 100 Professor Feng Learn to read data from user and fill a two-dimensional array. Learn how to compute the sum of one row or one column in a 2D array Learn how to compute the sum, average of a 2D array */ #include<iostream> #include<cmath> #include<iomanip> using namespace std; double bananaMon=0; //Global Variables to be used in the program double bananaSat=0; double totalSum=0.0; //Global variable total sum double findGroupTotal();...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT