# 请教:两个相互关联的重用类的定义

ps:千辛万苦在网上找到一习题解答,这题里面竟然是ignore,郁闷

...全文
52 4 点赞 打赏 收藏 举报

4 条回复

• 打赏
• 举报

freefalcon 2004-05-07

——欣赏，有前途，赞一个，:)

struct student //只包含基本属性
{
string name;
int age;
string number; //学号
};

struct course
{
string name;
string number; //编号
};

struct student_course
{
string student_number; //学号
string course_number; //课程号
int score; //分数
}

class course_manager //选课系统类
{
public:
void student_select_course(const student& s, const course& c); //选课
void get_student_courses(vector<course>& vec); //查询选了哪些课
...........
private:
vector<student> students; //所有学生
vector<course> courses; //所有课程
vector<student_course> scs; //关系表
};

• 打赏
• 举报

cngdzhang 2004-05-07

class Course
{
private:
int coursenum;
double point;
Student student[30];
int currentStudent;
public:
double getPoint()
{
return point;
}
void setPoint(double p)
{
point=p;
}
int getStudentNumber()
{
return currentStudent;
}
{
student[currentStudent]=st;
currentStudent++;
}
double getAvgScore()
{
int i;
double sum=0.0;
for(i=0;i<currentStudent;i++) sum+=student[i].getscore(scorenum);
return sum/currentStudent;
}

}
• 打赏
• 举报

cngdzhang 2004-05-07

class student
{
private:
char name[20];
int course[5];
double coursescore[5];
int toalcourse;
public:
void getName(char *s)
{
strcpy(s,name);
};
void setName(char *s);
{
strcpy(name,s);
}
double getScore(int c)
{
if(c<=0 || c>totalcourse) return -1;
return coursescore[c-1];
}
void setScore(int c,double score)
{
if(c<=0 || c>totalcourse) return;
coursescore[c-1]=score;
}
double getAvgScore()
{
double sum=0.0;
int i;
for(i=0;i<totalcourse;i++) sum+=coursescore[i];
return sum/totalcourse;
}
{
course[totalcourse]=c;
coursescore[toalcourse]=0.0;
totalcourse++;
}
};
• 打赏
• 举报

6.0w+

C++ 语言相关问题讨论，技术干货分享，前沿动态等

2004-05-07 09:02