Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Setting up a Class

How do I set up a Person Class to include attributes name,date of birth,date of joining,payroll reference. Methods are: default constructor;constuctor with all details;display;changeName;getName;getDob;getReference;validateAge;?????????????
0
c9725458
Asked:
c9725458
  • 7
  • 5
  • 2
  • +1
1 Solution
 
msmitsCommented:
Probably by reading a text-book on C++ first...
You could just define the class with all the items you mention as member variables and the functions you mention as member functions.

0
 
c9725458Author Commented:
That doesn't really help. I'm not too good at C++. I've tried reading about this but I don't get it
0
 
c9725458Author Commented:
Adjusted points to 100
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
msmitsCommented:
Maybe it is best to attend the lectures next time :-) This is very basic C++, the description I gave should be enough to get you on the way. If it doesn't you may be needing an easier book on C++.

0
 
nietodCommented:
If you will attempt your homework and post what you get done, we would be happy to ofter suggestions.  Or if you have SPECIFIC questions we can answer them. Other than that, it would be unethical for us to help you.
0
 
c9725458Author Commented:
Thanks I'll do that.
0
 
c9725458Author Commented:
Am I on the right track for creating the .h file?

.h file

class Person{
             charName;
             intDOB;
             intDateOfJoining;
             intPayrollRef;
Person();    //default constructor??

bool SetElement(whatever attributes);

int GetElement(whatever attributes,
               bool& bError);  
0
 
nietodCommented:
Good start.  you are missing spaces after your types.  should be "char name" not "charname".

continued.
0
 
nietodCommented:
Now

char Name;

will store only one character.  Most names are longer than that.  You can use a fixed size aray to store the name so long as you don't have names longer than the array size like

char Name[21];

which can store a name up to 20 characters long (plus one more char for terminator.)  The other option is to store the name in a dynamically alocated array.  The class must manage this array to prevent memory leaks.  If you are not familair with new and delete, go with the fixed size array.

You are hoping to store dates in a integer?  how will you do that?  Most people store dates as 3 seperate values (month, day, year).  Since you have more than one date in the class you might want to create a date class to store the date.  It could store three values.  The month, the date, and the year.  The month could be an integer or an enumerated type.  The date and the year should probably be integers.  

Try these changes and post back what you get.
0
 
c9725458Author Commented:
Still on the right track?
.cpp
#include<Person.h>
#include<iostream.h>
#include<conio.h>

Person ::Person();

bool Person::SetElement(variables)
{  
    //main part
};  //end of Person::SetElement

char Person::GetElement (variables,
                         bool& bError)
{
  // main part
} //end of Person::GetElement()
0
 
c9725458Author Commented:
Thanks for the help.
I'll come back in the next couple of days and check my solution with you if that's alright.
0
 
nietodCommented:
I'm not sure what you are hoping to do with the set element/get element stuff.  Why not continue to get the class's data members into the class (like in your first try).  Then we'll worry about the procedure member.
0
 
RONSLOWCommented:
Her are my comments on what you've done...

class Person{
// this is fine

  char Name;
// this only holds a single charactre - not much of a name!
// change to 'char Name[MAXNAME];' and add before this
// 'enum { MAXNAME=xxx};' where xxx is max number of chars (+1)
// that a name can hold

  int DOB;
// I'd use one of the standard C types for the date rather
// than putting it in an int.

  int DateOfJoining;
// same here

  int PayrollRef;
// assuming a payroll ref is jsut an integer number

  Person();    //default constructor??
// yes .. this is the default constructor

  bool SetElement(whatever attributes);
// instead of this, a better choise is to have separate
// set/get for each attribute.  eg.
//   bool SetPayrollRef(int newPayrollRef) {
//     PayrollRef = newPayrollRef;
//     return true; // cannot fail
//   }

int GetElement(whatever attributes,
               bool& bError);  
// I'd reverse this to make it consistent with SetElement
// andalso make it a const function (because it does not
// change your person object
// ie.
//    bool GetElement(whatever& attributes) const;
// eg.
//    bool GetPayrollRef(int& oldPayrollRef) const {
//      oldPayrollRef = PayrollRef;
//      return true; // cannot fail
//    }

Hope this helps you.

0
 
nietodCommented:
How is it going?  I figured you would try my suggestions and get back.  Or did you get it working?
0
 
c9725458Author Commented:
I'm working on the next part of the assesment now. Thanks for your help.
I'll post it when I've had a good go.
0
 
RONSLOWCommented:
Hope my comments were helpful as well.

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now