//student.h
#pragma once
#include<string>
#include<iostream>
using namespace std;
class student
{
public:
student(void);
~student(void);
void setValues(int n,string str,char c);
void display();
protected:
int num;string name;
char sex;
};
//student.cpp
#include"student.h"
using namespace std;
student::student(void){}
student::~student(void){}
void student::setValues(int n,string str,char c)
{num=n;name=str;sex=c;}
void student::display()
{
cout<<num<<""<<name<<""<<sex<<endl;
}
//postgraduent.h
#include"student.h"
class postgraduent:public student
{
public:
postgraduent(void);
~postgraduent(void);
void setAdvisor(string str)
{advisor=str;}
string getAdvisor(){return advisor;}
private:
string advisor;
};
//postgraduent.cpp
#include "postgraduent.h"
postgraduent::postgraduent(void)
{
}
postgraduent::~postgraduent(void)
{
}
//main.cpp
#include"postgraduent.h"
void main()
{
postgraduent xq;
xq.setValues(1122,"Xiao Qiang",'M');
xq.getAdvisor("Prof.Zhu");
xq.display();
cout<<"Advisor:"<<xq.getAdvisor()<<endl;
}
标签:string,postgraduent,练习,第三天,str,student,include,部分,void From: https://www.cnblogs.com/kuandong24/p/17324104.html