C++实现简单信息管理系统
作者:伊丽莎逼
本文实例为大家分享了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" #include<stdlib.h> using namespace std; int main(){ system("color 0F"); //信息管理系统选项 tasks(); return 0; }
这里包括了万能头、界面样式、用户操作、教师类定义四个头文件。
万能头文件如下:
#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif
界面样式代码如下:
.h文件代码:
#ifndef INTERFACE #define INTERFACE #include"stdc++.h" using namespace std; //教师信息管理系统界面样式 void MainFace(); //信息管理系统界面样式 void outFace(); #endif INTERFACE
.cpp文件代码:
#include"interface.h" //教师信息管理系统界面样式 void MainFace(){ cout<<" "<<"---------------------------------------------------------------"<<endl; cout<<" "<<"------------- 欢迎进入教师信息管理系统 -------------"<<endl; cout<<" "<<"---------------------------------------------------------------"<<endl; cout<<" "<<"---- 1.添加教师信息 ---------- 2.更改一位教师信息 -------"<<endl; cout<<" "<<"---- 3.删除教师信息 ---------- 4.显示所有教师信息 -------"<<endl; cout<<" "<<"---- 5.从文件录入教师信息 ---------- 6.显示教师信息 -------"<<endl; cout<<" "<<"---- 7.对教师信息进行排序 ---------- 0.退出当前界面 -------"<<endl; cout<<" "<<"---------------------------------------------------------------"<<endl; } //信息管理系统界面样式 void outFace(){ cout<<" "<<"---------------------------------------------------------------"<<endl; cout<<" "<<"------------ 欢迎进入信息管理系统 ---------------"<<endl; cout<<" "<<"---------------------------------------------------------------"<<endl; cout<<" "<<"---- 1.学生登入 -------- 2.教师登入 ----------"<<endl; cout<<" "<<"---- 3.关于 -------- 0.退出系统 ----------"<<endl; cout<<" "<<"---------------------------------------------------------------"<<endl; cout<<" "<<"测试使用的教师账号:teacher 密码:123456789 "<<endl; }
用户操作代码如下:
.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 <windows.h> //账号密码 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<<"拜拜"<<endl; Sleep(1000); break; }else if (task==1){ //学生信息管理系统 cout<<"该功能暂未开放,敬请期待"<<endl; }else if(task==2){ //教师信息管理系统 string Id,passwrod; cout<<"请输入教师账号、密码:"; cin>>Id>>passwrod; //检验账号密码是否正确 if(Id==R_Id){ if(passwrod==R_password){ acts(); }else{ cout<<"密码错误"<<endl; } }else{ cout<<"账号错误"<<endl; } }else if(task==3){ cout<<"-----------------------------------------------------"<<endl; cout<<"完整代码和使用方法请参观网址: "<<endl; cout<<"https://blog.csdn.net/TeqGin/article/details/92760558"<<endl; cout<<"-----------------------------------------------------"<<endl; cout<<"作者:1808190126 软件一班 许达峰 "<<endl; cout<<"-----------------------------------------------------"<<endl; }else{ cout<<"无效输入"<<endl; } //清屏 system("pause"); system("CLS"); outFace(); //选择 cout<<"请输入0-2"<<endl; } } //教师信息管理系统选项 void acts(){ int a; List head=NULL; //清屏 system("pause"); system("CLS"); MainFace(); cout<<"请输入0-7:"; while(cin>>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<<"将返回主界面"<<endl; head=clearAll(head); Sleep(1000); break; } //清屏 system("pause"); system("CLS"); MainFace(); cout<<"请输入0-7:"; } }
用户操作定义还包括下属的数字命令文件
数字命令文件代码如下:
.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<<"---------------------------------------------------"<<endl; cout<<"--1更改姓名 2更改身份证号 3更改年龄 --"<<endl; cout<<"---------------------------------------------------"<<endl; cout<<"--4更改教师工号 5更改工资 6.更改执教课程-"<<endl; cout<<"---------------------------------------------------"<<endl; cout<<"--7.更改课程学分 -"<<endl; cout<<"---------------------------------------------------"<<endl; cout<<"请输入1-7:"; cin>>choose; cout<<endl; cout<<"请输入你希望更改的教师的工号"<<endl; cin>>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<<"无效输入"<<endl; } return head; } //显示所有教师信息 List dataFace(List head){ List current=head; cout<<"---------------------------------------------------------------------------"<<endl; cout<<" 姓名 身份证号 年龄 教师工号 工资 执教课程 课程学分 "<<endl; cout<<"---------------------------------------------------------------------------"<<endl; if(current==NULL){ cout<<"表格为空!"<<endl; }else{ while(current){ current->self.showmessage(); cout<<endl; cout<<"---------------------------------------------------------------------------"<<endl; current=current->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<<"该教师不存在!"<<endl; } }else{ cout<<"该表为空!"<<endl; } return head; } //显示教师信息 List showTeacherActs(List head){ int choose; cout<<"----------------------------------------------"<<endl; cout<<"1.根据姓名检索 2.根据身份证号检索"<<endl; cout<<"----------------------------------------------"<<endl; cout<<"3.根据教师工号检索 4.根据工资检索 "<<endl; cout<<"-----------------------------------------------"<<endl; cout<<"5.根据教师年龄检索 6.根据执教课程检索"<<endl; cout<<"-----------------------------------------------"<<endl; cin>>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<<"无效操作"<<endl; } return head; } //从文件录入教师信息 List readin(List head){ ifstream fin; string Point,LesName; Lesson course; cout<<"如果要使用本功能,请确保1808190126许达峰文件夹位于D盘。"<<endl; char address[]="D:\\1808190126许达峰\\Data.txt"; string Name,Identify,Age,teacherId,salary; List current,record,recall; fin.open(address); current=head; recall=head; if(head==NULL){ recall=head; }else{ //通过遍历找到空结点 while(current->next){ current=current->next; recall=current->next; } if(current==head) recall=current->next; } if(!fin.is_open()){ cout<<"打开文件失败!"<<endl; }else{ while(fin>>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<<"-----------------------------------------"<<endl; cout<<"1.根据教师年龄排序 2.根据教师工号排序"<<endl; cout<<"-----------------------------------------"<<endl; cout<<"3.根据教师工资排序 "<<endl; cout<<"-----------------------------------------"<<endl; cin>>choose; if(choose==1){ head=bubbleSofAge(head); }else if(choose==2){ head=bubbleSoftTeacherId(head); }else if(choose==3){ head=bubbleSoftSalary(head); }else{ cout<<"a无效操作!"<<endl; } return head; } //根据教师工号搜索指定教师 List findTeacher(List head,string teacherId){ List current=head; if(current==NULL) return current; while(current->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<<"请输入新名字"<<endl; cin>>Name; current->self.changeName(Name); }else{ cout<<"该教师不存在"<<endl; } }else{ cout<<"该表为空!"<<endl; } } //更改身份证号 void changeIdentify(List head,string teacherId){ List current=findTeacher(head,teacherId); if(current){ if(current->self.getTeacherId()==teacherId){ string Identify; cout<<"请输入新身份证号"<<endl; cin>>Identify; current->self.changeIdentify(Identify); }else{ cout<<"该教师不存在"<<endl; } }else{ cout<<"该表为空!"<<endl; } } //更改年龄 void changeAge(List head,string teacherId){ List current=findTeacher(head,teacherId); if(current){ if(current->self.getTeacherId()==teacherId){ string Age; cout<<"请输入新年龄"<<endl; cin>>Age; current->self.changeAge(Age); }else{ cout<<"该教师不存在"<<endl; } }else{ cout<<"该表为空!"<<endl; } } //更改教师工号 void changeTeacherId(List head,string teacherId){ List current=findTeacher(head,teacherId); if(current){ if(current->self.getTeacherId()==teacherId){ string TeacgerId; cout<<"请输入新教师工号"<<endl; cin>>TeacgerId; current->self.changeTeacherId(TeacgerId); }else{ cout<<"该教师不存在"<<endl; } }else{ cout<<"该表为空!"<<endl; } } //更改工资 void changeSalary(List head,string teacherId){ List current=findTeacher(head,teacherId); if(current){ if(current->self.getTeacherId()==teacherId){ string Salary; cout<<"请输入新工资"<<endl; cin>>Salary; current->self.changeSalary(Salary); }else{ cout<<"该教师不存在"<<endl; } }else{ cout<<"该表为空!"<<endl; } } //更改课程名称 void changeLesName(List head,string teacherId){ List current=findTeacher(head,teacherId); if(current){ if(current->self.getTeacherId()==teacherId){ string LesName; cout<<"请输入新课程名称"<<endl; cin>>LesName; current->self.changeCoureseLesName(LesName); }else{ cout<<"该教师不存在"<<endl; } }else{ cout<<"该表为空!"<<endl; } } //更改课程学分 void changePoint(List head,string teacherId){ List current=findTeacher(head,teacherId); if(current){ if(current->self.getTeacherId()==teacherId){ string Point; cout<<"请输入新课程学分"<<endl; cin>>Point; current->self.changeCouresePoint(Point); }else{ cout<<"该教师不存在"<<endl; } }else{ cout<<"该表为空!"<<endl; } } //检索姓名 void searchName(List head){ List current=head; string Name; cout<<"请输入教师姓名:"; cin>>Name; cout<<"---------------------------------------------------------------------------"<<endl; cout<<" 姓名 身份证号 年龄 教师工号 工资 执教课程 课程学分 "<<endl; cout<<"---------------------------------------------------------------------------"<<endl; //遍历 if(current){ while(current){ if(current->self.getName()==Name){ current->self.showmessage(); cout<<endl; cout<<"---------------------------------------------------------------------------"<<endl; } current=current->next; } }else{ cout<<"该表格为空!"<<endl; } } //检索身份证号 void searchIdentify(List head){ List current=head; string Identify; cout<<"请输入教师身份证:"; cin>>Identify; cout<<"---------------------------------------------------------------------------"<<endl; cout<<" 姓名 身份证号 年龄 教师工号 工资 执教课程 课程学分 "<<endl; cout<<"---------------------------------------------------------------------------"<<endl; //遍历 if(current){ while(current){ if(current->self.getIdentify()==Identify){ current->self.showmessage(); cout<<endl; cout<<"---------------------------------------------------------------------------"<<endl; } current=current->next; } }else{ cout<<"该表格为空!"<<endl; } } //检索教师工号 void searchTeacherId(List head){ List current=head; string teacherId; cout<<"请输入教师工号:"; cin>>teacherId; cout<<"---------------------------------------------------------------------------"<<endl; cout<<" 姓名 身份证号 年龄 教师工号 工资 执教课程 课程学分 "<<endl; cout<<"---------------------------------------------------------------------------"<<endl; //遍历 if(current){ while(current){ if(current->self.getTeacherId()==teacherId){ current->self.showmessage(); cout<<endl; cout<<"---------------------------------------------------------------------------"<<endl; } current=current->next; } }else{ cout<<"该表格为空!"<<endl; } } //检索工资 void searchSalary(List head){ List current=head; string salary; cout<<"请输入教师工资:"; cin>>salary; cout<<"---------------------------------------------------------------------------"<<endl; cout<<" 姓名 身份证号 年龄 教师工号 工资 执教课程 课程学分 "<<endl; cout<<"---------------------------------------------------------------------------"<<endl; //遍历 if(current){ while(current){ if(current->self.getSalary()==salary){ current->self.showmessage(); cout<<endl; cout<<"---------------------------------------------------------------------------"<<endl; } current=current->next; } }else{ cout<<"该表格为空!"<<endl; } } //检索年龄 void searchAge(List head){ List current=head; string age; cout<<"请输入教师工资:"; cin>>age; //输出样式 cout<<"---------------------------------------------------------------------------"<<endl; cout<<" 姓名 身份证号 年龄 教师工号 工资 执教课程 课程学分 "<<endl; cout<<"---------------------------------------------------------------------------"<<endl; //遍历 if(current){ while(current){ if(current->self.getAge()==age){ current->self.showmessage(); cout<<endl; cout<<"---------------------------------------------------------------------------"<<endl; } current=current->next; } }else{ cout<<"该表格为空!"<<endl; } } //根据执教课程检索 void searchCourseLesName(List head){ List current=head; string LesName; cout<<"请输入执教课程:"; cin>>LesName; //输出样式 cout<<"---------------------------------------------------------------------------"<<endl; cout<<" 姓名 身份证号 年龄 教师工号 工资 执教课程 课程学分 "<<endl; cout<<"---------------------------------------------------------------------------"<<endl; //遍历 if(current){ while(current){ if(current->self.getCourseLesName()==LesName){ current->self.showmessage(); cout<<endl; cout<<"---------------------------------------------------------------------------"<<endl; } current=current->next; } }else{ cout<<"该表格为空!"<<endl; } } //基于冒泡排序的根据教师年龄排序 List bubbleSofAge(List head){ Teacher T; int n=0; List current=head,record; //统计一共有多少人数 while(current){ n++; current=current->next; } current=head; //排序 for(int i=0;i<n;i++){ while(current->next){ record=current->next; if(record->self.getAge()<current->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<n;i++){ while(current->next){ record=current->next; if(record->self.getTeacherId()<current->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<n;i++){ while(current->next){ record=current->next; if(record->self.getSalary()<current->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<<" "<<this->Name<<" "<<this->Identify<<" "<<this->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<<" "<<teacherId<<" "<<salary<<" "; this->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<<this->LesName<<" "<<this->Point; }
程序已经基本完成,但是不知道为什么在文件读入那边读取第二次时程序会崩溃,这个问题亟待解决。
这个问题已经解决,是之前的代码在读取第二次的时候还是从head开始,导致一个空间被分配了两次,这样是不行,修改代码以后程序能正常运行了。现在的代码都是正确代码。
这个程序写了两天,算不上很长,但是也不短了,这其实是一个很简单的程序,主要是使用vs code来写,然后用VC6.0进行编译,很多问题没办法一下子找到,要慢慢的去一个地方一个地方的测试,花费了很多时间,几个比较复杂的功能完成以后,后面就驾轻就熟了,这个程序算是第二次写,之前有说要用更好的方法完成,确实也做到了,虽然不是很完善,不过下一次就打算使用QT来写图形界面程序。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。