谢谢radcat和song4两位版主回答我的问题^_^
----------------------------------------------------------------------
这是个模拟银行提款机的简易程序,该一共包含三个文件.(*This is program is unfinished)
被注释掉的代码表示该代码还在测试和开发当中.
-----------------------------------------------------------------------------
//Cpp1.cpp
#include<iostream.h>
#include<string.h>
#include"Savings.h"
void main()
{
//loading.....
Savings save[30]={Savings("mashengbo","abc123"),Savings("maozhendong","abc456"),Savings("yangmaosheng","abc789"),Savings("zengfanpu","cba123"),Savings("baiweiwei","cba456"),Savings("hanyang","cba789")};
//menu.........
int chooseno_a;
cout<<"Welcome to Construction Bank.Connecting data......"<<endl;
cout<<"1-Login"<<" 2-Register"<<" 3-Help"<<" 4-Exit"<<endl;
cin>>chooseno_a;
/*if (chooseno_a==1) goto loop_b;
else if (chooseno_a==2) goto loop_regist;
else if (chooseno_a==3) cout<<"connecting help information..."<<endl;
else if (chooseno_a==4) {cout<<"quitting......\nPlease close the windows^_^"<<endl;goto loop_end;}
else cout<<"Error input"<<endl;*/
//input and checking operation....
loop_b:
char input_name[20],input_pass[20];
cout<<"please enter your name:"<<endl;
cin>>input_name;
cout<<"Please enter your password:"<<endl;
cin>>input_pass;
for (int i=0,int temp=0;i<30;i++)
{
if (save[i].Check(input_name,input_pass)==1)
temp=1;
if (temp==1)
{
cout<<"Login successfully...."<<endl;
goto loop_ok;
}
}
cout<<"The user is unfound,please enter again."<<endl;
goto loop_b;
//loop_ok,login successfully
loop_ok:
cout<<"Connecting the account......"<<endl;
//the following code is just for stoppting the program.
/*loop_end:
*/ cout<<"Program finsiehed...Please close the window..."<<endl;
for(;;)
{int wait;
cin>>wait;}
/*loop_regist:
cout<<"Connecting the regist system......"<<endl;*/
}
----------------------------------------------------------------
//Savings.cpp
#include<iostream.h>
#include<string.h>
#include"Savings.h"
Savings::Savings(char x[20],char y[20])
{
strcpy(IDname,x);
strcpy(password,y);
}
Savings::Savings()
{
strcpy(this->IDname,"noname");
strcpy(this->password,"void");
}
Savings::~Savings()
{
}
int Savings::Check(char x[20],char y[20])
{
if (strcmp(x,this->IDname)==0)
{
if (strcmp(y,this->password)==0)
return 1;
}
else return 0;
}
------------------------------------------------------------------------
//Savings.h
#include<iostream.h>
class Savings
{
public:
Savings();
Savings(char *,char *);
virtual ~Savings();
int Check(char *,char *); //check the password is it is correct.
protected:
char IDname[20];
char password[20];
};
-----------------------------------------------------------------------------
我是大一新生,自己看了看书,水平有限。希望各位高手能够详细的指点。十分感谢!
程序已经放出来了,我想制作一个模仿ATM的程序。
question one:查找问题(已解决)
考虑到实际,必须保护用户名和密码的安全。所以我选择用类来做。可是在检查密码是否正确遇到了问题。我想设一个成员函数CHECK收到用户名和密码后,可以调出正确密码和输入密码进行比较,通过返回0和1值判断是否可以继续程序。可是在调用户名时,发现,类只是个模子,不可以分配空间,怎样可以使类的内部函数具有查找数据的功能是我十分疑惑的地方。
question twe:隐身问题(已解决)
在输入密码时,怎样实现隐身功能?就是,怎样使输入时在屏幕显示“****”而不显示真实的密码?
question three:菜单引导问题(已解决)
教科书上说GOTO不要经常使用,不利于可读性。可是像在原程序中菜单部分的引导除了GOTO,还可以用什么方法可以实现呢?
[此贴子已经被作者于2006-11-7 15:41:00编辑过]