Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法理解在C中应用结构指针和数组_C_Arrays_Structure - Fatal编程技术网

无法理解在C中应用结构指针和数组

无法理解在C中应用结构指针和数组,c,arrays,structure,C,Arrays,Structure,好的,我的任务是创建一个成绩册,它将: 添加学生 增加课程 将学生添加到课程中 为每门课程的学生增加分数 按课程划分的平均成绩 学生平均成绩 最后一个是给我带来麻烦的原因。我不得不在上周某个时候提交这个项目,所以我使用了一个廉价的解决方法,基本上让用户为他们做的每一个等级事务写下一个“等级ID”,如果他们想得到任何东西的平均值,他们只需要输入任意数量的等级ID,然后将它们平均。现在我们将回到这段代码,并实现它的一些其他方面,但我真的需要弄清楚如何使它更像一个现实的程序。这将允许用户只输入一个

好的,我的任务是创建一个成绩册,它将:

  • 添加学生
  • 增加课程
  • 将学生添加到课程中
  • 为每门课程的学生增加分数
  • 按课程划分的平均成绩
  • 学生平均成绩
最后一个是给我带来麻烦的原因。我不得不在上周某个时候提交这个项目,所以我使用了一个廉价的解决方法,基本上让用户为他们做的每一个等级事务写下一个“等级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.
            }
    }
void addenroll(注册*材料、课程*cstuff、学生*sstuff)
{                                                                                                                               
int i,j;
内部温度;
printf(“请输入您要添加学生的课程ID。\n”);
scanf(“%d”、&temp);
对于(i=0;i课程\ u cnt;i++)
{
如果(temp==cstuff->课程列表[i]。课程id)
{
stuff->enroll\u list[stuff->enroll\u cnt].e\u课程id=temp;
}
}
printf(“您希望添加多少名学生?\n”);
智力选择;
scanf(“%d”,选择(&C);
对于(i=0;ienroll\u列表[stuff->enroll\u cnt].e\u课程\u id);
scanf(“%d”、&temp);
对于(j=0;jstu_cnt;j++)
if(temp==sstuff->stu-list[j].stu-id)//将学生id存储在此处
{
printf(“id匹配成功\n\n”);
//这就是我上次被困的地方。。。
//我知道这是正确匹配的,在这里我将添加一名学生到课程中
//另外,稍后在添加成绩时,我需要使用类似的方法来查找相应的学生
//只是不知道怎么。。。
//我会让这个注册列表[这个]指向我的学生列表[j]。学生id
//但我不确定要用什么格式,而且一旦我完成了这个
//我需要在这里添加分数,我可以在每门课程的基础上轻松找到和平均分数,因为
//注册只包含一门课程,所以我只需要平均每门课程的注册人数
//我只需要找到某个学生的平均成绩,因为成绩将存储在一个数组中
//仅在此特定注册中。由于它位于此注册中,因此将不会
//与任何特定的学生匹配,只是一个充满分数的数组。
}
}

例如,我的问题是:用户决定将一名学生添加到一个类中。因此,我的程序将进入注册列表[0];假设这里增加了5个学生。然后在注册列表[0]中。成绩是该注册中所有成绩的数组。但当他们增加另一个班级时,比如说只有3名学生被列入了招生名单[1]。。。那里的成绩由每个注册列表保存,而不是由学生id链接。它只是注册列表[#]中的一个数组,所以我可以得到每个班级的平均成绩,我只是不知道如何跟踪每个id的学生。
a couple of ideas come immediately to mind.

1) for the student, traverse their sub records, 
   accumulating the count of grades and the sum of grades.
   then when at the end of the traversal, calculate the average

2) add fields one for the number of grades, one for the sum of the grades
   update those two fields when a grade is added
   and when the average is needed, use those two fields