C++實現(xiàn)信息管理系統(tǒng)
更新時間:2022年03月12日 14:46:31 作者:Come to the Sunday
這篇文章主要為大家詳細介紹了C++實現(xiàn)信息管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C++實現(xiàn)信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
有一個信息管理系統(tǒng),要求檢查每一個登錄系統(tǒng)的用戶(User)的用戶名和口令,系統(tǒng)檢查合格以后方可登錄系統(tǒng),用C++程序予以描述。
代碼如下:
#include<iostream> using namespace std; class Information{ private:char *Users;//用戶名 ?? ??? ?char *Password;//密碼 ?? ??? ?char *Password1;//第二次輸入的密碼 ?? ??? ?char *users;//登錄時輸入的用戶名 ?? ??? ?char *password;//登錄時輸入的密碼 public: ?? ?Information(char *Users="1234567",char *Password="qwer1234"){ //構(gòu)造函數(shù) ?? ??? ?this->Users=Users,this->Password=Password; ?? ?} ?? ?~Information(){} //析構(gòu)函數(shù) ?? ?void deleteusers(){//用戶名重復時刪除該注冊 ?? ??? ?Users="______"; ?? ??? ?Password="______"; ?? ?} ? ? int Login(char *users,char *password){//登錄 ?? ??? ?int b=1;//控制登錄的成功或失敗 ?? ??? ?for(int o=0,p=0;o<strlen(Users)&&o<strlen(users)&&p<strlen(Password)&&p<strlen(password);o++,p++){ ?? ??? ?if((*(Users+o)==*(users+o))&&(*(Password+p)==*(password+p))) ? b=0;//成功為零,失敗為一 ?? ??? ?else {b=1; break;} ?? ??? ?} ?? ??? ?return b; ?? ?} ?? ?int setinformation(){//注冊 ?? ??? ?int judge1=0; ?? ??? ?cout<<"請設(shè)置您的用戶名:"; ?? ??? ?Users=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>Users; ?? ??? ?cout<<"請設(shè)置您的密碼:"; ?? ??? ?Password=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>Password; ?? ??? ?cout<<"請再次輸入您設(shè)置的密碼:"; ?? ??? ?Password1=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>Password1;//用戶名密碼輸入 ?? ??? ?if(strlen(Password)==strlen(Password1)){ ?? ??? ?for(int p=0;p<strlen(Password);p++){ ?? ??? ?if(*(Password+p)==*(Password1+p)) ?judge1=judge1+1; //判斷兩次輸入的密碼是否相等 ?? ??? ?} ?? ??? ?if(judge1==p) return 1; ?? ??? ?else return 0; ?? ?} ?? ??? ?else return 0; ?? ?} ?? ?char *getUsers(){return Users;}//返回用戶名以判斷注冊的用戶名是否重復 }; int main(){ ?? ?Information inf[100];//用戶信息的數(shù)組 ?? ?int a=0;//用戶的個數(shù) ?? ?int c,e;//功能選擇 ?? ?char *u;//登錄時用戶名輸入 ?? ?char *p;//登錄時密碼輸入 ?? ?int a1,b1;//控制判斷條件 ?? ?for(int d=0;d<100;d++){ ?? ??? ?cout<<"1-注冊;2-登錄:";//功能選擇 ?? ??? ?cin>>c; ?? ??? ?switch(c){ ?? ?case 1:{ ?? ??? ?for(int i=0;i<=100;i++){ ?? ??? ??? ?int con=inf[i].setinformation();//用戶注冊 ?? ??? ??? ?a1=0; ?? ??? ??? ?for(int j=0;j<a;j++){ ?? ??? ??? ??? ?char *f=inf[j].getUsers(); ?? ??? ??? ??? ?char *h=inf[a].getUsers(); ?? ??? ??? ??? ?if(strlen(f)==strlen(h)){ ?? ??? ??? ??? ??? ?int judge2=0; ?? ??? ??? ??? ?for(int o=0;o<strlen(f);o++){ ?? ??? ??? ??? ?if(*(f+o)==*(h+o)) ? judge2=judge2+1; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if(judge2==o) ??? ?{cout<<"用戶名已存在,請重新設(shè)置"<<endl;i--; a1=1;inf[a].deleteusers();a--;break;} ?? ??? ??? ?} ?? ??? ??? ?} ?? ??? ??? ??? ?if(con==0&&a1==0) { cout<<"兩次輸入密碼不相同,請重新設(shè)置"<<endl;i--;inf[a].deleteusers();a--;} ?? ??? ??? ??? ?else if(con==1&&a1==0) ?cout<<"設(shè)置成功!"<<endl; ?? ??? ??? ?a=a+1;//個數(shù)加一 ?? ??? ??? ?cout<<"'1'繼續(xù),'2'返回"<<endl;//是否繼續(xù)注冊 ?? ??? ??? ?cin>>e; ?? ??? ??? ?if(e==2){break;} ?? ??? ??? ?else if(e==1){continue;} ?? ??? ??? ?else if(e!=1&&e!=2) ?{cout<<"輸入無效"<<endl; ? break;} ?? ??? ?} ?? ??? ?break; ?? ?} ?? ?case 2:{ ?? ??? ?cout<<"請輸入用戶名: "; ?? ??? ?u=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>u; ?? ??? ?cout<<"請輸入密碼: ?"; ? ? ? ? p=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>p; ?? ??? ?for(int z=0;z<=a;z++){ ?? ??? ??? ?b1=inf[z].Login(u,p); ?? ??? ??? ?if(b1==0){ cout<<"Successfully loging in."<<endl<<"Welcome to my world!"<<endl;break;}//登錄成功 ?? ??? ?} ?? ??? ?if(b1==1) cout<<"The user is not exist or the password is wrong."<<endl;//登錄失敗 ?? ??? ?break; ?? ?} ?? ?default: cout<<"abnormal input"<<endl; ?? ??? ?} ?? ?} ?? ?return 0; }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C語言數(shù)據(jù)結(jié)構(gòu) 棧的基礎(chǔ)操作
這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu) 棧的基礎(chǔ)操作的相關(guān)資料,需要的朋友可以參考下2017-05-05