当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
VSCode的有用插件
[paper summary] zero shot semantic segmentation
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
Etcd database source code analysis - initialization overview
Detailed comparison of Hynix emmc5.0 and 5.1 series
Automated testing selenium foundation -- webdriverapi
海力士EMMC5.0及5.1系列对比详解
拓扑排序和关键路径的图形化显示
2022年T电梯修理操作证考试题库及模拟考试
2022广东省赛——编码信息获取 解析flag
随机推荐
Get the ID of the record just inserted from laravel
JS string splicing enhancement
[QT] timer
中科磐云—模块A 基础设施设置与安全加固 评分标准
flink1.13 sql基础语法(一)DDL、DML
How to build your own knowledge engine? Community open application
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
[untitled]
[matlab] communication signal modulation general function - low pass filter
力扣(LeetCode)184. 部门工资最高的员工(2022.07.03)
Notepad++--显示相关的配置
C语言简易学生管理系统(含源码)
Using jsts in esmodule environment
简单g++和gdb调试
中科磐云—数据分析与取证数据包flag
定制一个自己项目里需要的分页器
Unity is connected to the weather system
[matlab] general function of communication signal modulation bandpass filter
[matlab] matlab simulation modulation system - VSB system
NTFS security permissions