寻求C++高手,帮哈忙...
由于要半期考试,我们的c++BT老师出了个BT的题,我实在做不出来,望哪位高手指点指点!不甚感激![size=18pt][font=宋体]用C++语言编程实现如下功能:[/font] [/size][size=18pt][/size]
[size=12pt]1. [/size] [size=12pt][font=宋体]定义一个学生类其私有数据成员为:int num(学号);int age(年龄);float score(成绩);char *tname(指导教师);[/font] [/size][size=12pt][/size]
[size=12pt][font=宋体]静态数据成员为:[/font] [/size][size=12pt][/size]
[size=12pt]static float sum[font=宋体](总分);static int count(累加计数器);(均初始化为0)[/font] [/size][size=12pt][/size]
[size=12pt][font=宋体]公有成员函数:[/font] [/size][size=12pt][/size]
[size=12pt][font=宋体]构造函数:要求采用全默认值,参数初始化表的方式定义[/font] [/size][size=12pt][/size]
[size=12pt][font=宋体](默认值:1000,18,100,[/font] [/size][size=12pt]”[/size] [size=12pt]wang[/size] [size=12pt]”[/size] [size=12pt][font=宋体])[/font] [/size][size=12pt][/size]
[size=12pt]char[/size] [size=12pt] *show[font=宋体]();//功能:返回指导教师的姓名;[/font] [/size][size=12pt][/size]
[size=12pt]static[/size] [size=12pt] void display[font=宋体](teacher &);//功能:作教师类的友元函数,输出指导教师[/font] [/size][size=12pt][/size]
[size=12pt] [font=宋体]姓名,年龄,职称,所指导学生数,其总成绩;平均成绩[/font] [/size][size=12pt][/size]
[size=12pt]void total[font=宋体]();//功能:计算总分,累加参与统计的学生数。[/font] [/size][size=12pt][/size]
[size=12pt]static float average[font=宋体]();//功能:计算平均分。[/font] [/size][size=12pt][/size]
[size=12pt]2. [/size] [size=12pt][font=宋体]定义一个教师类其私有数据成员为:char *name(教师姓名);int age(年龄);int pt(教师职称:1:教师2:副教授3讲师4:助教)[/font] [/size][size=12pt][/size]
[size=12pt][font=宋体]公有成员函数:构造函数//代三个函数的构造函数。[/font] [/size][size=12pt][/size]
[size=12pt] char *showt[font=宋体]() //功能:返回教师的姓名。[/font] [/size][size=12pt][/size]
[size=12pt][font=宋体]友元函数:friend void student::display(teacher &);[/font] [/size][size=12pt][/size]
[size=12pt]3. [/size] [size=12pt][font=宋体]主函数:功能:创建学生对象数组stud[5]并初始化;创建教师对象t1;以此教师姓名检索出他所指导的学生数,并计算出其总分和平均分。最终要求输出指导教师姓名,年龄,职称,所指导学生数,其总成绩,平均成绩[/font] [/size][size=12pt][/size]
[size=12pt][/size]
[size=12pt][/size]
[size=12pt][font=宋体]要求:此题学生需在5月1日前独立完成,检查方式根据各班任课老师要求操作。[/font] [/size][size=12pt][/size]
我是菜鸟,不过我找时间写写看哈
我是菜鸟,不过我找时间帮你写写看哈::08:: ::08:: 关于作业程序,有钱我就帮忙^_^ 这个问题不是我等菜菜 能帮的了的。。。实在不好意思哦。。。。::08:: ::08::
我写了点,有些实在不会,你看下(主函数没写,有点问题)
#include <iostream>using namespace std;
class teacher;
class student
{
private:
int num; //学号
int age; //年龄
float score; //成绩
char *tname; //指导教师
static float total; //总分
static int count; //累加计数器
public:
[color=#ff00] student(int num=1000,int age=18,float score=100,char *tname=new char[5]="wang")[/color] //这一行编译有问题
{
this->num = num;
this->age = age;
this->score = score;
this->tname = new char [strlen(tname)+1];
strcpy(this->tname,tname);
total+=score;
count++;
}
char *show();
void display(teacher&);
};
class teacher{
private:
char *name; //教师姓名
int age; //年龄
int pt; //教师职称:1:教师2:副教授3讲师4:助教
public:
teacher(char *name,int age,int pt,int total)
{
this->name = new char[strlen(name)+1];
strcpy(this->name,name);
this->age = age;
this->pt = pt;
}
char *showt()
{
cout<<"老师姓名: "<<name<<endl;
}
friend void student::display(teacher&);
};
char *student::show()
{
return tname;
}
void student::display(teacher& t)
{
cout<<"教师姓名:"<<[url=http://t.name/][color=#0000ff]t.name[/color][/url]<<endl;
cout<<"教师年龄:"<<t.age<<endl;
cout<<"教师职称:";
switch([url=http://t.pt/][color=#0000ff]t.pt[/color][/url])
{
case 1:
cout<<"教师"<<endl;
break;
case 2:
cout<<"副教授"<<endl;
break;
case 3:
cout<<"讲师"<<endl;
break;
case 4:
cout<<"助教"<<endl;
break;
}
cout<<"所指导的学生数:"<<student::count<<endl;
cout<<"总成绩:"<<student::total<<endl;
cout<<"平均成绩:"<<student::total/student::count<<endl;
}
谢咯
确实是高手啊,感谢额我再继续把勒个完善一哈哈额 恩有水平呵呵::01:: ::01:: ::01:: 我晕我很菜的,我们这很多高手~~~~去年acm大赛都有进亚洲区比赛的~~~ 我还没学到这里呢...新手一个..............::07:: ::07:: ::07:: ::07:: 继续学习中 5楼的师兄把主函数写出来嘛~~~::18:: 晕,,这不是大学里面的课程设计吗??这还叫BT啊?>
回复 5# 的帖子
student(int num=1000,int age=18,float score=100,char *tname=new char[5]="wang") //这一行编译有问题形参中不用使用NEW操作符申请内存的,改为
student(int num=1000,int age=18,float score=100,char *tname="wang") 就OK了
页:
[1]
