当前位置:网站首页>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】【机器学习】糖尿病遗传风险检测挑战赛
- Yarn 'TSC' is not an internal or external command, nor is it a runnable program or batch file. The problem that the command cannot be found after installing the global package
- 2021年山东省中职组“网络空间安全”B模块windows渗透(解析)
- The charm of SQL optimization! From 30248s to 0.001s
- Keeping alive to realize MySQL automatic failover
- Getting started with SQL - combined tables
- Apple dominates, Samsung revives, and domestic mobile phones fail in the high-end market
- Phpexcel export Emoji symbol error
- Rowselection emptying in a-table
- Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool
猜你喜欢

Principle analysis and source code interpretation of service discovery

B站这个视频我是跪着看完的

Alibaba cloud technology expert haochendong: cloud observability - problem discovery and positioning practice

2022 zhongkepan cloud - server internal information acquisition and analysis flag

Spolicy request case

Wechat applet learning notes 1
![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](/img/21/5dceab9815b503f0b62d26a430d7eb.png)
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

服务器内存故障预测居然可以这样做!

Common errors when starting projects in uniapp ---appid

Data communication foundation TCPIP reference model
随机推荐
Usage of the formatter attribute of El table
Flask framework beginner-03-template
数通基础-Telnet远程管理设备
Docker configuring MySQL Cluster
Transform between tree and array in JS (hide the children field if the child node of the tree is empty)
Basic usage of protobuf
论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
在Blazor 中自定义权限验证
I finished watching this video on my knees at station B
Sublime install plug-ins
编写一个在bash / shell 和 PowerShell中均可运行的脚本
regular expression
In the same CONDA environment, install pytroch first and then tensorflow
The diagram of user login verification process is well written!
The problem of four columns of Hanoi Tower
AirTest
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
Production of a-modal drag function in antui
MySQL的逻辑架构
Server memory failure prediction can actually do this!
