当前位置:网站首页>About student management system (registration, login, student side)
About student management system (registration, login, student side)
2022-07-25 09:53:00 【Hills and valleys】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
List of articles
Preface
Here is the implementation of some small modules of the student management system :
Tips : The following is the main body of this article , The following cases can be used for reference
One 、 Registration module
How to write the registration module ?
1. First, you need to create a file to save the registered account and password , This eliminates the need to re register every time you log in , Just check whether this account exists in the file when logging in
2. Then we need to judge whether the account number entered each time is legal .( It refers to whether the entered student ID really exists ) At this time, we also need a file , To store all the student information that can be used to register .
So we need to judge whether the account number entered by the user corresponds Real students , And this account Not registered , You also need to check Save the account and password .
1. Registration module
void zhuce() {
// Here is the registration module
Sleep(1000);
system("cls");
// Registered account
printf(" Please enter your account number :");
char num[NUM_S];
scanf("%s", num);
Node* head = (Node*)malloc(sizeof(Node));
head = duqu_class1();// Here is to find out whether the account is legal
int k = -1;
while (head) {
if (strcmp(head->num, num) == 0) {
k = 0;
break;
} else {
k = 1;
head = head->next;
}
}
if (k == 1) {
printf(" I can't find your account , Please re-enter !\n");
zhuce();
}
struct count* count = (struct count*)malloc(sizeof(count));
count = duqu_count();// Judge whether the entered account has been registered
while (count) {
if (strcmp(count->num, num) == 0) {
printf(" This account has been registered , Please re-enter :\n");
zhuce();
break;
} else {
k = 2;
count = count->next;
}
}
char password1[PASS_S];// When the account is legal and not registered, you will come to this step
char password2[PASS_S];// We need to ask the user to enter the password twice , Achieve the purpose of determining the password
if (k == 2) {
printf(" Please input a password :");
scanf("%s", password1);
printf(" Please confirm the password :");
scanf("%s", password2);
if (strcmp(password1, password2) == 0) {
// There is no direct comparison here password1 and password2, Because they are all string types , The variable name should be a string address
printf(" Registered successfully !\n");
struct count* Head = (struct count*)malloc(sizeof(struct count));
struct count* p = Head;
strcpy(Head->num, num);
strcpy(Head->password, password1);
// It should be noted that you can't directly let Head->password=password
//password Is a string , You should use strcpy Function to copy it , The reason and the above strcmp The same function
save_count(Head);// For accounts that have been successfully registered , It should be saved in the account file
Head->next = NULL;
Head = Head->next;
}
} else {
// When the passwords entered twice are inconsistent , The user will be prompted that the passwords entered are inconsistent , Then return to the registration page
printf(" The two passwords are not the same ! Please re-enter :\n");
zhuce();
}
}
2. Judge whether the account exists
Read the information in the file ( There needs to be a named class1.txt The file of ), Read this file
Node* duqu_class1() {
// Read the information in the file into the linked list
Sleep(1000);
system("cls");
FILE* fp;
fp = fopen("class1.txt", "r");
Node* head, * p, * end;
head = p = (Node*)malloc(sizeof(Node));
while (!feof(fp)) {
end = (Node*)malloc(sizeof(Node));
fscanf(fp, "%s %s %s %d %d %d\n", end->name, end->num, end->class, &end->score1, &end->score2, &end->score3);
p->next = end;
p = end;
}
fclose(fp);
head = head->next;
p->next = NULL;
return head;
}
3. Judge whether the account is not registered
Here is the function to judge whether the read account has been registered , Note the return type of the function here (count.txt) It is a file used to store all registered accounts and passwords
struct count* duqu_count() {
Sleep(1000);
system("cls");
FILE* fp = fopen("count.txt", "r");
if (fp == NULL) {
perror(fopen);
return;
}
struct count* Head, * p, * end;
Head = p = (struct count*)malloc(sizeof(struct count));
while (!feof(fp)) {
end = (struct count*)malloc(sizeof(struct count));
fscanf(fp, "%s %s\n", end->num, end->password);
p->next = end;
p = end;
}
fclose(fp);
Head = Head->next;
p->next = NULL;
return Head;
}
4. Save the successfully registered account
Here is the function to save the successfully registered account and password , We still save the successfully registered account and password to count.txt In file
void save_count(struct count* head) {
// Save the registered account
Sleep(1000);
system("cls");
struct count* con = (struct count*)malloc(sizeof(struct count));
FILE* fp;
fp = fopen("count.txt", "a");
if (fp == NULL) {
perror(fopen);
} else {
con = head;
struct count* Headcount = con;
fprintf(fp, "%s %s\n", con->num, con->password);
con = con->next;
printf(" The account and password have been saved successfully !\n");
fclose(fp);
}
}
Two 、 Login module
1. Sign in
When the user enters , We only need Read the previous file storing the account and password , Just check whether the account number and password entered by the user are correct .
void denglu_stu() {
// Log in to the student account
Sleep(1000);
system("cls");
char num[NUM_S];
printf(" Please enter your account number :");
scanf("%s", num);
char password[PASS_S];
printf(" Please input a password :");
scanf("%s", password);
int i = 0;
struct count* Head = duqu_count();
// This function has been previously declared , Don't explain too much
while (Head) {
if (strcmp(Head->num, num) == 0 && strcmp(Head->password, password) == 0) {
printf(" Login successful !\n");
menu_stu();
i = 1;
break;
} else {
Head = Head->next;
}
}
if (i != 1) {
printf(" The student number or password entered is incorrect , Or this student ID has not been registered !\n");
}
}
3、 ... and . Students check their scores
struct student* Head=NULL;
Head = duqu_class1();
// It is still the previous function of reading student information
char num[NUM_S];
printf(" Please enter your student number :\n");
scanf("%s", num);
int i = 0;
while (Head) {
if (strcmp(Head->num, num) == 0) {
printf("%d %d %d", Head->score1, Head->score2, Head->score3);
i = 1;
break;
} else {
Head = Head->next;
}
}
if (i != 1) {
printf(" The student number entered is incorrect , Please re-enter !\n");
chaxun(k);
}
Four . Students check their grades
struct student* Head=NULL;
Head = duqu_class1();
while (Head) {
printf("%5s %5s %5s %5d %5d %5d\n", Head->name, Head->num, Head->class, Head->score1, Head->score2, Head->score3);
Head = Head->next;
}
summary
Register in the student management system , Login and other modules , Note that we need to operate the file . Be sure to pay attention to the way the file is opened , Otherwise, you may find that you have got another empty file after the operation .
边栏推荐
猜你喜欢

