用c++编写银行账户管理系统

发布网友 发布时间:2022-04-27 00:12

我来回答

1个回答

热心网友 时间:2022-06-21 05:21

4个头文件[cpp] #include "LinkList.h" class Bank { private: LinkList * list; int account_number; public: Bank(); ~Bank(); void set_list(LinkList *list); LinkList *get_list(); LinkList *make_list(); Record *make_record(string userName,string passWord,double balance); int creat_number(); int get_number(); string get_userName(); string get_passWord(); double get_balance(); Record *find_record(int number); void open_acount(); void close_acount();//销户 void find_acount(); void deposit();//存款 void withdraw();//取款 }; [html] #include "Node.h" class LinkList { private: Node *head; int len; public: LinkList(); ~LinkList(); void set_head(Node *head); Node *get_head();//获得头节点 int get_len(); Node *make_node(Record *record);//制作一个节点,目的是插入record void insert_node(Node *node);//插入一个节点 Node *find_node(int number);//找到一个节点,通过账户(number)查找 void display_LinkList(); };
[html] #include "Record.h" class Node { private: Record *record; Node *next; public: Node(); ~Node(); void set_record(Record *record); void set_next(Node *next); Record *get_record(); Node *get_next(); void display_Node(); };
[cpp] #include <iostream> #include <string> using namespace std; class Record { private: int number; double salary; string userName; string passWord; int flag; public: Record(); void set_number(int number); void set_salary(double salary); void set_userName(string userName); void set_passWord(string passWord); void set_flag(int flag); int get_number(); double get_salary(); string get_userName(); string get_passWord(); int get_flag(); void display(); };
4个资源文件文件[cpp] #include "bank.h" #include <iostream> using namespace std; Bank::Bank() { this->list=this->make_list(); this->account_number = 10000; } Bank::~Bank() { delete this->list;//自动调用~LinkList() this->list=NULL; } void Bank::set_list(LinkList *list) { this->list=list; } LinkList *Bank::get_list() { return this->list; } LinkList *Bank::make_list() { return new LinkList(); } Record *Bank::make_record(std::string userName, std::string passWord, double balance) { Record * r = new Record(); int number = this->creat_number(); r->set_number(number); r->set_userName(userName); r->set_passWord(passWord); r->set_salary(balance); r->set_flag(1); return r; } int Bank::creat_number() { return this->account_number = this->account_number+1; } int Bank::get_number() { int number; cout<<"请输入账号....."<<endl; cin>>number; cout<<"账号:"<<number<<endl; return number; } string Bank::get_userName() { string userName; cout<<"请输入用户名....."<<endl; cin>>userName; cout<<"用户名:"<<userName<<endl; return userName; } string Bank::get_passWord() { string paseWord; cout<<"请输入密码....."<<endl; cin>>paseWord; // cout<<"paseWord:"<<paseWord<<endl; return paseWord; } double Bank::get_balance() { double balance; cout<<"请输入金额....."<<endl; cin>>balance; cout<<"金额:"<<balance<<endl; return balance; } Record *Bank::find_record(int number) { Node *n=this->list->find_node(number); if(n != NULL) { return n->get_record(); } return NULL; } void Bank::open_acount() { //1获取账户输入的信息 string userName=this->get_userName(); string passWord=this->get_passWord(); double balance = this->get_balance(); //2 使用输入数据创建record 记录 Record *r = this->make_record(userName,passWord,balance); //3 创建node节点,封装record记录 Node *n=this->list->make_node(r); //4将node节点插入到linkliast this->list->insert_node(n); cout<<"您的账号是"<<this->account_number<<endl; } void Bank::close_acount() { int i=3; int flag; // 1 获取账户信息 int number = this->get_number(); string passWord = this->get_passWord(); // 2 在链表中找到账节点,找到账户信息 Node *node=this->list->find_node(number); if(node == NULL) { cout<<"账户不存在"<<endl; return ; } Record *record =node ->get_record(); // 3 密码验证 for(i=3;i>=1;i--) { if(record->get_passWord() == passWord) // 4 用户状态改变 { do { cout<<"确定要销户?(0 销户,1 不销户)"<<endl; cin>>flag; if(flag == 1) { record->set_flag(flag); return ; } else if(flag == 0) { record->set_flag(flag); record->set_salary(0); return ; } else { cout<<"输入错误,请重新输入"<<endl; } } while(1); cout<<"还有"<<i<<"次机会"<<endl; } } } void Bank::deposit() { int balance=0; //1 获取账户账号以及密码 int number = this->get_number(); string passWord = this->get_passWord(); //2 从链表中找到账户信息 Node *node=this->list->find_node(number); if(node == NULL) { cout<<"账户不存在"<<endl; return ; } Record *record =node ->get_record(); //3 密码验证,存款 if(record->get_passWord() == passWord) { double balance=this->get_balance()+record->get_salary(); record->set_salary(balance); cout<<"存款成功"<<endl; return ; } } void Bank::withdraw() { int balance=0; //1 获取账户账号以及密码 int number = this->get_number(); string passWord = this->get_passWord(); //2 从链表中找到账户信息 Node *node=this->list->find_node(number); if(node == NULL) { cout<<"账户不存在"<<endl; return ; } Record *record =node ->get_record(); //3 密码验证,取款 if(record->get_passWord() == passWord) { double balance=record->get_salary()-this->get_balance(); if(balance>=0) { record->set_salary(balance); cout<<"取款成功"<<endl; return ; } else { cout<<"您的余额不足"<<endl; return ; } } } void Bank::find_acount() { int number = this->get_number(); string passWord = this->get_passWord();
return 0; }追问谢谢啦哈,好心人!!!
对了,问一下哈,您能不能给用Word文档给整理一下,看起来有点乱诶....
好心人,帮帮忙,整理好给发有邮箱里呗...邮箱jiangbaoliang123@163.com,
在此,发自内心的感谢!!!

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com