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

complete the program WITHOUT editing the main program. More precisely, your job

ID: 3601709 • Letter: C

Question

complete the program WITHOUT editing the main program. More precisely, your job is to create two functions based on the documentation provided and by examining how those functions are called within the main program. Keep in mind that you need to write both the function prototypes as well as the function definitions.

#include <iostream>
#include <vector>

using namespace std;

//Global constants
const int HOW_MANY_INPUT = 5;
//Prototypes...


//Main program...
int main()
{
vector <int> input;

for(int i=0; i<HOW_MANY_INPUT; i++)
{
input.push_back( getDigit() );
}

int biggest = largestNumber( input );
cout<<"The biggest number entered was "<<biggest<<endl;

return 0;
}

//Function definitions...

/**
* getDigit() asks the user "Enter a digit:" but validates that the user input
* is between 0 and 9. If the input is out of that range, an error prints that
* "The digit must be at least 0 and no bigger than 9" and then asks the user
* to enter a digit again. This will repeat until a valid digit is entered.
* Once a valid digit is entered, it should be returned.
**/


/**
* largestNumber() receives a vector of integers and finds which one is the
* greatest value and returns it.
**/

Explanation / Answer

#include <iostream>

#include <vector>

using namespace std;

//Global constants

const int HOW_MANY_INPUT = 5;

//Prototypes...

int getDigit();

int largestNumber(vector<int>);

//Main program...

int main()

{

vector <int> input;

for(int i=0; i<HOW_MANY_INPUT; i++)

{

input.push_back( getDigit() );

}

int biggest = largestNumber( input );

cout<<"The biggest number entered was "<<biggest<<endl;

return 0;

}

int getDigit()

{

int num;

while(true)

{

cout<<"Please enter a number:";

cin>>num;

if(num>=0 && num<10)

{

return num;

}

cout<<"The digit must be at least 0 and no bigger than 9."<<endl;

}

}

int largestNumber(vector<int> v)

{

int l = v.size();

int max = v[0];

for(int i=0;i<l;i++)

{

if(v[i]>max)

{

max = v[i];

}

}

return max;

}