在选择挂失账号时程序崩溃,不知道怎么解决,感谢解答
#pragma once
#include<iostream>
using namespace std;
#include"user.cpp"
#include<fstream>
#include<conio.h>
#include<string>
#define file "user.txt"
class function {
public:
function() {
}
user* date = new user(1, "zhangsan", "password", 100, 1);
void adduser() {//开户
fstream fs;
int numuser = 0;
fs.open(file, ios::in);
while ( fs>>id && fs >> Name && fs >> password && fs>>Money && fs>>State ){
++numuser;
}
cout << "总人数为" << numuser<<endl;
fs.close();
fs.open(file, ios::app | ios::out);
cout << "你的账号为:" << Id + numuser << endl;
cout << "请输入姓名" << endl;
cin >> Name;
string Password1;
string Password2;
flag:
cout << "请输入长度50以内的密码并按回车键确定" << endl;
//密码输入
char ch;
while ((ch = _getch()) != 13)
{
Password1 += ch;
cout << "*";
}
cout << endl << "请再次输入以确定密码并按回车键确定" << endl;
while ((ch = _getch()) != 13)
{
Password2 += ch;
cout << "*";
}
if (Password2 == Password1) {
cout << "密码正确" << endl;
}
else {
cout << "密码错误" << endl;
system("pause");
Password1 = '\0';
Password2 = '\0';
goto flag;
}
cout << "输入充值的金额" << endl;
cin >> Money;
fs << Id + numuser << " "//账号
<< Name << " " //姓名
<< Password2 << " "//密码
<< Money << " "//余额
<< State << endl;//状态
fs.close();
}
void frozen() {//账号挂失
cout << "请输入需要挂失的账号:" << endl;
int account;
cin >> account;
user u1(1, "zhangsan", "password", 100, 1);
int a = u1.getdata1(account);
cout << a << endl;
system("pause");
if (a == 1) {//存在且正常
getdate();
for (int i = 0; i < 100; i++) {
if (date[i].id == account) {
date[i].State = 0;
break;
}
}
fstream ofs;
int i = 0;
int nume = 0;
ofs.open(file, ios::trunc);
while (ofs >> id && ofs >> Name && ofs >> password && ofs >> Money && ofs >> State) {
ofs << date[i].id << " "//账号
<< date[i].Name << " " //姓名
<< date[i].Password << " "//密码
<< date[i].money << " "//余额
<< date[i].State << endl;//状态
i++;
}
cout << "该账号已冻结成功"<<endl;
system("pause");
ofs.close();
}
else if (a == 2) {
cout << "该用户账号已被冻结" << endl;
system("pause");
}
else if (a == 0) {
cout << "未查找到该用户" << endl;
system("pause");
}
}
void getdate() {//获取用户信息保存到数组
fstream ofs;
int i = 0;
int nume = 0;
ofs.open(file, ios::in);
while (ofs >> id && ofs >> Name && ofs >> password && ofs >> Money && ofs >> State) {
ofs >> date[i].id
>> date[i].Name
>> date[i].Password
>> date[i].money
>> date[i].State;
i++;
}
ofs.close();
}
string Name;
int Id = 10000;
int id;
int Money = 0;
int State = 1;
string password;
~function() {
delete this->date;
this->date = NULL;
}
};
#pragma once
#include<iostream>
using namespace std;
#include<string>
#define file "user.txt"
#include<fstream>
class user {
friend class function;
public:
user( int id, string name, string password, int money,int State) {
this->Name = name;
this->id = id;
this->Password = password;
this->State = State;
}
user** getdata(int account) {//获取文档信息
fstream ofs;
int i = 0;
int nume = 0;
ofs.open(file, ios::in);
while (ofs >> id && ofs >> Name && ofs >> Password && ofs >> money && ofs >> State) {
nume++;//总人数
}
arry[nume];
while (ofs >>id && ofs >> Name && ofs >>Password && ofs >> money && ofs >> State) {
user* User = NULL;
User = new user(id, Name, Password, money, State);
arry[i] = User;
i++;
}
ofs.close();
return arry;
}
int getdata1(int account) {//获取用户信息及状态
fstream ofs;
int i = 0;
int nume = 0;
ofs.open(file, ios::in);
while (ofs >> id && ofs >> Name && ofs >> Password && ofs >> money && ofs >> State) {
if (id == account && State == 1) {//存在且正常
ofs.close();
return 1;
}
else if (id == account && State == 0) {// 存在但冻结
ofs.close();
return 2;
}
}
ofs.close();
cout << "用户不存在" << endl;
return 0;
}
string Name;
int id;
string Password;
int money;
int State;
user* arry[];
~user() {
}
};
#include<iostream>
#pragma once
#include"function.cpp"
#include"user.cpp"
#include<conio.h>
using namespace std;
void showMenu() {
cout << "\t\t\t欢迎使用银行管理系统ATM" << endl;
cout << "***********************************************************"<<endl;
cout << "请选择您的操作:"<<endl;
cout << "0.退出系统 1.开户 2.登录个人账户 3.挂失 4.解挂" << endl;
cout << "***********************************************************" << endl;
cout << "请选择相应菜单项:" << endl;
}
void showMenu1() {
cout << "\t\t\t欢迎使用银行管理系统ATM" << endl;
cout << "***********************************************************" << endl;
cout << "请选择您的操作:" << endl;
cout << "0.退出系统 1.存款 2.取款 3.查询" << endl;
cout << "4. 转 账 5.销户 6.改密 " << endl;
cout << "***********************************************************" << endl;
cout << "请选择相应菜单项:" << endl;
}
void choose() {
int b = 1;
while (b) {
system("cls");
showMenu1();
cin >> b;
switch (b) {
system("cls");
showMenu1();
case 0:cout << "感谢使用" << endl;//0.退出系统
system("pause");
exit(0);
break;
case 1://1.存款
break;
case 2://2.取款
break;
case 3://3.查询
break;
case 4://4.转 账
break;
case 5://5. 销户
break;
case 6://6.改密
break;
default:
cout << "请正确输入" << endl;
system("pause");
break;
}
}
}
int main() {
int a = 1;
function T;
while (a) {
system("cls");
showMenu();
cin >> a;
switch (a) {
showMenu();
case 0:cout << "感谢使用" << endl;//0.退出系统
system("pause");
exit(0);
break;
case 1:T.adduser();//1.开户
break;
case 2:
system("cls");
choose();//2.登录个人账户
break;
case 3:T.frozen();//3.挂失
break;
case 4://4.解挂
break;
default:
cout << "请正确输入" << endl;
system("pause");
break;
}
}
return 0;
}