#include <string>
#include <iostream>
using namespace std;
//People类
class People
{
public:
string Name;
void PrintName();
};
//Student类公有继承 People类
class Student : public People
{
public:
int SID;
void PrintSID();
};
void People::PrintName()
{
cout << "姓名:" << Name << endl;
}
void Student::PrintSID()
{
//输出 SID
cout << "学号:" << SID << endl;
}
void Set(int sid, string name, Student* ptr)
{
//给 ptr 对象的两个属性赋值
ptr->SID=sid;
ptr->Name = name;
}
int main()
{
int id;
string name;
cin >> id >> name;
Student st;
Set(id, name, &st);
st.PrintSID();
st.PrintName();
}
头歌实训项目【公有继承——学生信息类】
最新推荐文章于 2024-05-18 00:33:12 发布