#include<iostream>
using namespace std;
#include<string>
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::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;
}
class postgraduent : public student {
public:
postgraduent(void);
~postgraduent(void);
void setAdvisor(string str) {
advisor = str;
}
string getAdvisor() {
return advisor;
}
private:
string advisor;
};
postgraduent::postgraduent(void) {
}
postgraduent::~postgraduent(void) {
}
void main() {
postgraduent xq;
xq.setValues(1122, "小强", 'M');
xq.setAdvisor("Prof.Zhu");
xq.display();
cout << "Advisor:" << xq.getAdvisor() << endl;
system("pause");
}
#include<iostream>
using namespace std;
#include<string>
class CPolygon {
protected:
int width, height;
public:
void set_values(int a, int b)
{
width = a; height = b;
}
};
class CRectangle : public CPolygon {
public:
int area()
{
return (width * height);
}
};
class CTriangle : public CPolygon {
public:
int area()
{
return (width * height / 2);
}
};
标签:string,int,postgraduent,public,student,4.22,void From: https://www.cnblogs.com/lml66/p/17344393.html