C++编程 建立一个person类 包括姓名,性别,年龄。派生出一个student类,增加 学号 成绩。

2025-02-26 12:55:29
推荐回答(2个)
回答1:

错误很多

class person
{
char *name,sex;
int age;
public:
person(char *pname,char s,int a) //你应该定义构造函数,因为你在子类中的构造函数调用了基类的构造函数
{
name=pname;
sex=s;
age=a;
}
}; //类定义结束要加分号
class student:public person
{
public:
student(char *pname,char s,int a,char n,float f):person(pname,s,a) //必须定义基类的构造函数才可以在子类的构造函数中调用基类的构造函数
{
number=n;
score=f;
}
void dispaly()
{ cout<<"姓名:"< }
private:
char number;
float score;
}; //类结束要加分号
void main()
{
student s1("李明","男",21,"090301",82");
s1.display();
}

回答2:

你调试运行,看看错误号,把错误号发上来