预测2021年:加速实现RPA以外的超自动化成果

【RNN】剖析RNN 之 从RNN-(Simple|LSTM) 到 序列生成 再到 seq2seq框架(encoder-decoder,或称为seq2seq)

TensorFlow raw_rnn - 实现seq2seq模式中将上一时刻的输出作为下一时刻的输入

从Anaconda到TensorFlow到Jupyter一路踩坑一路填平

AMD EPYC 9664旗舰规格曝光:96核192线程 480MB缓存 3.8GHz频率

Raspberry sect door ban system based on face recognition

Creation of adjacency matrix of undirected connected graph output breadth depth traversal

MLX90640 红外热成像传感器测温模块开发笔记(二)

Segmentation based deep learning approach for surface defect detection

如何安装pytorch?—— 一种最简单有效的方法!
随机推荐
Principle analysis of self supervised depth estimation of fish eye image and interpretation of omnidet core code
SD/SDIO/EMMC
【机器翻译】SCONES——用多标签任务做机器翻译
初识Opencv4.X----图像卷积
pytorch使用tensorboard实现可视化总结
【降维打击】希尔伯特曲线
CDA LEVELⅠ2021新版模拟题一(附答案)
从鱼眼到环视到多任务王炸——盘点Valeo视觉深度估计经典文章(从FisheyeDistanceNet到OmniDet)(下)
First knowledge of opencv4.x --- image convolution
Defect detection network -- hybrid supervision (kolektor defect data set reproduction)
CCF 201503-3 节日
Some usages of Matlab's find() function (quickly find qualified values)
MLX90640 红外热成像传感器测温模块开发笔记(二)
【数据挖掘】第四章 分类任务(决策树)
无向连通图邻接表的创建输出广度深度遍历
ECO简介
CDA Level1复盘总结
ARM GIC简介
Solve the problem that esp8266 cannot connect mobile phones and computer hotspots
括号匹配问题