C 语言学生记录系统

2024年8月28日 | 阅读34分钟

在本文中,您将学习一个演示如何在C语言中构建学生记录系统的项目。您将通过一个程序来学习这个概念,该程序详细介绍了整个过程中发生的所有功能。

什么是学生记录系统,为什么我们应该使用它?

一个简单生成的数据库,用于存储学生的所有详细信息,包括学生的姓、名、学号、CGPA、注册课程等。我们需要使用它来保护学生数据并随时检索。我们将构建一个主要基于switch语句和基本编程语言成员的程序。

使用学生记录系统可以执行的操作包括:

  • 添加学生详细信息
  • 按学号检索学生数据
  • 按名字检索学生数据
  • 特定课程注册的学生总数
  • 删除学生数据
  • 更新学生数据
  • 学生总数

让我们将整个软件分解成几个部分,每个部分包含一个方法,按顺序描述上述操作之一。在找到所有操作的方法后,让我们将所有讨论的方法合并起来,形成处理和表示学生记录系统的软件。这使得我们的工作更易于访问和理解。

1. add_student()

此方法允许添加新学生的信息。它从用户那里获取输入数据,并将相同的数据存储在学生记录系统中。它还在添加学生信息时检查学号的唯一性,因为任何学生的学号都必须是唯一的。让我们通过一个程序来详细了解“add_student()”方法。

一个演示“add_student()”方法,执行添加新学生信息的程序

上述程序或方法的说明

“add_student()”方法用于添加新学生的信息。这是手动完成的,在各自的步骤中获取每个细节作为输入,最后,数据被存储在系统的数据库中。根据要求,声明变量并初始化为初始值。例如,j的值初始化为“0”,因为它必须从第0次迭代开始迭代。同样,学号、名字等的值也声明为必须从用户那里获取的输入。上面讨论的涉及输入学生详细信息的所有过程都发生在这个方法或函数体中。

输入是通过“scanf”扫描值来获取的,为了打印一些详细信息的列表,通过循环进行迭代。这是一个简单生成的方法,其中使用了语言的所有基本成员,如循环、打印语句、扫描语句等。学生信息的输入根据其数据类型进行。这样,就完成了“add_student()”方法的运行。

2. find_using_roll()

此方法用于通过提供唯一的学号作为输入来查找指定学生的全部详细信息。它获取学生的学号作为输入,以查找具有该指定学号(通过输入)的学生的信息。这就是为什么为每个学生提供唯一的学号,以便保护他们的身份并仅通过学号轻松检索数据。让我们通过一个程序来理解这个概念,该程序详细说明了“find_using_roll()”方法。

一个演示“find_using_roll()”方法,通过学号检索学生信息的程序

上述程序或方法的说明,与之前讨论的方法进行比较

“find_using_roll()”方法与第一个方法“add_student()”的声明方式完全不同。因为“add_student()”方法接受所有学生信息的输入,而不管具体要求,并添加新学生的信息。但是,“find_using_roll()”方法接受现有学生的学号作为输入,然后根据给定的学号查找该学生的所有信息。涉及输入学生详细信息的所有过程都发生在这个方法或函数体中。这是“add_student()”和“find_using_roll()”方法之间的区别。

基础条件是学号,并核对所有学生的详细信息。一旦找到匹配项,将打印该特定学生的信息。在“find_using_roll()”方法的程序中遵循的其余过程与“add_student()”方法非常相似。这样,就完成了“find_using_roll()”方法的运行。

3. find_using_fname()

此方法用于通过提供名字作为输入来查找指定学生的全部详细信息。因此,“find_using_fname()”方法以学生的名字作为输入,以查找具有该指定名字(通过输入)的学生的信息。让我们通过一个程序来理解这个概念,该程序详细说明了“find_using_fname()”方法。

一个演示“find_using_fname()”方法,通过名字检索学生信息的程序

