Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

here ya go I was given the basic outline of the program from my teacher and we w

ID: 3544340 • Letter: H

Question

here ya go

I was given the basic outline of the program from my teacher and we were told to do all the functions. I have already done all the functions but im having trouble getting them into the outline correctly. Heres the outline and all the functions all i need is help copy and pasting it all together so it runs.


#include <iostream>
#include <iomanip>

using namespace std;

/ Function Prototypes /

string Menu();
int getValue( string, int, int );
void doAverage();
double calcAverage( int, int );
void doFactorial();
int calcFactorial( int );
void doMtoNth();
int calcMtoNth( int, int );
void doRange();
int calcRange( int, int, int, int );
int main()
{
string userChoice;

userChoice = Menu();

while ( userChoice != "Q" && userChoice != "q" )
{
if (userChoice == "1")
{
doAverage();
}
else if ( userChoice == "2" )
{
doFactorial();
}
else if ( userChoice == "3" )
{
doMtoNth();
}
else if (userChoice == "4")
{
doRange();
}

userChoice = Menu();
}//end of the while loop

//system("pause");
return 0;
}

Code your Functions below this line

string Menu()
{

string userChoice;

cout << "Special Purpose Calculator";

cout << " 1) Average";
cout << " 2) Factorial ";
cout << " 3) M to the Nth Power";
cout << " 4) Range";

cout << " Q) Quit";

cout << " Enter your choice?";

cin >> userChoice;

return userChoice;

}
int getValue(string prompt, int lowBound, int upBound)
{
int number;

cout << prompt << lowBound << " and " << upBound << ": ";

do
{
if (number < lowBound || number > upBound)
{
cout << " Error: " << number << " is invalid. Try again: ";
}
}
while (number < lowBound || number > upBound);

return number;
}

void doAverage()
{
string state1 = "Enter a sum to be averaged between ";
string state2 = "Enter the number of entries ";

int lowBoundA = 1,
upBoundA = 1000,
lowBoundB = 1,
upBoundB = 1000,
sum,
count;

double average;

sum = getValue(state1, lowBoundA, upBoundA);
count = getValue(state2, lowBoundB, upBoundB);

average = calcAverage(sum, count);

cout << " The average is: ";

return;
}

double calcAverage( int sum, int count )
{
double average;

average = (double) sum/count;

return average;
}

void doFactorial()
{
string state1 = "Enter a number between: ";

int lowBound = 0,
upBound = 10,
numfactorial,
factorial;

numfactorial = getValue(state1, lowBound, upBound);
factorial = calcFactorial(numfactorial);

return;
}

int calcFactorial( int number )
{
int count,
factorial = 1,
numfactorial;

count = numfactorial;
cout << " The factorial value is: ";

while (count > 0)
{
factorial = factorial * count;
cout << count << " x";
count --;
}

cout << " = " << factorial;

return factorial;
}

void doMtoNth()
{
string state1 = "Enter a value: ";
string state2 = "Enter a value: ";

int lowBoundA = 1,
upBoundA = 10,
lowBoundB = 1,
upBoundB = 8,
M,
N,
MtoNth;

double average;

M = getValue(state1, lowBoundA, upBoundA);
N = getValue(state2, lowBoundB, upBoundB);
MtoNth = calcMtoNth (M, N);

cout << " " << M << " to the " << N << "th power is: ";
cout << MtoNth;

return;
}

int calcMtoNth( int M, int N )
{
int MtoNth = 1,
count = 1,
Nth;

while (count <= Nth)
{
MtoNth *=M;
count ++;
}

return MtoNth;

}
void doRange()
{
string state1 = "Enter a number between ";
string state2 = "Enter another number between ";

int lowBound = 0,
upBound = 1000,
num1,
num2,
num3,
num4,
range = 0;

double average;

num1 = getValue(state1, lowBound, upBound);
num2 = getValue(state2, lowBound, upBound);
num3 = getValue(state2, lowBound, upBound);
num4 = getValue(state2, lowBound, upBound);
range = calcRange(num1, num2, num3, num4);

cout << " The range of " << num1 << ", " << num2 << ", " << num3 << ", " << num4 << "is " << range;

return;
}

int calcRange( int number1, int number2, int number3, int number4 )
{
int max,
min,
range;

if (number1 >= number2)
max = number1;

else
max = number2;

if (number3 >= max)
max = number3;

if (number4 >= max)
max = number4;

if (number1 <= number2)
min = number1;

else
min = number2;

if (number3 <= min)
min = number3;

if (number4 <= min)
min = number4;

range = max - min;

return range;

}

and heres the outline all the functions have to go into

#include <iostream>

#include <iomanip>


using namespace std;


//Place your symbolic constant definitions after this line


//Place your function prototypes after this line


int main()

