求大神帮忙解决 - 爱问答

(爱问答)

求大神帮忙解决

#include<iostream.h>#include<string.h>class student{  private:   int x;   char y[16];   float z;   public:    student(int a,char b[16],float c)    {     x=a;    strcpy(y,b);          z=c;   cout<<"调用学生类构造函数"<<endl;    }    void show()    {cout<<"学号"<<x<<' '<<"姓名"<<y<<' '<<"分数"<<z<<endl;}    ~student()    {cout<<"调用学生析类构函数"<<endl;}};class teacher{  private:   int q;   char w[16];   float e;   public:    teacher(int u,char i[16],float o)    {     q=u;    strcpy(w,i);          e=o;   cout<<"调用教师类构造函数"<<endl;    }    void show()    {cout<<"职工号"<<q<<' '<<"姓名"<<w<<' '<<"工资"<<e<<endl;}    ~teacher()    {cout<<"调用教师类析构函数"<<endl;}};class stu_tea:public student,public teacher{    public:    stu_tea(int a,char b[16],float c ,int u,char i[16],float o) :student(a,b[16],c),teacher(u,i[16],o)    {    strcpy(y,b) strcpy(w,i);}    void show()    {cout<<"职工号信息"<<endl;}    ~stu_tea()    {cout<<"调用助教类析构函数"<<endl;}};void main(){  stu_tea t(10001,"abc",88,10002,"chi",4000);t.student::show();t.teacher::show ();t.stu_tea::show ();t.student::~student ();t.teacher::~teacher ();t.stu_tea::~stu_tea ();}

1。下次提问一定要排好版的

2。你的问题主要出在

public:  

  stu_tea(int a,char b[16],float c ,int u,char i[16],float o) :student(a,b[16],c),teacher(u,i[16],o) 

   {    strcpy(y,b) strcpy(w,i);}   

其中又有多个问题

1)student构造的第二个参数是数组,你的b[16]是数组的元素非数组

2)同样teacher的i[16]也是

3) strcpy(y,b) strcpy(w,i);两个函数间少分号了

4) 即使改为strcpy(y,b);strcpy(w,i);,你的y,w都是父类的私有成员,你的继承类是不能访问的,也你的初始化已完成对y,w的赋值了啊,所以是画蛇添足了

直接改为

    stu_tea(int a,char b[16],float c ,int u,char i[16],float o) :student(a,b,c),teacher(u,i,o) //修改

        {

            //  strcpy(y,b) ; //删除

            //  strcpy(w,i);  //删除

        }

3。你的

#include<iostream.h>

void main()

这样的写法是非ISO C++标准的写法,只能用于上世纪淘汰的vc++6.0(你的教材太老了)

标准的是

#include<iostream>

#include<string.h>

using namespace std;

...

int main()

{

...

return 0;

}

程序的最终结果为

求大神帮忙解决

相关标签:大神

下一篇:如何把安装目录重命名后,让程序仍能运行

上一篇:javaWeb使用EL表达式和JSTL怎么实现页面的文本框中输入内容,单击页面提交按钮后,输入框

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?