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

Write a C++ program to: a. Prompt the user for two positive integers, divide the

ID: 3729950 • Letter: W

Question

Write a C++ program to:

a. Prompt the user for two positive integers, divide the larger by the smaller, and print the answer as a quotient and remainder.

b. Use main( ) as the driver function. Allow the user to run the program as many times as desired.

c. Write 5 functions that main( ) calls to accomplish the task:

1. getIntegers( ): Prompts the user for two positive integers. Use reference parameters.

2. findLargeAndSmall( ): Determines which of the integers is larger and which is smaller. Returns the larger and smaller integers via reference parameters.

3. calcQuotient( ): Calculates and returns the quotient of the larger integer divided by the smaller.

4. calcRemainder( ): Calculates and returns the remainder of the larger integer divided by the smaller.

5. displayResults( ): Prints the quotient and the remainder in the form typically used for long division problems in grade school. e.g. The answer for 7/2 is displayed as 3 R1.

Sample I/O:

**************************************************************

This program will ask you to enter two positive integers.

It will divide the larger by the smaller and display the

result as a quotient and remainder.

**************************************************************

Please enter your first integer and press <Enter>: 5

Please enter your second integer and press <Enter>: 9

The answer for 9/5 is 1 R 4

Would you like to process another set of numbers (Y or N)? y

**************************************************************

This program will ask you to enter two positive integers.

It will divide the larger by the smaller and display the

result as a quotient and remainder.

**************************************************************

Please enter your first integer and press <Enter>: 7

Please enter your second integer and press <Enter>: 2

The answer for 7/2 is 3 R 1

Would you like to process another set of numbers (Y or N)? y

**************************************************************

This program will ask you to enter two positive integers.

It will divide the larger by the smaller and display the

result as a quotient and remainder.

**************************************************************

Please enter your first integer and press <Enter>: 3

Please enter your second integer and press <Enter>: 5

The answer for 5/3 is 1 R 2

Would you like to process another set of numbers (Y or N)? n

Explanation / Answer

#include <iostream>
#include <fstream>
using namespace std;
int findLargeAndSmall(int x,int y)
{
if(x<y)
return x;
else
return y;
}
int calcQuotient(int x,int y)
{
return y/x;
}
int calcRemainder(int x,int y)
{
return y%x;
}
void displayResults(int x,int y,int Quo,int Rem)
{
cout<<"The answer for "<<y<<"/"<<x<<" is "<<Quo<<" R "<<Rem;
}
void getIntegers()
{
int x, y,min,max,sum,Quo,Rem;
cout<<endl<<"Please enter your first integer and press <Enter>: ";
cin>>x;
cout<<"Please enter your second integer and press <Enter>: ";
cin>>y;
sum = x+y;
min =findLargeAndSmall(x,y);
max = sum-min;
Quo = calcQuotient(min,max);
Rem = calcRemainder(min,max);
displayResults(min,max,Quo,Rem);
}
int main ()
{
char c;
while(1)
{
cout<<endl<<"**************************************************************";
cout<<endl<<"This program will ask you to enter two positive integers.";
cout<<endl<<"It will divide the larger by the smaller and display the";
cout<<endl<<"result as a quotient and remainder.";
cout<<endl<<"**************************************************************";
getIntegers();
cout<<endl<<"Would you like to process another set of numbers (Y or N)? ";
cin>>c;
if(c=='y'||c=='Y')
continue;
else
break;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote