学生生日管理系统呕心沥血整理版.docx
- 文档编号:24668760
- 上传时间:2023-05-30
- 格式:DOCX
- 页数:16
- 大小:106.99KB
学生生日管理系统呕心沥血整理版.docx
《学生生日管理系统呕心沥血整理版.docx》由会员分享,可在线阅读,更多相关《学生生日管理系统呕心沥血整理版.docx(16页珍藏版)》请在冰豆网上搜索。
学生生日管理系统呕心沥血整理版
实验报告
1任务概述(任务说明)
写一个基于文件的小型管理系统。
2设计思路(包括技术基础等)
3程序结构描述
建立两个类:
ZHL_Student类和ZHL_Birthday类
创建几个功能函数:
voidZHL_print();
voidZHL_Input();
voidZHL_Add();
voidZHL_Remove();
voidZHL_Change();
voidZHL_Search();
intSearch(char[]);
voidZHL_Write();
voidZHL_Exit();
4源码,文档化
ZHL_Stu。
h
#ifndefSTU_H_
#defineSTU_H_
#include〈iostream>
#include #include〈string〉 usingnamespacestd; externintCount; classZHL_Birthday { public: intyear,month,day; voidSetBirthday(intY,intM,intD) { year=Y; month=M; day=D; } }; classZHL_Student: publicZHL_Birthday { public: voidSet(char*stu_name,char*stu_num,intYear,intMonth,intDay) { strncpy(Stu_Name,stu_name,sizeof(stu_name)); strncpy(Stu_Num,stu_num,sizeof(stu_num)); SetBirthday(Year,Month,Day); } char*Get_Stu_Name() { returnStu_Name; } char*Get_Stu_Num() { returnStu_Num; } voidGet_Name(charName[]) { strncpy(Stu_Name,Name,sizeof(Name)); } voidGet_Num(charNum[]) { strncpy(Stu_Num,Num,sizeof(Num)); } voidZHL_Read(); private: charStu_Name[20]; charStu_Num[20]; }; ZHL_StudentStu[100]; voidZHL_Read() { intn=0; stringtmp; ifstreamReadFile; ReadFile.open(”ZHL_Student_Note。 txt",ios: : in); if(ReadFile。 fail()) { cout<<”打开失败……"〈 exit(0); } else while(getline(ReadFile,tmp)) n++; ReadFile。 close(); charName[20],Num[20]; inti=0; fstreamStu_Note_File; Stu_Note_File。 open(”ZHL_Student_Note。 txt”,ios: : in); for(;i〈n;i++) Stu_Note_File>〉Name〉>Num; Stu[i].Get_Name(Name); Stu[i].Get_Num(Num); Stu_Note_File。 close(); intYear,Month,Day; fstreamBir_Note_File; Bir_Note_File。 open(”ZHL_Birthday_Note。 txt",ios: : in); for(;Count Bir_Note_File>>Year〉〉Month〉>Day; Stu[Count].SetBirthday(Year,Month,Day); Stu_Note_File.close(); } #endif ZHL_Function。 h #include〈iostream> #include"ZHL_Stu。 h” #include〈cstdlib〉 #include〈string〉 #include #include〈fstream> usingnamespacestd; externZHL_StudentStu[100]; intCount=0; //功能表 voidZHL_print(); voidZHL_Input(); voidZHL_Add(); voidZHL_Remove(); voidZHL_Change(); voidZHL_Search(); intSearch(char[]); voidZHL_Write(); voidZHL_Exit(); voidZHL_print() { cout〈<"==================================="< cout〈〈”+1增+”< cout〈<"+2删+”〈〈endl; cout〈〈”+3改+”〈〈endl; cout〈〈”+4查+"<〈endl; cout<〈"+5保存+"〈〈endl; cout<〈”+6退出+"〈 cout<〈”===================================”<〈endl; } voidZHL_Input() { intOp_Num=0; Again: cout<<”请输入操作(数字: 1、增;2、删;3、改;4、查;5、保存;6、退出): "〈〈endl; cin>>Op_Num; switch(Op_Num) { case1: ZHL_Add(); gotoAgain; break; case2: ZHL_Remove(); gotoAgain; break; case3: ZHL_Change(); gotoAgain; break; case4: ZHL_Search(); gotoAgain; break; case5: ZHL_Write(); gotoAgain; break; case6: ZHL_Exit(); gotoAgain; break; default: { cout〈<”输入错误! 请重新输入……”〈〈endl; gotoAgain; break; } } } voidZHL_Add() { intD0_Again=1; while(D0_Again=1) { if(Count〉=100) { cout〈〈”人数已满……"〈〈endl; break; } charstu_name[20],stu_num[20]; cout〈<"请输入学生的名字(回车结束): "<〈endl; cin>>stu_name; cout〈〈”请输入学生的学号(回车结束): ”〈 cin>〉stu_num; intYear,Month,Day; cout〈〈”请输入学生的生日(如: 200011): "〈 cin>>Year〉>Month〉〉Day; Stu[Count]。 Set(stu_name,stu_num,Year,Month,Day); Count++; cout<<”继续增加: 1、Yes;0、Not? "〈 cin>〉D0_Again; if(D0_Again! =1) break; } } voidZHL_Remove() { intD0_Again=1; inti=0; charStu_Name[20]; while(D0_Again==1) { if(Stu[i].Get_Stu_Name()==NULL) { cout<〈”没有学生可删……”〈 break; } cout<〈"请输入要删除的学生名字: ”<〈endl; cin>〉Stu_Name; intSearch_Num=Search(Stu_Name); if(Search_Num! =—1) { for(intj=Search_Num;Stu[j]。 Get_Stu_Name()! =NULL;j++) Stu[j]。 Set(Stu[j+1]。 Get_Stu_Name(),Stu[j+1]。 Get_Stu_Num(),Stu[j+1]。 year,Stu[j+1].month,Stu[j+1].day); } cout〈<”继续删除: 1、Yes;0、Not? "〈〈endl; cin>〉D0_Again; if(D0_Again! =1) break; } } voidZHL_Change() { inti=0; intD0_Again=1; charStu_Name[20]; while(D0_Again=1) { cout〈〈”请输入要修改的学生名字: ”〈〈endl; cin>>Stu_Name; intSearch_Num=Search(Stu_Name); if(Search_Num! =—1) { intYear,Month,Day; cout<〈”请输入修改后的学生生日(如: 200011): ”〈〈endl; cin〉>Year〉>Month〉〉Day; Stu[Search_Num]。 Set(Stu[Search_Num]。 Get_Stu_Name(),Stu[Search_Num].Get_Stu_Num(),Year,Month,Day); } cout<〈”继续修改: 1、Yes;0、Not? ”〈〈endl; cin〉〉D0_Again; if(D0_Again! =1) break; } } voidZHL_Search() { inti=0; intD0_Again=1; charStu_Name[20]; while(D0_Again=1) { cout〈〈”请输入要查看的学生名字: ”〈 cin〉〉Stu_Name; intSearch_Num=Search(Stu_Name); if(Search_Num! =—1) { cout〈〈”名字: "〈 cout<<”学号: ”〈 Get_Stu_Num()〈〈endl; cout<〈"生日: ”<〈Stu[Search_Num]。 year〈<”/"< } cout〈〈"继续查看: 1、Yes;0、Not? ”<〈endl; cin〉>D0_Again; if(D0_Again! =1) break; } } intSearch(charStu_Name[]) { inti=0; while(i〈Count) { if(strcmp(Stu_Name,Stu[i]。 Get_Stu_Name())==0) { cout<〈"没有这个学生……”; returni; } i++; } return—1; } voidZHL_Write() { fstreamStu_Note_File; Stu_Note_File.open(”ZHL_Student_Note.txt”,ios: : app); if(Stu_Note_File。 fail()) { cout〈<”打开失败……”〈 exit(0); } for(inti=0;Stu[i].Get_Stu_Name()! ='\0';i++) Stu_Note_File< Get_Stu_Name()〈<”"〈 Stu_Note_File.close(); fstreamBir_Note_File; Bir_Note_File。 open(”ZHL_Birthday_Note。 txt”,ios: : app); if(Bir_Note_File.fail()) { cout〈<”打开失败……"<〈endl; exit(0); } for(inti=0;Stu[i]。 Get_Stu_Name()! =NULL;i++) Bir_Note_File〈 month〈<””< day〈〈endl; Bir_Note_File.close(); } voidZHL_Exit() { exit(0); } 学生生日管理系统。 cpp //学生生日管理系统。 cpp: 定义控制台应用程序的入口点。 // #include"stdafx。 h” #include〈iostream〉 #include"ZHL_Functions.h” #include”ZHL_Stu.h” usingnamespacestd; int_tmain(intargc,_TCHAR*argv[]) { ZHL_Read(); ZHL_print(); ZHL_Input(); return0; } 5执行过程截屏 6总结 对于此次的作业,我找出了许多课本,也上网查阅了许多资料,还请教了同学。 这次的作业,我也遇到了一些问题,比如,对于文件流操作不熟,所以经常写错。 为此我请教了对这方面比较厉害的同学,还上网查阅了资料。 终于写出正确的了. 经过这次的作业,我重拾并巩固了以前的知识.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 生日 管理 系统 呕心沥血 整理