?? main.cpp
字號:
//主程序,文件名稱為main.cpp
#include<iostream>
#include<string> //此文件中包含許多關于字符處理的函數。
#include<fstream> //要定義文件流對象。
#include<iomanip> //要用到格式控制函數setw()。
#include<cstdlib> //要用到exit(1).
#include"select_max.h"
#include"read.h"
#include"add.h"
#include"del.h"
#include"display_simple.h"
#include"pay_average.h"
#include"refer.h"
#include<cstdlib> //此文件中有atoi()函數。
#include"str.h" //自定義的關于字符串處理的函數庫。
using namespace std;
void help(); //幫助函數的聲明。
void main()
{
/******************************用戶驗證模塊**************************************/
char UserNameInput[256]; //用戶輸入的用戶名
char PasswordInput[256]; //用戶輸入的密碼
bool temp1=false; //驗證用戶的輸入格式
bool temp2=false; //驗證用戶的輸入格式
int error=0; //錯誤的次數。
cout<<"**************************************************\n";
cout<<"***************職工信息管理系統登陸***************\n";
cout<<"**************************************************\n";
cout<<"用戶:";
gets(UserNameInput); //輸入用戶名。
cout<<"密碼:";
gets(PasswordInput); //輸入密碼。
temp1=check(UserNameInput); //驗證用戶的輸入格式。
temp2=check(PasswordInput);
int t1=strcmp(UserNameInput,"lhh"); //將用戶的輸入與正確的內容相比較。
int t2=strcmp(PasswordInput,"520"); //也可以從數據庫中讀取驗證信息!
while(temp1==false || temp2==false || t1!=0 || t2!=0)
{
error++;
if(error==3)
{
cout<<"您的錯誤次數已經超過3次,程序將退出!"<<endl;
cout<<"***************************************************\n";
cout<<"*******************!未授權用戶!********************\n";
cout<<"***************************************************\n";
cout<<"請按任意鍵退出該程序:";
string tempstr;
cin>>tempstr;
break;
}
cout<<"用戶名或密碼錯誤,請重新輸入!\n"<<endl;
cout<<"用戶:";
gets(UserNameInput);
cout<<"密碼:";
gets(PasswordInput);
temp1=check(UserNameInput);
temp2=check(PasswordInput);
t1=strcmp(UserNameInput,"lhh");
t2=strcmp(PasswordInput,"520");
}
if(error>=3)
exit(1); //驗證用戶的錯誤次數,如果錯誤次數為3次以上,就返回false
/**************************開始進入導航模式********************************/
char select_string[256]; //選擇主菜單操作.
int select_int;
bool temp=false; //驗證用戶的輸入格式
int p;
for( ; ; )
{
cout<<"請按以下提示進行操作"<<endl;
cout<<"1.設置職工最大數"<<endl;
cout<<"2.職工信息查詢"<<endl; //此函數未實現。
cout<<"3.增加職工記錄"<<endl;
cout<<"4.刪除職工記錄"<<endl;
cout<<"5.生成信息簡表"<<endl;
cout<<"6.顯示原始記錄"<<endl;
cout<<"7.顯示簡表記錄"<<endl;
cout<<"8.顯示工資平均值"<<endl;
cout<<"9.幫助菜單"<<endl; //此函數未實現。
cout<<"0.退出該系統"<<endl;
cout<<"請選擇你想進行的操作:";
cin>>select_string;
temp=check_num(select_string); // 調用check_num函數,判斷用戶的輸入
while(!temp)
{
cout<<"對不起,您的輸入中含有非法字符,只能是阿拉伯數字(0-9)!"<<endl;
cout<<"請重新輸入:";
cin>>select_string;
temp=check_num(select_string);
}
select_int=atoi(select_string); //將字符串轉化成整型數字。
while(select_int!=1 &&select_int!=2 && select_int!=3 && select_int!=4 && select_int!=5
&&select_int!=6 &&select_int!=7 &&select_int!=8 &&select_int!=9 &&select_int!=0)
{
cout<<"對不起,您的輸入有誤,只能是阿拉伯數字(0-9)!"<<endl;
cin>>select_string;
temp=check_num(select_string);
while(!temp)
{
cout<<"對不起,您的輸入含有非法字符,只能是阿拉伯數字(0-9)!"<<endl;
cout<<"請重新輸入:";
cin>>select_string;
temp=check_num(select_string);
}
select_int=atoi(select_string); //將字符串轉化成整型數字。
}
//驗證用戶輸入完畢。
switch(select_int)
{
case 1:
select_max(); //調用設置職工最大數函數。
break;
case 2:
refer(); //調用職工信息查詢函數。
break;
case 3:
add(); //調用增加職工記錄函數add()
break;
case 4:
del(); //調用刪除職工記錄函數del();
break;
case 5:
display_simple(0); //調用display_simple函數,并且不顯示簡表信息。
break;
case 6:
read(1); //調用從文件讀記錄函數read,并顯示原始記錄。
break;
case 7:
display_simple(1); //調用display_simple函數,并且顯示簡表信息。
break;
case 8:
pay_average(); //調用顯示工資平均值函數pay_average()。
break;
case 9:
help(); //調用幫助函數,顯示關于程序的一些說明。
break;
case 0:
p=0;
break; //退出程序。
}
if(p==0)
break;
} //for循環結束。
} //main()函數結束。
void help()
{
cout<<endl;
cout<<"********************幫助********************************"<<endl;
cout<<"本程序是一個很簡單的程序,進入主菜單后,您可以按\n"
<<"照提示進行相應的操作\n"
<<"1、設置職工最大數函數是用來初始化職工信息管理系統\n"
<<"的,如果錯誤操作,將導致原始職工記錄全部丟失,只\n"
<<"剩下系統初始化的一些職工記錄!\n"
<<"2、職工信息查詢菜單可以用來查詢某一職工的個人信息,\n"
<<"包括職工編號、姓名、性別、年齡和工資!\n"
<<"3、增加職工記錄菜單可以向職工信息管理系統中添加職工信息\n"
<<"4、刪除職工記錄菜單可以從職工信息管理系統中刪除已有的職\n"
<<"工信息,注意:職工信息一旦刪除將不能恢復!\n"
<<"5、生成簡表信息,是和顯示簡表信息菜單協調工作的,為了減\n"
<<"少麻煩,顯示簡表記錄菜單中已經包含了此菜單的作用。\n"
<<"6、顯示原始記錄菜單,它的作用是顯示職工信息管理系統中的\n"
<<"所有職工信息,而菜單職工信息查詢一次只能顯示一個記錄。\n"
<<"7、顯示簡表記錄,作用類似于菜單6,只不過顯示的項目有限\n"
<<"8、顯示工資平均值,將計算并顯示該信息管理系統中所有職\n"
<<"工的工資平均值(只保留整數位)\n"
<<"9、幫助菜單,向用戶提供每個菜單的作用及其使用幫助\n"
<<"0、退出該系統。不必擔心,在退出系統之前,用戶之前\n"
<<"的所有操作將保存。您完全不必擔心會丟失數據!\n"
<<"如果還有其它問題,請致電025-51730095,或發送E-mail到\n"
<<"lhh_nj@163.com,或加QQ:258697202.我們將竭誠為您服務\n";
cout<<"********************幫助********************************"<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -