Question

In: Computer Science

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

Tony Gaddis 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 × 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 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. 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.

Solutions

Expert Solution

#include <iostream>

using namespace std;

const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;

const string DAYS[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

double findGroupTotal(double food[NUM_MONKEYS][NUM_DAYS]) {
        double total = 0;

        for(int i=0; i<NUM_MONKEYS; i++) {
            for(int j=0; j<NUM_DAYS; j++) {
                total += food[i][j];                
            }
        }       
        return total;
}

double findLeastAmtFood(double food[NUM_MONKEYS][NUM_DAYS]) {
        double leastAmt = food[0][0];

        for(int i=0; i<NUM_MONKEYS; i++) {
            for(int j=0; j<NUM_DAYS; j++) {
                if(leastAmt > food[i][j]) {
                    leastAmt = food[i][j];
                }
            }
        }   
        return leastAmt;
}

double findGreatestAmtFood(double food[NUM_MONKEYS][NUM_DAYS]){
        double greatestAmt = food[0][0];

        for(int i=0; i<NUM_MONKEYS; i++) {
            for(int j=0; j<NUM_DAYS; j++) {
                if(greatestAmt < food[i][j]) {
                    greatestAmt = food[i][j];
                }
            }
        }   
        return greatestAmt;
}

void fillData(double food[NUM_MONKEYS][NUM_DAYS]) {
        for(int j=0; j<NUM_DAYS; j++) {
            for(int i=0; i<NUM_MONKEYS; i++) {
                cout << "Enter food for Monkey:" << (i+1) << ", " << DAYS[j] << "  : ";
                cin >> food[i][j];
                while(food[i][j] < 0) {
                        cout << "Invalid input. Try again: " << endl;
                        cin >> food[i][j];
                }
            }
        }       
}

int main() {  
        double food[NUM_MONKEYS][NUM_DAYS];

        fillData(food);
        double groupTotal = findGroupTotal(food);
        double leastAmtFood = findLeastAmtFood(food);
        double greatestAmtFood = findGreatestAmtFood(food);


        cout << "Average food ate per day: " << (groupTotal/(NUM_DAYS*NUM_MONKEYS)) << endl;
        cout << "Least amount of food ate on a day: " << leastAmtFood << endl;
        cout << "Greatest amount of food ate on a day: " << greatestAmtFood << endl;
}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Starting out with Control Structures: Program challenges in C++ by Tony Gaddis This problem was adapted...
Starting out with Control Structures: Program challenges in C++ by Tony Gaddis This problem was adapted from questions 9 and 10 on page 661 Write a program that keeps track of a speakers’ bureau. The program should use a structure to store the following data about a speaker: Name, Telephone Number, Speaking Topic, Fee Required. The program should use a vector of structures. It should let the user enter data into the vector, change the contents of any element, and...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
Tony Gaddis C++ Conference Sessions An upcoming conference about C/C++ programming has three sessions planned: -...
Tony Gaddis C++ Conference Sessions An upcoming conference about C/C++ programming has three sessions planned: - A session on the new features of C++ 17 - A session on functional programming in C/C++ - A session on lamda functions Attendees can subscribe for any session. The organizers want to keep track of which attendees are attending which session. Write a program that stores this information in a two-dimensional array of Booleans, where each row represents an attendee and each column...
C++ Tony Gaddis 8.11: Using Files-- String Selection Sort Modification Modify the selectionSort function presented in...
C++ Tony Gaddis 8.11: Using Files-- String Selection Sort Modification Modify the selectionSort function presented in this chapter so it sorts an array of strings instead of an array of ints. Test the function with a driver program that reads an integer, N, from standard input and then reads the first N strings from a file called href="asfunction:_root.doTutor,7,CPP">names. (Assume that N is less than or equal to 20.) Input Validation. If N read in from standard input is greater than...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O)...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O) to play a game of tic-tac-toe. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The players take turns making moves and the program keeps track of whose turn it is. Player X moves first. The program should run a loop that: Displays the contents...
Ava wants to use a database to keep track of the data recordsfor her insurance...
Ava wants to use a database to keep track of the data records for her insurance company and to enforce the following business policies/requirements: USE MS ACCESS TO CREATE A DATABASE & RELATIONASHIP-Every customer must be uniquely identified.-A customer can have many insurance policies.-Every insurance policy must be uniquely identified.-An insurance policy must belong to a valid customer.-Every customer must be served by a valid insurance agent (employee).-An insurance agent (employees) serves many customers.-Every insurance agent (employee) must be uniquely...
C# The Zookeepers need a system to keep track of all their animals. They need to...
C# The Zookeepers need a system to keep track of all their animals. They need to be able to enter all their animals into the system in a way that allows them to identify and locate them. This requires identifying them by species, age and one characteristic unique to their species. There are three cages and the user must input information about the animal in each one. After accepting input for all three cages, the program should output the contents...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
C# The Zookeepers need a system to keep track of all their animals. They need to...
C# The Zookeepers need a system to keep track of all their animals. They need to be able to enter all their animals into the system in a way that allows them to identify and locate them. This requires identifying them by species, age and one characteristic unique to their species. There are three cages and the user must input information about the animal in each one. After accepting input for all three cages, the program should output the contents...
A music player or music organization program can keep track of how many different artists are in a library. First note how many different
A music player or music organization program can keep track of how many different artists are in a library. First note how many different artists are in your music library. Then find the probability that if 25 songs are selected at random, none will have the same artist.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT