#include<iostream>
#include<string> // 使用 <string> 替代之前的头文件
using std::cout;
using std::endl;
class person
{
public:
// 使用 const char* 而不是 char*
person(const char* a, const char* b)
{
name = a;
num = b;
}
void Getterab()
{
cout << "name:" << name << " " << "num:" << num << " ";
}
private:
const char* name; // 使用 const char* 而不是 char*
const char* num; // 使用 const char* 而不是 char*
};
class student : public person
{
private:
const char* number;
double score;
public:
student(const char* a, const char* b, const char* c, double d) : person(a, b)
{
number = c;
score = d;
}
void show()
{
Getterab();
cout << "number:" << number << " " << "score:" << score << "\n";
}
};
class teacher : public person
{
private:
const char* section;
const char* job;
public:
teacher(const char* a, const char* b, const char* c, const char* d) : person(a, b)
{
section = c;
job = d;
}
void show1()
{
Getterab();
cout << "section:" << section << " " << "job:" << job << endl;
}
};
int main()
{
student a("张三", "24", "1", 82);
a.show();
teacher b("李四", "01", "网络系", "老师");
b.show1();
return 0;
}
C++-编写一个学生和教师数据输入和显示程序 学生数据有编号、姓名、班号和成绩; 教师数据有编号、姓名、职称和部门。 要求将编号、姓名的输入和显示设计成一个类person,并作为学生数据操作类
于 2020-08-04 20:11:34 首次发布