well the problem is i want to write the person's name from preson class to instructor class using inhertiance, i have come up with the following code but gives error .. can someone tell me what am i missing or what can be done. its like sharing from person class to instructor class thats what i need...
#include <iostream>
#include <string>
using namespace std;
class Person
{
public:
Person() { }
Person( string nam, string day);
string get_name()const;
string get_date()const;
void print()const;
private:
string name;
string date;
};
Person::Person( string nam,string day)
{
name= nam;
date= day;
}
string Person::get_name() const
{
return name;
}
string Person::get_date() const
{
return date;
}
void Person::print()const
{
cout<<"\nMr/Mrs: "<<name<<" was born on "<<date<<"\n";
}
class Instructor : public Person
{
public:
Instructor () {}
Instructor(double sal);
double get_salry() const;
string get_infoname()const;
string get_infodate1()const;
void print()const;
private:
double salry;
string date1;
string namei;
};
Instructor::Instructor(double sal)
{
salry=sal;
}
double Instructor::get_salry() const
{
return salry;
}
string Instructor::get_infoname()const
{
namei=Person::get_name();
return namei;
}
string Instructor::get_infodate1()const
{
date1=Person::get_date();
return date1;
}
void Instructor::print()const
{
system("cls");
cout <<"============================================\n";
cout <<"Instructor Name : " <<namei <<"\n";
cout <<"Instructor D.O.B : " <<date1<<"\n";
cout <<"Instructor Salary : " <<salry<<"\n";
cout <<"============================================\n";
}
int main ()
{
string nam1;
string dat1;
string maj1;
int val;
double sal1;
cout<< "Please enter the name of Person \n";
getline (cin,nam1);
cout<< "Please enter the date of birth in the format dd/mm/yyyy \n";
cin>>dat1;
cout<< " Please Enter one of the below choices \n 1 for instructor \n";
cout<< " 0 for none of the above \n";
cin>>val;
if (val==1)
{
system("cls");
cout<<" Please enter the Instructor's Salary:\n";
cin>>sal1;
Instructor obj(sal1);
obj.print();
}
if (val==0)
{
Person obj(nam1,dat1);
obj.print();}
return 0;
}