/**********************************************************/
//Class : Student类
//parm :
//comment :
//return : void
//Author :
//date : 2011.10.30
/**********************************************************/
#include <iostream.h>
#include <string.h>
#include <stdio.h>
class Student{
public:
Student(char *n,char *s,int num,double *sco);
~Student();
double GetSum();
double GetAver();
double GetMax();
double GetMin();
void Show();
private:
char *name; //student name
char *stuno; //student no
int score_num; //score number
double *score; //student score
};
Student::Student(char *n,char *s,int num,double *sco)
{
name=new char[20];
stuno=new char[10];
strcpy(name,n);
strcpy(stuno,s);
score_num = num;
score=new double[score_num];
for(int i = 0;i < score_num;i++)
{
*(score + i)=*(sco + i);
}
}
Student::~Student()
{
delete []name;
delete []stuno;
delete []score;
}
double Student::GetSum()
{
double temp = 0;
for(int i = 0;i < score_num;i++)
temp += *(score + i);
return temp;
}
double Student::GetAver()
{
return GetSum() / score_num;
}
double Student::GetMax()
{
double temp = *score;
for(int i = 0;i < score_num;i++)
if(temp < *(score + i))
temp = *(score + i);
return temp;
}
double Student::GetMin()
{
double temp = *score;
for(int i = 0;i < score_num;i++)
if(temp > *(score + i))
temp = *(score + i);
return temp;
}
void Student::Show()
{
cout<<"The student's name is:"<<name<<endl;
cout<<"The student's stuno is:"<<stuno<<endl;
cout<<"The student's score are:"<<endl;
for(int i = 0;i < score_num;i++)
cout<<*(score + i)<<" ";
cout<<endl;
cout<<"The student's sum of score is:"<<GetSum()<<endl;
cout<<"The student's Average of score is:"<<GetAver()<<endl;
cout<<"The student's maximum of score is:"<<GetMax()<<endl;
cout<<"The student's minimum of score is:"<<GetMin()<<endl;
}
void main()
{
char *name=new char[20];
char *stuno=new char[8];
int num;
cout<<"Please input the student's name:"<<endl;
cin>>name;
cout<<"Please input the student's NO:"<<endl;
cin>>stuno;
cout<<"Please input the num of student's score:"<<endl;
cin>>num;
double *score = new double[num];
cout<<"Please input the scores of student:"<<endl;
for(int i = 0;i < num;i++)
cin>>score[i];
Student stu1(name,stuno,num,score);
stu1.Show();
}

被折叠的 条评论
为什么被折叠?