上述程序或方法的说明,与之前讨论的方法进行比较

“find_using_fname()”方法与第一个方法“add_student()”的声明方式完全不同,但与“find_using_roll()”方法相似。因为“add_student()”方法接受所有学生信息的输入,而不管具体要求,并添加新学生的信息。涉及输入学生详细信息的所有过程都发生在这个方法或函数体中。

但是,“find_using_roll()”方法接受现有学生的学号作为输入,然后根据给定的学号查找该学生的所有信息。同样,“find_using_fname()”方法接受现有学生的名字作为输入,然后打印该相应学生的所有信息。这是“find_using_fname()”和“find_using_roll()”方法之间的主要相似之处。

基础条件是名字,并核对所有学生的详细信息。一旦找到匹配项,将打印该特定学生的信息。在“find_using_fname()”方法的程序中遵循的其余过程与“add_student()”方法非常相似,并且与“find_using_roll()”方法完全相似。这样,就完成了“find_using_fname()”方法的运行。

5. find_using_course()

此方法用于通过提供课程ID作为输入来查找注册特定课程的总学生信息。因此,“find_using_course()”方法以课程ID作为输入,然后打印所有注册了通过输入提及的课程的学生的信息。让我们通过一个程序来理解通过输入查找详细信息这一概念,该程序详细说明了“find_using_fname()”方法。

一个演示“find_using_course()”方法,通过课程ID检索特定课程注册学生信息的程序

上述程序或方法的说明,与之前讨论的方法进行比较

“find_using_course()”方法与第一个方法“add_student()”的声明方式完全不同,但与“find_using_roll()”和“find_using_fname()”方法相似。因为“add_student()”方法接受所有学生信息的输入,而不管具体要求,并添加新学生的信息。涉及输入学生详细信息的所有过程都发生在这个方法或函数体中。

但是,“find_using_roll()”方法接受现有学生的学号作为输入,然后根据给定的学号查找该学生的所有信息。同样,“find_using_fname()”方法接受现有学生的名字作为输入,然后打印该相应学生的所有信息,而“find_using_course()”方法接受课程ID作为输入,查找注册学生,遍历现有学生的详细信息,然后逐个打印相应学生的所有信息。这个特性是“find_using_fname()”、“find_using_roll()”和“find_using_course()”方法之间的主要相似之处之一。

基础条件是课程ID,并核对所有学生的详细信息以查找相关的课程ID,并与作为输入的课程ID进行比较。一旦找到匹配项,将打印注册或入学的这些特定学生的信息。相同的迭代将持续到达到该课程注册学生的最多数量。这样,就完成了“find_using_course()”方法的运行。

5. delete()

此方法用于通过提供学号作为输入来删除学生的信息。因此,“delete()”方法以用户提供的学生学号作为输入,然后删除具有该学号的学生的所有详细信息或数据。让我们通过一个程序来理解通过输入查找详细信息这一概念,该程序详细说明了“delete()”方法。

一个演示“delete()”方法,通过相应的学号删除学生信息的程序

上述程序或方法的说明,并与之前讨论的方法进行比较

“delete()”方法的声明方式与之前讨论和声明的所有方法,即“add_student()”、“find_using_fname()”、“find_using_roll()”和“find_using_course()”完全不同。 “add_student()”方法接受所有学生信息的输入,而不管具体要求,并添加新学生的信息。涉及输入学生详细信息的所有过程都发生在这个方法或函数体中。

“find_using_roll()”方法接受现有学生的学号作为输入,然后根据给定的学号查找该学生的所有信息。同样,“find_using_fname()”方法接受现有学生的名字作为输入,然后打印该相应学生的所有信息,而“find_using_course()”方法接受课程ID作为输入,查找注册学生,遍历现有学生的详细信息,然后逐个打印相应学生的所有信息。

