作者:只是遇不到他_740 | 来源:互联网 | 2023-06-01 20:23
题目:设计评选优秀教师和学生的程序先定义一个基类CBase,类中有保护成员姓名:name[10],虚函数isgood(),由CBase派生的两个类:student和teacher,在stude
题目:设计评选优秀教师和学生的程序
先定义一个基类CBase,类中有保护成员姓名:name[10],虚函数isgood(),由CBase派生的两个类:student和teacher,在student中定义私有成员学号stunymber和考试成绩score1、score2、score3,定义setscore()设置三门成绩的值,并定义isgood()函数,如果学生平均成绩大于90分且最低分不低于85分,则isgood()返回ture,否则返回false。在teacher类中定义教工号teanumber和论文名称数组Paper[],定义SetPaper输入论文题目保存到Paper[]中,再定义isgood()函数,如果论文数目多于三篇则isgood()返回ture,否则返回false,最后设计完整的程序进行演示,输出评选结果
24 个解决方案
呵呵!是课程设计吧!我想还是你自己先写吧!有问题再讨论!
我也要做真个题,真实巧哦!
呵呵,正在写,一起讨论下吧!
都说的那么清楚了,基本上就是用代码翻译了。自己写吧,很简单的。
没有写注释,相信你能看的懂的!
#include
#include
using namespace std;
class CBase
{
public:
char name[10];
public:
virtual bool isgoods(void) = 0;
};
class Student : public CBase
{
private:
int stunumber;
int score1;
int score2;
int score3;
public:
bool isgoods()
{
bool flag = false;
int average = (score1+score2+score3)/3;
if(average>90)
flag = true;
if(flag && score1 >= 85 && score2 >= 85 && score3 >= 85)
return true;
else
return false;
}
void setSocore(int sorce1,int score2,int score3)
{
this->score1 = sorce1;
this->score2 = score2;
this->score3 = score3;
}
};
class Teacher : public CBase
{
private:
int teanumber;
vector Paper;
public:
bool isgoods()
{
int size = Paper.size();
if(size > 3)
return true;
else
return false;
}
void setPaper(string name)
{
Paper.push_back(name);
}
};
//测试
#include
using namespace std;
#include "MyClass.cpp"
void main()
{
Student *stu = new Student();
Teacher *tea = new Teacher();
stu->setSocore(100,100,100);
if(stu->isgoods())
cout << "the stu01 is ture!" << endl;
else
cout << "the stu01 is false" << endl;
stu->setSocore(100,80,100);
if(stu->isgoods())
cout << "the stu02 is ture!" << endl;
else
cout << "the stu02 is false" << endl;
tea->setPaper("number1");
tea->setPaper("number2");
tea->setPaper("number3");
if(tea->isgoods())
cout << "the tea01 is turn!" << endl;
else
cout << "the tea01 is false!" << endl;
tea->setPaper("number4");
if(tea->isgoods())
cout << "the tea02 is turn!" << endl;
else
cout << "the tea02 is false!" << endl;
}
结果:
the stu01 is ture!
the stu02 is false!
the tea01 is false!
the tea02 is turn!
比较简单的题,大家相互学习吗,也不必太计较那些分吧。
不过楼主还是自己写着,不懂的地方大家讨论,这样才能进步!
题目上都说得这么清楚了,类,私有成员等都很明白了,楼主真的可以自己试一下的啊。