C++實(shí)現(xiàn)信息管理系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
有一個(gè)信息管理系統(tǒng),要求檢查每一個(gè)登錄系統(tǒng)的用戶(User)的用戶名和口令,系統(tǒng)檢查合格以后方可登錄系統(tǒng),用C++程序予以描述。
代碼如下:
#include<iostream> using namespace std; class Information{ private:char *Users;//用戶名 ?? ??? ?char *Password;//密碼 ?? ??? ?char *Password1;//第二次輸入的密碼 ?? ??? ?char *users;//登錄時(shí)輸入的用戶名 ?? ??? ?char *password;//登錄時(shí)輸入的密碼 public: ?? ?Information(char *Users="1234567",char *Password="qwer1234"){ //構(gòu)造函數(shù) ?? ??? ?this->Users=Users,this->Password=Password; ?? ?} ?? ?~Information(){} //析構(gòu)函數(shù) ?? ?void deleteusers(){//用戶名重復(fù)時(shí)刪除該注冊(cè) ?? ??? ?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(){//注冊(cè) ?? ??? ?int judge1=0; ?? ??? ?cout<<"請(qǐng)?jiān)O(shè)置您的用戶名:"; ?? ??? ?Users=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>Users; ?? ??? ?cout<<"請(qǐng)?jiān)O(shè)置您的密碼:"; ?? ??? ?Password=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>Password; ?? ??? ?cout<<"請(qǐng)?jiān)俅屋斎肽O(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;}//返回用戶名以判斷注冊(cè)的用戶名是否重復(fù) }; int main(){ ?? ?Information inf[100];//用戶信息的數(shù)組 ?? ?int a=0;//用戶的個(gè)數(shù) ?? ?int c,e;//功能選擇 ?? ?char *u;//登錄時(shí)用戶名輸入 ?? ?char *p;//登錄時(shí)密碼輸入 ?? ?int a1,b1;//控制判斷條件 ?? ?for(int d=0;d<100;d++){ ?? ??? ?cout<<"1-注冊(cè);2-登錄:";//功能選擇 ?? ??? ?cin>>c; ?? ??? ?switch(c){ ?? ?case 1:{ ?? ??? ?for(int i=0;i<=100;i++){ ?? ??? ??? ?int con=inf[i].setinformation();//用戶注冊(cè) ?? ??? ??? ?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<<"用戶名已存在,請(qǐng)重新設(shè)置"<<endl;i--; a1=1;inf[a].deleteusers();a--;break;} ?? ??? ??? ?} ?? ??? ??? ?} ?? ??? ??? ??? ?if(con==0&&a1==0) { cout<<"兩次輸入密碼不相同,請(qǐng)重新設(shè)置"<<endl;i--;inf[a].deleteusers();a--;} ?? ??? ??? ??? ?else if(con==1&&a1==0) ?cout<<"設(shè)置成功!"<<endl; ?? ??? ??? ?a=a+1;//個(gè)數(shù)加一 ?? ??? ??? ?cout<<"'1'繼續(xù),'2'返回"<<endl;//是否繼續(xù)注冊(cè) ?? ??? ??? ?cin>>e; ?? ??? ??? ?if(e==2){break;} ?? ??? ??? ?else if(e==1){continue;} ?? ??? ??? ?else if(e!=1&&e!=2) ?{cout<<"輸入無效"<<endl; ? break;} ?? ??? ?} ?? ??? ?break; ?? ?} ?? ?case 2:{ ?? ??? ?cout<<"請(qǐng)輸入用戶名: "; ?? ??? ?u=(char *)malloc(20*sizeof(char)); ?? ??? ?cin>>u; ?? ??? ?cout<<"請(qǐng)輸入密碼: ?"; ? ? ? ? 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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C語言數(shù)據(jù)結(jié)構(gòu) 棧的基礎(chǔ)操作
這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu) 棧的基礎(chǔ)操作的相關(guān)資料,需要的朋友可以參考下2017-05-05用C++面向?qū)ο蟮姆绞絼?dòng)態(tài)加載so的方法
下面小編就為大家?guī)硪黄肅++面向?qū)ο蟮姆绞絼?dòng)態(tài)加載so的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12C++進(jìn)程的創(chuàng)建和進(jìn)程ID標(biāo)識(shí)詳細(xì)介紹
傳統(tǒng)的C++(C++98)中并沒有引入線程這個(gè)概念。linux和unix操作系統(tǒng)的設(shè)計(jì)采用的是多進(jìn)程,進(jìn)程間的通信十分方便,同時(shí)進(jìn)程之間互相有著獨(dú)立的空間,不會(huì)污染其他進(jìn)程的數(shù)據(jù),天然的隔離性給程序的穩(wěn)定性帶來了很大的保障2022-08-08C++?Qt實(shí)現(xiàn)一個(gè)解除文件占用小工具
這篇文章主要為大家詳細(xì)介紹了如何利用C++?Qt實(shí)現(xiàn)一個(gè)解除文件占用小工具,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-09-09C++實(shí)現(xiàn)LeetCode(55.跳躍游戲)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(55.跳躍游戲),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07