Question: Program For this assignment, you will need to write a header and source file for a class called Monkey. You should define two symbolic constants

Program

For this assignment, you will need to write a header and source file for a class called Monkey.

You should define two symbolic constants inside the Monkey.h header file but before the class declaration:

 static const int NUMMONKEYS = 3; static const int NUMDAYS = 7; 

Use them in all of your methods, rather than hardcoding values. We want our program to continue working if we eventually get more monkeys, or we want to track a different number of days.

The Monkey class which will contain the following private data members:

An array of C++ strings containing the names of the monkeys, initialized to "Curious George", "Mojo" and "Marcel".

A two dimensional NUMMONKEYS by NUMDAYS array of float variables that will hold the number of pounds of food each monkey ate each day.

Your class must contain the following public methods:

Monkey()

The constructor takes no parameters and returns nothing. It will read the contents of the file monkeyfood.txt and store each float value into the two dimensional array.

getName()

This method takes an integer index as its parameter and returns a C++ string. This method will return the name of the monkey at the specified index in the monkey names array.

printArray()

This method takes no parameters and returns nothing. It will print a report similar to the following:

Curious George 6.00 7.30 5.50 6.00 5.50 6.50 7.40 Mojo 6.30 7.60 5.60 8.00 7.50 6.90 5.70 Marcel 8.10 9.00 6.50 7.00 6.70 8.00 7.50 

totalFoodEaten()

This method takes no parameters, and returns a float, the total pounds of food consumed for all of the monkeys for the week.

avgDailyConsumption()

This method takes no parameters, and returns a float, the average consumption for all of the monkeys for the week. (Hint, you can use totalFoodEaten() in this function. Divide by the number of monkeys * the number of days. Do not hardcode 21!)

avgDailyPerMonkey()

This method takes one parameter, an integer representing the monkey for whom we want to calculate the 7 day food average. The method returns a float which is the average food consumption for that monkey.

mostEaten()

This method takes no parameters and returns nothing. This method will go through the array and find the greatest amount of food eaten during the week by any one monkey on any one day and print the name of the monkey and the greatest amount eaten.

Program Output

The names of all the monkeys Curious George Mojo Marcel Weekly consumption for all monkeys Curious George 6.00 7.30 5.50 6.00 5.50 6.50 7.40 Mojo 6.30 7.60 5.60 8.00 7.50 6.90 5.70 Marcel 8.10 9.00 6.50 7.00 6.70 8.00 7.50 Total Food Eaten This Week: 144.60 pounds Average Daily Consumption for All Monkeys: 6.89 pounds Average Daily Consumption per Monkey Curious George 6.31 Mojo 6.80 Marcel 7.54 Marcel ate the most - 9.00 pounds 

Driver Program

A driver program, assign3.cpp, is provided for this assignment. The purpose of a driver program is to test other pieces that you code. You do not need to write the driver program yourself. A copy of the driver program can also be found on turing at /home/turing/t90kjm1/CS241/Code/Spring2017/Assign3/assign3.cpp.

/*************************************************************** CSCI 241 Program 3 Spring 2017 Programmer: Section: Date Due: Purpose: Tracks amount of food eaten by three monkeys ***************************************************************/ #include  #include  #include "Monkey.h" using std::cout; using std::endl; using std::left; int main() { Monkey m; int i; //subscript // Print the names of all the monkeys cout << "The names of all the monkeys: "; for (i = 0;i < NUMMONKEYS; i++) cout << m.getName(i) << endl; cout << endl << endl; // Call printArray cout << "Weekly consumption for all monkeys "; m.printArray(); // Print Total Food Eaten cout << " Total Food Eaten This Week: " << m.totalFoodEaten() << " pounds "; // Print Average consumption per family cout << " Average Daily Consumption for All Monkeys: " << m.avgDailyConsumption() << " pounds" << endl; // Print weekly amount per monkey cout << " Average Daily Consumption per Monkey "; for (i = 0; i < NUMMONKEYS; i++) cout << left << setw(15) << m.getName(i) << m.avgDailyPerMonkey(i) << endl; cout << endl << endl; // Find the monkey who ate the most m.mostEaten(); return 0; } 

Implementation Hints

The driver program should not be modified for your final submission. But while you're developing, modifying the driver program can definitely be in your best interest. For example, you may want to comment out various parts of main and develop one method at a time.

Makefile

A makefile is required for this assignment, and all future 241 assignments. A sample makefile is given below.

# # PROGRAM: assign3 # PROGRAMMER: your name # LOGON ID: your z-id # DATE DUE: due date of program # # Compiler variables CCFLAGS = -Wall -std=c++11 # Rule to link object code files to create executable file assign3: assign3.o Monkey.o g++ $(CCFLAGS) -o assign3 assign3.o Monkey.o # Rules to compile source code files to object code assign3.o: assign3.cpp Monkey.h g++ $(CCFLAGS) -c assign3.cpp Monkey.o: Monkey.cpp Monkey.h g++ $(CCFLAGS) -c Monkey.cpp # Pseudo-target to remove object code and executable files clean: -rm *.o assign3 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!