HelloWorld_java_ 2022-03-31 01:21 采纳率: 88.2%
浏览 1168
已结题

引发了异常: 读取访问权限冲突。 **_Pnext** 是 0xFDFDFE05。

在选择挂失账号时程序崩溃,不知道怎么解决,感谢解答


#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;

}
  • 写回答

2条回答 默认 最新

  • 赵4老师 2022-03-31 09:50
    关注

    崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月15日
  • 已采纳回答 4月7日
  • 创建了问题 3月31日

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败