当前位置:网站首页>On the compilation of student management system of C language course (simple version)
On the compilation of student management system of C language course (simple version)
2022-07-26 10:06:00 【SingleDog_ seven】
Curriculum requirements 
According to the requirements of course design , We need to add the following functions to our management system :1, Menu mode works ;2, Input function ;3, Browsing function ;4, Query function ;5, Sorting function ;6, Delete function ;7, Modify the function ;8, Save function .
We will complete the writing step by step with the idea of modularization .
Construction of structure
We already know the requirements of the curriculum , According to the requirements, we can build the following structure :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 30
int n=0; // Create global variables to control the number of people entered
struct student{ // Defining structure
char sumber[10]; // Student number
char name[15]; // full name
int age; // Age
char gender; // Gender
char birthday; // date of birth
char site; // Address
int sum; // Phone number
char mail; // email
}stu[N];
After building the structure , We will write module words for functions ;
menu
The first is the preparation of the menu :
void show() // Show menu
{
printf(" ----------1. Enter student information ----------\n");
printf(" ----------2. Search for student information ----------\n");
printf(" ----------3. Browse student information ----------\n");
printf(" ----------4. Modify student information ----------\n");
printf(" ----------5. Save student information ----------\n");
printf(" ----------6. Delete student information ----------\n");
printf(" --------------0. sign out --------------\n");
}
Use several consecutive outputs to complete the preparation of the menu .
Enter student information
We use entering function :
int entering() // Enter student information
{
int a;
printf(" Please enter the number of students to add :");
scanf("%d",&a);
int i;
for(i=n;i<a+n;i++) // Add to the existing number
{
printf(" Please enter the student number : ");
scanf("%s", stu[i].sumber);
printf(" Please enter the student's name : ");
scanf("%s",&stu[i].name);
printf(" Please enter the age of the student : ");
scanf("%d",&stu[i].age);
printf(" Please enter the gender of the student : ");
scanf("%s",&stu[i].gender);
printf(" Please enter the date of birth of the student : ");
scanf("%s",&stu[i].birthday);
printf(" Please enter the student's address : ");
scanf("%s",&stu[i].site);
printf(" Please enter the student's phone number : ");
scanf("%d",&stu[i].sum);
printf(" Please enter the student's email : ");
scanf("%s",&stu[i].mail);
printf("\n");
}
n=n+a; // Now the number of people in the system
}
Browse student information
Use browse function :
void browse() // Browse student information
{
if(n==0) // When n by 0 Give a hint when : No information
{
printf(" There is currently no student information \n");
return;
}
printf(" Student number full name Age Gender date of birth Address Phone number email \n");
for(int i=0;i<=n;i++)
{
printf("%s %s %d %s %s %s %d %s", stu[i].sumber, stu[i].name, stu[i].age, stu[i].gender, stu[i].birthday, stu[i].site, stu[i].sum, stu[i].mail);
}
system("pause");
}
If n=0 Will give a prompt without information ;
Search for student information
Here I use the student ID to search :
void inquire() // Search for student information
{
char num[10];
printf(" Please enter your student number :");
scanf("%s",&num);
int i;
for(i=0;i<n;i++)
{
if(strcmp(stu[i].sumber, num) == 0) // Traverse and query personal information
{
printf(" Student number full name Age Gender date of birth Address Phone number email ");
printf("%s %s %d %s %s %s %d %s", stu[i].sumber, stu[i].name, stu[i].age, stu[i].gender, stu[i].birthday, stu[i].site, stu[i].sum, stu[i].mail);
break;
}
}
if(i==n)
printf(" Check no one \n");
}
Save information
void save(){
int i;
FILE *fp;
char filename[16];
printf(" Please enter a file name to save :\n");
scanf("%s", filename);
fp = fopen(filename, "w");
for (i = 0; i < n; i++){
fprintf(fp, "%s%s%d%s%s%s%d%s\n", stu[i].sumber, stu[i].name, stu[i].age, stu[i].gender,
stu[i].birthday, stu[i].site, stu[i].sum, stu[i].mail);
}
printf(" Saved successfully !!!\n");
fclose(fp);
system("pause");
}
I don't quite understand this part , If you know something, you can discuss it together .
Delete the information
Use student ID to search , Delete the student number , And move the back position forward .
void del() // Delete
{
int i, j, flag;
char s1[10];
printf(" Please enter the student number to be deleted :\n");
scanf("%s", s1);
flag = 0;
for (i = 0; i < n; i++)
{
if (strcmp(s1, stu[i].sumber) == 0)
{
flag = 1;
for (j = i; j < n - 1; j++)
{
stu[j] = stu[j + 1];// Just move all the students in the back one
}
}
if (flag == 1) break;// Indicates that the student to be deleted has been found , End of cycle
}
if (0 == flag)
{
printf(" The student number does not exist !!!\n");
}
if (1 == flag)
{
printf(" Delete successful \n");
n--;
}
system("pause");
Modify the information
Use the submenu to modify the information of the target .
void remove() // modify
{
int i,g;
char name[15],number[9],sex,birthday,site,mail;
int age,sum;
printf(" Please enter the name of the student to be modified : \n");
getchar();
gets(name);
while(1)
{
g=0;
for(i=0;i<n;i++)
{
int num1;
if(strcmp(name,stu[i].name)==0) // Traverse to find information , Create submenu
{
g=1;
printf(" ---------- 1. Change the student number ----------\n");
printf(" ---------- 2. Change the name ----------\n");
printf(" ---------- 3. Change the age ----------\n");
printf(" ---------- 4. Change gender ----------\n");
printf(" ----------5. Modify phone number ----------\n");
printf(" ----------6. Modify the date of birth ----------\n");
printf(" ---------- 7. Change address ----------\n");
printf(" ---------- 8. Modify email ----------\n");
printf(" ---------- 9. Exit the submenu ----------\n");
printf(" Please enter the service of the submenu :");
scanf("%d",&num1);
switch(num1) // Change information
{
case 1:
printf(" Please enter a new student number :");
getchar();
gets(number);
strcpy(stu[i].sumber,number);
break;
case 2:
printf(" Please enter a new name :");
getchar();
gets(name);
strcpy(stu[i].name,name);
break;
case 3:
printf(" Please enter a new age :");
scanf("%d",&age);
stu[i].age=age;
break;
case 4:
printf(" Please enter a new gender :");
scanf("%d",&sex);
stu[i].gender=sex;
break;
case 5:
printf(" Please enter a new phone number :");
scanf("%d",&sum);
stu[i].sum=sum;
break;
case 6:
printf(" Please enter a new date of birth :");
scanf("%s",&birthday);
stu[i].birthday=birthday;
break;
case 7:
printf(" Please enter a new address :");
scanf("%d",&site);
stu[i].site=site;
break;
case 8:
printf(" Please enter a new mailbox :");
scanf("%d",&mail);
stu[i].mail=mail;
break;
case 9:
return;
break;
default:
printf(" Please be there. 1--9 Choose between !\n");
}
}
}
if(g==0)
printf(" Check no one ");
}
}
choice
utilize switch Statement to jump to the function used , It is similar to the function of selecting submenu in modification .
void choose(int i)
{
switch(i){
case 1:entering();break;
case 2:inquire();break;
case 3:browse();break;
case 4:remove();break;
case 5:save();break;
case 6:del();break;
case 0:return;break;
default :printf(" Incorrect input ");
}
}
Here are all the codes of the management system :
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 30
int n=0; // Create global variables to control the number of people entered
struct student{ // Defining structure
char sumber[10]; // Student number
char name[15]; // full name
int age; // Age
char gender; // Gender
char birthday; // date of birth
char site; // Address
int sum; // Phone number
char mail; // email
}stu[N];
// Defined function
int entering() // Enter student information
{
int a;
printf(" Please enter the number of students to add :");
scanf("%d",&a);
int i;
for(i=n;i<a+n;i++) // Add to the existing number
{
printf(" Please enter the student number : ");
scanf("%s", stu[i].sumber);
printf(" Please enter the student's name : ");
scanf("%s",&stu[i].name);
printf(" Please enter the age of the student : ");
scanf("%d",&stu[i].age);
printf(" Please enter the gender of the student : ");
scanf("%s",&stu[i].gender);
printf(" Please enter the date of birth of the student : ");
scanf("%s",&stu[i].birthday);
printf(" Please enter the student's address : ");
scanf("%s",&stu[i].site);
printf(" Please enter the student's phone number : ");
scanf("%d",&stu[i].sum);
printf(" Please enter the student's email : ");
scanf("%s",&stu[i].mail);
printf("\n");
}
n=n+a; // Now the number of people in the system
}
void browse() // Browse student information
{
if(n==0) // When n by 0 Give a hint when , No information
{
printf(" There is currently no student information \n");
return;
}
printf(" Student number full name Age Gender date of birth Address Phone number email \n");
for(int i=0;i<=n;i++)
{
printf("%s %s %d %s %s %s %d %s", stu[i].sumber, stu[i].name, stu[i].age, stu[i].gender, stu[i].birthday, stu[i].site, stu[i].sum, stu[i].mail);
}
system("pause");
}
void inquire() // Search for student information
{
char num[10];
printf(" Please enter your student number :");
scanf("%s",&num);
int i;
for(i=0;i<n;i++)
{
if(strcmp(stu[i].sumber, num) == 0) // Traverse and query personal information
{
printf(" Student number full name Age Gender date of birth Address Phone number email ");
printf("%s %s %d %s %s %s %d %s", stu[i].sumber, stu[i].name, stu[i].age, stu[i].gender, stu[i].birthday, stu[i].site, stu[i].sum, stu[i].mail);
break;
}
}
if(i==n)
printf(" Check no one \n");
}
void save(){
int i;
FILE *fp;
char filename[16];
printf(" Please enter a file name to save :\n");
scanf("%s", filename);
fp = fopen(filename, "w");
for (i = 0; i < n; i++){
fprintf(fp, "%s%s%d%s%s%s%d%s\n", stu[i].sumber, stu[i].name, stu[i].age, stu[i].gender,
stu[i].birthday, stu[i].site, stu[i].sum, stu[i].mail);
}
printf(" Saved successfully !!!\n");
fclose(fp);
system("pause");
}
void del() // Delete
{
int i, j, flag;
char s1[10];
printf(" Please enter the student number to be deleted :\n");
scanf("%s", s1);
flag = 0;
for (i = 0; i < n; i++)
{
if (strcmp(s1, stu[i].sumber) == 0)
{
flag = 1;
for (j = i; j < n - 1; j++)
{
stu[j] = stu[j + 1];// Just move all the students in the back one
}
}
if (flag == 1) break;// Indicates that the student to be deleted has been found , End of cycle
}
if (0 == flag)
{
printf(" The student number does not exist !!!\n");
}
if (1 == flag)
{
printf(" Delete successful \n");
n--;
}
system("pause");
}
void remove() // modify
{
int i,g;
char name[15],number[9],sex,birthday,site,mail;
int age,sum;
printf(" Please enter the name of the student to be modified : \n");
getchar();
gets(name);
while(1)
{
g=0;
for(i=0;i<n;i++)
{
int num1;
if(strcmp(name,stu[i].name)==0) // Traverse to find information , Create submenu
{
g=1;
printf(" ---------- 1. Change the student number ----------\n");
printf(" ---------- 2. Change the name ----------\n");
printf(" ---------- 3. Change the age ----------\n");
printf(" ---------- 4. Change gender ----------\n");
printf(" ----------5. Modify phone number ----------\n");
printf(" ----------6. Modify the date of birth ----------\n");
printf(" ---------- 7. Change address ----------\n");
printf(" ---------- 8. Modify email ----------\n");
printf(" ---------- 9. Exit the submenu ----------\n");
printf(" Please enter the service of the submenu :");
scanf("%d",&num1);
switch(num1) // Change information
{
case 1:
printf(" Please enter a new student number :");
getchar();
gets(number);
strcpy(stu[i].sumber,number);
break;
case 2:
printf(" Please enter a new name :");
getchar();
gets(name);
strcpy(stu[i].name,name);
break;
case 3:
printf(" Please enter a new age :");
scanf("%d",&age);
stu[i].age=age;
break;
case 4:
printf(" Please enter a new gender :");
scanf("%d",&sex);
stu[i].gender=sex;
break;
case 5:
printf(" Please enter a new phone number :");
scanf("%d",&sum);
stu[i].sum=sum;
break;
case 6:
printf(" Please enter a new date of birth :");
scanf("%s",&birthday);
stu[i].birthday=birthday;
break;
case 7:
printf(" Please enter a new address :");
scanf("%d",&site);
stu[i].site=site;
break;
case 8:
printf(" Please enter a new mailbox :");
scanf("%d",&mail);
stu[i].mail=mail;
break;
case 9:
return;
break;
default:
printf(" Please be there. 1--9 Choose between !\n");
}
}
}
if(g==0)
printf(" Check no one ");
}
}
void show() // Show menu
{
printf(" ----------1. Enter student information ----------\n");
printf(" ----------2. Search for student information ----------\n");
printf(" ----------3. Browse student information ----------\n");
printf(" ----------4. Modify student information ----------\n");
printf(" ----------5. Save student information ----------\n");
printf(" ----------6. Delete student information ----------\n");
printf(" --------------0. sign out --------------\n");
}
void choose(int i)
{
switch(i){
case 1:entering();break;
case 2:inquire();break;
case 3:browse();break;
case 4:remove();break;
case 5:save();break;
case 6:del();break;
case 0:return;break;
default :printf(" Incorrect input ");
}
}
int main()
{
int a;
show();
do{
printf("\n Please enter the service you want to select : ");
scanf("%d",&a);
choose(a);
}while(a);
return 0;
}
You are welcome to correct anything wrong .
边栏推荐
- 【Datawhale】【机器学习】糖尿病遗传风险检测挑战赛
- JS judge the data types object.prototype.tostring.call and typeof
- Set view dynamic picture
- R language ggplot2 visualization: align the legend title to the middle of the legend box in ggplot2 (default left alignment, align legend title to middle of legend)
- Flutter event distribution
- Learning notes: what are the common array APIs that change the original array or do not change the original array?
- Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da
- Server memory failure prediction can actually do this!
- Rowselection emptying in a-table
- Wechat applet development
猜你喜欢
Distributed network communication framework: how to publish local services into RPC services
【荧光字效果】
在Blazor 中自定义权限验证
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component
R language ggplot2 visualization: align the legend title to the middle of the legend box in ggplot2 (default left alignment, align legend title to middle of legend)
2021 windows penetration of "Cyberspace Security" B module of Shandong secondary vocational group (analysis)
regular expression
Development to testing: a six-year road to automation starting from 0
Xiaobai makes a wave of deep copy and shallow copy
开发转测试:从0开始的6年自动化之路...
随机推荐
Distributed network communication framework: how to publish local services into RPC services
[datawhale] [machine learning] Diabetes genetic risk detection challenge
Draw arrows with openlayer
Show default image when wechat applet image cannot be displayed
网易云UI模仿--&gt;侧边栏
输入整数后输入整行字符串的解决方法
Flask框架初学-03-模板
Usage of the formatter attribute of El table
Error in render: "typeerror: cannot read properties of undefined (reading 'length')" --- error when calling interface
Flask framework beginner-03-template
Opencv image processing
30分钟彻底弄懂 synchronized 锁升级过程
MySQL function
IEEE conference upload font problem
Solution of inputting whole line string after inputting integer
Vs2019 configuring opencv
苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收
Basic usage of protobuf
数通基础-STP原理
Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool