Must compile on C++ using codeblocks. Don't submit half answered. /*------------------------------- ...
链接在这http://www.chegg.com/homework-help/questions-and-answers/must-compile-c-using-codeblocks-don-t-submit-half-answered-filename-labcpp-specification-p-q16707413
/*---------------------------------------------------------------------------
// FILENAME: Lab.cpp
// SPECIFICATION: This program uses a 3 x 7 two dimensional array to store how
// many pounds of food three monkeys eats each day in a week.
// The array is passed to functions to find total, average and
// food consumption in a specific day, etc.
// INSTRUCTIONS: Read the following code skeleton and add your own code
// according to the comments. Ask your TA or your class-
// mates for help and/or clarification.
// When you see //---- that is where you need to add code.
//-------------------------------------------------------------------------*/
#include <iostream>
#include <iomanip>
using namespace std;
const double NUM_MONKEYS = 3;
const double NUM_DAYS = 7;
// Function prototypes
void getData(double[NUM_MONKEYS][NUM_DAYS]);
//declare a function called 'findGroupTotal' that takes a 2-dimensional array as input
//parameter (similar to above getData) and returns a double value representing the total
//amount of food the 3 monkeys consumed in a week
double findGroupTotal(double[NUM_MONKEYS][NUM_DAYS]);
int main()
{
// A 2-D array that holds the pounds of food consumed
// by each monkey on each day of the week
double food[NUM_MONKEYS][NUM_DAYS];
// Call the getData function to input the data into the 2-D array 'food'
getData(food[NUM_MONKEYS][NUM_DAYS]);
cout << fixed << showpoint << setprecision(2);
//call 'findGroupTotal' function on 2-D array 'food' to compute the
//total amount of food eaten by the 3 monkeys in a whole week.
double total = findGroupTotal(food[NUM_MONKEYS][NUM_DAYS]);
//Declare a double variable called 'dailyAvg', it represents average amount
//of food eaten per day by the 3 monkeys. Compute its value by using 'total'
double dailyAvg = total / NUM_DAYS;
// Display the dailyAvg by showing a message on screen.
cout << "\n\nAverage amount of food eaten per day \n"
<< "by the entire family of monkeys = " << dailyAvg << " pounds. \n\n";
//Find Monkey #1's consumption of food during the week.
//Note: for 'food' 2-D array, each row represents a different monkey and
// each column represents a different day of the week. Index for both
// row and column starts from 0.
double totalOne = 0.0;
for (int day = 0; day < NUM_DAYS; day++)
totalOne += food[0][day];
cout << "Monkey #1 eat total of " << totalOne << " pounds of food in this week. \n\n";
//Use above as an example, find Monkey #2's consumption of food during the week
//and show the output on screen similarly. Declare all necessary local variables
double totaltwo = 0.0;
for (int day = 0; day < NUM_DAYS; day++)
totaltwo += food[0][day];
cout << "Monkey #2 eat total of " << totaltwo << " pounds of food in this week. \n\n";
//Use above as an example, find Monkey #3's consumption of food during the week
//and show the output on screen similarly. Declare all necessary local variables
double totalthree = 0.0;
for (int day = 0; day < NUM_DAYS; day++)
totalthree += food[0][day];
cout << "Monkey #2 eat total of " << totalthree << " pounds of food in this week. \n\n";
//Find the average of food the 3 monkeys eat on Monday
double totalMonday = 0.0;
for (int monkey = 0; monkey < 3; monkey ++)
totalMonday += food[monkey][0];
double averageMon = totalMonday / 3.0;
cout << "The 3 monkeys eat an average " << averageMon << " pounds of food on Monday. \n";
//Use above as an example, find the average of food the 3 monkeys eat on Saturday
//and show the output on screen similarly. Declare all necessary local variables
double totalSaturday = 0.0;
for (int monkey = 0; monkey < 3; monkey ++)
totalSaturday += food[monkey][0];
double averageSat = totalSaturday / 3.0;
cout << "The 3 monkeys eat an average " << averageMon << " pounds of food on Monday. \n";
cout << "The 3 monkeys eat an average " << averageSat << " pounds of food on Saturday. \n";
return 0;
}
//*********************************************************
// getData Function
// Note: we use a nested for loop here, the outer for loop
// iterates on monkeys and the inner for loop iterates
// on days of the week.
//*********************************************************
void getData(double food[NUM_MONKEYS][NUM_DAYS])
{
for (int monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
//**When submit on server, you need to comment out the following cout line
cout << "\nEnter pounds of food eaten by monkey #" << (monkey+1) << " on \n";
for (int day = 0; day < NUM_DAYS; day++)
{
cout << "day " << (day+1) << ": ";
//write a cin statement that store the data user entered inside 'food' 2-D array
cin >> food[monkey][day];
}
}
}
//*****************************************************************
// The findGroupTotal function takes a 2-dimensional array as input
// parameter and returns a double value representing the total
// amount of food the 3 monkeys consumed in a whole week
//*****************************************************************
double findGroupTotal(double food[NUM_MONKEYS][NUM_DAYS]);
{
double total = 0.0;
//you need to write a nested for loop to compute the total
//the outer for loop iterates on monkeys and the inner for loop
//iterates on days of the week.
for (int monkey = 0; monkey < NUM_MONKEYS; monkey++)
{
for (int day = 0; day < NUM_DAYS; day++)
total += food[monkey][day];
}
return total;
}
谢谢!