This program is in c++ how could I make the following changes? Modify, do not re
ID: 2873907 • Letter: T
Question
This program is in c++ how could I make the following changes?
Modify, do not rewrite, source2.cpp. In general, make the program as scalable as possible. “scalable”, for this program, means that one can change the number of monkeys or changing the number of days the monkey are fed by changing the data file and one or two global constants.
1. Do not use any global variables. Global constants are ok
2. Remove all 1D arrays from the program
3. Increase the number of monkeys from 3 to 32
4. Feed the monkey 7 days a week instead of 5
5. Use 2D arrays almost everywhere
6. Use 2D array parameters almost everywhere
7. Write a function to compute the average amount of food eaten per day by the whole family of monkeys; write a function to compute the least amount of food eaten by any monkey; write a function to compute the most amount of food eaten by any monkey.
8. Read the monkey data from a file rather than interactively. Your file will contain 32 x 7 = 224 integers. Write a function to read the data from a file. Make sure the data is good. Define sensible upper and lower bounds for monkey daily monkey food consumption.
#include<iostream>
#include<string>
using namespace std;
double monkeyday1;
double monkeyday2;
double monkeyday3;
double monkeyday4;
double monkeyday5;
double monkey2day1;
double monkey2day2;
double monkey2day3;
double monkey2day4;
double monkey2day5;
double monkey3day1;
double monkey3day2;
double monkey3day3;
double monkey3day4;
double monkey3day5;
void getdataMonkey(double & monkeyday1, double& monkeyday2, double& monkeyday3, double& monkeyday4, double& monkeyday5);
void getdataMonkey2(double & monkey2day1, double& monkey2day2, double& monkey2day3, double& monkey2day4, double& monkey2day5);
void getdataMonkey3(double & monkey3day1, double& monkey3day2, double& monkey3day3, double& monkey3day4, double& monkey3day5);
double DailyPounds[3][5] = { { monkeyday1, monkeyday2, monkeyday3, monkeyday4, monkeyday5 },{ monkey2day1, monkey2day2, monkey2day3, monkey2day4, monkey2day5 },{ monkey3day1, monkey3day2, monkey3day3, monkey3day4, monkey3day5 } };
double averageDaily(double& aveMonday, double& aveTuesday, double& aveWednesday, double& aveeThursday, double& aveFriday);
double greatestamount(double& greatest);
double leastamount(double& least);
int main()
{
double aveMonday;
double aveTuesday;
double aveWednesday;
double aveeThursday;
double aveFriday;
double greatesteaten;
double leasteaten;
getdataMonkey(monkeyday1, monkeyday2, monkeyday3, monkeyday4, monkeyday5);
getdataMonkey2(monkey2day1, monkey2day2, monkey2day3, monkey2day4, monkey2day5);
getdataMonkey3(monkey3day1, monkey3day2, monkey3day3, monkey3day4, monkey3day5);
averageDaily(aveMonday, aveTuesday, aveWednesday, aveeThursday, aveFriday);
cout << "The daily amount of food eaten by the three monkeys is: ";
cout << "Monday = " << aveMonday << " lbs." << endl;
cout << "Tuesday = " << aveTuesday << " lbs." << endl;
cout << "Wednesday = " << aveWednesday << " lbs." << endl;
cout << "Thursday = " << aveeThursday << " lbs." << endl;
cout << "Friday = " << aveFriday << " lbs." << endl;
cout << " ";
greatestamount(greatesteaten);
cout << "The mmonkey ate " << greatesteaten << "lbs." << endl;
cout << " ";
leastamount(leasteaten);
cout << "The mmonkey ate " << leasteaten << "lbs." << endl;
cout << " ";
system("pause");
return 0;
}
void getdataMonkey(double & monkeyday1, double& monkeyday2, double& monkeyday3, double& monkeyday4, double& monkeyday5)
{
double monday;
double tuesday;
double wednesday;
double thursday;
double friday;
cout << "Please enter the pounds eaten by the first monkey during the week. ";
cout << "Monday: ";
cin >> monday;
cout << "Tuesday: ";
cin >> tuesday;
cout << "Wednesday: ";
cin >> wednesday;
cout << "Thursday: ";
cin >> thursday;
cout << "Friday: ";
cin >> friday;
while (monday < 0 || tuesday < 0 || wednesday < 0 || thursday < 0 || friday < 0)
{
cout << "Sorry!!! Negative values are not allow." << endl;
cout << "Please re-enter the pounds eaten by the first monkey during the week. ";
cout << "Monday: ";
cin >> monday;
cout << "Tuesday: ";
cin >> tuesday;
cout << "Wednesday: ";
cin >> wednesday;
cout << "Thursday: ";
cin >> thursday;
cout << "Friday: ";
cin >> friday;
}
monkeyday1 = monday;
monkeyday2 = tuesday;
monkeyday3 = wednesday;
monkeyday4 = thursday;
monkeyday5 = friday;
}
void getdataMonkey2(double & monkey2day1, double& monkey2day2, double& monkey2day3, double& monkey2day4, double& monkey2day5)
{
double monday;
double tuesday;
double wednesday;
double thursday;
double friday;
cout << "Please enter the pounds eaten by the second monkey during the week. ";
cout << "Monday: ";
cin >> monday;
cout << "Tuesday: ";
cin >> tuesday;
cout << "Wednesday: ";
cin >> wednesday;
cout << "Thursday: ";
cin >> thursday;
cout << "Friday: ";
cin >> friday;
while (monday < 0 || tuesday < 0 || wednesday < 0 || thursday < 0 || friday < 0)
{
cout << "Sorry!!! Negative values are not allow." << endl;
cout << "Please re-enter the pounds eaten by the second monkey during the week. ";
cout << "Monday: ";
cin >> monday;
cout << "Tuesday: ";
cin >> tuesday;
cout << "Wednesday: ";
cin >> wednesday;
cout << "Thursday: ";
cin >> thursday;
cout << "Friday: ";
cin >> friday;
}
monkey2day1 = monday;
monkey2day2 = tuesday;
monkey2day3 = wednesday;
monkey2day4 = thursday;
monkey2day5 = friday;
}
void getdataMonkey3(double & monkey3day1, double& monkey3day2, double& monkey3day3, double& monkey3day4, double& monkey3day5)
{
double monday;
double tuesday;
double wednesday;
double thursday;
double friday;
cout << "Please enter the pounds eaten by the third monkey during the week. ";
cout << "Monday: ";
cin >> monday;
cout << "Tuesday: ";
cin >> tuesday;
cout << "Wednesday: ";
cin >> wednesday;
cout << "Thursday: ";
cin >> thursday;
cout << "Friday: ";
cin >> friday;
while (monday < 0 || tuesday < 0 || wednesday < 0 || thursday < 0 || friday < 0)
{
cout << "Sorry!!! Negative values are not allow." << endl;
cout << "Please re-enter the pounds eaten by the third monkey during the week. ";
cout << "Monday: ";
cin >> monday;
cout << "Tuesday: ";
cin >> tuesday;
cout << "Wednesday: ";
cin >> wednesday;
cout << "Thursday: ";
cin >> thursday;
cout << "Friday: ";
cin >> friday;
}
monkey3day1 = monday;
monkey3day2 = tuesday;
monkey3day3 = wednesday;
monkey3day4 = thursday;
monkey3day5 = friday;
}
double averageDaily(double& aveMonday, double& aveTuesday, double& aveWednesday, double& aveeThursday, double& aveFriday)
{
double DailyPounds[3][5] = { { monkeyday1, monkeyday2, monkeyday3, monkeyday4, monkeyday5 },{ monkey2day1, monkey2day2, monkey2day3, monkey2day4, monkey2day5 },{ monkey3day1, monkey3day2, monkey3day3, monkey3day4, monkey3day5 } };
aveMonday = (DailyPounds[0][0] + DailyPounds[1][0] + DailyPounds[2][0]) / 3;
aveTuesday = (DailyPounds[0][1] + DailyPounds[1][1] + DailyPounds[2][1]) / 3;
aveWednesday = (DailyPounds[0][2] + DailyPounds[1][2] + DailyPounds[2][2]) / 3;
aveeThursday = (DailyPounds[0][3] + DailyPounds[1][3] + DailyPounds[2][3]) / 3;
aveFriday = (DailyPounds[0][4] + DailyPounds[1][4] + DailyPounds[2][4]) / 3;
return aveMonday, aveTuesday, aveWednesday, aveeThursday, aveFriday;
}
double greatestamount(double& greatest)
{
double DailyPounds[3][5] = { { monkeyday1, monkeyday2, monkeyday3, monkeyday4, monkeyday5 },{ monkey2day1, monkey2day2, monkey2day3, monkey2day4, monkey2day5 },{ monkey3day1, monkey3day2, monkey3day3, monkey3day4, monkey3day5 } };
int i = 0;
double monkey1 = 0;
double monkey2 = 0;
double monkey3 = 0;
for (i = 0; i < 5; i++)
{
if (monkey1 < DailyPounds[0][i])
monkey1 = DailyPounds[0][i];
if (monkey2 < DailyPounds[1][i])
monkey2 = DailyPounds[1][i];
if (monkey3 < DailyPounds[2][i])
monkey3 = DailyPounds[2][i];
}
if (monkey1 > monkey2 && monkey1> monkey3)
{
cout << "Monkey 1 ate the greatest amount of food. ";
greatest = monkey1;
}
if (monkey2 > monkey1 && monkey2 > monkey3)
{
cout << "Monkey 2 ate the greatest amount of food. ";
greatest = monkey2;
}
if (monkey3 > monkey1 && monkey3 > monkey2)
{
cout << "Monkey 3 ate the greatest amount of food. ";
greatest = monkey3;
}
return greatest;
}
double leastamount(double& least)
{
double DailyPounds[3][5] = { { monkeyday1, monkeyday2, monkeyday3, monkeyday4, monkeyday5 },{ monkey2day1, monkey2day2, monkey2day3, monkey2day4, monkey2day5 },{ monkey3day1, monkey3day2, monkey3day3, monkey3day4, monkey3day5 } };
int i = 0;
double monkey1 = 100000;
double monkey2 = 100000;
double monkey3 = 100000;
for (i = 0; i < 5; i++)
{
if (monkey1 > DailyPounds[0][i])
monkey1 = DailyPounds[0][i];
if (monkey2 > DailyPounds[1][i])
monkey2 = DailyPounds[1][i];
if (monkey3 > DailyPounds[2][i])
monkey3 = DailyPounds[2][i];
}
if (monkey1 < monkey2 && monkey1< monkey3)
{
cout << "Monkey 1 ate the least amount of food. ";
least = monkey1;
}
if (monkey2 < monkey1 && monkey2 < monkey3)
{
cout << "Monkey 2 ate the least amount of food. ";
least = monkey2;
}
if (monkey3 < monkey1 && monkey3 < monkey2)
{
cout << "Monkey 3 ate the greatest amount of food. ";
least = monkey3;
}
return least;
}
Explanation / Answer
This question is not related to calculus.
It is related to computer science engineering.
Sorry, I cannot solve it.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.