⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccp.cpp

📁 高校人员信息管理系统.这是一个基于C++平台的一个简单的系统
💻 CPP
字号:
#include <iostream.h>
#include <fstream.h>
#include <ctype.h>
#include <string.h>

//全局数据,对象
double TSalary;       //教师的基本工资
double LSalary;		  //实验员的基本工资
double APSalary;	  //行政人员的基本工资
int ID;               //员工标识(要保证唯一)

class Person  //员工类
{

protected:
	int No;  //编号
	char Name[20];  //姓名
	int Duty;       //岗位
	double Earning; //收入
	Person *next;
public:
	Person(char ID,char *Name,int Duty)
	{
		this->Duty=Duty;
		strcpy(this->Name,Name);
		this->No=ID;
	}
	virtual void CalcSalary()=0; 
	virtual void Output()=0;
	friend class School;
};

class Teacher:public Person  //教师类
{
private:
	double ClassHour;        //上学期完成课时量
public:
	Teacher(char ID,char *Name,int Duty,double ClassHour):Person(ID,Name,Duty)
	{
	this->ClassHour=ClassHour;
	}

	double GetClassHour()
	{
		return ClassHour;
	}
	
	void SetClassHour(double Amount)
	{
		this->ClassHour=Amount;
	}
	void CalcSalary()
	{
		Earning=TSalary+(ClassHour-20)*20;
	}
	void Output()
	{
		CalcSalary();
		cout<<No<<"\t"<<Name<<"\t教师\t"<<"\t\t"<<Earning<<endl;
	}
};

class Labtechnician:public Person
{
private:
	double ClassHour;        //上学期完成课时量
public:
	Labtechnician(char ID,char *Name,int Duty,double ClassHour):Person(ID,Name,Duty)
	{
	this->ClassHour=ClassHour;
	}

	double GetClassHour()
	{
		return ClassHour;
	}
	
	void SetClassHour(double Amount)
	{
		this->ClassHour=Amount;
	}
	void CalcSalary()
	{
		Earning=LSalary+(ClassHour-15)*20+150;	//150为实验补贴
	}
	void Output()
	{
		CalcSalary();
		cout<<No<<"\t"<<Name<<"\t实验员\t"<<"\t\t"<<Earning<<endl;
	}
};

class ATman:public Person  //行政人员兼职教师类
{
private:
	double ClassHour;        //上学期完成课时量
public:
	ATman(char ID,char *Name,int Duty,double ClassHour):Person(ID,Name,Duty)
	{
	this->ClassHour=ClassHour;
	}
	double GetClassHour()
	{
		return ClassHour;
	}
	void SetClassHour(double s)
	{
		ClassHour=s;
	}
	void CalcSalary()
	{
		Earning=250+APSalary+TSalary+(ClassHour-15)*20;
	}
	void Output()
	{
		CalcSalary();
		cout<<No<<"\t"<<Name<<"\t行政人员兼职教师\t"<<Earning<<endl;
	}
};

class APman:public Person  //行政人员类
{

public:
	APman(char ID,char *Name,int Duty):Person(ID,Name,Duty){}
	void CalcSalary()
	{
		Earning=APSalary+250;//250为行政补贴
	}
	void Output()
	{
		CalcSalary();
		cout<<No<<"\t"<<Name<<"\t行政人员\t\t"<<Earning<<endl;
	}
};

class TLman:public Person  //教师兼职实验人员
{
private:
	double ClassHour;//教师兼职实验人员上学期完成课时量
public:
	TLman(char ID,char *Name,int Duty,double ClassHour):Person(ID,Name,Duty)
	{
		this->ClassHour=ClassHour;
	}
	double GetClassHour()
	{
		return ClassHour;
	}
	void SetClassHour(double Amount)
	{
		this->ClassHour=Amount;
	}
	void CalcSalary()
	{
		Earning=(ClassHour-25)*20+TSalary+150+LSalary;//150为实验补贴
	}
	void Output()
	{
		CalcSalary();
		cout<<No<<"\t"<<Name<<"\t教师兼职实验人员\t"<<Earning<<endl;
	}
};