而“delete()”方法则处理删除特定学生的信息,该学生的学号由用户输入。此方法有助于清除缓存或不需要的学生信息。基础条件是学号,并核对所有学生的详细信息以查找相关的学号,并与作为输入的学号进行比较。一旦找到匹配项,将从数据库中删除具有所需学号的这些特定学生的信息。相同的迭代将持续到找到匹配的学号。这样,就完成了“delete()”方法的运行。

6. update()

此方法用于通过提供学号作为输入来更新学生的信息。因此,“update()”方法以用户提供的学生学号作为输入,然后更新具有该学号的学生的所有详细信息或数据。有时,您不需要更新所有详细信息,但只需要更新某些详细信息。在这种情况下,也可以使用此方法。让我们通过一个程序来理解通过输入查找详细信息这一概念,该程序详细说明了“update()”方法。

一个演示“update()”方法,通过相应的学号更新学生信息的程序

上述程序或方法的说明,并与之前讨论的方法进行比较

“update()”方法的声明方式与之前讨论和声明的所有方法,即“add_student()”、“find_using_fname()”、“find_using_roll()”、“find_using_course()”和“delete()”完全不同。“add_student()”方法接受所有学生信息的输入,而不管具体要求,并添加新学生的信息。涉及输入学生详细信息的所有过程都发生在这个方法或函数体中。

“find_using_roll()”方法接受现有学生的学号作为输入,然后根据给定的学号查找该学生的所有信息。同样,“find_using_fname()”方法接受现有学生的名字作为输入,然后打印该相应学生的所有信息,而“find_using_course()”方法接受课程ID作为输入,查找注册学生,遍历现有学生的详细信息,然后逐个打印相应学生的所有信息。“delete()”方法处理删除特定学生的信息,该学生的学号由用户输入。

而“update()”方法则处理更新特定学生的信息,该学生的学号由用户输入。此方法有助于保持学生信息的最新。在此方法中,旧信息将被替换并用新信息更新,并且会要求输入新信息。用户将有一个选择,从中选择他希望更新哪个详细信息。

基础条件是学号,并核对所有学生的详细信息以查找相关的学号,并与作为输入的学号进行比较。一旦找到匹配项,将根据需要更新数据库中具有所需学号的这些特定学生的信息。相同的迭代将持续到找到匹配的学号。

例如,如果从数字1、2、3、4和5中选择了数字4,其中1表示“更新学生的名字”,2表示“更新学生的姓”,3表示“更新学生的学号”,4表示“更新学生的CGPA”,5表示“更新学生注册的课程”。因此,当输入为4时,将更新学生的CGPA,旧CGPA将被新CGPA替换。这样,就完成了“update()”方法的运行。

7. count()

“count()”方法用于通知用户数据库中存在的学生总数以及考虑最大学生数后可以接收的新生数量。因此,此方法告知用户现有多少学生以及考虑该学院内可容纳的最大学生数后还有多少空位。

一个演示“count()”方法,计算学生总数并考虑最大学生数来表明空缺数量的程序

上述程序或方法的说明

“count()”方法用于计算学生总数并打印新生的空缺位置。在之前的方法中,即添加新学生的方法中,声明了一个变量“i”来存储被添加的学生数量,并且每次迭代,“i”的值都会增加。最后,变量“i”的最终值被固定。该值等于存储在数据库中的学生信息的总数。因此,打印“i”的值是为了知道学生总数。将“i”的值从可存储的最大学生数中减去,即可知道学生的空缺数量。

这些是负责构建“C语言学生记录系统”程序的方法或函数。该程序是上述所有方法的组合。让我们构建程序。

一个演示“C语言学生记录系统”的程序

上述程序针对相应输入的输出

