当前位置:网站首页>C language simple student management system (including source code)
C language simple student management system (including source code)
2022-07-04 05:19:00 【Curz crisp】
Project screenshots :
Here is the complete source code ;
cpp file :
#include "StudentManagerSystem.h"
int main() {
// Change console font color
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
int num;
while (1) {
welcome();
scanf("%d", &num);
switch (num) {
case 1: // Enter student information
InputStudent();
break;
case 2: // Print student information
PrintStudent();
break;
case 3: // Save student information
SaveStudent();
break;
case 4: // Read student information
ReadStudent();
break;
case 5: // Count the number of all students
CountStudent();
break;
case 6: // Search for student information
FindStudent();
break;
case 7: // Modify student information
ModifyStudent();
break;
case 8: // Delete student information
DeleteStudent();
break;
case 9: // Exit the system
return 0;
}
}
return 0;
}
The header file :
#pragma once
#include<bits/stdc++.h>
#include <windows.h>
using namespace std;
// Clear the screen after each operation
void cleanScreen() {
system("pause"); // Pause
system("cls"); // Clear the screen
}
// The welcome screen
void welcome() {
printf("*************************************************\n");
printf("\t\t Welcome to student management system \t\t\t\n");
printf("*************************************************\n");
printf("*\t\t Please select the function list \t\t\t*\n");
printf("*************************************************\n");
printf("*\t\t1. Enter student information \t\t\t*\n");
printf("*\t\t2. Print student information \t\t\t*\n");
printf("*\t\t3. Save student information \t\t\t*\n");
printf("*\t\t4. Read student information \t\t\t*\n");
printf("*\t\t5. Count the number of all students \t\t*\n");
printf("*\t\t6. Search for student information \t\t\t*\n");
printf("*\t\t7. Modify student information \t\t\t*\n");
printf("*\t\t8. Delete student information \t\t\t*\n");
printf("*\t\t9. Exit the system \t\t\t*\n");
printf("\n");
}
typedef struct student {
char name[30]; // name
int age; // Age
long long stuNum; // Student number
int score; // fraction
}Student;
typedef struct _Node {
Student stu;
struct _Node* pNext;
}Node;
Node* g_pHead = NULL; // Initialization header pointer
// Enter student information
void InputStudent() {
Node* pNewNode = (Node*)malloc(sizeof(Node)); // Note that this is (sizeof(Node)), instead of sizeof(Node*)!!!
pNewNode->pNext = NULL;
// The first interpolation
if (g_pHead == NULL) {
g_pHead = pNewNode;
}
else {
pNewNode->pNext = g_pHead;
g_pHead = pNewNode;
}
// input data
printf(" Please enter student information :\n");
printf(" Enter a name :\n");
scanf("%s", pNewNode->stu.name);
printf(" Enter the age :\n");
scanf("%d", &pNewNode->stu.age);
printf(" Enter the student id :\n");
scanf("%lld", &pNewNode->stu.stuNum);
printf(" Enter the score :\n");
scanf("%d", &pNewNode->stu.score);
printf(" Student information entered successfully !\n");
cleanScreen();
}
// Output student information
void PrintStudent() {
Node* p = g_pHead;
printf("*************************************************\n");
printf(" Student number \t\t full name \t\t Age \t\t fraction \n");
while (p != NULL) {
printf("%-16lld", p->stu.stuNum);
printf("%-16s", p->stu.name);
printf("%-16d", p->stu.age);
printf("%-16d\n", p->stu.score);
p = p->pNext;
}
cleanScreen();
}
// Save student information
void SaveStudent() {
// Open file
FILE* fp = fopen("C:\\Users\\14185\\Desktop\\stuinfo.dat", "w");
if (fp == NULL) {
printf(" File opening failure \n");
return;
}
// Write data to file ( Traversing the linked list )
Node* p = g_pHead;
while (p != NULL) {
fwrite(&p->stu, 1, sizeof(Student), fp);
p = p->pNext;
}
// Close file
fclose(fp);
printf(" Data saved successfully !\n");
cleanScreen();
}
// Read the data in the file
void ReadStudent() {
FILE* fp = fopen("C:\\Users\\14185\\Desktop\\stuinfo.dat", "r");
if (fp == NULL) {
printf(" Failed to read file !\n");
return;
}
Student stu;
while (fread(&stu, 1, sizeof(Student), fp)) {
Node* pNewNode = (Node*)malloc(sizeof(Node));
pNewNode->pNext = NULL;
memcpy(pNewNode, &stu, sizeof(Student));
if (g_pHead == NULL) {
g_pHead = pNewNode;
}
else {
pNewNode->pNext = g_pHead;
g_pHead = pNewNode;
}
fclose(fp);
printf(" File read successful !\n");
cleanScreen();
}
}
// Count the number of all students
void CountStudent() {
int cnt = 0;
Node* p = g_pHead;
while (p != NULL) {
++cnt;
p = p->pNext;
}
printf(" The total number of students is :%d\n", cnt);
cleanScreen();
}
// Find students
void FindStudent() {
long long stuNum; // Student number
printf(" Please enter the student number you want to find :\n");
scanf("%lld", &stuNum);
Node* p = g_pHead;
while (p != NULL) {
if (p->stu.stuNum == stuNum) {
printf(" Student number :%lld full name :%s Age :%d fraction :%d\n",p->stu.stuNum, p->stu.name, p->stu.age, p->stu.score);
cleanScreen();
return;
}
p = p->pNext;
}
printf(" No relevant student information was found .\n");
cleanScreen();
}
// Modify student information
void ModifyStudent() {
printf(" Please enter the student number that needs to modify the student information :\n");
long long stuNum;
scanf("%lld", &stuNum);
Node* p = g_pHead;
while (p != NULL) {
if (p->stu.stuNum == stuNum) {
printf(" Please input the modified information ( Student number / full name / Age / fraction ):\n");
scanf("%lld %s %d %d", &p->stu.stuNum, p->stu.name, &p->stu.age, &p->stu.score);
cleanScreen();
return;
}
p = p->pNext;
}
printf(" No student information found .\n");
cleanScreen();
}
// Delete student information
void DeleteStudent() {
printf(" Please enter the student number of the student information to be deleted :\n");
long long stuNum;
scanf("%lld", &stuNum);
Node* p1, *p2; // Note that there p2 Plus an asterisk in front !
// If the linked list is empty at the beginning
if (g_pHead == NULL) {
printf(" No student information found .\n");
cleanScreen();
return;
}
// If the point to be deleted happens to be the head node
if (g_pHead->stu.stuNum == stuNum) {
p1 = g_pHead;
g_pHead = g_pHead->pNext;
free(p1);
printf(" Delete successful !\n");
cleanScreen();
return;
}
// The point to be deleted is in the middle
Node* p = g_pHead;
while (p->pNext != NULL) {
if (p->pNext->stu.stuNum == stuNum) {
p2 = p->pNext;
p->pNext = p->pNext->pNext;
free(p2);
printf(" Delete successful !\n");
cleanScreen();
return;
}
}
printf(" No student information found .\n");
cleanScreen();
return;
}
边栏推荐
- 简易零钱通
- 《Cross-view Transformers for real-time Map-view Semantic Segmentation》论文笔记
- 远程桌面客户端 RDP
- TCP状态转换图
- 中职组网络安全—内存取证
- NTFS 安全权限
- With the advent of the IP era, how can E-sports hotels take advantage of the "east wind" of games?
- Annex II: confidentiality agreement for offensive and defensive drills docx
- VB.net 简单的处理图片,黑白(类库——7)
- Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
猜你喜欢
PostgreSQL has officially surpassed mysql. Is this guy too strong!
Unity is connected to the weather system
VB.net 简单的处理图片,黑白(类库——7)
全国职业院校技能大赛(中职组)网络安全竞赛试题—解析
Ping port artifact psping
LabVIEW错误对话框的出现
Topological sorting and graphical display of critical path
LM small programmable controller software (based on CoDeSys) note XXI: error 3703
[paper summary] zero shot semantic segmentation
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
随机推荐
2022危险化学品经营单位安全管理人员上岗证题库及答案
A summary of the 8544 problem that SolidWorks Standard cannot obtain a license
Annex I: power of attorney for 202x XXX attack and defense drill
Graduation design of small programs -- small programs of food and recipes
Remote desktop client RDP
Annex II: confidentiality agreement for offensive and defensive drills docx
[matlab] communication signal modulation general function interpolation function
Simulink与Arduino串口通信
中科磐云—D模块解析以及评分标准
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
补某视频网站的js,进行视频解密
Zhongke Panyun - 2022 Guangxi reverse analysis ideas
Zkevm (12) state proof of appliedzkp
National vocational college skills competition (secondary vocational group) network security competition questions - Analysis
Void convolution, deformable convolution, deformable ROI pooling
Zhongke panyun-d module analysis and scoring standard
appliedzkp zkevm(11)中的EVM Proof
Daily question brushing record (12)
2022广东省赛——编码信息获取 解析flag
VB.net 调用FFmpeg简单处理视频(类库——6)