#include <iostream.h>
#include <string.h>
class Student
{
public:
Student(int age,string& sex,string& name)
:m_age(age),m_sex(sex),m_name(name)
{
}
Student()
{
}
virtual void setAge(int age)
{
m_age = age;
}
virtual void setSex(string& sex)
{
m_sex = sex;
}
virtual void setName(string& name)
{
m_name = name;
}
virtual int getAge()
{
return m_age;
}
virtual string& getSex()
{
return m_sex;
}
virtual string& getName()
{
return m_name;
}
virtual void print()=0;
private:
int m_age;
string m_sex;//0 for male/1 for female
string m_name;
};
class Undergraduate : public Student
{
public:
Undergraduate(int age,string& sex,string& name,string& degree)
:Student(age,sex,name),m_degree(degree)
{
}
Undergraduate()
{
}
void setAge(int age)
{
Student::setAge(age);
}
void setSex(string& sex)
{
Student::setSex(sex);
}
void setName(string& name)
{
Student::setName(name);
}
void setDegree(string& degree)
{
m_degree = degree;
}
int getAge()
{
return Student::getAge();
}
string& getSex()
{
return Student::getSex();
}
string& getName()
{
return Student::getName();
}
string& getDegree()
{
return m_degree;
}
void print()
{
cout << this->getName() << ',' << this->getAge() << ','
<< this->getSex() << ',' << this->getDegree() << endl;
}
private:
string m_degree;
};
class Graduate : public Student
{
public:
Graduate(int age,string& sex,string& name,string& degree)
:Student(age,sex,name),m_degree(degree)
{
}
Graduate()
{
}
void setAge(int age)
{
Student::setAge(age);
}
void setSex(string& sex)
{
Student::setSex(sex);
}
void setName(string& name)
{
Student::setName(name);
}
void setDegree(string& degree)
{
m_degree = degree;
}
int getAge()
{
return Student::getAge();
}
string& getSex()
{
return Student::getSex();
}
string& getName()
{
return Student::getName();
}
string& getDegree()
{
return m_degree;
}
void print()
{
cout << this->getName() << ',' << this->getAge() << ','
<< this->getSex() << ',' << this->getDegree() << endl;
}
private:
string m_degree;
};
int main()
{
Undergraduate wang;
int age = 23;
string sex = "nan";
string name = "wangming";
string degree = "benke";
wang.setName(name);
wang.setAge(age);
wang.setSex(sex);
wang.setDegree(degree);
wang.print();
Graduate liu;
name = "liujun";
age = 27;
sex = "nan";
degree = "shuoshi";
liu.setAge(age);
liu.setName(name);
liu.setSex(sex);
liu.setDegree(degree);
liu.print();
}