广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >C++实现简单信息管理系统
  • 475
分享到

C++实现简单信息管理系统

2024-04-02 19:04:59 475人浏览 薄情痞子
摘要

本文实例为大家分享了c++实现简单信息管理系统的具体代码,供大家参考,具体内容如下 信息管理系统 因为学校布置了写一个信息管理系统的作业,所以写下了这个信息管理系统,这是用cpp写的

本文实例为大家分享了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&&current->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&&current->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来写图形界面程序。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: C++实现简单信息管理系统

本文链接: https://www.lsjlt.com/news/142872.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • C++实现简单信息管理系统
    本文实例为大家分享了C++实现简单信息管理系统的具体代码,供大家参考,具体内容如下 信息管理系统 因为学校布置了写一个信息管理系统的作业,所以写下了这个信息管理系统,这是用cpp写的...
    99+
    2022-11-13
  • C++实现简单学生信息管理系统
    本文实例为大家分享了C++实现学生信息管理系统的具体代码,供大家参考,具体内容如下 编译环境: Microsoft Visual Studio 2019 3个头文件: Fileope...
    99+
    2022-11-13
  • C语言实现简单学生信息管理系统
    学生信息管理系统的功能有,也可以自己增加或者改进一些函数功能。 在main函数里调用这8个函数 学生信息包含姓名、年龄、学号、成绩,需要定义一个结构体(结构体是全局变量,所以需要全...
    99+
    2022-11-13
  • C语言实现简单职工信息管理系统
    本文实例为大家分享了C语言实现职工信息管理系统的具体代码,供大家参考,具体内容如下 代码实现如下: #include <stdio.h>//输入、输出指令 #includ...
    99+
    2022-11-13
  • Java实现简单学生信息管理系统
    最近在学习Java,所以写了个学生信息管理系统,话不多说,上代码。 Student.java: package com.mumu; public class Student {...
    99+
    2022-11-12
  • Java实现简单客户信息管理系统
    目录一、目标二、系统结构设计三、键盘访问的实现四、Customer类五、CustomerList类六、CustomerView类七、代码本文实例为大家分享了Java实现客户信息管理系...
    99+
    2022-11-13
  • C++实现信息管理系统
    本文实例为大家分享了C++实现信息管理系统的具体代码,供大家参考,具体内容如下 有一个信息管理系统,要求检查每一个登录系统的用户(User)的用户名和口令,系统检查合格以后方可登录系...
    99+
    2022-11-13
  • Python实现简单的学生信息管理系统
    本文实例为大家分享了Python实现学生信息管理系统的具体代码,供大家参考,具体内容如下 要求描述: 学生的信息包括:学号,姓名,年龄,性别,出生日期,地址,电话,E-mail等等。...
    99+
    2022-11-13
  • java实现简单的客户信息管理系统
    本文实例为大家分享了java实现简单客户信息管理系统的具体代码,供大家参考,具体内容如下 全篇文章开源,源码供读者使用。这是一篇关于java的客户信息管理系统的文章,里面简单实现了数...
    99+
    2022-11-13
  • C/C++实现图书信息管理系统
    本文实例为大家分享了c/c++实现图书信息管理系统的具体代码,供大家参考,具体内容如下 程序流程图 源代码 #include <stdio.h> #include ...
    99+
    2022-11-12
  • java如何实现简单的客户信息管理系统
    这篇文章主要介绍“java如何实现简单的客户信息管理系统”,在日常操作中,相信很多人在java如何实现简单的客户信息管理系统问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”java如何实现简单的客户信息管理系统...
    99+
    2023-06-30
  • C++实现职工信息管理系统
    本文实例为大家分享了c++实现职工信息管理系统的具体代码,供大家参考,具体内容如下 1、项目需求 2、功能实现的具体思路为: (1) 经行职工信息的读入,用while循环进行读入,...
    99+
    2022-11-13
  • 基于C++实现信息管理系统
    基于c++设计的信息管理系统,供大家参考,具体内容如下 1、使用类+函数实现2、使用STL容器的vector3、fstream的文件存储方式4、xls文件读入 写出5、数据的四大功能...
    99+
    2022-11-13
  • C++实现图书信息管理系统
    本文实例为大家分享了C++实现图书信息管理系统的具体代码,供大家参考,具体内容如下 1.题目: 类型有:编号:ISBN书名:name价格:price 完成如下的功能: ①录入:从键盘...
    99+
    2022-11-13
  • C++实现简单酒店管理系统
    本文实例为大家分享了C++实现简单酒店管理系统的具体代码,供大家参考,具体内容如下 酒店管理系统设计报告 一、 需求分析 题目要求如下: 某酒店有客房若干间,其中客房分为不同等级,如...
    99+
    2022-11-13
  • C++实现简单学生管理系统
    本文实例为大家分享了C++实现简单学生管理系统的具体代码,供大家参考,具体内容如下 实现学生管理,其中关键字可以自行替换。经过Visual C++6.0验证可执行成功。 #inclu...
    99+
    2022-11-13
  • Java基础——学生成绩信息管理系统(简单实现)
    需求 1、 定义一个学生类 Student,包含姓名、成绩信息; 2、使用 ArrayList集合存储学生对象; 3、 对集合中的元素进行增删查改的操作。 一、定义学生类 学生类可以包含姓名、成绩、学号、年龄等等,这里...
    99+
    2023-10-20
    java 开发语言 后端
  • C++实现教职工信息管理系统
    本文实例为大家分享了C++实现教职工信息管理系统的具体代码,供大家参考,具体内容如下 一.问题描述 一个小公司包含四类人员:经理,技术人员,销售人员和销售经理,各类人员的工资计算方法...
    99+
    2022-11-13
  • C++实现学生信息管理系统(Map实现)
    本文实例为大家分享了C++实现学生信息管理系统的具体代码,供大家参考,具体内容如下 1、 作品的功能描述: 实现一个学生信息管理系统,通过对学生信息类中的成员进行增、删、改、查从而实...
    99+
    2022-11-13
  • C++实现简单通讯录管理系统
    本文实例为大家分享了C++实现简单的通讯录管理系统的具体代码,供大家参考,具体内容如下 一、代码 #include <iostream> #include <str...
    99+
    2022-11-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作