×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Creating a class

Creating a class

Creating a class

(OP)
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.

RE: Creating a class

After that let's divide your homework grade into equal parts...
 

RE: Creating a class

(OP)
LOL. ok can you help me out I don't want anyone to do it for me I just want to start the steps.

RE: Creating a class

Post what you have so far and let us know what parts you're having trouble with.

RE: Creating a class

(OP)
Ok thanks

RE: Creating a class

(OP)
#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. "

 

RE: Creating a class

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().

Quote:

(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.

RE: Creating a class

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close