第三次实验参考代码

/**********************************************************/ //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(); }
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值