VB文件IO遇到了问题!急!

VB文件IO遇到了问题!急!,第1张

if p(i)<>0 then SResult = SResult + Chr(p(i))

'给你另外写了个,比你原先做的可能会好点

Function GetPassWord() As String '解密

Dim strPW As String

filename = AppPath + "\密码txt"

Open filename For Input As #1

Input #1, x

Close #1

ReDim p(Len(x) / 2, 2)

For i = 1 To Len(x) Step 2

GetPassWord= GetPassWord & Chr(Asc(Mid(x, i, 1)) Xor Asc(Mid(x, i + 1, 1)))

Next i

End Function

Sub PutPassWord(x As String) '加密

Dim strKey As String

Dim i As Integer

Dim p() As String

Dim strRel As String

Randomize

ReDim p(Len(x), 2)

For i = 1 To Len(x)

p(i, 0) = Mid(x, i, 1): p(i, 1) = Chr(Int(Rnd 26 + 48))

strRel = strRel & Chr(Asc(p(i, 0)) Xor Asc(p(i, 1))) & p(i, 1)

Next i

filename =AppPath + "\密码txt"

Open filename For Output As #1

Print #1, strRel

Close #1

End Sub

Private Sub Command1_Click()

PutPassWord Text1

End Sub

Private Sub Command2_Click()

Text2 = GetPassWord

End Sub

#include <iostream>

using namespace std;

///////////////////////////////用户类//////////////////////////////////////

class User

{

private:

int money;

string userName;

string password;

public:

User();

~User();

User(string userName, string password);

int saveMoney(int money);// 存款

int getMoney(int money); // 取款

int checkMoney(); // 查询余额

string getUserName(); // 取得用户名

string getPassword(); // 取得密码

};

User::User()

{

money = 0;

}

User::User(string userName, string password)

{

money = 0;

this->userName = userName;

this->password = password;

}

int User::saveMoney(int money)

{

this->money += money;

return this->money;

}

int User::getMoney(int money)

{

this->money -= money;

return this->money;

}

int User::checkMoney()

{

return this->money;

}

string User::getUserName()

{

return this->userName;

}

string User::getPassword()

{

return this->password;

}

/////////////////////////////////////////////////////////////////////////

///////////////////////////////////数据库类,用来存储用户//////////////////////

class DataBase

{

private:

User users[40]; // 默认数据可最多能存放40个用户

int userNumber; // 已注册用户的数量

public:

DataBase();

~DataBase();

bool add(User user); // 添加新用户

User getUser(int i); // 按照索引取得用户

User getUser(string name); // 按照用户名取得用户

int getUserNumber(); // 取得数据库中用户的数量

};

DataBase::DataBase()

{

userNumber = 0;

}

DataBase::~DataBase()

{

delete users;

}

bool DataBase::add(User user)

{

if(userNumber < 40 && getUser(user->getUserName()) == NULL) // 如果当前用户名在数据库中不存在

{

users[userNumber] = user;

userNumber++;

return true; // 返回true表示新用户添加成功

}

return false; // 返回false表示新用户添加失败

}

User DataBase::getUser(int i)

{

if(i > 40 || i < 0) return NULL;

return users[i];

}

User DataBase::getUser(string userName)

{

for(int i = 0; i < userNumber; i++)

{

User user = getUser(i);

if(user->getUserName() == userName) return user;

}

return NULL;

}

/////////////////////////////////////////////////////////////////////////

DataBase database;

int welcom();

// 注册

User user_register();

User user_login();

int exit();

int user_process();

int main()

{

int state;

int user_state;

User user;

do

{

state = welcom();

switch(state)

{

case 1:

user = user_register(); // 用户注册

if(NULL != user)

{

cout<<"\n注册成功\n";

do

{

user_state = user_process();

switch(user_state)

{

case 1:// 存钱

{

cout<<"输入存钱金额:";

int num;

cin>>num;

cout<<"余额为:"<<user->saveMoney(num)<<endl;;

}

break;

case 2:// 取钱

{

cout<<"输入取钱金额:";

int num;

cin>>num;

cout<<"余额为:"<<user->getMoney(num)<<endl;

}

break;

case 3:// 查看余额

{

cout<<"余额为:"<<user->checkMoney()<<endl;

}

break;

case 4://返回

user_state = 0;

default: break;

}

} while(user_state);

user = NULL;

}

else cout<<"\n注册失败\n";

break;

case 2:

user = user_login(); // 用户登陆

if(NULL != user)

{

cout<<"登陆成功"<<endl;

do

{

user_state = user_process();

switch(user_state)

{

case 1:// 存钱

{

cout<<"输入存钱金额:";

int num;

cin>>num;

cout<<"余额为:"<<user->saveMoney(num)<<endl;;

}

break;

case 2:// 取钱

{

cout<<"输入取钱金额:";

int num;

cin>>num;

cout<<"余额为:"<<user->getMoney(num)<<endl;

}

break;

case 3:// 查看余额

{

cout<<"余额为:"<<user->checkMoney()<<endl;

}

break;

case 4://返回

user_state = 0;

default: break;

}

} while(user_state);

user = NULL;

}

else cout<<"\n登陆失败\n";

break;

case 3:

state = exit();

break;

default: break;

}

}

while(state);

return 0;

}

int welcom()

{

cout<<"\t\t欢迎使用ATM系统\n";

cout<<"\t\t 1用户注册 \n";

cout<<"\t\t 2用户登录 \n";

cout<<"\t\t 3退出系统 \n";

cout<<"\t\t\n";

int num;

cin>>num;

return num;

}

// 注册

User user_register()

{

string userName;

string password;

cout<<"请输入账号:";

cin>>userName;

if(NULL != databasegetUser(userName)) // 如果用户名存在

return NULL; // 注册失败

cout<<"请输入密码:";

cin>>password;

User user = new User(userName, password);

databaseadd(user);

return user; // 注册成功

}

User user_login()

{

string userName;

string password;

cout<<"请输入账号:";

cin>>userName;

cout<<"请输入密码:";

cin>>password;

User user = databasegetUser(userName);

if(NULL != user) // 如果用户存在

if(user->getPassword() == password)

return user; // 如果密码匹配则登陆成功

return NULL; // 如果用户不存在

}

int exit()

{

return 0; // 退出系统

}

int user_process()

{

cout<<"\t\t\n";

cout<<"\t\t 请选择 *** 作类型 \n";

cout<<"\t\t 1存 钱 \n";

cout<<"\t\t 2取 钱 \n";

cout<<"\t\t 3查 看 余 额 \n";

cout<<"\t\t 4返 回 \n";

cout<<"\t\t\n";

int num;

cin>>num;

return num;

}

以上就是关于VB文件IO遇到了问题!急!全部的内容,包括:VB文件IO遇到了问题!急!、用c++编写ATM程序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9335551.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存