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
  • C++ question #include <iostream> using namespace std; void printReverse(int); int main() {     int number = 12345;...

    C++ question #include <iostream> using namespace std; void printReverse(int); int main() {     int number = 12345;     cout << "Original : " << number << endl;     cout << "Reversed : ";     printReverse(number); } void printReverse(int x) {     if (x == 0)        return;     cout << x % 10;     printReverse(x /= 10);     } Modify the above recursive program to output the number in the same order. Note that the program still should break up the number and then output it in the...

  • Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int);...

    Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?

  • #include<iostream> using namespace std; void calcSumAndDiff(int ,int, int &, int &); void calcSumAndDiff(int n1,int n2, int...

    #include<iostream> using namespace std; void calcSumAndDiff(int ,int, int &, int &); void calcSumAndDiff(int n1,int n2, int &sum, int &diff){ sum = n1 + n2; diff = n1 - n2; } int main() { int n1,n2,sum,diff; n1=30;n2=10; calcSumAndDiff(n1,n2,sum,diff); cout<<"Sum is :"<<sum<<endl; cout<<"Diff is:"<<diff<<endl; system("pause"); }

  • Make the function take in the variables by reference #include <iostream> using namespace std; //Make the...

    Make the function take in the variables by reference #include <iostream> using namespace std; //Make the function take in the variables by reference void add_to_first_and_reset(int total, int to_add){    total += to_add; to_add = 0; } int main(){ int sum = 0, temp = 0;    for(int i = 0; i < 10; i++){ cin >> temp; add_to_first_and_reset(sum,temp); cout << sum << " " << temp << endl; }    }

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

  • What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int &...

    What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int & x); int z = 10; void main() { char x = 'y'; int y = 5; int z = 100; y = DontPanic(z); cout << x << " " << y << " " << z << endl; } int DontPanic(int & x) { int * p; p = & z; x = (*p)++ + 1; cout << x << " " << *p...

  • #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main()...

    #include <iostream> using namespace std; int * newZeroArray(int size) { //your code here } int main() { int size = 10; int * A = newZeroArray(size); for(int i = 0; i < size; i++) cout << A[i] << " "; cout << endl; }Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...

  • #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...

    #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the array"<<endl;    cin>>SIZE;     int *numlist = new int[SIZE];     // Read SIZE integers from the keyboard     for (int i = 0; i<SIZE; i++ )    {        cout << "Enter value #" << i+1 << ": ";        cin >> numlist[i];     }     // Display the numbers in a reverse order     for (int i = SIZE; i > 0; i--...

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

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