网站首页 编程语言 正文
本文实例为大家分享了C++实现简单信息管理系统的具体代码,供大家参考,具体内容如下
信息管理系统
因为学校布置了写一个信息管理系统的作业,所以写下了这个信息管理系统,这是用cpp写的一个简单程序。
基本思路是通过控制台程序,然后通过数字命令来进行操作。
该程序编译了多文件;
因为是学校的作业所以我把万能头换成了
#include"stdc++.h"
功能和万能头一致。
该系统使用了链表来链接各个数据。
程序的基本功能是打算写两个系统,输入1和账号密码进入学生管理系统
输入2和账号密码进入教师管理系统
但是我只写了教师管理系统,因为这是学校的作业,而且之前我有写过学生管理系统了,所以没打算再写一次,以后有时间再说。
进入教师管理系统以后 :
输入1:用户自己增加教师信息
输入2:用户可以通过教师工号更改教师的姓名或身份证号或年龄或教师工号或者工资或者执教课程或课程学分。
输入3:通过教师工号来删除特定教师
输入4:显示所有的教师信息
输入5:从指定文件(D:\1808190126许达峰\Data.txt)读入信息。
输入6:显示符合某个特定信息的教师,可以用教师姓名、身份证、工号、工资、年龄、执教课程进行检索
输入7:可以通过教师工号、工资、年龄进行排序(从小到大)
输入0:退出系统。
主程序代码如下:
#include"stdc++.h" #include"interface.h" #include"actions.h" #include"teacherMessage.h" #includeusing namespace std; int main(){ system("color 0F"); //信息管理系统选项 tasks(); return 0; }
这里包括了万能头、界面样式、用户操作、教师类定义四个头文件。
万能头文件如下:
#ifndef _GLIBCXX_NO_ASSERT #include#endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if __cplusplus >= 201103L #include #include #include #include #include #include #include #include #include #endif // C++ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include
#include
界面样式代码如下:
.h文件代码:
#ifndef INTERFACE #define INTERFACE #include"stdc++.h" using namespace std; //教师信息管理系统界面样式 void MainFace(); //信息管理系统界面样式 void outFace(); #endif INTERFACE
.cpp文件代码:
#include"interface.h" //教师信息管理系统界面样式 void MainFace(){ cout<<" "<<"---------------------------------------------------------------"<
用户操作代码如下:
.h文件
#ifndef ACTIONS #define ACTIONS #include"stdc++.h" #include"teacherMessage.h" using namespace std; typedef struct teacherDate * List; typedef struct teacherDate Data; //链表的构成元素 struct teacherDate { Teacher self; List next; }; //教师信息管理系统选项 void acts(); //主界面选项 void tasks(); #endif
.cpp文件
#include"actions.h" #include"interface.h" #include"teacherSystem.h" #include//账号密码 const string R_Id="teacher"; const string R_password="123456789"; //主界面选项 void tasks(){ int task; outFace(); cout<<"请输入0-2:"; while(cin>>task){ if(task==0){ cout<<"拜拜"< >Id>>passwrod; //检验账号密码是否正确 if(Id==R_Id){ if(passwrod==R_password){ acts(); }else{ cout<<"密码错误"< >a){ if(a==1){ //增加教师信息 head=add(head); }else if(a==2){ //更改教师信息 head=changeActs(head); }else if(a==3){ //删除教师信息 head=excludeActs(head); }else if(a==4){ //显示所有教师信息 head=dataFace(head); }else if(a==5){ //从文件录入教师信息 head=readin(head); }else if(a==6){ //显示教师信息 head=showTeacherActs(head); }else if(a==7){ //对教师信息进行排序 head=softData(head); }else if(a==0){ cout<<"将返回主界面"<
用户操作定义还包括下属的数字命令文件
数字命令文件代码如下:
.h文件
#ifndef TEACHERSYSTEM #define TEACHERSYSTEM #include"stdc++.h" #include"actions.h" using namespace std; //增加教师信息 List add(List head); //更改教师信息 List changeActs(List head); //删除教师信息 List excludeActs(List head); //显示所有教师信息 List dataFace(List head); //从文件录入教师信息 List readin(List head); //显示教师信息 List showTeacherActs(List head); //对教师信息进行排序 List softData(List head); //清除所有数据,防止内存泄露 List clearAll(List head); //根据教师工号搜索指定教师 List findTeacher(List head,string teacherId); #endif TEACHERSYSTEM
.cpp文件
#include"teacherSystem.h" #include"interface.h" #include"teacherMessage.h" #include"changeActions.h" //增加教师信息 List add(List head){ string Name,Age,teacherId,salary; string Identify; string LesName,Point; Lesson course; if(head==NULL){ //为首结点动态分配空间 head=new Data; cout<<"请依次输入教师的姓名、身份证号(后四位)、年龄、教师工号、工资、执教课程、课程学分:"; cin>>Name>>Identify>>Age>>teacherId>>salary>>LesName>>Point; //将数据传入Teacher类中 course.getData(LesName,Point); head->self.getData(Name,Identify,Age,teacherId,salary,course); //令下一个结点为空 head->next=NULL; }else{ List current,record; current=head; //通过遍历找到空结点,把数据分配到空结点中 while(current->next){ current=current->next; record=current->next; } if(current==head) record=current->next; cout<<"请依次输入教师的姓名、身份证号(后四位)、年龄、教师工号、工资、执教课程、课程学分:"; cin>>Name>>Identify>>Age>>teacherId>>salary>>LesName>>Point; course.getData(LesName,Point); //为新结点动态分配空间 record= new Data; record->self.getData(Name,Identify,Age,teacherId,salary,course); //令下一个结点为空 record->next=NULL; current->next=record; } return head; } //更改教师信息 List changeActs(List head){ int choose; string teacherId; cout<<"---------------------------------------------------"<>choose; cout< >teacherId; if(choose==1){ changeName(head,teacherId); }else if(choose==2){ changeIdentify(head,teacherId); }else if(choose==3){ changeAge(head,teacherId); }else if(choose==4){ changeTeacherId(head,teacherId); }else if(choose==5){ changeSalary(head,teacherId); }else if(choose==6){ changeLesName(head,teacherId); }else if(choose==7){ changePoint(head,teacherId); }else{ cout<<"无效输入"< self.showmessage(); cout< next; } } return head; } //删除教师信息 List excludeActs(List head){ string teacherId; cout<<"请输入你要删除的教师的教师工号:"; cin>>teacherId; List current=head,before; if(current){ while(current->next!=NULL&¤t->self.getTeacherId()!=teacherId){ before=current; current=current->next; } if(current->self.getTeacherId()==teacherId){ if(current==head){ List record=head; head=head->next; delete record; return head; }else{ before->next=current->next; delete current; } }else{ cout<<"该教师不存在!"< >choose; if(choose==1){ searchName(head); }else if(choose==2){ searchIdentify(head); }else if(choose==3){ searchTeacherId(head); }else if(choose==4){ searchSalary(head); }else if(choose==5){ searchAge(head); }else if(choose==6){ searchCourseLesName(head); }else{ cout<<"无效操作"< next){ current=current->next; recall=current->next; } if(current==head) recall=current->next; } if(!fin.is_open()){ cout<<"打开文件失败!"< >Name>>Identify>>Age>>teacherId>>salary>>LesName>>Point){ recall=new Data; if(head==NULL){ head=recall; }else{ current->next=recall; } course.getData(LesName,Point); recall->self.getData(Name,Identify,Age,teacherId,salary,course); recall->next=NULL; current=recall; } fin.clear(); } return head; } //对教师信息进行排序 List softData(List head){ int choose; cout<<"-----------------------------------------"< >choose; if(choose==1){ head=bubbleSofAge(head); }else if(choose==2){ head=bubbleSoftTeacherId(head); }else if(choose==3){ head=bubbleSoftSalary(head); }else{ cout<<"a无效操作!"< next!=NULL&¤t->self.getTeacherId()!=teacherId){ current=current->next; } return current; } //清除所有数据,防止内存泄露 List clearAll(List head){ List current=head,record; if(head!=NULL){ while(current){ record=current->next; delete current; current=record; } } return head=NULL; }
教师系统操作还包括以下文件:
.h文件:
#ifndef CHANGEACTIONS #define CHANGEACTIONS #include"stdc++.h" #include"actions.h" using namespace std; //更改姓名 void changeName(List head,string teacherId); //更改身份证号 void changeIdentify(List head,string teacherId); //更改年龄 void changeAge(List head,string teacherId); //更改教师工号 void changeTeacherId(List head,string teacherId); //更改工资 void changeSalary(List head,string teacherId); //更改课程名称 void changeLesName(List head,string teacherId); //更改课程学分 void changePoint(List head,string teacherId); //检索姓名 void searchName(List head); //检索身份证号 void searchIdentify(List head); //检索教师工号 void searchTeacherId(List head); //检索工资 void searchSalary(List head); //检索年龄 void searchAge(List head); //根据执教课程检索 void searchCourseLesName(List head); //基于冒泡排序的根据教师年龄排序 List bubbleSofAge(List head); //基于冒泡排序的根据教师工号排序 List bubbleSoftTeacherId(List head); //基于冒泡排序的根据教师工资排序 List bubbleSoftSalary(List head); #endif CHANGEACITIONS
.cpp文件:
#include"changeActions.h" #include"teacherMessage.h" #include"teacherSystem.h" //更改姓名 void changeName(List head,string teacherId){ List current=findTeacher(head,teacherId); if(current){ if(current->self.getTeacherId()==teacherId){ string Name; cout<<"请输入新名字"<>Name; current->self.changeName(Name); }else{ cout<<"该教师不存在"< self.getTeacherId()==teacherId){ string Identify; cout<<"请输入新身份证号"< >Identify; current->self.changeIdentify(Identify); }else{ cout<<"该教师不存在"< self.getTeacherId()==teacherId){ string Age; cout<<"请输入新年龄"< >Age; current->self.changeAge(Age); }else{ cout<<"该教师不存在"< self.getTeacherId()==teacherId){ string TeacgerId; cout<<"请输入新教师工号"< >TeacgerId; current->self.changeTeacherId(TeacgerId); }else{ cout<<"该教师不存在"< self.getTeacherId()==teacherId){ string Salary; cout<<"请输入新工资"< >Salary; current->self.changeSalary(Salary); }else{ cout<<"该教师不存在"< self.getTeacherId()==teacherId){ string LesName; cout<<"请输入新课程名称"< >LesName; current->self.changeCoureseLesName(LesName); }else{ cout<<"该教师不存在"< self.getTeacherId()==teacherId){ string Point; cout<<"请输入新课程学分"< >Point; current->self.changeCouresePoint(Point); }else{ cout<<"该教师不存在"< >Name; cout<<"---------------------------------------------------------------------------"< self.getName()==Name){ current->self.showmessage(); cout< next; } }else{ cout<<"该表格为空!"< >Identify; cout<<"---------------------------------------------------------------------------"< self.getIdentify()==Identify){ current->self.showmessage(); cout< next; } }else{ cout<<"该表格为空!"< >teacherId; cout<<"---------------------------------------------------------------------------"< self.getTeacherId()==teacherId){ current->self.showmessage(); cout< next; } }else{ cout<<"该表格为空!"< >salary; cout<<"---------------------------------------------------------------------------"< self.getSalary()==salary){ current->self.showmessage(); cout< next; } }else{ cout<<"该表格为空!"< >age; //输出样式 cout<<"---------------------------------------------------------------------------"< self.getAge()==age){ current->self.showmessage(); cout< next; } }else{ cout<<"该表格为空!"< >LesName; //输出样式 cout<<"---------------------------------------------------------------------------"< self.getCourseLesName()==LesName){ current->self.showmessage(); cout< next; } }else{ cout<<"该表格为空!"< next; } current=head; //排序 for(int i=0;i next){ record=current->next; if(record->self.getAge() self.getAge()){ T=record->self; record->self=current->self; current->self=T; } current=current->next; } current=head; } return head; } //基于冒泡排序的根据教师工号排序 List bubbleSoftTeacherId(List head){ Teacher T; int n=0; List current=head,record; //统计一共有多少人数 while(current){ n++; current=current->next; } current=head; //排序 for(int i=0;i next){ record=current->next; if(record->self.getTeacherId() self.getTeacherId()){ T=record->self; record->self=current->self; current->self=T; } current=current->next; } current=head; } return head; } //基于冒泡排序的根据教师工资排序 List bubbleSoftSalary(List head){ Teacher T; int n=0; List current=head,record; //统计一共有多少人数 while(current){ n++; current=current->next; } current=head; //排序//排序 for(int i=0;i next){ record=current->next; if(record->self.getSalary() self.getSalary()){ T=record->self; record->self=current->self; current->self=T; } current=current->next; } current=head; } return head; }
教师类定义代码如下
.h文件
#ifndef TEACHERMESSAGE #define TEACHERMESSAGE #include"stdc++.h" using namespace std; //课程类 class Lesson{ private: string LesName; string Point; public: Lesson(){} ~Lesson(){} public: //传输数据 void getData(string LesName,string Point); //输出样式 void LesInterFace(); //更改课程名称 void changeLesName(string LesName); //更改学分 void changePoint(string Point); //获取课程名称 string getLesName(); //获取学分 string getPoint(); }; //人员类 class Person{ protected: string Name; string Identify; string Age; Lesson course; public: Person(){} ~Person(){} public: //传输数据 void getData(string Name,string Identity,string Age,Lesson course); //输出数据 void showmessage(); //更改姓名 void changeName(string name); //更改身份证 void changeIdentify(string Identify); //更改年龄 void changeAge(string Age); //更改课程名称 void changeCoureseLesName(string LesName); void changeCouresePoint(string Point); //获取姓名 string getName(); //获取身份证号 string getIdentify(); //获取年龄 string getAge(); //获取课程名称 string getCourseLesName(); }; //教师类 class Teacher:public Person{ protected: string teacherId; string salary; public: Teacher(){} ~Teacher(){} public: //传输数据 void getData(string Name,string Identity,string Age,string teacherId,string salary,Lesson course); //输出 void showmessage(); //更改教师工号 void changeTeacherId(string teacherId); //更改工资 void changeSalary(string salary); //获取教师工号 string getTeacherId(); //获取工资 string getSalary(); }; #endif
.cpp文件
#include"teacherMessage.h" //传输数据 void Person::getData(string Name,string Identity,string Age,Lesson course){ this->Name=Name; this->Identify=Identity; this->Age=Age; this->course=course; } //输出数据 void Person::showmessage(){ cout<<" "<Name<<" "< Identify<<" "< Age; } //更改姓名 void Person::changeName(string Name){ this->Name=Name; } //更改身份证 void Person::changeIdentify(string Identify){ this->Identify=Identify; } //更改年龄 void Person::changeAge(string Age){ this->Age=Age; } //更改课程名称 void Person::changeCoureseLesName(string LesName){ this->course.changeLesName(LesName); } void Person::changeCouresePoint(string Point){ this->course.changePoint(Point); } //获取年龄 string Person::getAge(){ return this->Age; } //获取姓名 string Person::getName(){ return this->Name; } //获取身份证号 string Person::getIdentify(){ return this->Identify; } //获取课程名称 string Person::getCourseLesName(){ return this->course.getLesName(); } //传输数据 void Teacher::getData(string Name,string Identity,string Age,string teacherId,string salary,Lesson course){ Person::getData(Name,Identity,Age,course); this->teacherId=teacherId; this->salary=salary; } //输出 void Teacher::showmessage(){ Person::showmessage(); cout<<" "< course.LesInterFace(); } //更改工资 void Teacher::changeSalary(string salary){ this->salary=salary; } //更改教师工号 void Teacher::changeTeacherId(string teacherId){ this->teacherId=teacherId; } //获取教师工号 string Teacher::getTeacherId(){ return this->teacherId; } //获取工资 string Teacher::getSalary(){ return this->salary; } void Lesson::getData(string LesName,string Point){ this->LesName=LesName; this->Point=Point; } void Lesson::changeLesName(string LesName){ this->LesName=LesName; } void Lesson::changePoint(string Point){ this->Point=Point; } string Lesson::getLesName(){ return this->LesName; } string Lesson::getPoint(){ return this->Point; } void Lesson::LesInterFace(){ cout< LesName<<" "< Point; }
程序已经基本完成,但是不知道为什么在文件读入那边读取第二次时程序会崩溃,这个问题亟待解决。
这个问题已经解决,是之前的代码在读取第二次的时候还是从head开始,导致一个空间被分配了两次,这样是不行,修改代码以后程序能正常运行了。现在的代码都是正确代码。
这个程序写了两天,算不上很长,但是也不短了,这其实是一个很简单的程序,主要是使用vs code来写,然后用VC6.0进行编译,很多问题没办法一下子找到,要慢慢的去一个地方一个地方的测试,花费了很多时间,几个比较复杂的功能完成以后,后面就驾轻就熟了,这个程序算是第二次写,之前有说要用更好的方法完成,确实也做到了,虽然不是很完善,不过下一次就打算使用QT来写图形界面程序。
原文链接:https://blog.csdn.net/TeqGin/article/details/92760558
相关推荐
- 2022-10-24 Android Flutter实现上拉加载组件的示例代码_Android
- 2022-10-14 linux【centos 7】 yum 安装 tesseract 4.1
- 2022-07-14 一文教会你用redux实现computed计算属性_React
- 2023-05-16 Android ActivityManagerService启动流程详解_Android
- 2022-10-24 vscode使用Eslint+Prettier格式化代码的详细操作_C 语言
- 2023-04-03 React中使用Mobx的方法_React
- 2023-07-05 docker容器部署nginx外网不通端口监听只有tcp6没走tcp问题
- 2022-09-26 C++实现页面的缓冲区管理器_C 语言
- 最近更新
-
- window11 系统安装 yarn
- 超详细win安装深度学习环境2025年最新版(
- Linux 中运行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存储小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基础操作-- 运算符,流程控制 Flo
- 1. Int 和Integer 的区别,Jav
- spring @retryable不生效的一种
- Spring Security之认证信息的处理
- Spring Security之认证过滤器
- Spring Security概述快速入门
- Spring Security之配置体系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置权
- redisson分布式锁中waittime的设
- maven:解决release错误:Artif
- restTemplate使用总结
- Spring Security之安全异常处理
- MybatisPlus优雅实现加密?
- Spring ioc容器与Bean的生命周期。
- 【探索SpringCloud】服务发现-Nac
- Spring Security之基于HttpR
- Redis 底层数据结构-简单动态字符串(SD
- arthas操作spring被代理目标对象命令
- Spring中的单例模式应用详解
- 聊聊消息队列,发送消息的4种方式
- bootspring第三方资源配置管理
- GIT同步修改后的远程分支