?? thesystemofworkerssalary.txt
字號:
system("cls");
if(head==NULL) //若調用次函數以前的頭指針head為空
{
cout<<" 這是一個空表,請先輸入職工信息!\n";
return(head);
}
else
{
p1=head; //否則將頭指針賦給p1
while(id!=p1->id&&p1->next!=NULL)
//尋找結點當p1所指的職工編號不是輸入的職工編號并且p1所指的next指針不為空
{
p1=p1->next; //p2指向原p1指向的結點p1后移一個結點
}
if(id==p1->id) //如果要查找的職工編號是p1所指的職工編號
{
cout<<"------------------------------------------------------------------------------\n";
cout<<"|編 號| |姓 名| |性別| |基本工資| |加班工資| |其他獎金| |總額|\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<setw(6)<<p1->id
<<setw(10)<<p1->name
<<setw(10)<<p1->sex
<<setw(10)<<p1->paid[0]
<<setw(10)<<p1->paid[1]
<<setw(12)<<p1->paid[2]
<<setw(12)<<p1->total<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
else
cout<<"信息中沒有編號為"<<id<<"的職工.\n"; //結點沒找到
return(head);
}
}
//------------定義paixu()函數將職工的工資總額從大到小排列并輸出
void Information::paixu(student *head)
{
system("cls");
int i,k,m=0,j;
student *p[N];//定義一個指向struct student的結構體指針數組p
if(head!=NULL)//如果頭指針是空則繼續
{ m=count(head);
cout<<"------------------------------------------------------------------------------\n";
cout<<" *職工工資統計表*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"|編號| |姓名| |性別| |基本工資| |加班工資| |其他獎金| |總額| |名次|\n";
cout<<"------------------------------------------------------------------------------\n";
p1=head;
for(k=0;k<m;k++)
{
p[k]=p1;
p1=p1->next;
}
for(k=0;k<m-1;k++) //選擇排序法
for(j=k+1;j<m;j++)
if(p[k]->total<p[j]->total)
{
p2=p[k];
p[k]=p[j];
p[j]=p2;
} //從大到小排列的指針
for(i=0;i<m;i++)
{
cout<<setw(6)<<p[i]->id
<<setw(8)<<p[i]->name
<<setw(9)<<p[i]->sex
<<setw(10)<<p[i]->paid[0]
<<setw(10)<<p[i]->paid[1]
<<setw(10)<<p[i]->paid[2]
<<setw(10)<<p[i]->total
<<setw(10)<<i+1<<endl;
cout<<"------------------------------------------------------------------------------\n";
}
}
}
//------------>求各工資的平均值的函數
void Information::average(student *head)
{
int k,m;
float arg1=0,arg2=0,arg3=0;
if(head==NULL)//如果頭指針是空則繼續
{
cout<<" 這是一個空表,請先輸入職工信息!\n";
}
else
{
m=count(head);
p1=head;
for(k=0;k<m;k++)
{
arg1+=p1->paid[0];
arg2+=p1->paid[1];
arg3+=p1->paid[2];
p1=p1->next;
}
arg1/=m;arg2/=m;arg3/=m;
cout<<" *各項工資的平均值*\n";
cout<<"------------------------------------------------------------------------------\n";
cout<<"\t\t基本工資的平均值: "<<setw(4)<<arg1
<<"\n"<<"\t\t加班工資的平均值: "<<setw(4)<<arg2
<<"\n"<<"\t\t獎金的平均值: "<<setw(4)<<arg3<<"\n";
cout<<"------------------------------------------------------------------------------\n";
}
}
//------------------->保存函數.
void Information::save(student *head)
{
system("cls");
ofstream out("data",ios::out);
out<<count(head)<<endl;
while(head!=NULL)
{ out<<head->name<<"\t"
<<head->id<<"\t"<<"\t"
<<head->sex<<"\t"
<<head->paid[0]<<"\t"
<<head->paid[1]<<"\t"
<<head->paid[2]<<"\t"
<<head->total<<endl;
head=head->next;
}
}
//———————————>讀取文件的信息
student *Information::Read()
{
system("cls");
int i=0;
p1=p2=( student *)malloc(LEN);
head=NULL;
ifstream in("data",ios::out);
in>>i;
if(i==0){cout<<" data 文件中的數據為空,請先輸入數據!"<<endl; return 0;}
else {
cout<<"\n原文件已保存的信息如下:\n";
cout<<" ………………………………………………………………………………………………"<<endl;
cout<<"|姓 名| |編 號| |性別| |基本工資| |加班工資| |其他獎金| |總額|\n";
cout<<" ………………………………………………………………………………………………"<<endl;
for(;i>0;i--)
{
p1=(student *)malloc(LEN);
in>>st.name>>st.id>>st.sex
>>st.paid[0]>>st.paid[1]>>st.paid[2]>>st.total;
strcpy(p1->name,st.name);
p1->id=st.id;
strcpy(p1->sex,st.sex);
p1->paid[0]=st.paid[0];
p1->paid[1]=st.paid[1];
p1->paid[2]=st.paid[2];
p1->total=st.total;
if(n==0)head=p1; //如果是輸入第一組職工信息就將指針p1賦給指針head
else p2->next=p1; //否則將p1賦給p2所指結構體的next指針
p2=p1; //將指針p1賦給指針p2
n++; //將n的值加1
//顯示讀入數據
cout<<" "<<p1->name<<"\t"
<<p1->id<<" \t"
<< p1->sex <<" \t"
<< p1->paid[0] <<" \t"
<< p1->paid[1] <<" \t"
<< p1->paid[2] <<" \t"
<< p1->total<<endl;
cout<<" ………………………………………………………………………………………………"<<endl;
}
cout<<" 數據已經成功讀取完畢!\n\n"<<endl;
p2->next=NULL;
return (head);
}
}
//-------------------->菜單
void Menu()
{
Information person;
student *head=NULL;
int choice;
long i;
do{
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ _ _ _ 歡迎進入職工成績統計管理 _ _ _ ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;
cout<<"\t "<<endl;
cout<<"\t 相關操作選項 "<<endl;
cout<<"\t "<<endl;
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※"<<endl;
cout<<"\t※ 0. 讀取文件信息 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 1. 職工數據輸入 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 2. 顯示職工工資 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 3. 排序統計工資 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 4. 查找職工工資 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 5. 增加職工工資 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 6. 刪除職工工資 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 7. 修改職工信息 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 8. 成功保存信息 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※ 9. 安全退出系統 ※"<<endl;
cout<<"\t※ ※"<<endl;
cout<<"\t※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"<<endl;
cout<<" 請輸入您的選擇(0--9):";
cin>>choice;
while(choice<0||choice>9)
{
cout<<" 對不起您的輸入錯誤!請輸入您的選擇(0--9): ";
cin>>choice;
}
switch(choice)
{
case 0:
head=person.Read();break;
case 1:
head=person.creat();
break;
case 2:
person.output(head);
break;
case 3:
person.paixu(head); person.average(head);
cout<<" 參加工作的職工人數為:"<<person.count(head)<<"人\n\n";
break;
case 4:
cout<<" 請輸入要查找的編號:";
cin>>i;
while(i<0||i>100000)
{
cout<<" 對不起您的輸入錯誤!請重新輸入: ";
cin>>i;
}
person.find(head,i);
break;
case 5:
head=person.insert(head);
person.output(head);
break;
case 6:
cout<<" 請輸入要刪除的編號:";
cin>>i;
while(i<0||i>100000)
{
cout<<" 對不起您的輸入錯誤!請重新輸入: ";
cin>>i;
}
head=person.cancel(head,i);
person.output(head);
break;
case 7:
cout<<" 請輸入要修改的編號:";
cin>>i;
while(i<0||i>100000)
{
cout<<" 對不起您的輸入錯誤!請重新輸入: ";
cin>>i;
}
person.modify(head,i);
break;
case 8:
cout<<"信息已經成功保存!"<<endl;
person.save(head);
break;
case 9:
system("cls");
break;
default :
cout<<" 對不起您的輸入有誤!請重新輸入:\n";
break;
}
}
while(choice!=9);
}
//----------------->管理員登陸
void Pass()
{
char UserName[30];
char Passward[20];
int i=0;
cout<<"****************************************************************************\n";
cout<<"\n\t為保護職工成績信息,只有管理員才可以進行管理!\n";
cout<<"\n\t管理員名和登陸密碼都只有4次機會,如果超過將自動退出系統!\n\n";
cout<<"****************************************************************************\n";
cout<<"\n請輸入管理員名:";
cin>>UserName;
while (strcmp(UserName,"fangfangff")!=0)
{
if(i>=3)
exit(0); //超過4次則登陸失敗,退出系統
i++;
cout<<"\n管理員名無效!請重新輸入:";
cin>>UserName;
}
cout<<"\n請輸入密碼:";
cin>>Passward;
while(strcmp(Passward,"fangfangff")!=0)
{
if(i>=3)
exit(0); //超過4次則登陸失敗,退出系統
i++;
cout<<"\n密碼輸入錯誤!請重新輸入:"<<endl;
cin>>Passward;
}
cout<<"\n\t\t歡迎管理員的到來!!!!!\n"<<endl;
}
//------------------------------>主函數.
int main(void)
{
system("color 012"); //設置背景色和字體顏色
zuozhe();
system("PAUSE"); //系統暫停
system("cls"); //系統清屏
Pass();
system("PAUSE");
system("cls");
Menu();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -