Moon Pie Theft: Description and Specifications Jane steals Moonpies from her bro
ID: 3852787 • Letter: M
Question
Moon Pie Theft:
Description and Specifications
Jane steals Moonpies from her brother on a regular basis
Implement this program in three files: Moonpie.h, Moonpie.cpp, and Functions.cpp.
Write a program named that will:
Ask how many days Jane stole moon pies.
Create a function called makeArray that will accept the number of days and will return a pointer to a dynamically allocated array based on this number.
Create a function called enterStolenMoonPies and call this function from your main function. You will send the array and number of days to this function. You will populate the array by asking the user how many moon pies Jane stole on each day.
Then, create a function called totalMoonPies and call this function from your main function. You will send the array and number of days to this function. In this function, you will figure out how many moon pies in total has been stolen by Jane – then return this value back to main.
Then, create a function called averageMoonPies and call this function rom your main function. You will send the array, number of days, and the total # moon pies stolen to this function. In this function, you will figure out the average number of moon pies that were stolen per day – then return this value back to main.
Then, create a function called highestMoonPies and call this function from your main function. You will send the array and number of days to this function. In this function, you will figure out the most moon pies Jane stole in a single day and then return this value back to main.
Then, create a function called lowestMoonPies and call this function from your main function. You will send the array and number of days to this function. In the function, you will figure out the least number of moon pies Jane stole in a single day and then return this value back to main.
Last, print out the total, average, highest and lowest in an easy-to-read way in the main function
Make sure to use POINTER NOTATION in every function and in the main function.
Make sure to release the memory of the dynamically allocated array before ending the program.
Sample Output:
How many days did Jane steal moon pies? 5
Enter the number of moon pies stolen on each day.
DAY 1 : 3
DAY 2 : 6
DAY 3 : 1
DAY 4 : 7
DAY 5 : 2
------------------------RESULTS---------------------------
Total # of Moon Pies Stolen : 19
Average # of Moon Pies Stolen : 3.8
Highest # of Moon Pies Stolen : 7
Fewest # of Moon Pies Stolen : 1
Submission Guidelines
Explanation / Answer
Header file
file:Moonpie.h
#ifndef MOONPIE
#define MOONPIE
extern int* makeArray(int);
extern void enterStolenMoonPies(int*, int);
extern int totalMoonPies (int*, int);
extern double averageMoonPies (int*, int);
extern int highestMoonPies (int*, int);
extern int lowestMoonPies (int*, int);
#endif
Utility files
File name: Functions.cpp
#include<iostream>
int* makeArray(int days) {
int *arr = new int[days];
return arr;
}
void enterStolenMoonPies(int *arr, int days) {
std::cout << "Enter the number of moon pies stolen on each day. ";
for (int i = 0; i < days; i++) {
cout << "DAY "<< i+1 <<" : ";
cin >> arr[i];
}
}
int totalMoonPies (int *arr, int days) {
int sum = 0;
for (int i = 0; i < days; i++)
sum += arr[i];
return sum;
}
double averageMoonPies (int *arr, int days) {
int sum = totalMoonPies(arr, days);
return (double)sum/days;
}
int highestMoonPies (int *arr, int days) {
int highest = arr[0];
for (int i = 1; i < days; i++)
if (arr[i] > highest)
highest = arr[i];
return highest;
}
int lowestMoonPies (int *arr, int days) {
int lowest = arr[0];
for (int i = 1; i < days; i++)
if (arr[i] < lowest)
lowest = arr[i];
return lowest;
}
File: Moonpie.cpp
#include<iostream>
#include "Moonpie.h"
using namespace std;
int main() {
int days;
cout << "How many days did Jane steal moon pies?";
cin >> days;
int *stealList = makeArray(days);
int total = totalMoonPies (stealList, days);
double avg = averageMoonPies(stealList, days);
int highest = highestMoonPies(stealList, days);
int lowest = lowestMoonPies (stealList, days);
delete[] stealList;
cout << "------------------------RESULTS--------------------------- ";
cout << "Total # of Moon Pies Stolen : " << total << endl;
cout << "Average # of Moon Pies Stolen :" << avg << endl;
cout << "Highest # of Moon Pies Stolen :" << highest << endl;
cout << "Fewest # of Moon Pies Stolen :" << lowest << endl;
}
i hope this helps
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.