class School  //高校类
{
private:
	Person *Worker;  //员工表
	void Clear();  //清除内存中数据
public:
	School()
	{
		Worker=0;      
		Load();
	}
	~School()
	{
		Person *p;
		p=Worker;
		while(p)
		{
			p=p->next;
			delete Worker;
			Worker=p;
		}
		Worker=0;
	}
	void Find(char Name[20]);//按姓名查找
	void Find(int ID);//按编号查找
	void Add();     //增加人员
	void Delete();  //删除人员
	void Modify();  //修改人员
	void Query();   //查询人员
	void Set();     //基础数据设置
	void Save();    //数据存盘(包括基础数据,人员数据)
	void Load();    //数据装入(包括基础数据,人员数据)
};
  
void School::Clear()  //清除内存中人员数据(内部使用)
{
	Person* p=Worker;
	while(p)
	{
		Worker=p->next;
		delete p;
		p=Worker;
	}
}

void School::Find(char Name[20])
{

}
void School::Add()
{
	Person *p;  //新结点指针
	int Duty;  
	char Name[20];
	double ClassHour;

	cout<<"\n** 新增员工 **\n";  
  
  //输入员工信息
	ID++;
	cout<<"输入岗位(1-教师2-行政人员兼职教师3-教师兼职实验员4-行政人员5-实验员):";  cin>>Duty;
	cout<<"输入姓名:";  cin>>Name;
	if(Duty!=4)
	{
		cout<<"上个月完成课时量:";  cin>>ClassHour;
	}

  //创建新员工结点
	switch(Duty)
	{
		case 1:p=new Teacher(ID,Name,Duty,ClassHour); break;
		case 2:p=new ATman(ID,Name,Duty,ClassHour);  break;
		case 3:p=new TLman(ID,Name,Duty,ClassHour);   break;
		case 4:p=new APman(ID,Name,Duty);  break;
		case 5:p=new Labtechnician(ID,Name,Duty,ClassHour); break;
	}
	p->next=0;

  //员工结点加入链表
	if(Worker)  //若已经存在结点
	{
		Person *p2;
		p2=Worker;
		while(p2->next)  //查找尾结点
		{
			p2=p2->next;
		}
		p2->next=p;  //连接
	}
	else  //若不存在结点(表空)
	{
		Worker=p;  //连接
	}  
}

void School::Delete()  //删除人员
{
	int No;
	cout<<"\n** 删除员工 **\n";
	cout<<"ID:";  cin>>No;

  //查找要删除的结点
	Person *p1,*p2;  p1=Worker;
	while(p1)
	{
		if(p1->No==No)
		break;
		else
		{
			p2=p1;
			p1=p1->next;
		}
	}

  //删除结点
	if(p1!=NULL)//若找到结点,则删除
	{
		if(p1==Worker)  //若要删除的结点是第一个结点
		{
			Worker=p1->next;
			delete p1;
		}
		else  //若要删除的结点是后续结点
		{
			p2->next=p1->next;
			delete p1;
		}
		cout<<"找到并删除\n";
	}
	else  //未找到结点
    cout<<"未找到!\n";
}

