Question

Implement a function divide, which receives a dividend and a divisor, returns the quotient and the...

Implement a function divide, which receives a dividend and a divisor, returns the quotient and the reminder. Your program should include the following testing main function and return the expected output.

int main ()

{

int quotient, remainder;

divide(487, 32, quotient, remainder);

std::cout << quotient << “,” <<remainder << std::endl;// expected output: 32,7

divide(0, 51, quotient, remainder);

std::cout << quotient << “,” <<remainder << std::endl;// expected output: 0,0

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

void divide(int n1, int n2, int &q, int &r) {
    q = n1 / n2;
    r = n1 % n2;
}

int main() {
    int quotient, remainder;
    divide(487, 32, quotient, remainder);
    std::cout << quotient << "," << remainder << std::endl;// expected output: 15,7
    divide(0, 51, quotient, remainder);
    std::cout << quotient << "," << remainder << std::endl;// expected output: 0,0
}

Add a comment
Know the answer?
Add Answer to:
Implement a function divide, which receives a dividend and a divisor, returns the quotient and the...
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
  • You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function...

    You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function into a file named Q1.cpp. Q1.cpp should only include your function implementation, the necessary #include directives if needed, and should not contain anything else such as the main function or global variable declarations. Test your code using a separate main.cpp file where you implement a sufficient number of test cases. You should use Q1.h as a header file and Q1main.cpp as a main function...

  • 4. Write a function that returns a value to the main program illustrated below. In the...

    4. Write a function that returns a value to the main program illustrated below. In the function, the variable passed by the main program needs to be evaluated using a switch statement. The value returned is determined by the case that it matches. (10 points) If value is: return 10 return 20 3 return 30 Anything else, return 0 Main program: #include <iostream> using namespace std; int findValue (int); int main) { Int numb, retvalue cout << "In Enter a...

  • #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...

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • Programming Assignment 7 Implement a function named fibo that will get a 20 element initialized an...

    Programming Assignment 7 Implement a function named fibo that will get a 20 element initialized an array of zeros from the main function. It will set the array to the Fibonacci sequence. This sequence starts with 1 and 2 as the first 2 elements and each element thereafter is the sum of the previous two elements. (1, 2, 3, 5, 8, 13…). Add another function named findNum that will get the newly created array by fibo from the main function....

  • You are to write two functions, printString() and testString(), which are called from the main function....

    You are to write two functions, printString() and testString(), which are called from the main function. printString (string) prints characters to std::cout with a space after every character and a newline at the end. testString (string) returns true if the string contains two consecutive characters that are the same, false otherwise. See the main() to see how the two functions are called. Some sample runs are given below: string: “hello” printString prints: h e l l o testString returns: true...

  • c++ Implement the following function: 1) Name: ProcessLine a. Parameters: Int 10 character array line, charc...

    c++ Implement the following function: 1) Name: ProcessLine a. Parameters: Int 10 character array line, charc b. Job: The function will modify line such that every occurrence of c is replaced by a "*". It will also return the count of c in line. The main() function is provided. You only need to implement the function Processline. #include <iostream> #include <string> using namespace std; int main() char line 200), c; int Count; { cout<<"Enter some text: "; cin.get(line, 200); cout<<"Enter...

  • Complete a partially written C++ program that includes a function that return a value. The program...

    Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...

  • Transform the find function of Question 4 into a function template. Here is the program used...

    Transform the find function of Question 4 into a function template. Here is the program used to test your template, followed by the output of that program: #include <iostream> #include <string> #include "find.h" using namespace std; #define NUM_ELEMENTS(a) (sizeof(a) / sizeof(a[0])) int main() {         cout << "int" << endl;         cout << "---" << endl;         int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};         cout << "3 is at location " << find(arr1, NUM_ELEMENTS(arr1),...

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