1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 1
You can add the Student data now !! 
Enter the first name of the Student: Nikhitha
Enter the last name of the Student: Manne
Enter the roll number of the Student: 21
Enter the CGPA that the student achieved: 8.95
List of courses with their respective course ids: 1
2
3
4
5



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 2
You can find the Student data by entering a roll number now !! 
Enter the roll number of the Student: 21
The details of the Student with the roll given number are
The First name of the student is Nikhitha
The Last name of the student is Manne
The CGPA of the student is 8.950000
The course ID is 1
The course ID is 2
The course ID is 3
The course ID is 4
The course ID is 5



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 3
You can find the Student data by entering the first name now !! 
Enter the first name of the Student: Nikhitha
The details of the student are displayed below
The First name of the student is Nikhitha
The Last name of the student is Manne
The Roll Number of the student is 21
 The CGPA of the student is 8.950000
The course ID is 1
The course ID is 2
The course ID is 3
The course ID is 4
The course ID is 5



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 3
You can find the Student data by entering the first name now !! 
Enter the first name of the Student: Nikhitha
The details of the student are displayed below
The First name of the student is Nikhitha
The Last name of the student is Manne
The Roll Number of the student is 21
 The CGPA of the student is 8.950000
The course ID is 1
The course ID is 2
The course ID is 3
The course ID is 4
The course ID is 5



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 4
You can find the Student data who have enrolled in the course. Enter the course ID of the desired course: 
1
The details of the Students who have registered with the corresponding course id: 
The first name of the student is Nikhitha
The last name of the student is Manne
The Roll number of the student is 21
The CGPA of the student is 8.950000



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 5
Enter the roll number of the student that you want to update: 21
Enter the number for which details you want to update: 
1. First name of the student
2. Last name of the student
3. Roll number of the student
4. CGPA of the student
5. Courses registered by the student
1
Enter the first name that you want to update : 
Nikki
The Details of the Student are updated successfully !!



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 7
The total number of Students is: 1

The maximum number of students is 50
49 more students can be added



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 6
Enter the roll number of the student that you want to delete: 21
The details of the student bearing the given roll number are successfully removed


1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 2
You can find the Student data by entering a roll number now !! 
Enter the roll number of the Student: 21
The course ID is 0
The course ID is 0
The course ID is 0
The course ID is 0
The course ID is 0



1. Add the details of the student
2. Find the details of the student by using roll number
3. Find the details of the student by using first name
4. Find the details of the student by using course id
5. Update the details of the student by using roll number
6. Delete the details of the student by using roll number
7. Find the total number of students
8. Exit
Enter the choice number that you want to perform: 8
Exit successful!!

上述程序及其相应输出的说明

对于上述程序,在收到上一个输出后,逐一输入所有可能的输入。选项以其各自的序号给出,以便用户可以通过输入选择其中一个。选项及其对应的编号是:

  1. 添加学生信息
  2. 通过学号查找学生信息
  3. 通过名字查找学生信息
  4. 通过课程ID查找学生信息
  5. 通过学号更新学生信息
  6. 通过学号删除学生信息
  7. 查找学生总数
  8. 退出

因此,将要求用户从上述操作列表中选择所需选项,并将执行所选的操作。如果选择第一个选项,即“添加学生信息”,则可以添加新学生的信息。如果选择第二个选项,即“通过学号查找学生信息”,则可以通过学号查找已存在学生的信息。如果选择第三个选项,即“通过名字查找学生信息”,则可以通过名字查找已存在学生的信息。

同样,如果选择第四个选项,即“通过课程ID查找学生信息”,则可以通过学生注册的课程ID查找已存在学生的信息。如果选择第五个选项,即“通过学号更新学生信息”,则可以通过相应的学号更新已存在学生的信息。如果选择第六个选项,即“通过学号删除学生信息”,则可以通过相应的学号从数据库中删除已存在学生的信息。如果选择第七个选项,即“查找学生总数”,则将显示学生总数。如果选择第八个选项,“退出”,您将退出终端。

为了访问和执行这些操作,最初会声明相应的函数和方法,以便在需要时可以根据需要访问它们。这样,就可以创建存储和保护学生详细信息的数据库系统。