当前位置:网站首页>Student Information Management System (first time...)
Student Information Management System (first time...)
2022-08-05 10:57:00 【51CTO】
Because I didn't read books before doing questions,结果cI did not see the input and output of the last document on the language book.Yesterday, the senior asked us to write a management system.我懵了..
Just spent an hour looking at the input and output of the file,Let's write a simple student information management system first.If there are any omissions, please leave a comment..I will improve.
由于第一次写,Sorry for the rough code...
对了,我还发现一个问题,Hope the bloggers will reply.
How can I wrap the data written to the file in the text.
I added after the filefputc('\n'),Is to achieve a newline,But I can't find it when I search.
Hope someone can answer..谢谢!!
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
using namespace std;
struct node
{
char name[ 20], banji[ 20]; //学生的姓名,班级
char age[ 5], xuehao[ 21]; //学生的年龄,学号.Of course other details can be added,比如手机号码,家庭住址等等、
} stu[ 500];
FILE * fp;
int i;
bool cmp1( node x, node y) //Sort by student's class
{
if( strcmp( x. banji, y. banji) < 0) return true;
if( strcmp( x. banji, y. banji) == 0 && strcmp( x. xuehao, y. xuehao) < 0) return true;
return false;
}
bool cmp2( node x, node y) //按照学生的学号排序
{
if( strcmp( x. xuehao, y. xuehao) < 0) return true;
if( strcmp( x. xuehao, y. xuehao) == 0 && strcmp( x. banji, y. banji) < 0) return true;
return false;
}
void find()
{
if(( fp = fopen( "susu.doc", "r")) == NULL)
{
printf( "不能打开文件\n");
exit( 0) ;
}
while( 1)
{
system( "cls");
printf( "**************************Student information search interface********************************\n");
printf( " 1.Find by name and class\t\t2.根据学号查找\n");
printf( " 3.返回主界面\n");
printf( "**************************************************************************\n");
char ch = getchar();
if( ch == '1')
{
while( 1)
{
system( "cls"); //清屏
int mark =- 1;
char na[ 20], ban[ 20];
printf( "请输入学生班级:");
scanf( "%s", ban);
printf( "请输入学生姓名:");
scanf( "%s", na);
for( int j = 0; j < i; j ++)
{
fread( & stu[ j], sizeof( struct node), 1, fp);
if( strcmp( stu[ j]. name, na) == 0 && strcmp( stu[ j]. banji, ban) == 0)
mark = j;
}
if( mark !=- 1)
printf( "%s %s %s %s\n", stu[ mark]. name, stu[ mark]. banji, stu[ mark]. xuehao, stu[ mark]. age);
else
printf( "没有这个人\n");
fclose( fp);
getchar();
printf( "是否继续查找?是【Y】/否【N】");
char ch = getchar();
if( ch == 'n' || ch == 'N')
break;
}
}
if( ch == '2')
{
while( 1)
{
system( "cls");
char num[ 21];
int mark =- 1;
printf( "请输入学生学号\n");
scanf( "%s", num);
for( int j = 0; j < i; j ++)
{
fread( & stu[ j], sizeof( struct node), 1, fp);
if( strcmp( stu[ j]. xuehao, num) == 0)
mark = j;
}
if( mark !=- 1)
printf( "姓名:%s\t班级:%s\t学号:%s\t年龄:%s\n", stu[ mark]. name, stu[ mark]. banji, stu[ mark]. xuehao, stu[ mark]. age);
else
printf( "没有此学号\n");
fclose( fp);
getchar();
printf( "是否继续查找?是【Y】/否【N】");
char ch = getchar();
if( ch == 'n' || ch == 'N')
break;
}
}
if( ch == '3')
break;
}
}
void add() //增加
{
if(( fp = fopen( "susu.doc", "a")) == NULL)
{
printf( "不能打开文件\n");
exit( 0) ;
}
printf( "**************************学生信息添加界面********************************\n");
while( 1)
{
system( "cls"); //清屏
printf( "请输入学生的班级:");
scanf( "%s", stu[ i]. banji);
printf( "请输入学生的姓名:");
scanf( "%s", stu[ i]. name);
printf( "请输入学生的学号: ");
scanf( "%s", & stu[ i]. xuehao);
printf( "请输入学生的年龄: ");
scanf( "%s", & stu[ i]. age);
if( fwrite( & stu[ i], sizeof( struct node), 1, fp) != 1)
printf( "写入错误\n");
else
printf( "写入成功\n");
getchar();
printf( "是否继续输入?是【Y】/否【N】");
char ch = getchar();
if( ch == 'y' || ch == 'Y')
i ++;
else
break;
}
fclose( fp);
}
void del() //Explain the deletion process,Just read the file first,Find the one that needs to be deleted,然后mark标记一下.writing file,当写到mark时跳过.
{
while( 1)
{
system( "cls");
printf( "**************************Student information deletion interface********************************\n");
printf( " 1.Delete based on name and class\t\t2.根据学号删除\n");
printf( " 3.返回主菜单\n");
printf( "**************************************************************************\n");
char ch = getchar();
if( ch == '1')
{
while( 1)
{
system( "cls");
if(( fp = fopen( "susu.doc", "rb")) == NULL)
{
printf( "error\n");
exit( 0);
}
int mark =- 1;
char na[ 20], ban[ 20];
printf( "请输入学生班级:");
scanf( "%s", ban);
printf( "请输入学生姓名:");
scanf( "%s", na);
for( int j = 0; j < i; j ++)
{
fread( & stu[ j], sizeof( struct node), 1, fp);
if( strcmp( stu[ j]. name, na) == 0 && strcmp( stu[ j]. banji, ban) == 0)
{
mark = j;
printf( "确认删除:姓名:%s\t班级:%s\t学号:%s\t年龄:%s\n吗?(Y/N)\n", stu[ mark]. name, stu[ mark]. banji, stu[ mark]. xuehao, stu[ mark]. age);
break;
}
}
fclose( fp);
if( mark ==- 1)
printf( "找不到这个人\n");
else
{
getchar();
char ch = getchar();
if( ch == 'y' || ch == 'Y')
{
fp = fopen( "susu.doc", "wb");
for( int j = 0; j < i; j ++)
{
if( j != mark)
fwrite( & stu[ j], sizeof( struct node), 1, fp);
}
fclose( fp);
printf( "删除成功\n");
}
else
printf( "删除失败\n");
}
getchar();
printf( "是否继续删除?是【Y】/否【N】\n");
ch = getchar();
if( ch == 'y' || ch == 'Y')
i --;
else
break;
}
}
if( ch == '2')
{
while( 1)
{
system( "cls");
if(( fp = fopen( "susu.doc", "rb")) == NULL)
{
printf( "error\n");
exit( 0);
}
int mark =- 1;
char num[ 21];
printf( "请输入学生学号:");
scanf( "%s", num);
for( int j = 0; j < i; j ++)
{
fread( & stu[ j], sizeof( struct node), 1, fp);
if( strcmp( stu[ j]. xuehao, num) == 0)
{
mark = j;
printf( "确认删除:姓名:%s\t班级:%s\t学号:%s\t年龄:%s\n吗?(Y/N)\n", stu[ mark]. name, stu[ mark]. banji, stu[ mark]. xuehao, stu[ mark]. age);
break;
}
}
fclose( fp);
if( mark ==- 1)
printf( "找不到这个人\n");
else
{
getchar();
char ch = getchar();
if( ch == 'y' || ch == 'Y')
{
fp = fopen( "susu.doc", "wb");
for( int j = 0; j < i; j ++)
{
if( j != mark)
fwrite( & stu[ j], sizeof( struct node), 1, fp);
}
fclose( fp);
printf( "删除成功\n");
}
else
printf( "删除失败\n");
}
getchar();
printf( "是否继续删除?是【Y】/否【N】\n");
ch = getchar();
if( ch == 'y' || ch == 'Y')
i --;
else
break;
}
}
if( ch == '3')
break;
}
}
void sca() //浏览
{
system( "cls");
printf( "**************************Student information browsing interface********************************\n");
if(( fp = fopen( "susu.doc", "rb")) == NULL)
{
printf( "error\n");
exit( 0);
}
printf( " \t姓名\t\t班级\t\t学号\t\t年龄\n");
for( int j = 0; j < i; j ++)
{
fread( & stu[ j], sizeof( struct node), 1, fp);
printf( "%15s%15s%15s%15s\n", stu[ j]. name, stu[ j]. banji, stu[ j]. xuehao, stu[ j]. age);
}
printf( "**************************************************************************\n");
fclose( fp);
system( "pause");
}
void arry() //排序
{
if(( fp = fopen( "susu.doc", "rb")) == NULL)
{
printf( "error\n");
exit( 0);
}
while( 1)
{
node sort_temp[ 500];
system( "cls");
printf( "**************************Student information sorting interface********************************\n");
printf( " 1.Sort by class\t\t2.根据学号排序\n");
printf( " 3.返回主菜单\n");
printf( "**************************************************************************\n");
char ch = getchar();
if( ch == '1')
{
for( int j = 0; j < i; j ++)
{
fread( & stu[ j], sizeof( struct node), 1, fp);
sort_temp[ j] = stu[ j];
}
fclose( fp);
fp = fopen( "susu.doc", "wb");
sort( sort_temp, sort_temp + i, cmp1);
for( int j = 0; j < i; j ++)
fwrite( & sort_temp[ j], sizeof( struct node), 1, fp);
fclose( fp);
sca();
}
if( ch == '2')
{
for( int j = 0; j < i; j ++)
{
fread( & stu[ j], sizeof( struct node), 1, fp);
sort_temp[ j] = stu[ j];
}
fclose( fp);
fp = fopen( "susu.doc", "wb");
sort( sort_temp, sort_temp + i, cmp2);
for( int j = 0; j < i; j ++)
fwrite( & sort_temp[ j], sizeof( struct node), 1, fp);
fclose( fp);
sca();
}
if( ch == '3')
break;
}
}
int get_i() //Get how many students there are
{
if(( fp = fopen( "susu.doc", "r")) == NULL)
fopen( "susu.doc", "w");
for( i = 0;; i ++)
{
if( fread( & stu[ i], sizeof( struct node), 1, fp) == 1)
continue;
else
break;
}
fclose( fp);
return i;
}
int main()
{
while( 1)
{
system( "cls");
printf( "**************************学生信息管理系统********************************\n");
printf( " There are currently students in the school%d人\n", get_i());
printf( " 1.查询学生信息\t\t2.新增学生信息\n");
printf( " 3.删除学生信息\t\t4.浏览学生信息\n");
printf( " 5.学生信息排序\t\t6.退出程序\n");
printf( "**************************************************************************\n");
char ch = getchar();
if( ch == '1') //查询学生信息
find();
else if( ch == '2') //添加学生信息
add();
else if( ch == '3') //删除学生信息
del();
else if( ch == '4') //浏览学生信息
sca();
else if( ch == '5') //对学生信息排序
arry();
else
return 0;
getchar();
}
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
- 226.
- 227.
- 228.
- 229.
- 230.
- 231.
- 232.
- 233.
- 234.
- 235.
- 236.
- 237.
- 238.
- 239.
- 240.
- 241.
- 242.
- 243.
- 244.
- 245.
- 246.
- 247.
- 248.
- 249.
- 250.
- 251.
- 252.
- 253.
- 254.
- 255.
- 256.
- 257.
- 258.
- 259.
- 260.
- 261.
- 262.
- 263.
- 264.
- 265.
- 266.
- 267.
- 268.
- 269.
- 270.
- 271.
- 272.
- 273.
- 274.
- 275.
- 276.
- 277.
- 278.
- 279.
- 280.
- 281.
- 282.
- 283.
- 284.
- 285.
- 286.
- 287.
- 288.
- 289.
- 290.
- 291.
- 292.
- 293.
- 294.
- 295.
- 296.
- 297.
- 298.
- 299.
- 300.
- 301.
- 302.
- 303.
- 304.
- 305.
- 306.
- 307.
- 308.
- 309.
- 310.
- 311.
- 312.
- 313.
- 314.
- 315.
- 316.
- 317.
- 318.
- 319.
- 320.
- 321.
- 322.
- 323.
- 324.
- 325.
- 326.
- 327.
- 328.
- 329.
- 330.
- 331.
- 332.
- 333.
- 334.
- 335.
- 336.
- 337.
- 338.
- 339.
- 340.
- 341.
- 342.
- 343.
- 344.
- 345.
- 346.
- 347.
- 348.
- 349.
- 350.
- 351.
- 352.
- 353.
- 354.
- 355.
- 356.
- 357.
- 358.
- 359.
- 360.
- 361.
- 362.
- 363.
- 364.
- 365.
- 366.
- 367.
- 368.
1.删除学生信息,No student found no response resolved
边栏推荐
- 一张图看懂 SQL 的各种 join 用法!
- Linux:记一次CentOS7安装MySQL8(博客合集)
- 华为分析&联运活动,助您提升游戏总体付费
- PostgreSQL 2022 报告:流行度上涨,开源、可靠性和扩展是关键
- The query that the user's test score is greater than the average score of a single subject
- How OpenHarmony Query Device Type
- 《分布式云最佳实践》分论坛,8 月 11 日深圳见
- 今天告诉你界面控件DevExpress WinForms为何弃用经典视觉样式
- RT-Thread记录(一、RT-Thread 版本、RT-Thread Studio开发环境 及 配合CubeMX开发快速上手)
- PCB layout must know: teach you to correctly lay out the circuit board of the op amp
猜你喜欢
随机推荐
The host computer develops C# language: simulates the STC serial port assistant to receive the data sent by the microcontroller
hdu4545 魔法串
gradle尚硅谷笔记
The query that the user's test score is greater than the average score of a single subject
时间格式2020-01-13T16:00:00.000Z中的T和Z分别表示什么,如何处理
lvgl 实现状态提示图标自动对齐补位显示
张朝阳对话俞敏洪:一边是手推物理公式,一边是古诗信手拈来
GPU-CUDA-图形渲染分析
字节一面:TCP 和 UDP 可以使用同一个端口吗?
GCC编译的时候头文件搜索规则
双因子与多因子身份验证有什么区别?
Chapter 5: Multithreaded Communication—wait and notify
今天告诉你界面控件DevExpress WinForms为何弃用经典视觉样式
PostgreSQL 2022 报告:流行度上涨,开源、可靠性和扩展是关键
FPGA: Basic Getting Started Button Controlling LED Lights
Google启动通用图像嵌入挑战赛
【深度学习】mmclassification mmcls 实战多标签分类任务教程,分类任务
Custom filters and interceptors implement ThreadLocal thread closure
Use KUSTO query statement (KQL) to query LOG on Azure Data Explorer Database
【加密解密】明文加密解密-已实现【已应用】