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
```
You might also like to view...
Match the following terms to their meanings:
I. Compact on Close check box II. Application Title box III. Application Title IV. Layout view V. Quick Access Toolbar A. Text that displays in the Access title bar when a database is opened B. If left blank, the file path, name, file, and application name display instead C. Can be disabled D. With this option selected, the database will be compacted and repaired each time it is closed E. Can be modified for all databases or just the current database
AutoFit is applied to a column by double-clicking on the right border of the column in the ________
Fill in the blank(s) with the appropriate word(s).