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 #include 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 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<<"请输入账号....."<>number; cout<<"账号:"<>userName; cout<<"用户名:"<>paseWord; // cout<<"paseWord:"<>balance; cout<<"金额:"<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<<"您的账号是"<account_number<get_number(); string passWord = this->get_passWord(); // 2 在链表中找到账节点,找到账户信息 Node *node=this->list->find_node(number); if(node == NULL) { cout<<"账户不存在"<get_record(); // 3 密码验证 for(i=3;i>=1;i--) { if(record->get_passWord() == passWord) // 4 用户状态改变 { do { cout<<"确定要销户?(0 销户,1 不销户)"<>flag; if(flag == 1) { record->set_flag(flag); return ; } else if(flag == 0) { record->set_flag(flag); record->set_salary(0); return ; } else { cout<<"输入错误,请重新输入"<get_number(); string passWord = this->get_passWord(); //2 从链表中找到账户信息 Node *node=this->list->find_node(number); if(node == NULL) { cout<<"账户不存在"<get_record(); //3 密码验证,存款 if(record->get_passWord() == passWord) { double balance=this->get_balance()+record->get_salary(); record->set_salary(balance); cout<<"存款成功"<get_number(); string passWord = this->get_passWord(); //2 从链表中找到账户信息 Node *node=this->list->find_node(number); if(node == NULL) { cout<<"账户不存在"<get_record(); //3 密码验证,取款 if(record->get_passWord() == passWord) { double balance=record->get_salary()-this->get_balance(); if(balance>=0) { record->set_salary(balance); cout<<"取款成功"<get_number(); string passWord = this->get_passWord();
return 0; }