用C++设计的一个学生管理系统

该系统包含增加,删除,修改,查询,浏览的功能,分别用五个文件编写。

//employee.h

#include<iostream>
#include<string>
using namespace std;
class Date//出生日期
{
protected:
int year;
int month;
int day;
public:
void Set(int y,int m,int d);//初始化
int GetYear(); 
int GetMonth();
int GetDay();
};
class Person
{
protected:
char name[20];//姓名
char sex;//性别
char tel[20];//电话号码
char add[30];//家庭住址
Date birthday;
public:
Person();
void Input();
void Output();
char* GetName();//提取姓名
void DeleteN();//删除
};
class Employee:public Person
{
protected:
char number[10];//职工号
char position[20]; //职位
char department[20];//部门
double wage;//工资
public:
char* GetNum(); //提取职工号
void Input();
void Output();
};

 

//employee1.cpp

#include<iostream>
#include<string>
using namespace std;
class Date//出生日期
{
protected:
int year;
int month;
int day;
public:
void Set(int y,int m,int d);//初始化
int GetYear(); 
int GetMonth();
int GetDay();
};
class Person
{
protected:
char name[20];//姓名
char sex;//性别
char tel[20];//电话号码
char add[30];//家庭住址
Date birthday;
public:
Person();
void Input();
void Output();
char* GetName();//提取姓名
void DeleteN();//删除
};
class Employee:public Person
{
protected:
char number[10];//职工号
char position[20]; //职位
char department[20];//部门
double wage;//工资
public:
char* GetNum(); //提取职工号
void Input();
void Output();
};


//interface.h

#include<iostream>
#include<string>
using namespace std;
#include"employee.h"
const int N=200;//设置系统人数
class Interface
{
protected:
Employee e[N];
int num;//职工信息人数
public:
Interface();
void menu();//设计界面
void Run();//系统启动
void Input();//输入职工信息
void Browse();//浏览信息
void Change();//修改信息
void Delete();//删除信息
void Search();//查询信息
bool SearchNa();//按姓名查询职工信息
bool SearchNum();//按工号查询
};


//interface.cpp

#include"interface.h"
#include<string>
#include<iostream>
#include<cstdlib>
using namespace std;
Interface::Interface()
{
num=0;
}
void Interface::menu()//设计界面
{
cout<<"\n*****************************************"<<endl;
cout<<"*          欢迎使用本系统!             *"<<endl;
cout<<"*            1.录入信息                 *"<<endl;
cout<<"*            2.查询信息                 *"<<endl;
cout<<"*            3.浏览信息                 *"<<endl;
cout<<"*            4.修改信息                 *"<<endl;
cout<<"*            5.删除信息                 *"<<endl;
cout<<"*            0.退    出                 *"<<endl;
cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
}
void Interface::Run()//启动系统
{
int choice;
do
{
system("pause");
system("cls");
menu();
cout<<"\n请输入您的选择:";
cin>>choice;

switch(choice)
{
case 1:
Input();
break;
case 2:
Search();
break;
case 3:
Browse();
break;
case 4:
Change();
break;
case 5:
Delete();
break;
case 0:
cout<<"\n您已退出本系统!欢迎再次使用!"<<endl;
break;
}
}while(choice);
system("pause");
}
void Interface::Input()
{
if(num==N)//输入人数=设置人数
{
cout<<"\n人数已满!无法录入!\n";
return;
}
int i=num;
cout<<"\n请输入员工信息:"<<endl;
e[i].Input();
cout<<"\n录入成功!即将返回菜单!"<<endl;
num++;
}
void Interface::Browse()//浏览信息
{
cout<<endl;
if(num==0)
{
cout<<"\n没有职工信息!\n";
return;
}
else
{
cout<<"\n您要查看的职工信息如下:\n";
for(int i=0;i<num;i++)
e[i].Output();
cout<<"\n全部职工信息如上!即将返回菜单!"<<endl;
}
}
void Interface::Search()//查询
{
int N;
do
{
cout<<"\n请输入您要选择查询的方式(1为按姓名查询,2为按工号查询,0为退出):"<<endl;
cin>>N;
switch(N)
{
case 1:
SearchNa();
break;
case 2:
SearchNum();
break;
case 0:
Run();
break;
}
}while(N);
}
bool Interface::SearchNa()
{
char na[20];
cout<<"\n请输入要查询的员工姓名:";
cin>>na;
for(int i=0;i<num;i++)
if(strcmp(e[i].GetName(),na)==0)//strcmp函数用于比较两个字符串
break;
if(i==num)
{
cout<<"\n查无此人!"<<endl;
return false;
}
else
{
cout<<"\n您要查询的员工的信息如下:"<<endl;
e[i].Output();
}
return true;
}
bool Interface::SearchNum()
{
char n[10];
cout<<"\n请输入要查询的员工工号:";
cin>>n;
for(int i=0;i<num;i++)
if(strcmp(e[i].GetNum(),n)==0)
break;
if(i==num)
{
cout<<"\n查无此人!"<<endl;
return false;
}
   else
{
cout<<"\n您要查询的员工的信息如下:"<<endl;
e[i].Output();
}
return true;
}
void Interface::Change()
{
char na[20];
cout<<"\n请输入要修改的员工的姓名:";
cin>>na;
for(int i=0;i<num;i++)
if(strcmp(e[i].GetName(),na)==0)
break;
if(i==num)
cout<<"\n查无此人!"<<endl;
else
{
cout<<"\n请输入新的员工信息:"<<endl;
e[i].Input();
cout<<"\n修改成功!即将返回菜单!"<<endl;
}
}
void Interface::Delete()
{
char na[20];
char n;
cout<<"\n请输入员工姓名:";
cin>>na;
for(int i=0;i<num;i++)
if(strcmp(e[i].GetName(),na)==0)
break;
if(i==num)
cout<<"\n查无此人!"<<endl;
else
{
e[i].DeleteN();
cout<<"\n删除成功!即将返回菜单!"<<endl;
}
}

//main.cpp

#include"interface.h"
int main()
{
Interface in;
cout<<"|------------------------------|\n";
cout<<"|          Welcome!            |\n";
cout<<"|       欢迎使用本系统!       |\n";
cout<<"|------------------------------|\n";
cout<<endl;
in.Run();
return 0;
}   



















  • 4
    点赞
  • 73
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值