//
// main.cpp
// 银行管理系统
//
// Created by 丁小未 on 13-7-23.
// Copyright (c) 2013年 dingxiaowei. All rights reserved.
//
//项目:银行管理系统
//系统实现的主要有管理,取款机管理,用户查询等功能:
//*管理模块:存款、取款、开户、销户、修改信息、办卡、挂失卡;
//*用户查询模块;
//*取款机信息管理模块:管理员管理查询和维护、客户查询和取款等功能;
//可以考虑利率
#include <iostream>
using namespace std;
#include <string>
#include <fstream>
#include <time.h>
#include <vector>
#define MAX 20
class Person
{
public:
string cardNum;//卡号
string cardName;//用户名
double money;//余额
string beginTime;//开户日期
bool useState=false;//是否挂失
/*******用户的功能***********/
//查询我当前用户的账户余额
double SelectMoney()
{
return money;
}
//选择挂失和解锁卡
bool ChooseUseState(bool f)
{
useState = f;
return useState;
}
//取钱
double GetMoney(double m)
{
if (m>money) {
cout<<"您的余额不足!"<<endl;
}
return money -= m;
}
//存钱
double AddMoney(double m)
{
return money += m;
}
//构造函数
Person(string cardnum,string cardname,double money,string begintime,bool usestate)
{
this->cardNum = cardnum;
this->cardName = cardname;
this->money = money;
this->beginTime = begintime;
this->useState = usestate;
}
//默认构造函数
Person(){};
//运算符重载
// Person&person = (const Person &other)
// {
//
// }
};
int total=0;//记录总数
Person person[MAX];//定义一个person数组
double price=0.1;//默认汇率
/*******************函数申明******************************************/
void set_psw();//设置密码
int psw_check();//密码验证
void Show_menu();//显示菜单
int get_managermenu_choice();//接受管理员菜单选择
void PrintPersonTitle();//打印头信息
char* GetTime();//获取系统当前时间
void Show_Iden_menu();//身份选择菜单
int get_Idemenu_choice();//接受身份菜单选择
void inputInfile(Person person[],int n);//将类数组写入文件
void Show_PersonMenu();//显示普通用户功能菜单
void Show_Managermenu();//显示管理员功能菜单
int get_personmenu_choice();//普通用户接受功能菜单
int findPerson(Person *person,int n,string findName);//查找名字返回序列号
bool ISManager(string &name,string &pwd);//验证管理员身份
bool ISPerson(string &name,string &pwd);//验证用户信息
/**********************************************************************/
//查找名字返回序列号
int findPerson(Person *person,int n,string findName)
{
int i;
int m=-1;
for (i=0; i<n; i++) {
if (person[i].cardName == findName) {
m=i;
break;
}
}
return m;//返回person的下标
}
//将类数组写入文件,数组本身就是地址传递
void inputInfile(Person person[],int &n)
{
ofstream onfile;//写入文件类
onfile.open("Person.txt");
for (int i=0; i<n; i++) {
onfile<<person[i].cardNum<<" "<<person[i].cardName<<" "<<person[i].money<<" "<<person[i].beginTime<<" "<<person[i].useState<<"\n"<<endl;
}
onfile.close();
}
//管理员共有继承自普通人
class Manager:public Person
{
public:
//开户
void addPerson(Person person[],int &n)
{
char f='y';
string sTemp;
char *t=GetTime();
ofstream onfile;//写入文件
onfile.open("person.txt");
do {
cout<<"输入卡号:";
cin>>sTemp;
onfile<<sTemp<<" ";
person[n].cardNum = sTemp;
cout<<"请输入用户名:";
cin>>sTemp;
onfile<<sTemp;
onfile<<sTemp<<" ";
person[n].cardName = sTemp;
onfile<<0<<" ";//余额默认是0
person[n].money = 0;
sTemp = t;
onfile<<sTemp<<" ";//开户时间
person[n].beginTime = sTemp;
onfile<<0;//0代表没有挂失,正常使用
person[n].useState = false;
onfile<<"\n";
++n;
cout<<"还要继续开户吗?(y/n)";
cin>>f;
} while (f=='y');
}
//销户
void deletePerson(Person person[],int &n,string delname)
{
int i;
int j=0;
for (i = 0; i<n; i++) {
if (person[i].cardName == delname) {
for (j=i; j<n-1; j++) {
person[j].cardName = person[j+1].cardName;
person[j].cardNum = person[j+1].cardNum;
person[j].money = person[j+1].money;
person[j].beginTime = person[j+1].beginTime;
person[j].useState = person[j+1].useState;
}
n--;
i--;
}
}
//从写入文件
ofstream onfile;//写入文件类
onfile.open("Person.txt");
for (int i=0; i<n; i++) {
onfile<<person[i].cardNum<<" "<<person[i].cardName<<" "<<person[i].money<<" "<<person[i].beginTime<<" "<<person[i].useState<<"\n"<<endl;
}
onfile.close();
}
//修改卡的信息
void alterPerson(string name,Person person[],int &n)
{
int i=findPerson(person,total, name);
if(i<0)
{
cout<<"对不起,没有该账户!"<<endl;
}
else
{
double _money;
string sTemp;
int jj;
cout<<"从新修改账户信息:"<<endl;
cout<<"修改账户号:";
cin>>sTemp;
person[i].cardNum = sTemp;
cout<<"修改账户名:";
cin>>sTemp;
person[i].cardName = sTemp;
cout<<"修改账户余额:";
cin>>_money;
person[i].money = _money;
cout<<"修改挂失/解锁(1.挂失 2.解锁)";
cin>>jj;
if (jj==1) {
person[i].useState = true;
}
else
{
person[i].useState = false;
}
}
//将信息重写入文档
ofstream onfile;//写入文件类
onfile.open("Person.txt");
for (int i=0; i<n; i++) {
onfile<<person[i].cardNum<<" "<<person[i].cardName<<" "<<person[i].money<<" "<<person[i].beginTime<<" "<<person[i].useState<<"\n"<<endl;
}
onfile.close();
}
//选择某用户卡的挂失和解锁
void chooseUseFunction(string name,Person person[],int &n)
{
int i=findPerson(person,total, name);
if(i<0)
{
cout<<"对不起,没有该账户!"<<endl;
}
else
{
int jj;
cout<<"修改挂失/解锁(1.挂失 2.解锁)";
cin>>jj;
if (jj==1) {
person[i].useState = true;
}
else
{
person[i].useState = false;
}
}
//将信息重写入文档
ofstream onfile;//写入文件类
onfile.open("Person.txt");
for (int i=0; i<n; i++) {
onfile<<person[i].cardNum<<" "<<person[i].cardName<<" "<<person[i].money<<" "<<person[i].beginTime<<" "<<person[i].useState<<"\n"<<endl;
}
onfile.close();
}
//用户查询(查询所有的卡信息)
void showAllCard(Person person[],int &n)
{
cout<<"当前有"<<n<<"条记录:"<<endl;
PrintPersonTitle();
for (int i=0; i<n; i++) {
cout<<person[i].cardNum<<" "<<person[i].cardName<<" "<<person[i].money<<" "<<person[i].beginTime<<" "<<person[i].useState<<endl;
}
}
};
/*********************************************************************/
void IdMenu(Manager &manager);//身份菜单响应
void managermenu(Manager &manager);//管理员菜单相应
void personmenu();//用户菜单
/********************函数定义*****************************************/
//获取当前系统时间
char* GetTime()
{
{
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
char *p = asctime(timenow);
return p;
}
}
//身份菜单响应
void IdMenu(Manager &manager)
{
Show_Iden_menu();//菜单显示
switch (get_Idemenu_choice())
{
case 1:
{
//进入管理员身份验证
string n,s;
cout<<"请输入管理员账号:";
cin>>n;
cout<<"请输入管理员密码:";
cin>>s;
if (ISManager(n, s)) {
managermenu(manager);
}
else
{
cout<<"验证错误"<<endl;
}
}
break;
case 2:
//进入客户身份验证
{
string n,s;
cout<<"请输入账户名:";
cin>>n;
cout<<"请输入账户密码:";
cin>>s;
// if (ISManager(n, s)) {
// managermenu(manager);
// }
if (ISPerson(n,s)) {
cout<<"验证用户成功"<<endl;
}
else{
cout<<"验证用户失败";
}
}
break;
default:
cout<<"选择错误"<<endl;
break;
}
}
//验证客户信息
bool ISPerson(string &name,string &pwd)
{
int i=0;
string password="dingxiaowei";
for (i=0; i<total; i++) {
if(person[i].cardName == name&&password==pwd);
{
return true;
break;
}
}
if (i==total) {
return false;
}
}
//验证管理员身份
bool ISManager(string &name,string &pwd)
{
string n,p;
ifstream infile;//读取文件类
infile.open("manager.txt");
if(infile.is_open())
{
infile>>n>>p;
}
else
{
cout<<"打开失败!";
}
if (n==name&&p==pwd)
{
return true;
}
else
{
return false;
}
}
//管理员菜单相应
void managermenu(Manager &manager)
{
bool flag = false;
do
{
Show_Managermenu();//显示菜单
switch (get_managermenu_choice()) {
case 1://增加记录
manager.addPerson(person,total);
break;
case 2://删除记录
{
cout<<"请输入您要销户的名字:";
string name;
cin>>name;
manager.deletePerson(person,total, name);
}
break;
case 3://查询记录
{
cout<<"请输入您要修改的账户名:";
string name;
cin>>name;
manager.alterPerson(name, person, total);
}
break;
case 4://修改记录
{
cout<<"请输入您修改挂失或解锁的账户名:";
string name;
cin>>name;
manager.chooseUseFunction(name,person, total);
}
break;
case 5://查询所有记录
manager.showAllCard(person,total);
break;
case 0:
flag = true;
IdMenu(manager);//返回上一级
break;
default:
printf("*************************\n");
printf(" 欢迎再次使用本系统,谢谢 \n");
printf("*************************\n");
break;
}
}while (flag==false);
}
//打印个体用户头信息
void PrintPersonTitle()
{
cout<<"--------------------------------------------------------\n";
cout<<" 卡号 用户名 余额 开户日期 是否挂失 \n";
cout<<"--------------------------------------------------------\n";
}
//设置密码
void set_psw()
{
ofstream onfile;//写入文件类
string psw_set ,psw_check;
do
{
cout<<"You must set password first!\n";
cin>>psw_set;
cout<<"conform password:";
cin>>psw_check;
if(psw_check == psw_check)
{
cout<<"set password success!\n";
}
else
{
cout<<"error!\n";
}
}
while(psw_check != psw_set);
onfile.open("password.txt",ios::out);
onfile<<psw_set;
onfile.close();
}
//密码验证
int psw_check()
{
ifstream infile;//读取文件类
ofstream onfile;//文件写入类
unsigned int j=1;
string pword;
string password;
infile.open("password.txt",ios::in);
if (!infile.is_open())//如果打开失败,则重新设置密码
{
set_psw();//重新设置密码
}
//取值
infile>>password;
//打开成功验证密码
do {
cout<<"输入密码,你将有三次机会:"<<j<<"/3次机会"<<endl;
cin>>pword;
j++;
} while (password != pword && j<=3);
if (j<=3) {
cout<<"恭喜登陆成功!"<<endl;
return 1;//打开成功
}
else
{
cout<<"你已经输入了三次了,打开文件失败!"<<endl;
return 0;
}
}
//身份选择菜单
void Show_Iden_menu()
{
cout<<">>>>>>>>>>>>>>>>>欢迎您使用银行管理系统<<<<<<<<<<<<<<<<<<<<\n";
cout<<"*******************************************************\n";
cout<<" 1.银行管理员 | 2.普通用户 \n";
cout<<"*******************************************************\n";
}
//显示管理员菜单
void Show_Managermenu()
{
cout<<">>>>>>>>>>>>>>>欢迎您使用银行管理员管理系统<<<<<<<<<<<<<<<<\n";
cout<<"******************************************************\n";
cout<<" 1.开户 | 2.销户 \n";
cout<<" 3.修改卡号信息 | 4.挂失/解锁 \n";
cout<<" 5.查询所有记录 | 0.返回上级 \n";
cout<<"******************************************************\n";
}
//显示普通用户功能菜单
void Show_PersonMenu()
{
cout<<">>>>>>>>>>>>>>欢迎您使用银行客户管理系统<<<<<<<<<<<<<<<<<<<<\n";
cout<<"******************************************************\n";
cout<<" 1.查询余额 | 2.挂失/解锁 \n";
cout<<" 3.存款 | 4.取款 \n";
cout<<" 0.返回上级 | \n";
cout<<"******************************************************\n";
}
//普通用户接受菜单
int get_personmenu_choice()
{
int personmenu_ch;//菜单选项
do {
cout<<"请选择功能:";
cin>>personmenu_ch;
if (personmenu_ch<0||personmenu_ch>4) {
cout<<"输入有误!"<<endl;
}
} while (personmenu_ch<0||personmenu_ch>4);
return personmenu_ch;
}
//接受身份菜单选择
int get_Idemenu_choice()
{
int idmenu_ch;//菜单选项
do {
cout<<"请选择身份:";
cin>>idmenu_ch;
if (idmenu_ch<1||idmenu_ch>2) {
cout<<"输入有误!"<<endl;
}
} while (idmenu_ch<1||idmenu_ch>2);
return idmenu_ch;
}
//接受菜单选择
int get_managermenu_choice()
{
int menu_ch;//菜单选项
do {
cout<<"请选择菜单:";
cin>>menu_ch;
if (menu_ch<0||menu_ch>5) {
cout<<"error";
}
} while (menu_ch<0||menu_ch>5);
return menu_ch;
}
int main(int argc, const char * argv[])
{
Manager manager;
if (psw_check()) {
IdMenu(manager);
}
return 0;
}
==================== 迂者 丁小未 CSDN博客专栏=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
MyTel:13262983383
====================== 相互学习,共同进步 ===================