有哪位大佬帮忙编一下这个c++程序啊



程序参考#include<iostream>#include<string>usingnamespacestd;classStudent//基类Student{protected:stringname;//姓名intno;//学号public:Student(stringx,inty)//构造{name=x;no=y;}};classHSStudent:publicStudent//公用派生类HSStudent{protected:stringcourse[6]={"数学","语文","英语","生物","物理","化学"};intscore[6];//6门课的成绩private:voidmysort()//排序{inti,j,t;stringst;for(i=0;i<5;i++)for(j=i+1;j<6;j++)if(score[i]<score[j]){t=score[i];score[i]=score[j];score[j]=t;st=course[i];course[i]=course[j];course[j]=st;}}public:HSStudent(stringx,inty):Student(x,y){}voidinput()//输入成绩{for(inti=0;i<6;i++){cout<<course[i]<<":";cin>>score[i];}}voidoutput()//输出{mysort();cout<<name<<",学号:"<<no<<"的成绩为";for(inti=0;i<6;i++)cout<<course[i]<<""<<score[i]<<"";cout<<endl;}};intmain(){Student*s;//定义指向基类对象的指针变量stringa;intb;////输入学生的姓名、学号cout<<"姓名:";cin>>a;cout<<"学号:";cin>>b;s=newHSStudent(a,b);//调用构造((HSStudent*)s)->input();//输入6门成绩((HSStudent*)s)->output();}结果

上一篇: 下一篇:


相关目录文章: