【发布时间】:2015-04-28 06:27:38
【问题描述】:
好的,所以我的任务是创建一个成绩册,它将:
- 添加学生
- 添加课程
- 将学生添加到课程中
- 为每门课程的学生添加成绩
- 课程平均成绩
- 学生的平均成绩
最后一个给我带来了麻烦。我不得不在上周的某个时候完成这个项目,所以我使用了一种廉价的解决方法,基本上让用户为他们所做的每笔成绩交易写下一个“成绩 ID”,如果他们想要任何东西的平均值,他们只需要输入任何等级 ID 的数量和它的平均值。现在我们回到这段代码并实现它的其他方面,但我真的需要弄清楚如何让它更像一个现实的程序。它将允许用户只输入学生 ID 并获得他们特定的平均成绩,而不必知道每个学生的成绩 ID。但是……我就是不知道该怎么做。
所以我放弃了我的旧想法,重新开始,已经到了我上次碰壁并强制解决方法的地步。我把我坚持的部分注释掉了。这是我的 addenroll 函数,它将学生添加到课程中,并且与我为特定学生添加成绩的代码非常相似。
我可以上传我的结构代码.. .c 程序的其余部分等。我只是不希望我的帖子跨越这么多页面!
void addenroll(enrollment * stuff, courses * cstuff, students *sstuff)
{
int i,j;
int temp;
printf("Please enter the course ID you would like to add students to.\n");
scanf("%d",&temp);
for(i = 0; i<cstuff->course_cnt;i++)
{
if(temp == cstuff->course_list[i].course_id)
{
stuff->enroll_list[stuff->enroll_cnt].e_course_id = temp;
}
}
printf("How many students would you like to add?\n");
int choice;
scanf("%d", &choice);
for(i=0; i<choice; i++)
{
printf("Please enter the Student ID you would like to add to Course: %d\n", stuff->enroll_list[stuff->enroll_cnt].e_course_id);
scanf("%d", &temp);
for(j=0;j<sstuff->stu_cnt;j++)
if(temp == sstuff->stu_list[j].stu_id) //Storing the student ID here
{
printf("id match success\n\n");
//Here is where I got stuck last time...
//I know this has matched correctly, and here is where I would add a student to a course
//Also, later when adding grades I'll need to use this same sort of thing to find the corresponding student
//Just no idea how...
//I will have this enroll_list[this #].*e_stu_id point to my stu_list[j].stu_id
//But I'm not sure of the format to put this in, and also once I have this done
//I need to add grades here that I can find and average easily on a per course basis since each
//enrollment only holds one course so I need only to average each enrollment. The problem comes when
//I need only to find the average of a particular student, as the grades will be stored in an array held
//ONLY inside this specific enrollment. And since it is in this enrollment, it will not be
//matched with any particular student anymore, just an array full of grades.
}
}
【问题讨论】: