Write program segments that accomplish each of the following:

a) Calculate the integer part of the quotient when integer a is divided by integer b.
b) Calculate the integer remainder when integer a is divided by integer b.
c) Use the program pieces developed in (a) and (b) to write a function that inputs an integer between 1 and 32767 and prints it as a series of digits, each pair of which is separated by two spaces. For example, the integer 4562 should print as follows:

4 5 6 2


```
// Print input number as series of digits,
// each pair of which is separated by two spaces.
#include
using namespace std;

int quotient( int, int ); // function prototype
int remainder( int, int ); // function prototype
void printDigits( int ); // function prototype
int main()
{
int number; // input number

do
{
cout << "Enter an integer between 1 and 32767: ";
cin >> number;
} // end do
while ( number < 1 || number > 32767 );

cout << "The digits in the number are:\n";
printDigits( number ); // call function to print digits
cout << endl; // add trailing newline
} // end main

// Part A: determine quotient using integer division
int quotient( int a, int b )
{
return a / b;
} // end function quotient

// Part B: determine remainder using the modulus operator
int remainder( int a, int b )
{
return a % b;
} // end function remainder

// Part C: print digits of an integer separated by two spaces
void printDigits( int number )
{
int divisor = 10000; // current divisor

// prevent leading zeros from being printed
while ( number < divisor )
divisor = quotient( divisor, 10 );

// determine and print each digit
while ( divisor >= 1 )
{
// use quotient to determine current digit
cout << quotient( number, divisor ) << " ";

// update number to be remainder
number = remainder( number, divisor );

// update divisor for next digit
divisor = quotient( divisor, 10 );
} // end while
} // end function printDigits
```

Computer Science & Information Technology

You might also like to view...

private fields of a base class can be accessed in a derived class

a) by calling private methods declared in the base class b) by calling public or protected methods declared in the base class c) directly d) All of the above

Computer Science & Information Technology

While the AH ensures data integrity, confidentiality of data is provided by the __________ component of IPsec.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Explain the purpose of Link Quality Monitoring (LQM) when configured on a serial interface running PPP

What will be an ideal response?

Computer Science & Information Technology

Which of the following best meets the requirements of a strong password?

A. t*M&2.zY7 B. qwerty1234567890 C. p@ssw0rd D. johndoe123

Computer Science & Information Technology