void School::Modify()
{
	int No,Duty;
	char Name[20];  
	double ClassHour;

	cout<<"\n** 修改员工 **\n";
	cout<<"ID:";  cin>>No;

	//查找要修改的结点
	Person *p1,*p2;  p1=Worker;
	while(p1)
	{
		if(p1->No==No)
		break;
		else
		{
			p2=p1;
			p1=p1->next;
		}
	}

  //修改结点
	if(p1!=NULL)//若找到结点
	{
		p1->Output();
		cout<<"调整岗位(1-教师2-行政人员兼职教师3-教师兼职实验人员4-行政人员5-实验人员):";  cin>>Duty;
		if(p1->Duty!=Duty)  //若岗位发生变动
		{    
			//修改其它数据
			cout<<"输入姓名:";  cin>>Name;      
			if(Duty!=4)
			{
				cout<<"上个月完成课时量:";  cin>>ClassHour;
			}

      //创建新员工结点
			Person *p3;
			switch(Duty)
			{
				case 1:p3=new Teacher(p1->No,Name,Duty,ClassHour); break;
				case 2:p3=new ATman(p1->No,Name,Duty,ClassHour);  break;
				case 3:p3=new TLman(p1->No,Name,Duty,ClassHour);   break;
				case 4:p3=new APman(p1->No,Name,Duty);  break;
				case 5:p3=new Labtechnician(p1->No,Name,Duty,ClassHour); break;
			}

			//员工结点替换到链表
			p3->next=p1->next;
			if(p1==Worker)  //若要替换的结点是第一个结点
			Worker=p3;
			else  //若要删除的结点是后续结点
			p2->next=p3;

			//删除原来的员工结点
			delete p1;
    }
    else  //若岗位没有变动
    {
      cout<<"输入姓名:";  cin>>p1->Name;
      if(Duty==1)
      {
        cout<<"上个月完成课时量:";  cin>>ClassHour;  ((Teacher *)p1)->SetClassHour(ClassHour);
      }
	  else if(Duty==2)
	  {
        cout<<"上个月完成课时量:";  cin>>ClassHour;  ((ATman *)p1)->SetClassHour(ClassHour);
	  }
	  else if(Duty==3)
	  {
		cout<<"上个月完成课时量:";  cin>>ClassHour;  ((TLman *)p1)->SetClassHour(ClassHour);
	  }
	  else if (Duty==5)
	  {
        cout<<"上个月完成课时量:";  cin>>ClassHour;  ((Labtechnician *)p1)->SetClassHour(ClassHour);
	  }

    }
    cout<<"修改成功!\n";
  }
  else  //未找到结点
    cout<<"未找到!\n";
}

void School::Query()
{
	int chet,count(0);
  cout<<"\n** 查询人员本月销售信息 **\n";
  cout<<"编号"<<"\t"<<"姓名"<<"\t"<<"岗位"<<"\t\t\t"<<"工资(元/月)"<<endl; 
  
  Person *p=Worker;
  double sum2=0;  //工资总和
  while(p)
  {
    p->Output();
    sum2+=p->Earning;
    p=p->next;
  } 

  cout<<"本月实发工资总数:"<<sum2<<"元"<<endl;
  cout<<"请输入你要查询人员的编号:"; cin>>chet;
  Person *p4=Worker;
  while(p4)
	{
	   if(p4->No==chet) 
		 {
		   if(p4->Duty==1)
		   {
			   ((Teacher*)p4)->Output();
			   count++;
			   break;
		   }
		   else if(p4->Duty==2)
		   {
			   ((ATman*)p4)->Output();
			   count++;
				break;
		   }
		   else if(p4->Duty==3)
		   { 
			   ((TLman*)p4)->Output();
			   count++;
				break;
		   }
		   else if(p4->Duty==4)
		   { 
			   ((APman*)p4)->Output();
			   count++;
				break;
		   }
		   else if(p4->Duty==5)
		   { 
			   ((Labtechnician*)p4)->Output();
			   count++;
				break;
		   }

		 }
		else
		 {
			p4=p4->next;
		 }
	 }
  if(count==0) cout<<"未找到!"<<endl;
}

void School::Set()
{
  cout<<"\n** 设置基础数据 **\n";
  cout<<"教师基本工资["<<TSalary<<"元]:";          cin>>TSalary; 
  cout<<"行政人员基本工资["<<APSalary<<"元]:";	 cin>>APSalary;  
  cout<<"实验人员基本工资["<<LSalary<<"]:";    cin>>LSalary;       
  cout<<"员工标识[>="<<ID<<"]:";                     cin>>ID;
}

void School::Save()  //数据存盘(包括基础数据,人员数据),均采用文本文件
{
  ofstream fPerson,fBase;
  char c;

  cout<<"\n保存人员和基础数据,是否继续?[Y/N]:";  cin>>c;
  if(toupper(c)!='Y')return;

  //保存人员编号、姓名、岗位
  fPerson.open("person.txt",ios::out);  
  Person *p=Worker;
  while(p)
  {
    fPerson<<p->No<<"\t"<<p->Name<<"\t"<<p->Duty<<"\t";
    if(p->Duty==1)
      fPerson<<((Teacher*)p)->GetClassHour()<<"\t";
	else if (p->Duty==2)
		fPerson<<((ATman*)p)->GetClassHour()<<"\t";
	else if (p->Duty==3)
		fPerson<<((TLman*)p)->GetClassHour()<<"\t";
	else if (p->Duty==5)
      fPerson<<((Labtechnician*)p)->GetClassHour()<<"\t";

    fPerson<<endl;
    p=p->next;
  }
  fPerson.close();

  //保存基础数据
  fBase.open("base.txt",ios::out);
  fBase<<"教师基本工资\t"<<TSalary<<endl;  
  fBase<<"行政人员基本工资\t"<<APSalary<<endl;  
  fBase<<"实验人员基本工资\t"<<LSalary<<endl; 
  fBase<<"ID\t"<<ID<<endl;
  fPerson.close();

  cout<<"\n保存人员和基础数据已经完成...\n";
}

void School::Load()  //数据装入(包括基础数据,人员数据)
{
  //基础数据装入
  ifstream fBase;
  char buf[80];  //buf用于保存数据文件中的注释字符串
  fBase.open("base.txt",ios::in);
  fBase>>buf>>TSalary;       //教师基本工资
  fBase>>buf>>APSalary;  //行政人员基本工资
  fBase>>buf>>LSalary; //实验人员基本工资
  fBase>>buf>>ID;        //员工标识
  fBase.close();  

  //清除内存人员数据
  Clear();    
  //人员数据数据装入
  ifstream fPerson;
  Person *p=Worker;
  int No;  char Name[20];  int Duty;
  double ClassHour;


  fPerson.open("person.txt",ios::in);
  //读一条记录
  fPerson>>No>>Name>>Duty;
  if(Duty!=4)fPerson>>ClassHour;

  while(fPerson.good())
  {
    //创建员工结点
    switch(Duty)
    {
      case 1:p=new Teacher(No,Name,Duty,ClassHour);  break;
      case 2:p=new ATman(No,Name,Duty,ClassHour);  break;
      case 3:p=new TLman(No,Name,Duty,ClassHour);  break;
      case 4:p=new APman(No,Name,Duty);  break;
	  case 5:p=new Labtechnician(No,Name,Duty,ClassHour);  break;

    }
    p->next=0;

    //员工结点加入链表
    if(Worker)  //若已经存在结点
    {
      Person *p2;
      p2=Worker;
      while(p2->next)  //查找尾结点
      {
        p2=p2->next;
      }
      p2->next=p;  //连接
    }
    else  //若不存在结点(表空)
    {
      Worker=p;  //连接
    }  

    //读下一条记录
    fPerson>>No>>Name>>Duty;
    if(Duty!=4)fPerson>>ClassHour;
  }
  fPerson.close();

  cout<<"\n人员和基础数据已经装入...\n";
}

void main()
{
  char c;
  School a;
  do
  {
    cout<<"\n*** 高校工资管理系统 ***\n";
    cout<<"1-增加人员\n";
    cout<<"2-删除人员\n";
    cout<<"3-修改人员\n";
    cout<<"4-查询职工信息\n";
    cout<<"5-基础数据设置\n";
    cout<<"6-数据存盘\n";
    cout<<"7-数据装入\n";
    cout<<"8-退出\t请选择(1-8):";

    cin>>c;
    switch(c)
    {
      case '1':  a.Add();   break;
      case '2':  a.Delete();break;
      case '3':  a.Modify();break;
      case '4':  a.Query(); break;
      case '5':  a.Set();   break;
      case '6':  a.Save();  break;
      case '7':  a.Load();  break;
    }
  }while(c!='8');
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -