求一个工资管理系统 C源码

2024-12-05 05:16:42
推荐回答(1个)
回答1:

#include
#include
#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{
items[size]=newItem;
int place=size;
int parent=(place-1)/2;
while((parent>=0)&&(items[parent].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;iif(items[i].getID()==ID)
{rootItem=items[i];
swap(items[i],items[0]);
}
items[0]=items[--size];
heapRebuild(0);
}
else cout<<"\n错误:目录为空"<return rootItem;
}
void heapInit(){
setSize(0);
cout<<"空的项目"<void heapView(){
if(size==0){
cout<<"空的项目!"<}
else{
cout<<"共有项目数: "<for(int ct=0;ctcout<<"ID: "<<<" 工资数目: " <}
}
}
void search(int ID)
{ int N=0;
for(int i=0;iif(items[i].getID()==ID)
{N++;
cout<<"ID: "<<<" 名称: " <if(!N) cout<<"未找到匹配的ID"<}

void heapRebuild(int root)
{
int child=2*root+1;
if(child{
int rightChild=child+1;
if((rightChild=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<<"------------------------------------------------"<cout<<"-----------------*工资管理系统*-----------------"<cout<<"------------------------------------------------"<cout<<" 1.重置"<cout<<" 2.输入"<cout<<" 3.删除"<cout<<" 4.查询"<cout<<" 5.打印"<cout<<" 0.退出"<cout<<"------------------------------------------------"<}
void showTip(){
cout<<"---------------------------------^_^--操作完成!"<cout<<"------------------------------------选择0-5继续"<}
int main(){
string i="-1";
int ID,PRI;
string proName;
Elem in;
priQueue PQ;
PQ.priInit();
system("cls");
showMenu();
cout<<"选择菜单中的数字以便处理数据!"<cin>>i;
system("cls");
while(i!="0")
{ if(i=="1")
{ system("cls");
showMenu();
cout<<"你选择了1,项目将全部清空:"<PQ.priInit();
showTip();
}
else if(i=="2")
{system("cls");
showMenu();
cout<<"你选择了2,输入ID,优先级,工资"<cout<<"输入 ID(数字):"<cin>>ID;
cout<<"输入优先级(数字):"<cin>>PRI;
cout<<"输入工资数目(数字):"<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号"<cin>>ID;
PQ.priDelete(ID);
showTip();
}

else if(i=="4")
{system("cls");
showMenu();
cout<<"你选择了4,输入要查找的项目ID号"<cin>>ID;
PQ.search(ID);
showTip();
}

else if(i=="5")
{system("cls");
showMenu();
cout<<"你选择了5,整个系统工资情况显示如下:"<PQ.priView();
showTip();
}
else {
system("cls");
showMenu();
cout<<"无效输入!"<}
cin>>i;
system("cls");
}
return 0;
}