当前位置:网站首页>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 .
边栏推荐
猜你喜欢

SystemVerilog语法

深度估计自监督模型monodepth2在自己数据集的实战——单卡/多卡训练、推理、Onnx转换和量化指标评估

BSP3 电力监控仪(功率监控仪)端子定义和接线

~1 CCF 2022-06-2 treasure hunt! Big adventure!

Server CUDA toolkit multi version switching

初识Opencv4.X----图像直方图均衡

Defect detection network -- hybrid supervision (kolektor defect data set reproduction)

ARMV8体系结构简介

*7-1 CCF 2015-09-1 sequence segmentation

CUDA explanation - why GPU is used in deep learning
随机推荐
First knowledge of opencv4.x --- box filtering
Gartner 2022年顶尖科技趋势之超级自动化
A picture explains SQL join left and right
初识Opencv4.X----图像直方图均衡
yolov5实现小数据集的目标检测--kolektor缺陷数据集
深度学习 段错误(Segment Core/ Exit code 139)情况记录
单目深度估计自监督模型Featdepth解读(上)——论文理解和核心源码分析
1094 - Google recruitment
服务器cuda toolkit多版本切换
matlab的find()函数的一些用法(快速查找符合条件的值)
T5论文总结
Kotlin basic knowledge points
testbench简介
ARMv8通用定时器简介
@3-2 optimal threshold of CCF 2020-12-2 final forecast
ARMV8体系结构简介
¥ 1-3 SWUST OJ 942: reverse sequence table
1094--谷歌的招聘
CCF 201503-3 节日
SystemVerilog语法