Question

#include<iostream> using namespace std; void twodigits(int original, int& first, int& second) {    first = original...

#include<iostream>

using namespace std;

void twodigits(int original, int& first, int& second) {

   first = original / 10;

   second = original - first * 10;

}

int main(){

int original = 95;

int first = 0;

int second = 0;

twodigits(original, first, second);

cout << original << " => " << first << " and " << second << endl;

return 0;

}

Write a function that takes two integers, numerator and denominator, as input parameters and output their quotient and remainder. Use a main function test the function. Hint: Use call by reference to output the quotient and remainder as parameters (see an example for Code

Use the following formula to calculate quotient and remainder:

quotient = numerator / denominator;

remainder = numerator % denominator;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//------------- main.cpp ---------------
#include<iostream>
using namespace std;
//function getQuotientAndRemainder() that takes
//numerator, denominator for calculating quotient, remainder and stores
//the result in passed parameters using pass by reference.
//
void getQuotientAndRemainder(int numerator,int denominator,int &quo,int &rem)
{
//calculate quotient and store the result in reference variable quo.
quo = numerator / denominator;
//calculate remainder and store the result in reference variable rem.
rem = numerator % denominator;
  
}
//test the code using main.
int main()
{
//numerator and denominator for calculating quotient and remainder.
int numerator = 100;
int denominator = 6;
//variables to pass as reference to function.
int quo,rem;
//call the function getQuotientAndRemainder() with above 4 variables.
getQuotientAndRemainder(numerator,denominator,quo,rem);
cout<<"Numerator: "<<numerator<<endl;
cout<<"Denominator: "<< denominator<<endl;
cout<<"Quotient: "<<quo<<endl;
cout<<"Remainder: "<<rem<<endl;
return 0;
}
/*------------ Output ---------------
Numerator: 100   
Denominator: 6   
Quotient: 16   
Remainder: 4
*/

//screenshots

Add a comment
Know the answer?
Add Answer to:
#include<iostream> using namespace std; void twodigits(int original, int& first, int& second) {    first = original...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT