课程设计,工资管理系统完整源代码
发布网友
发布时间:2022-04-21 23:20
我来回答
共1个回答
热心网友
时间:2023-08-15 22:03
#include <iostream>
#include <string>
#define MaxHEAP 100
using namespace std;
class Elem{
private:
int objectID;
int priority;
string proName;
public:
Elem(int objectID=0,int priority=0){
setID(objectID);
setPri(priority);
setProN(proName);
}
int getID(){
return objectID;
}
int getPri(){
return priority;
}
string getProN(){
return proName;
}
void setID(int id){
objectID=id;
}
void setPri(int pri){
priority=pri;
}
void setProN(string s)
{
proName=s;
}
};
class Heap
{
private:
Elem items[MaxHEAP];
int size;
public :
Heap(){
Elem items[MaxHEAP];
setSize(0);}
void setSize(int sz)
{size=sz;}
int heapIsEmpty(){
return size==0;
}
void heapInsert(Elem newItem)
{if(size<MaxHEAP)
{
items[size]=newItem;
int place=size;
int parent=(place-1)/2;
while((parent>=0)&&(items[parent].getPri()<items[place].getPri()))
{
Elem temp=items[parent];
items[parent]=items[place];
items[place]=temp;
place=parent;
parent=(place-1/2);
}
++size;
}
heapRebuild(0);
}
Elem heapDelete(int ID)
{
Elem rootItem;
if(!heapIsEmpty())
{
for(int i=0;i<size;i++)
if(items[i].getID()==ID)
{rootItem=items[i];
swap(items[i],items[0]);
}
items[0]=items[--size];
heapRebuild(0);
}
else cout<<"\n错误:目录为空"<<endl;
return rootItem;
}
void heapInit(){
setSize(0);
cout<<"空的项目"<<endl;}
void heapView(){
if(size==0){
cout<<"空的项目!"<<endl;
}
else{
cout<<"共有项目数: "<<size<<endl;
for(int ct=0;ct<size;ct++){
cout<<"ID: "<<items[ct].getID()<<" 优先级: "<<items[ct].getPri()
<<" 工资数目: " <<items[ct].getProN()<<endl;
}
}
}
void search(int ID)
{ int N=0;
for(int i=0;i<size;i++)
if(items[i].getID()==ID)
{N++;
cout<<"ID: "<<items[i].getID()<<" 优先级: "<<items[i].getPri()
<<" 名称: " <<items[i].getProN()<<endl; }
if(!N) cout<<"未找到匹配的ID"<<endl;
}
void heapRebuild(int root)
{
int child=2*root+1;
if(child<size)
{
int rightChild=child+1;
if((rightChild<size)&&(items[rightChild].getPri()>=items[child].getPri()))
{child=rightChild;
}
if(items[root].getPri()<=items[child].getPri())
{
Elem temp=items[root];
items[root]=items[child];
items[child]=temp;
heapRebuild(child);
}
}
}
};
class priQueue
{private:
Heap h;
public:
priQueue(){
Heap();
}
int priIsEmpty(){
return h.heapIsEmpty();
}
void priInit(){
h.heapInit();
}
void priInsert(Elem newItem){
h.heapInsert(newItem);
}
Elem priDelete(int ID){
return h.heapDelete(ID);
}
void priView(){h.heapView();
}
void search(int ID)
{
h.search(ID);
}
};
void showMenu(){
cout<<"------------------------------------------------"<<endl;
cout<<"-----------------*工资管理系统*-----------------"<<endl;
cout<<"------------------------------------------------"<<endl;
cout<<" 1.重置"<<endl;
cout<<" 2.输入"<<endl;
cout<<" 3.删除"<<endl;
cout<<" 4.查询"<<endl;
cout<<" 5.打印"<<endl;
cout<<" 0.退出"<<endl;
cout<<"------------------------------------------------"<<endl;
}
void showTip(){
cout<<"---------------------------------^_^--操作完成!"<<endl;
cout<<"------------------------------------选择0-5继续"<<endl;
}
int main(){
string i="-1";
int ID,PRI;
string proName;
Elem in;
priQueue PQ;
PQ.priInit();
system("cls");
showMenu();
cout<<"选择菜单中的数字以便处理数据!"<<endl;
cin>>i;
system("cls");
while(i!="0")
{ if(i=="1")
{ system("cls");
showMenu();
cout<<"你选择了1,项目将全部清空:"<<endl;
PQ.priInit();
showTip();
}
else if(i=="2")
{system("cls");
showMenu();
cout<<"你选择了2,输入ID,优先级,工资"<<endl;
cout<<"输入 ID(数字):"<<endl;
cin>>ID;
cout<<"输入优先级(数字):"<<endl;
cin>>PRI;
cout<<"输入工资数目(数字):"<<endl;
cin>>proName;
in.setID(ID);
in.setPri(PRI);
in.setProN(proName);
PQ.priInsert(in);
showTip();
}
else if(i=="3")
{system("cls");
showMenu();
cout<<"你选择了3,请选择你要删除的ID号"<<endl;
cin>>ID;
PQ.priDelete(ID);
showTip();
}
else if(i=="4")
{system("cls");
showMenu();
cout<<"你选择了4,输入要查找的项目ID号"<<endl;
cin>>ID;
PQ.search(ID);
showTip();
}
else if(i=="5")
{system("cls");
showMenu();
cout<<"你选择了5,整个系统工资情况显示如下:"<<endl;
PQ.priView();
showTip();
}
else {
system("cls");
showMenu();
cout<<"无效输入!"<<endl;
}
cin>>i;
system("cls");
}
return 0;
}