| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 716 人关注过本帖
标题:求教各位大虾,有道题不大会,又不知错哪了
只看楼主 加入收藏
rony
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-4-6
收藏
 问题点数:0 回复次数:1 
求教各位大虾,有道题不大会,又不知错哪了

帮我看一下这道题啊...谢谢!
定义一个Student类,在该定义中包括:一个数据成员score(分数)及两个静态数据成员total(总分)和学生人数count;成员函数scoretotalcount(float s)用于设置分数,求总分和累计学生认数;静态成员函数sum()用于返回总分:静态成员函数average()求平均值.在main函数中输入某班同学成绩,调用上述函数求全班学生总分和平均分
我自己编了一个程序,可是不知错哪了,请帮帮忙,谢谢!程序见附件

搜索更多相关主题的帖子: 知错 
2007-04-06 04:50
Majorone
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-3-29
收藏
得分:0 

看不到你的附件,所以自己写了一个.
为了简单,没用指针,基本上可以满足题目的要求.

#include <iostream.h>

class Student
{
public:
Student()
{
count++;//when set up a object,the number of the students add one.
}
void scoretotalcount(double s);//set the score
static double sum();//return the total score
static double average();//average score
private:
double score;
static double total;//the sum of score
static int count;//number of students
};

double Student::total=0;
int Student::count=0;

void Student::scoretotalcount(double s)
{
score=s;
total=total+score;
}

double Student::sum()
{
return total;
}

double Student::average()
{
return (total/count);
}

void main()
{
int i=0,scor=0,k;
double sum_score,average_score;
cout<<"欢迎使用成绩统计系统"<<endl;
do
{ Student student;//此处本人认为有些不妥,只是为了满足题目而写,如需每个学生的成绩则需指针建链表比较好.
cout<<"请输入第"<<i+1<<"个学生的成绩:"<<endl;
cin>>scor;
student.scoretotalcount(scor);
cout<<"是否继续输入学生成绩?是选择1,否选择0:"<<endl;
cin>>k;
i++;
}while(k!=0);
sum_score=Student::sum();
cout<<"学生总分数为:"<<sum_score<<endl;
average_score=Student::average();
cout<<"学生平均分数为:"<<average_score<<endl;
}

2007-04-07 21:33
快速回复:求教各位大虾,有道题不大会,又不知错哪了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011211 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved