当前位置:网站首页>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
边栏推荐
- 提问题进不去。想问大家一个关于返回值的问题(图的遍历),求给小白解答啊
- nyoj754 黑心医生 结构体优先队列
- 用KUSTO查询语句(KQL)在Azure Data Explorer Database上查询LOG实战
- GCC编译的时候头文件搜索规则
- PPOCR 检测器配置文件参数详解
- 2022 Hangzhou Electric Power Multi-School Session 6 1008.Shinobu Loves Segment Tree Regular Questions
- MMDetection in action: MMDetection training and testing
- Image segmentation model - a combination of segmentation_models_pytorch and albumations to achieve multi-category segmentation
- In-depth understanding of timeout settings for Istio traffic management
- PostgreSQL 2022 Report: Rising popularity, open source, reliability and scaling key
猜你喜欢

linux下oracle常见操作以及日常积累知识点(函数、定时任务)

This notebook of concurrent programming knowledge points strongly recommended by Ali will be a breakthrough for you to get an offer from a big factory

PostgreSQL 2022 报告:流行度上涨,开源、可靠性和扩展是关键

【OpenCV】-仿射变换

苹果Meta都在冲的Pancake技术,中国VR团队YVR竟抢先交出产品答卷

登录功能和退出功能(瑞吉外卖)

Ali's new launch: Microservices Assault Manual, all operations are written out in PDF

Login function and logout function (St. Regis Takeaway)

使用Windbg过程中两个使用细节分享

Create a Dapp, why choose Polkadot?
随机推荐
PPOCR 检测器配置文件参数详解
Microcontroller: temperature control DS18B20
hdu4545 魔法串
如何测试一下现场的备机失败,转发主机的场景?
秘乐短视频挖矿系统开发详情
【深度学习】mmclassification mmcls 实战多标签分类任务教程,分类任务
CenOS MySQL入门及安装
[Translation] Chaos Net + SkyWalking: Better observability for chaos engineering
Common operations of oracle under linux and daily accumulation of knowledge points (functions, timed tasks)
How to choose coins and determine the corresponding strategy research
Chapter 5: Multithreaded Communication—wait and notify
Dynamics 365Online PDF导出及打印
Nature:猪死亡1小时后,器官再次运转
双因子与多因子身份验证有什么区别?
2022 Hangzhou Electric Power Multi-School Session 6 1008.Shinobu Loves Segment Tree Regular Questions
What are the standards for electrical engineering
一张图看懂 SQL 的各种 join 用法!
停电。。。烦烦烦!!!
记2022年七夕感慨
【综合类型第 35 篇】程序员的七夕浪漫时刻