2. (Save your program as a write answer as a program to: the a Prompt user for t
ID: 3834827 • Letter: 2
Question
2. (Save your program as a write answer as a program to: the a Prompt user for two positive integers, divide the larger by the smaller, and print the quotient and remainder. b. Use main() as driver function. Allow the user to run the program as many times as desired. c. 5 the to accomplish the task: functions that main() 1. Prompts the user for two positive integers. Use reference parameters. Returns the 2. Determines which of the integers is larger and which is smaller. larger and smaller integers via reference parameters. integer divided by the smaller. 3. calcQuotient(): Calculates and returns the of the larger the smaller. 4. calcRemainder(): Calculates and returns the remainder of the larger integer divided by division 5. Prints the quotient and the remainder in the form typically used for long 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 pressExplanation / Answer
#include <iostream>
using namespace std;
void getIntegers(int &a, int &b){
cout << "Enter your first integer and press <Enter>: ";
cin >> a;
cout << "Enter your second integer and press <Enter>: ";
cin >> b;
}
void getLargeAndSmall(int &a, int &b){
if(a < b){
int t = a;
a = b;
b = t;
}
}
int calcQuotient(int a, int b){
return (int)a/b;
}
int calcRemainder(int a, int b){
return a % b;
}
void displayResults(int a, int b){
cout<<"The answer for "<<a<<"/"<<b<<" is displayed as "<<calcQuotient(a,b)<<" R "<<calcRemainder(a,b)<<endl;
}
int main()
{
int a,b;
char ch = 'y';
while(ch=='y' || ch == 'Y'){
getIntegers(a,b);
getLargeAndSmall(a,b);
displayResults(a,b);
cout<<"Do you want to continue (y or n): ";
cin >> ch;
}
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter your first integer and press <Enter>: 7
Enter your second integer and press <Enter>: 2
The answer for 7/2 is displayed as 3 R 1
Do you want to continue (y or n): y
Enter your first integer and press <Enter>: 9
Enter your second integer and press <Enter>: 4
The answer for 9/4 is displayed as 2 R 1
Do you want to continue (y or n): n
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.