{

string userChoice;


//Get the user's menu choice


userChoice = Menu();


//While the user does not want to quit


while( userChoice != "Q" and userChoice != "q" )

{


//If the user selected option 1 from the menu, calculate an average


if( userChoice == "1" )

{

doAverage();

}


//If the user selected option 2 from the menu, calculate the factorial

//of a number


else if( userChoice == "2" )

{

doFactorial();

}


//If the user selected option 3 from the menu, calculate the result of

//of raising a number to a power


else if( userChoice == "3" )

{

doMtoNth();

}


//If the user selected option 4 from the menu, calculate the range of

//four numbers


else

{

doRange();

}


//Get the next menu choice from the user


userChoice = Menu();

}


return 0;

}


//Code your functions below this line

Explanation / Answer

#include <iostream>

#include <iomanip>

using namespace std;

/* Function Prototypes */

string Menu();

int getValue( string, int, int );

void doAverage();

double calcAverage( int, int );

void doFactorial();

int calcFactorial( int );

void doMtoNth();

int calcMtoNth( int, int );

void doRange();

int calcRange( int, int, int, int );


//////////////////////////////////////////MAIN////////////////////////////////////////////

int main()

{

string userChoice;

userChoice = Menu();

while ( userChoice != "Q" && userChoice != "q" )

{

if (userChoice == "1")

{

doAverage();

}

else if ( userChoice == "2" )

{

doFactorial();

}

else if ( userChoice == "3" )

{

doMtoNth();

}

else if (userChoice == "4")

{

doRange();

}


userChoice = Menu();

}//end of the while loop

//system("pause");

return 0;

}


string Menu()

{

string userChoice;

cout << "Special Purpose Calculator";

cout << " 1) Average";

cout << " 2) Factorial ";

cout << " 3) M to the Nth Power";

cout << " 4) Range";

cout << " Q) Quit";

cout << " Enter your choice?";

cin >> userChoice;

return userChoice;

}


int getValue(string prompt, int lowBound, int upBound)

{

int number;

cout << prompt << lowBound << " and " << upBound << ": ";

cin>>number;

do

{

if (number < lowBound || number > upBound)

{

cout << " Error: " << number << " is invalid. Try again: ";

cin>>number;

}

}

while (number < lowBound || number > upBound);

return number;

}



void doAverage()

{

string state1 = "Enter a sum to be averaged between ";

string state2 = "Enter the number of entries ";

int lowBoundA = 1,upBoundA = 1000,lowBoundB = 1,upBoundB = 1000,sum,count;

double average;

sum = getValue(state1, lowBoundA, upBoundA);

count = getValue(state2, lowBoundB, upBoundB);

average = calcAverage(sum, count);

cout << " The average is: "<<average<<endl;

return;

}



double calcAverage( int sum, int count )

{

double average;

average = (double)sum/(double)count;

return average;

}


void doFactorial()

{

string state1 = "Enter a number between: ";

int lowBound = 0,upBound = 10,numfactorial,factorial;

numfactorial = getValue(state1, lowBound, upBound);

factorial = calcFactorial(numfactorial);

return;

}



int calcFactorial( int number )

{

int factorial;

factorial = 1;

cout << " The factorial value is: ";

while (number > 0)

{

factorial *= number;

number--;

}

cout << " = " << factorial<<endl;

return factorial;

}



void doMtoNth()

{

string state1 = "Enter a value: ";

string state2 = "Enter a value: ";

int lowBoundA = 1,upBoundA = 10,lowBoundB = 1,upBoundB = 8,M,N,MtoNth;

double average;

M = getValue(state1, lowBoundA, upBoundA);

N = getValue(state2, lowBoundB, upBoundB);

MtoNth = calcMtoNth (M,N);

cout << " " << M << " to the " << N << "th power is: ";

cout << MtoNth<<endl;

return;

}



int calcMtoNth( int M, int N )

{

int MtoNth = 1,count = 1,Nth=N;

while (count <= Nth)

{

MtoNth *=M;

count ++;

}

return MtoNth;

}


void doRange()

{

string state1 = "Enter a number between ";

string state2 = "Enter another number between ";

int lowBound = 0,upBound = 1000,num1,num2,num3,num4,range = 0;

double average;

num1 = getValue(state1, lowBound, upBound);

num2 = getValue(state2, lowBound, upBound);

num3 = getValue(state2, lowBound, upBound);

num4 = getValue(state2, lowBound, upBound);

range = calcRange(num1, num2, num3, num4);

cout << " The range of " << num1 << ", " << num2 << ", " << num3 << ", " << num4 << " is " << range<<endl;

return;

}



int calcRange( int number1, int number2, int number3, int number4 )

{

int max,min,range;

if (number1 >= number2)

max = number1;

else

max = number2;

if (number3 >= max)

max = number3;

if (number4 >= max)

max = number4;


if (number1 <= number2)

min = number1;

else

min = number2;

if (number3 <= min)

min = number3;

if (number4 <= min)

min = number4;


range = max - min;

return range;

}