我想把這里做成一個回圈體,就是這個登錄界面,只有成功登陸或者選擇3的時候才可以退出回圈,這樣的話注冊完還能顯示出來這個登錄界面,但是現在就是你輸入2之后注冊完它貌似就結束回圈了。。。
#include<iostream>
#include<cmath>
#include<cassert>
#include<string>
#include <conio.h>
using namespace std;
void Login_Menu()
{
cout<<"\t**************************家庭財務幫手**************************"<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<"\t\t\t歡迎使用家庭財務助手"<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<"\t | <1>登錄 | "<<endl;
cout<<"\t | <2>注冊 | "<<endl;
cout<<"\t | <3>退出 | "<<endl;
cout<<"\t \t\t\t\t";
//getTime();
cout<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<endl;
cout<<"\t******************請輸入你進行的操作編號:...********************"<<endl;
cout<<"\t****************************************************************"<<endl;
}//登錄界面
void MainMenu()
{
cout<<"\t**************************家庭財務幫手**************************"<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<"\t\t\t請選擇功能"<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<"\t | <1>家庭成員收入資訊輸入 | "<<endl;
cout<<"\t | <2>家庭成員支出資訊輸入 | "<<endl;
cout<<"\t | <3>家庭成員資訊查詢 | "<<endl;
cout<<"\t | <4>家庭成員資訊洗掉 | "<<endl;
cout<<"\t | <5>家庭成員資訊修改 | "<<endl;
cout<<"\t | <6>回傳上一級 | "<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<"\t \t\t\t\t";
//getTime();
cout<<endl;
cout<<"\t****************************************************************"<<endl;
cout<<"\n\n";
cout<<"\t******************請輸入你進行的操作編號:...********************"<<endl;
}//登陸后進入的的主頁
class User
{
public:
User() {}
void Move(string n,string a)
{
username=n;
password=a;
}
string GetUsername(){return username;}//查詢姓名
string GetPassword(){return password;}
friend class ArrayOfUsers;
friend void Login(ArrayOfUsers users,int d);
private:
string username;
string password;
};
class ArrayOfUsers
{
public:
ArrayOfUsers(int size):size(size){
users=new User[size];
}
/*~ArrayOfUsers()
{
delete[] users;
}*/
User &element(int index){
assert(index>=0 && index<size);
return users[index];
}
void Add(string n,string a);
friend class User;
friend void Login(ArrayOfUsers users,int d);
private:
int a;
int size;
User* users;
static int record_index;
};
int ArrayOfUsers::record_index=0;
void ArrayOfUsers::Add(string n,string a)
{
users[record_index].username =n;
users[record_index].password =a;//這個成員函式的作用就相當于是把注冊的資訊依次賦值給之前創建的那10個成員,
record_index++;//而record_index則是用于記錄有幾個成員被賦過值,在以后登錄時候對比是否用戶名和密碼相符會用到()
}
void Login(ArrayOfUsers users,int d)
{
Login_Menu();
string username;
string password;
int login_select;
bool is_successfully_login = false;
bool is_account_found = false;
bool is_password_correct = false;
int i,h;
string f;
do{ //我想把這里做成一個回圈體,就是這個登錄界面,只有成功登陸或者選擇3的時候才可以退出回圈,這樣的話注冊完還能顯示出來這個登錄界面,還可以選擇下一步怎么做
cin>>login_select;
switch (login_select)
{
case 1:
for(i=1;i<d;i++)
{
f=users.element(i).GetUsername();
if(f!=" ")h=0;
else h=1;
}
if(h==0)
{
cout << "目前系統中還沒有賬戶,請創建賬戶后進行操作。" << endl;
cout << endl << "--注冊賬戶--" << endl;
cout << "用戶名: ";
setbuf(stdin, NULL); //重繪輸入緩沖區
getline(cin, username);
cout << "密碼: ";
setbuf(stdin, NULL); //重繪輸入緩沖區
getline(cin, password);
cout<<endl;
users.Add(username, password);
cout << "賬戶創建成功!" << endl;//沒有用戶的時候要先注冊
cout << endl << "--登陸賬戶--" << endl;
char a[9];
setbuf(stdin, NULL);
cout <<" 用戶名:";
cin>>username;
cout <<" 密碼:";
int i;
for(i=0;i<9;i++)
{
a[i]=getch();
cout << "*";
if(a[i]==13)//想實作回車能跳出回圈
break;
if(a[i] == '\b')//想實作退格鍵作用
{
cout << "\b\b";
}
}
cout << endl;
a[i] = 0;
password = a;
for (i = 0; i < users.record_index; i++)
{
if (users.element(i).username==username)
{
is_account_found = true;
cout << "已找到賬戶,檢查密碼..." << endl;
if(users.element(i).password== password)
{
cout << "驗證通過。歡迎登陸!" << endl ;
login_select = 3; //這里是成功登陸之后,這個時候才把
system("cls");
MainMenu(); //跳轉到主選單
break;
}
else
{
cout << "密碼輸入錯誤,請重新輸入。" << endl;
break;
}
}
}
if (is_account_found != true)
{
cout << "未找到該賬戶,請檢查輸入是否有誤。" << endl;
}
}
else{
cout << endl << "--登陸賬戶--" << endl;
char a[9];
setbuf(stdin, NULL);
cout <<" 用戶名:";
cin>>username;
cout <<" 密碼:";
int i;
for(i=0;i<9;i++)
{
a[i]=getch();
cout << "*";
if(a[i]==13)//想實作回車能跳出回圈
break;
if(a[i] == '\b')//想實作退格鍵作用
{
cout << "\b\b";
}
}
cout << endl;
a[i] = 0;
password = a;
for (i = 0; i < users.record_index; i++)
{
if (users.element(i).username==username)
{
is_account_found = true;
cout << "已找到賬戶,檢查密碼..." << endl;
if(users.element(i).password== password)
{
cout << "驗證通過。歡迎登陸!" << endl ;
is_successfully_login = true;
system("cls");
MainMenu(); //跳轉到主選單
break;
}
else
{
cout << "密碼輸入錯誤,請重新輸入。" << endl;
break;
}
}
}
if (is_account_found != true)
{
cout << "未找到該賬戶,請檢查輸入是否有誤。" << endl;
}
}break;
case 2:
cout << endl << "--注冊賬戶--" << endl;
cout << "用戶名: ";
setbuf(stdin, NULL); //重繪輸入緩沖區
getline(cin, username);
cout << "密碼: ";
setbuf(stdin, NULL); //重繪輸入緩沖區
getline(cin, password);
cout<<endl;
users.Add(username, password);
cout << "賬戶創建成功!" << endl;
system("pause");//點擊任意鍵繼續
system("cls");
Login_Menu();//沒有用戶的時候要先注冊
break;
case 3:exit(1);
}
}while(login_select == 3);
}
int main()
{
system("color F5");//控制界面登陸時候的顏色
int d=10;
ArrayOfUsers users(d); //預設定10個成員
Login(users,d);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/58974.html
標籤:基礎類
