-
C++ (
http://www.daniweb.com/forums/forum8.html)
| latour1972 | May 9th, 2008 4:06 pm | |
| How to start for this? Write two program segments (functions) that accomplish each of the following:
a) A function that Calculates the integer part of the quotient when integer a is divided by integer b.
b) A function that Calculates the integer remainder when integer a is divided by integer b.
Use the functions 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 |
| Salem | May 9th, 2008 4:19 pm | |
| Re: How to start for this? Do you know what quotient and remainder mean? |
| henpecked1 | May 9th, 2008 5:19 pm | |
| Re: How to start for this? they've actually given you the psuedocode for it, if it helps to get you started, just pick two numbers and do the math operation on paper and that will help you write your functions...make sure you use the correct operators indicated by the results the psuedocode asks for. Your instructor should have shown you how to do spaces in a cout statement for your spacing problem. |
| latour1972 | May 12th, 2008 4:10 pm | |
| Re: How to start for this? I know quotient and remainder mean but I still cant figure that out..... |
| tesuji | May 12th, 2008 8:16 pm | |
| Re: How to start for this? Hi latour1972,
maybe these will help you:
// Two function to computing quotient and remainder
int quotient (int z ) { return z / 10; }
int reminder ( int z ) { return z % 10; }
// Simple solution to split int number into its digits
void demon ()
{ int n, d0, d1, d2, d3, d4;
cout << "Enter an integer between 1 and 32767: ";
cin >> n;
cout << n << endl;
d4 = reminder(n); n = quotient(n);
d3 = reminder(n); n = quotient(n);
d2 = reminder(n); n = quotient(n);
d1 = reminder(n); d0= quotient(n);
cout << d0 << " " << d1 << " " << d2 << " " << d3 << " " << d4 << endl;
}
// Below solution works recursively. Do you understand this?
// if you call split (4562), result is 4 5 6 2
void split(int n){
int d = n % 10; n = n / 10;
if ( n > 0) split (n);
cout << d << " ";
}
krs,
tesu |
| latour1972 | May 13th, 2008 3:02 pm | |
| Re: How to start for this? tks.....
I am working on this.....and it helps me to understand....
Quote: Originally Posted by tesuji (Post 605707) Hi latour1972,
maybe these will help you:
// Two function to computing quotient and remainder
int quotient (int z ) { return z / 10; }
int reminder ( int z ) { return z % 10; }
// Simple solution to split int number into its digits
void demon ()
{ int n, d0, d1, d2, d3, d4;
cout << "Enter an integer between 1 and 32767: ";
cin >> n;
cout << n << endl;
d4 = reminder(n); n = quotient(n);
d3 = reminder(n); n = quotient(n);
d2 = reminder(n); n = quotient(n);
d1 = reminder(n); d0= quotient(n);
cout << d0 << " " << d1 << " " << d2 << " " << d3 << " " << d4 << endl;
}
// Below solution works recursively. Do you understand this?
// if you call split (4562), result is 4 5 6 2
void split(int n){
int d = n % 10; n = n / 10;
if ( n > 0) split (n);
cout << d << " ";
}
krs,
tesu | |
| All times are GMT -4. The time now is 3:16 am. | |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC