类的继承

#pragma once
#include<iostream>
#include<string>
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;
};

 

#include "student.h"


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;
}

 

#pragma once
#include"student.h"
#include<string>
#include<iostream>
using namespace std;
class postgraduent:public student
{
public:
postgraduent(void);
~postgraduent(void);
void setadvisor(string str)
{
advisor=str;
}
string getadviosr()
{
return advisor;
}
private:
string advisor;
};

 

#include "postgraduent.h"


postgraduent::postgraduent(void)
{
}


postgraduent::~postgraduent(void)
{
}

 

#include"postgraduent.h"
void main()
{
postgraduent xq;
xq.setvalues(1122,"xiao",'m');
xq.setadvisor("xiaoqiang");
xq.display();
cout<<"advisor"<<xq.getadviosr()<<endl;
}

 

posted @ 2023-05-22 22:04  八千里路云和月色  阅读(17)  评论(0)    收藏  举报