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