Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,628 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,039 people online right now. Registration is fast and FREE... Join Now!




Class Implementation

 
Reply to this topicStart new topic

Class Implementation

card
post 5 Apr, 2006 - 10:51 AM
Post #1


New D.I.C Head

*
Joined: 5 Apr, 2006
Posts: 1


My Contributions


OK, so I am REALLY new to object oriented programming and I am currently working on an assisgnment concerning inheritance.

Basically, my professor wants us to create a base class, then two more classes, each inheriting from the one before. The thing is, I have the declaration and implementation sections written, but I am not sure if I coded the constructors for all my classes properly or not. I attempted to use a base member initailization list in the constructors for both of my inheritance classes.

So, basically I need to know if I am doing this right.........I think I am but have no one to check it with or compare.



CODE
#include <iostreeam>
using namespace std;



//class declarations
class Person
{
 protected:
   char *ptrname;
   long social;
 public:
   Person (char * + '\0', long);
   void print ();
   ~Person (){cout<<"Destructor activated"<<endl;};
}

class Hourly_employee: public Person
{
 protected:
   float rate;
   float hours;
 public:
   Hourly_employee (char name, long social, float rate=19.50, float hours=40):Person(name,social), rate(whatrate), hours(howmanyhours);
   void print();
   ~Hourly_employee(){cout<<"Destructor activated"<<endl;
}

class Salaried_employee: public Hourly_employee
{
 protected:
   float salary;
 public:
   Salaried_employee (char name, long social, float whatrate, float howmanyhours, float salary=0):Hourly_employee(name,social,whatrate,howmanyhours),salary(calcsalary);
   void print();
}



//implementation section
Person::Person (char *ptrname, long socnum)
{
 name=new char [strlen(ptrname)+1];
 strcpy (name,ptrname);
 social=socnum;
}

void Person::print()
{
 cout<<"This is a call to the base function:"<<endl<<name<<endl<<social<<endl;
 return;
}

void Hourly_employee::print ()
{
 cout<<"This is a call to the employee function:"<<endl<<Person::print()<<whatrate<<endl<<howmanyhours<<endl;
 return;
}

void Salaried_employee::print()
{
 calcsalary=whatrate*howmanyhours;
 cout<<"This is a call to the salary function:"<<endl<<Hourly_employee::print()<<endl<<calcsalary<<endl;
 return;
}


Attached File(s)
Attached File  csc134_lab5_1 ( 1.43k ) Number of downloads: 4
User is offlineProfile CardPM

Go to the top of the page

henry
post 6 Apr, 2006 - 12:11 AM
Post #2


D.I.C Head

**
Joined: 3 Jan, 2006
Posts: 96


My Contributions


Here is my code with edited...................
I also study inherritance. But I know a bit only.... cannot help
My code can run.......don't be afraid

-----------------------------------------------------------------------------------
#include <iostream>
using namespace std;

//class declarations
class Person
{
protected:
char * name;
long social;
public:
Person (char * = "", long = 0);
void print ();
~Person (){cout<<"Destructor activated in Person"<<endl;}
};

class Hourly_employee: public Person
{
protected:
float rate;
float hours;
public:
Hourly_employee (char * n, long s, float r=19.50, float h=40 ):Person(n,s),rate®,hours(h){};
void print();
~Hourly_employee(){cout<<"Destructor activated in Hourly_employee "<<endl;}
};

class Salaried_employee: public Hourly_employee
{
protected:
float salary;
public:
Salaried_employee (char * name, long social, float whatrate, float howmanyhours, float sal=0):Hourly_employee(name, social, whatrate,howmanyhours),salary(sal){};
void print();
};


//implementation section
Person::Person (char * ptrname, long socnum)
{
name=new char [strlen(ptrname)+1];
strcpy (name,ptrname);
social=socnum;
}

void Person::print()
{
cout<<"This is a call to the base function:"<<endl<<name<<endl<<social<<endl;
return;
}

/*Hourly_employee::Hourly_employee( float r, float h)
{
rate=r;
hours=h;
}*/

void Hourly_employee::print ()
{
cout<<"This is a call to the employee function:"<<endl;
Person::print();
cout<<rate<<endl<<hours<<endl;
return;
}

/*Salaries_employee::Salaries_employee(float sal)
{
salary=sal;
}*/

void Salaried_employee::print()
{
salary=rate*hours;
cout<<"This is a call to the salary function:"<<endl;
Hourly_employee::print();
cout<<endl<<salary<<endl;
return;
}

void main()
{

Salaried_employee obj("Micheal",12,10,1,2);
obj.print();
}

---------------------------------------------------------------------------------

You program should put setdata so you can ask user to input........
Edit it.....by yourself.........I cannot help you in this rolleyes.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 03:41AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month