Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a class 1

Status
Not open for further replies.

Mirak

Programmer
Aug 1, 2001
28
0
0
Create a class called DigitSeparator. This class will only have one function called separator. Function separator will have ONE parameter of type long int which will be used to accept a six-digit number. Function separator will take the number passed to the parameter and separate it into its individual digits, multiply each separated digit by 2 and then print the digits separated from one another by three spaces each. (Hint: use a combination of integer division and modulus division to split the number into digits.) Create a driver program that will contain a main function that will create a DigitSeparator object and then call its separator function. Function main should ask the user for a number, and then pass this number to the function separator.

Can anyone help me creat this class new to programming and I have no Idea how to start.
 
After that let's divide your homework grade into equal parts...
 
LOL. ok can you help me out I don't want anyone to do it for me I just want to start the steps.
 
Post what you have so far and let us know what parts you're having trouble with.
 
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <string> // program uses C++ standard string class
using std::string;
using std::getline;

// Class DigitSeparator definition

class DigitSeparator

{

public:

// this function will will be used to accept six-digit number

int separator ( long int )

{
cout << " Please enter a six-digit number/n"; << int << endl;

} // ends function separator

}; // ends class DigitSeparator


Please let me know if I am going correct. I don't k now what he means by this line

"Function separator will take the number passed to the parameter and separate it into its individual digits, multiply each separated digit by 2 and then print the digits separated from one another by three spaces each. "

 
Looks good so far, except if you're putting the separator() function definition together with the declaration (i.e. not splitting it into a .h & .cpp file) then you need to give a variable name for the long parameter, and I don't see a requirement that separator() needs to return a value, so void should be fine:
Code:
void separator( long num ) // long and long int are the same thing.
Also, get the cout line out of separator. You need to get the number from the user in your main() function and just pass that number to separator().

(Hint: use a combination of integer division and modulus division to split the number into digits.)
Did your teacher talk about this? If not, it must be in the chapters of your book that you've read so far.
 
Hi, ok that is it yes and yes we need to have a .h and .cpp file. And yes he have asked us to use / and %. thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top