您的位置:首页 > 编程语言 > C语言/C++

看你是不是编程高手。。。。 用C++ 写一个学生类和课程类

2008-10-20 09:12 471 查看
3.1); lisi.add (&math char* argv[]){ course math("math"); course physics("physics"); stu zhangsan("zhangsan"); stu lisi("lisi"); zhangsan.add (&math cs)==0) return cours[i]->getscore(this->nm()); else cout << "he doesn't opt that course" << endl;}float stu::average (){ float sum=0; for (int i=0;i<cnt;++i) sum=cours[i]->getscore(this); return sum/cnt;}int main(int argc sc);}float stu::get_score(char* cs){ for (int i=0;i<cnt;++i) if (strcmp(cours[i]->nm() float sc){ cours[cnt++]=cs; cs->add(this nm);}void stu::add(course* cs nm)==0) return score[i]; else cout << "can not find that student" << endl;}float course::getscore (stu* st){ for (int i=0;i<cnt;++i) if (student[i]==st) return score[i];}float course::average(){ float sum=0; for (int i=0;i<cnt;++i) sum+=score[i]; return sum/cnt;}// student implementaionstu::stu(char* nm):cnt(0){ strcpy(name float sc){ student[cnt]=st; score[cnt++]=sc;}float course::getscore(char* nm){ for (int i=0;i<cnt;++i) if (strcmp(student[i]->nm() nm);}void course::add(stu* st float sc = 0); float get_score(char* nm); float average();};// course implemetaioncourse::course(char* nm):cnt(0){ strcpy(name float sc); float getscore(char* nm); float getscore(stu* st); float sc(int n){return score
;} float average();};// student class class stu{ char name[20]; int cnt; course* cours[5];public: stu(char* nm); char* nm() {return name;} void add(course* cs
#include <iostream.h>#include <string.h>class stu;#define size 20// course class class course { //static const size = 20; char name[20]; stu* student[size]; int cnt; float score[size];public: course(char* nm); char* nm() {return name;} void add(stu* st 4.5); cout << math.average (); int stop; cin >> stop; return 0;}大概就是这样的 你看看行不
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: