学生信息管理系统
先决条件: C/C++ 中的 Switch Case问题陈述:编写一个程序来构建一个简单的学生信息管理系统软件,该软件可以执行以下操作:
- 存储学生的名字。
- 存储学生的姓氏。
- 存储每个学生的唯一卷号。
- 存储每个学生的 CGPA。
- 存储学生注册的课程。
方法:这个想法是为每个操作形成一个单独的功能。所有的功能都统一在一起形成软件。
- 添加学生详细信息:从用户获取数据并将学生添加到学生列表中。在将学生添加到列表中时,检查卷号的唯一性。
- 按给定卷号查找学生:此函数是查找给定卷号的学生记录并打印详细信息。
- 按给定名字查找学生:此函数是查找具有给定名字的所有学生并打印他们的详细信息。
- 查找已注册课程的学生:此函数是查找已注册给定课程的所有学生。
- 学生人数:此函数是打印系统中的学生总数
- 删除学生:此函数是删除给定卷号的学生记录。
- 更新学生:此函数是更新学生记录。此函数不会要求所有字段的新详细信息,但用户应该能够选择他想要更新的内容。
Add
// Function to add the student into the database
void add_student()
{
printf("Add the Students Details\n");
printf("-------------------------\n");
printf("Enter the first name of student\n");
// First name of the student
st[i].fname = "Rahul";
printf("Enter the last name of student\n");
// Last name of the student
st[i].lname = "Kumar";
printf("Enter the Roll Number\n");
// Roll Number of the student
st[i].roll = 1;
printf("Enter the CGPA you obtained\n");
// CGPA of the student
st[i].cgpa = 8;
printf("Enter the course ID"
" of each course\n");
// Storing the courses every student
// is enrolled in
for (int j = 0; j < 5; j++) {
st[i].cid[j] = j;
}
i = i + 1;
}
Find by Roll No
// Function to find the details
// of the student by roll number
void find_rl()
{
int x;
printf("Enter the Roll Number"
" of the student\n");
// Roll number for which the details
// needs to be found
x = 1;
// Iterating through all the students
for (int j = 0; j < i; j++) {
// If the roll number is found
if (x == st[j].roll) {
printf("The Students Details are\n");
printf("The First name is %s\n",
st[j].fname);
printf("The Last name is %s\n",
st[j].lname);
printf("The CGPA is %f\n",
st[j].cgpa);
// Printing the courses
// in which the student
// is enrolled
for (int k = 0; k < 5; k++) {
printf(
"The course ID are %d\n",
st[j].cid[k]);
}
break;
}
}
}
Find by Name
// Function to search the students list
// by the given first name
void find_fn()
{
char a[50];
printf("Enter the First Name"
" of the student\n");
a = "Rahul";
int c = 0;
// Iterating through the students list
for (int j = 0; j <= i; j++) {
// Compare the first names
if (!strcmp(st[j].fname, a)) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[j].fname);
printf(
"The Last name is %s\n",
st[j].lname);
printf(
"The Roll Number is %d\n ",
st[j].roll);
printf(
"The CGPA is %f\n",
st[j].cgpa);
printf("Enter the course ID "
"of each course\n");
// Print the course ID's
for (int k = 0; k < 5; k++) {
printf(
"The course ID are %d\n",
st[j].cid[k]);
}
c = 1;
}
}
}
Find registered student
// Function to find all the students
// who have registered for a given course
void find_c()
{
int id;
printf("Enter the course ID \n");
// Course ID
id = 1;
int c = 0;
// Iterating through the students list
for (int j = 0; j <= i; j++) {
// Checking if the student
// has registered in the
// given course or not
for (int d = 0; d < 5; d++) {
if (id == st[j].cid[d]) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[j].fname);
printf(
"The Last name is %s\n",
st[j].lname);
printf(
"The Roll Number is %d\n ",
st[j].roll);
printf(
"The CGPA is %f\n",
st[j].cgpa);
c = 1;
break;
}
}
}
}
Count
// Function to print the
// total number of students
void tot_s()
{
printf("The total number of"
" Student is %d\n",
i);
printf("\n you can have a "
"max of 50 students\n");
printf("you can have %d more"
" students\n",
50 - i);
}
Delete
// Function to delete a student
// by the roll number
void del_s()
{
int a;
printf("Enter the Roll Number"
" which you want to delete\n");
a = 1;
// Iterating through the list and
// find the student with the given
// roll number
for (int j = 0; j <= i; j++) {
if (a == st[j].roll) {
for (int k = j; k < 49; k++)
st[k] = st[k + 1];
i--;
}
}
printf("The Roll Number is "
"removed Successfully\n");
}
Update
// Function to update the
// details of the student
void up_s()
{
printf("Enter the roll number"
" to update the entry: ");
long int x;
x = 1;
for (int j = 0; j < i; j++) {
if (st[j].roll == x) {
printf("1. first name\n"
"2. last name\n"
"3. roll no.\n"
"4. CGPA\n"
"5. courses\n");
int z;
// Updating the CGPA
z = 4;
switch (z) {
case 1:
printf("Enter the new
first name : \n");
scanf("%s", st[j].fname);
break;
case 2:
printf("Enter the new
last name : \n");
scanf("%s", st[j].lname);
break;
case 3:
printf("Enter the new
roll number : \n");
scanf("%d", &st[j].roll);
break;
case 4:
printf("Enter the new CGPA : \n");
st[j].cgpa = 9;
break;
case 5:
printf("Enter the new courses \n");
scanf("%d%d%d%d%d", &st[j].cid[0],
&st[j].cid[1], &st[j].cid[2],
&st[j].cid[3], &st[j].cid[4]);
break;
}
printf("UPDATED SUCCESSFULLY.\n");
}
}
}
C
// C program for the implementation of
// menu driven program for student
// management system
#include
#include
#include
#include
// Variable to keep track of
// number of students
int i = 0;
// Structure to store the student
struct sinfo {
char fname[50];
char lname[50];
int roll;
float cgpa;
int cid[10];
} st[55];
// Function to add the student
void add_student()
{
printf("Add the Students Details\n");
printf("-------------------------\n");
printf("Enter the first "
"name of student\n");
scanf("%s", st[i].fname);
printf("Enter the last name"
" of student\n");
scanf("%s", st[i].lname);
printf("Enter the Roll Number\n");
scanf("%d", &st[i].roll);
printf("Enter the CGPA "
"you obtained\n");
scanf("%f", &st[i].cgpa);
printf("Enter the course ID"
" of each course\n");
for (int j = 0; j < 5; j++) {
scanf("%d", &st[i].cid[j]);
}
i = i + 1;
}
// Function to find the student
// by the roll number
void find_rl()
{
int x;
printf("Enter the Roll Number"
" of the student\n");
scanf("%d", &x);
for (int j = 1; j <= i; j++) {
if (x == st[i].roll) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[i].fname);
printf(
"The Last name is %s\n",
st[i].lname);
printf(
"The CGPA is %f\n",
st[i].cgpa);
printf(
"Enter the course ID"
" of each course\n");
}
for (int j = 0; j < 5; j++) {
printf(
"The course ID are %d\n",
st[i].cid[j]);
}
break;
}
}
// Function to find the student
// by the first name
void find_fn()
{
char a[50];
printf("Enter the First Name"
" of the student\n");
scanf("%s", a);
int c = 0;
for (int j = 1; j <= i; j++) {
if (!strcmp(st[j].fname, a)) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[i].fname);
printf(
"The Last name is %s\n",
st[i].lname);
printf(
"The Roll Number is %d\n ",
st[i].roll);
printf(
"The CGPA is %f\n",
st[i].cgpa);
printf(
"Enter the course ID of each course\n");
for (int j = 0; j < 5; j++) {
printf(
"The course ID are %d\n",
st[i].cid[j]);
}
c = 1;
}
else
printf(
"The First Name not Found\n");
}
}
// Function to find
// the students enrolled
// in a particular course
void find_c()
{
int id;
printf("Enter the course ID \n");
scanf("%d", &id);
int c = 0;
for (int j = 1; j <= i; j++) {
for (int d = 0; d < 5; d++) {
if (id == st[j].cid[d]) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[i].fname);
printf(
"The Last name is %s\n",
st[i].lname);
printf(
"The Roll Number is %d\n ",
st[i].roll);
printf(
"The CGPA is %f\n",
st[i].cgpa);
c = 1;
break;
}
else
printf(
"The First Name not Found\n");
}
}
}
// Function to print the total
// number of students
void tot_s()
{
printf("The total number of"
" Student is %d\n",
i);
printf("\n you can have a "
"max of 50 students\n");
printf("you can have %d "
"more students\n",
50 - i);
}
// Function to delete a student
// by the roll number
void del_s()
{
int a;
printf("Enter the Roll Number"
" which you want "
"to delete\n");
scanf("%d", &a);
for (int j = 1; j <= i; j++) {
if (a == st[j].roll) {
for (int k = j; k < 49; k++)
st[k] = st[k + 1];
i--;
}
}
printf("The Roll Number"
" is removed Successfully\n");
}
// Function to update a students data
void up_s()
{
printf("Enter the roll number"
" to update the entry : ");
long int x;
scanf("%ld", &x);
for (int j = 0; j < i; j++) {
if (st[j].roll == x) {
printf("1. first name\n"
"2. last name\n"
"3. roll no.\n"
"4. CGPA\n"
"5. courses\n");
int z;
scanf("%d", &z);
switch (z) {
case 1:
printf("Enter the new "
"first name : \n");
scanf("%s", st[j].fname);
break;
case 2:
printf("Enter the new "
"last name : \n");
scanf("%s", st[j].lname);
break;
case 3:
printf("Enter the new "
"roll number : \n");
scanf("%d", &st[j].roll);
break;
case 4:
printf("Enter the new CGPA : \n");
scanf("%f", &st[j].cgpa);
break;
case 5:
printf("Enter the new courses \n");
scanf(
"%d%d%d%d%d", &st[j].cid[0],
&st[j].cid[1], &st[j].cid[2],
&st[j].cid[3], &st[j].cid[4]);
break;
}
printf("UPDATED SUCCESSFULLY.\n");
}
}
}
// Driver code
void main()
{
int choice, count;
while (i = 1) {
printf("The Task that you "
"want to perform\n");
printf("1. Add the Student Details\n");
printf("2. Find the Student "
"Details by Roll Number\n");
printf("3. Find the Student "
"Details by First Name\n");
printf("4. Find the Student "
"Details by Course Id\n");
printf("5. Find the Total number"
" of Students\n");
printf("6. Delete the Students Details"
" by Roll Number\n");
printf("7. Update the Students Details"
" by Roll Number\n");
printf("8. To Exit\n");
printf("Enter your choice to "
"find the task\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
find_rl();
break;
case 3:
find_fn();
break;
case 4:
find_c();
break;
case 5:
tot_s();
break;
case 6:
del_s();
break;
case 7:
up_s();
break;
case 8:
exit(0);
break;
}
}
}
下面是上述方法的实现:
C
// C program for the implementation of
// menu driven program for student
// management system
#include
#include
#include
#include
// Variable to keep track of
// number of students
int i = 0;
// Structure to store the student
struct sinfo {
char fname[50];
char lname[50];
int roll;
float cgpa;
int cid[10];
} st[55];
// Function to add the student
void add_student()
{
printf("Add the Students Details\n");
printf("-------------------------\n");
printf("Enter the first "
"name of student\n");
scanf("%s", st[i].fname);
printf("Enter the last name"
" of student\n");
scanf("%s", st[i].lname);
printf("Enter the Roll Number\n");
scanf("%d", &st[i].roll);
printf("Enter the CGPA "
"you obtained\n");
scanf("%f", &st[i].cgpa);
printf("Enter the course ID"
" of each course\n");
for (int j = 0; j < 5; j++) {
scanf("%d", &st[i].cid[j]);
}
i = i + 1;
}
// Function to find the student
// by the roll number
void find_rl()
{
int x;
printf("Enter the Roll Number"
" of the student\n");
scanf("%d", &x);
for (int j = 1; j <= i; j++) {
if (x == st[i].roll) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[i].fname);
printf(
"The Last name is %s\n",
st[i].lname);
printf(
"The CGPA is %f\n",
st[i].cgpa);
printf(
"Enter the course ID"
" of each course\n");
}
for (int j = 0; j < 5; j++) {
printf(
"The course ID are %d\n",
st[i].cid[j]);
}
break;
}
}
// Function to find the student
// by the first name
void find_fn()
{
char a[50];
printf("Enter the First Name"
" of the student\n");
scanf("%s", a);
int c = 0;
for (int j = 1; j <= i; j++) {
if (!strcmp(st[j].fname, a)) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[i].fname);
printf(
"The Last name is %s\n",
st[i].lname);
printf(
"The Roll Number is %d\n ",
st[i].roll);
printf(
"The CGPA is %f\n",
st[i].cgpa);
printf(
"Enter the course ID of each course\n");
for (int j = 0; j < 5; j++) {
printf(
"The course ID are %d\n",
st[i].cid[j]);
}
c = 1;
}
else
printf(
"The First Name not Found\n");
}
}
// Function to find
// the students enrolled
// in a particular course
void find_c()
{
int id;
printf("Enter the course ID \n");
scanf("%d", &id);
int c = 0;
for (int j = 1; j <= i; j++) {
for (int d = 0; d < 5; d++) {
if (id == st[j].cid[d]) {
printf(
"The Students Details are\n");
printf(
"The First name is %s\n",
st[i].fname);
printf(
"The Last name is %s\n",
st[i].lname);
printf(
"The Roll Number is %d\n ",
st[i].roll);
printf(
"The CGPA is %f\n",
st[i].cgpa);
c = 1;
break;
}
else
printf(
"The First Name not Found\n");
}
}
}
// Function to print the total
// number of students
void tot_s()
{
printf("The total number of"
" Student is %d\n",
i);
printf("\n you can have a "
"max of 50 students\n");
printf("you can have %d "
"more students\n",
50 - i);
}
// Function to delete a student
// by the roll number
void del_s()
{
int a;
printf("Enter the Roll Number"
" which you want "
"to delete\n");
scanf("%d", &a);
for (int j = 1; j <= i; j++) {
if (a == st[j].roll) {
for (int k = j; k < 49; k++)
st[k] = st[k + 1];
i--;
}
}
printf("The Roll Number"
" is removed Successfully\n");
}
// Function to update a students data
void up_s()
{
printf("Enter the roll number"
" to update the entry : ");
long int x;
scanf("%ld", &x);
for (int j = 0; j < i; j++) {
if (st[j].roll == x) {
printf("1. first name\n"
"2. last name\n"
"3. roll no.\n"
"4. CGPA\n"
"5. courses\n");
int z;
scanf("%d", &z);
switch (z) {
case 1:
printf("Enter the new "
"first name : \n");
scanf("%s", st[j].fname);
break;
case 2:
printf("Enter the new "
"last name : \n");
scanf("%s", st[j].lname);
break;
case 3:
printf("Enter the new "
"roll number : \n");
scanf("%d", &st[j].roll);
break;
case 4:
printf("Enter the new CGPA : \n");
scanf("%f", &st[j].cgpa);
break;
case 5:
printf("Enter the new courses \n");
scanf(
"%d%d%d%d%d", &st[j].cid[0],
&st[j].cid[1], &st[j].cid[2],
&st[j].cid[3], &st[j].cid[4]);
break;
}
printf("UPDATED SUCCESSFULLY.\n");
}
}
}
// Driver code
void main()
{
int choice, count;
while (i = 1) {
printf("The Task that you "
"want to perform\n");
printf("1. Add the Student Details\n");
printf("2. Find the Student "
"Details by Roll Number\n");
printf("3. Find the Student "
"Details by First Name\n");
printf("4. Find the Student "
"Details by Course Id\n");
printf("5. Find the Total number"
" of Students\n");
printf("6. Delete the Students Details"
" by Roll Number\n");
printf("7. Update the Students Details"
" by Roll Number\n");
printf("8. To Exit\n");
printf("Enter your choice to "
"find the task\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
find_rl();
break;
case 3:
find_fn();
break;
case 4:
find_c();
break;
case 5:
tot_s();
break;
case 6:
del_s();
break;
case 7:
up_s();
break;
case 8:
exit(0);
break;
}
}
}
输出:您要执行的任务 1. 添加学生详细信息 2. 按卷号查找学生详细信息 3. 按名字查找学生详细信息 4. 按课程 ID 查找学生详细信息 5. 查找学生总数6. 按卷号删除学生详细信息 7. 按卷号更新学生详细信息 8. 退出 输入您的选择以查找任务 1 添加学生详细信息 —————————- 输入学生 Rahul 的名字输入学生 Kumar 的姓 输入卷号 1 输入您获得的 CGPA 8 输入每门课程的课程 ID 1 2 3 4 5 您要执行的任务 1. 添加学生详细信息 2. 通过以下方式查找学生详细信息卷号 3. 按名字查找学生详细信息 4. 按课程 ID 查找学生详细信息 5. 查找学生总数 6. 按卷号删除学生详细信息 7. 按卷号更新学生详细信息 8. 退出输入您的选择以查找任务 2 输入学生的卷号 1 The Students Det ails 是 名字是 Rahul 姓氏是 Kumar CGPA 是 8.000000 输入每门课程的课程 ID 课程 ID 是 1 课程 ID 是 2 课程 ID 是 3 课程 ID 是 4 课程 ID 是 5 任务1. 添加学生详细信息 2. 按卷号查找学生详细信息 3. 按名字查找学生详细信息 4. 按课程 ID 查找学生详细信息 5. 查找学生总数 6. 删除按卷号的学生详细信息 7. 按卷号更新学生详细信息 8. 退出 输入您的选择以查找任务 3 输入学生的名字 Rahul 学生详细信息是 名字是 Rahul 姓氏是 Kumar The Roll编号为 1 CGPA 为 8.000000 输入每门课程的课程 ID 课程 ID 为 1 课程 ID 为 2 课程 ID 为 3 课程 ID 为 4 课程 ID 为 5 您要执行的任务 1. 添加学生详细信息 2. 按卷号查找学生详细信息 3. 查找学生详细信息 b y 名字 4. 按课程 ID 查找学生详细信息 5. 查找学生总数 6. 按卷号删除学生详细信息 7. 按卷号更新学生详细信息 8. 退出 输入您的选择以查找任务 4输入课程 ID 1 学生详细信息是 名字是 Rahul 姓氏是 Kumar 卷号是 1 CGPA 是 8.000000 您要执行的任务 1. 添加学生详细信息 2. 按卷号查找学生详细信息3. 按名字查找学生详细信息 4. 按课程 ID 查找学生详细信息 5. 查找学生总数 6. 按卷号删除学生详细信息 7. 按卷号更新学生详细信息 8. 退出 输入您的选择查找任务 5 学生总数为 1 您最多可以有 50 个学生 您可以再有 49 个学生 您要执行的任务 1. 添加学生详细信息 2. 按卷号查找学生详细信息. 按名字查找学生详细信息 4. 查找学生详细信息s 按课程 ID 5. 查找学生总数 6. 按卷号删除学生详细信息 7. 按卷号更新学生详细信息 8. 退出 输入您的选择以查找任务 6 输入您想要的卷号删除 1 卷号已成功删除 您要执行的任务 1. 添加学生详细信息 2. 按卷号查找学生详细信息 3. 按名字查找学生详细信息 4. 按课程 ID 查找学生详细信息 5.查找学生总数 6. 按卷号删除学生详细信息 7. 按卷号更新学生详细信息 8. 退出 输入您的选择以查找任务 2 输入学生的卷号 1 课程 ID 为 0课程 ID 为 0 课程 ID 为 0 课程 ID 为 0 课程 ID 为 0 您要执行的任务 1. 添加学生详细信息 2. 按卷号查找学生详细信息 3. 按名字查找学生详细信息4. 按课程 ID 查找学生详细信息 5. 查找 S 的总数学生 6. 按卷号删除学生详细信息 7. 按卷号更新学生详细信息 8. 退出 输入您的选择以查找任务 8