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:
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 |
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:
--------------------------------I used Visual Studio 2013, c++ Language, Console Application-------------
-------------ScreenShot-------------

------------------Code-------------------
// MonkeyProgram.cpp : Defines the entry point for the
console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include<string>
using namespace std;
void printArray(float** MonkeyFood)
{
cout << endl;
cout << "Pounds of Food Eaten by Monkey and Day
of Week" << endl;
cout << "Monkey Sun Mon Tue Wed Thu Fri Sat"
<< endl;
for (int i = 0; i < 3; i++)
{
cout << setw(3) << i+1
;
for (int j = 0; j < 7;
j++)
{
if (j==0)
cout << setw(9) <<
MonkeyFood[i][j];
else
cout << setw(10) <<
MonkeyFood[i][j];
}
cout << endl;
}
}
//printString function is used to give formatted message
output
void printString(string Message, float Result)
{
int MsgLength = Message.length();
int max = 60;
std::cout << std::fixed;
std::cout << std::setprecision(2);
if (MsgLength < max)
cout << Message <<
setw(max - MsgLength) << ": " << fixed <<
setprecision(1) << Result << " pounds" <<
endl;
else
cout << Message << ": "
<< fixed << setprecision(1) << Result << "
pounds" << endl;
}
void AverageFood(float** MonkeyFood)
{
float totalValue = 0;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 7;
j++)
{
totalValue +=
MonkeyFood[i][j];
}
cout << endl;
}
float avgValue = totalValue / 7;
printString("The average food eaten per day by all
monkeys", avgValue);
}
void LeastAmountFood(float** MonkeyFood)
{
float leastValue = MonkeyFood[0][0];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 7;
j++)
{
if
(MonkeyFood[i][j]<leastValue)
{
leastValue = MonkeyFood[i][j];
}
}
}
printString("The least amount of food eaten by any
monkey", leastValue);
}
void LargestAmountFood(float** MonkeyFood)
{
float highestValue = MonkeyFood[0][0];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 7;
j++)
{
if
(MonkeyFood[i][j]>highestValue)
{
highestValue = MonkeyFood[i][j];
}
}
}
printString("The largest amount of food eaten per by
any monkey", highestValue);
}
float** AddMonkeyFoodInputs()
{
float** MonkeyFood=new float*[3];
for (int i = 0; i < 3; i++)
{
MonkeyFood[i] = new float[7];
for (int j = 0; j < 7;
j++)
{
switch (j)
{
case 0:
cout << "Enter pounds of food eaten by
monkey " << (i + 1) << " on Sun: ";
break;
case 1:
cout << "Enter pounds of food eaten by
monkey " << (i + 1) << " on Mon: ";
break;
case 2:
cout << "Enter pounds of food eaten by
monkey " << (i + 1) << " on Tue: ";
break;
case 3:
cout << "Enter pounds of food eaten by
monkey " << (i + 1) << " on Wed: ";
break;
case 4:
cout << "Enter pounds of food eaten by
monkey " << (i + 1) << " on Thur: ";
break;
case 5:
cout << "Enter pounds of food eaten by
monkey " << (i + 1) << " on Fri: ";
break;
case 6:
cout << "Enter pounds of food eaten by
monkey " << (i + 1) << " on Sat: ";
break;
}
cin >>
MonkeyFood[i][j];
}
}
return MonkeyFood;
}
int main()
{
int i;
float** MonkeyFood;
MonkeyFood = AddMonkeyFoodInputs();//Add the inputs
and store.
printArray(MonkeyFood);//Print the array
AverageFood(MonkeyFood);//calculate the Average
LeastAmountFood(MonkeyFood);//Calculate Least amount
of food eaten by any monkey
LargestAmountFood(MonkeyFood);//Calculate largest
amount of food eaten per by any monkey
cin >> i;//Used to pause the
console
return 0;
}
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 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 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 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 #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 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 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 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: 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 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...