当前位置:网站首页>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;
}边栏推荐
- Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display
- The first introduction, stages and methods of defense system breakthrough from the perspective of the red team
- KMP match string
- [wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
- Appearance of LabVIEW error dialog box
- [matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)
- C语言简易学生管理系统(含源码)
- VSCode的有用插件
- LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
- VB.net 简单的处理图片,黑白(类库——7)
猜你喜欢

ping端口神器psping
![[paper summary] zero shot semantic segmentation](/img/78/ee64118d86a7e43ec4d1cb97191fbe.jpg)
[paper summary] zero shot semantic segmentation

Flask

ETCD数据库源码分析——初始化总览

小程序毕业设计---美食、菜谱小程序

Simulink and Arduino serial port communication
![[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术](/img/87/e0469e280365ed0261e2b551ebd888.png)
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术

【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre

Zhongke panyun-d module analysis and scoring standard

Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
随机推荐
Topological sorting and graphical display of critical path
KMP匹配字符串
【QT】制作MyComboBox点击事件
Notes on the paper "cross view transformers for real time map view semantic segmentation"
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
模拟小根堆
Using jsts in esmodule environment
Simple g++ and GDB debugging
Useful plug-ins for vscode
[matlab] matlab simulates digital baseband transmission system - digital baseband transmission system
光模块字母含义及参数简称大全
June 2022 summary
Detailed comparison of Hynix emmc5.0 and 5.1 series
Analysis of classical pointer and array written test questions in C language
中科磐云—2022广东木马信息获取解析
Get the ID of the record just inserted from laravel
[matlab] matlab simulation - low pass Gaussian white noise
Graduation design of small programs -- small programs of food and recipes
VSCode的有用插件