#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string>
#include<fstream>
#include<bits/stdc++.h>
using namespace std;
typedef struct Banker
{
string account_num;//银行账户
string name;//银行卡持有人姓名
string sex;//银行卡持有人性别
int password;//银行卡密码
long long money;//银行卡金额
int open_time;//开户日期
string states;//开户状态
Banker* next;
}*BankList;
//函数
void InitList();//初始化菜单
bool account_num_exist();//判断账户是否存在
void SelectAccount();//查询账户信息
void Open_an_ccount();//开户
void Pin_households();//销户
void Modify_account_password();//修改账户密码
void Sort_accountInfo();//账户排序
void deposit();//存款
void withdrawals();//取款
void transfer();//转账
double cal_year();//计算开户时长
void Calculation_interest();//利息计算
void save();//保存账户的信息
void ReadFile();//读入文件
void Menu();//主菜单
void Choice_a_file();//选择待操作的文件
//初始化菜单
void InitList(BankList& BL)
{
BL = new Banker;
BL->next = NULL;
}
//判断账户是否存在
bool account_num_exist(BankList& BL, string account_num)
{
Banker* p = BL->next;
while (p)
{
if (p->account_num == account_num)
return true;
p = p->next;
}
return false;
}
//1、查询账户信息
void SelectAccount(BankList& BL)
{
cout << "1:按账号查找:"<<endl;
cout << "2:按开户人姓名查找:"<<endl;
cout << "3:按开户日期查找:"<<endl;
string account_num;//账户
string name;//姓名
int open_time;//开户日期
int ch;
Banker* p = BL->next;
cin >> ch;
switch (ch)
{
case 1:
{
cout << "请输入需要查询的账号:";
cin >> account_num;
while (p)
{
if (p->account_num == account_num)
{
cout << "账户\t\t姓名\t性别\t密码\t金额\t\t开户日期\t开户状态" << endl;
cout << p->account_num << "\t" << p->name << "\t" << p->sex << "\t" << p->password
<< "\t" << p->money << "\t\t" << p->open_time << "\t" << p->states << endl;
return;
}
p = p->next;
}
}
break;
case 2:
{
cout << "请输入需要查询的开户人姓名:";
cin >> name;
while (p)
{
if (p->name == name)
{
cout << "账户\t\t姓名\t性别\t密码\t金额\t\t开户日期\t开户状态" << endl;
cout << p->account_num << "\t" << p->name << "\t" << p->sex << "\t" << p->password
<< "\t" << p->money << "\t\t" << p->open_time << "\t" << p->states << endl;
return;
}
p = p->next;
}
}
break;
case 3:
{
cout << "请输入需要查询的开户日期:";
cin >> open_time;
while (p)
{
if (p->open_time == open_time)
{
cout << "账户\t\t姓名\t性别\t密码\t金额\t\t开户日期\t开户状态" << endl;
cout << p->account_num << "\t" << p->name << "\t" << p->sex << "\t" << p->password
<< "\t" << p->money << "\t\t" << p->open_time << "\t" << p->states << endl;
return;
}p = p->next;
}
}
break;
default:
cout << "输入有误!" << endl;
break;
}
cout << "未查找到!" << endl;
}
//2、开户
void Open_an_ccount(BankList& BL)
{
Banker* p = new Banker;
p->next = NULL;
cout << "请输入需要开户的账户:";
cin >> p->account_num;
if (account_num_exist(BL, p->account_num))
{
cout << "开户失败,账户已存在" << endl;
return;
}
cout << "请输入需要开户的姓名:";
cin >> p->name;
cout << "请输入需要开户的性别(男,女):";
cin >> p->sex;
cout << "请输入需要开户的密码(6位):";
cin >> p->password;
cout << "请输入需要开户的金额:";
cin >> p->money;
cout << "请输入需要开户的开户日期(如:20150602):";
cin >> p->open_time;
cout << "请输入需要开户的开户状态(活期,定期):";
cin >> p->states;
Banker* pp = BL;
while (pp->next)
{
pp = pp->next;
}
pp->next = p;
cout << "开户成功!" << endl;
}
//3、销户
void Pin_households(BankList& BL)
{
string account_num;//账户
int password;//密码
Banker* p = BL;
cout << "请输入需要销户的账户:";
cin >> account_num;
if (account_num_exist(BL, account_num))
{
cout << "请输入需要销户的密码:";
cin >> password;
while (p->next != NULL)
{
if (p->next->account_num == account_num && p->next->password == password)
{
cout << "销户成功!" << endl;
Banker* pt = p->next;
p->next = pt->next;
delete pt;
return;
}
p = p->next;
}
cout << "输入的密码有误!" << endl;
}
else
{
cout << "此账户不存在!" << endl;
}
}
//4、修改账户密码
void Modify_account_password(BankList& BL)
{
string account_num;//账户
int password;//密码
Banker* p = BL->next;
cout << "请输入需要修改的账户:";
cin >> account_num;
if (account_num_exist(BL, account_num))
{
cout << "请输入需要修改的账户密码:";
cin >> password;
while (p != NULL)
{
if (p->account_num == account_num && p->password == password)
{
cout << "请输入新的密码:";
cin >> p->password;
cout << "修改成功!" << endl;
return;
}
p = p->next;
}
cout << "密码错误!" << endl;
}
else
{
cout << "此账户不存在!" << endl;
}
}
//5、账户排序
void Sort_accountInfo(BankList& BL)
{
int ch;
cout << "1:按账号排序" << endl;
cout << "2:按开户人姓名排序" << endl;
cout << "3:按金额排序" << endl;
cout << "4:按开户日期排序" << endl;
cout << "请输入选择的排序编号:" << endl;
cin >> ch;
Banker* p1 = BL->next;
switch (ch)
{
case 1:
{
for (; p1->next != NULL; p1 = p1->next)
{
for (Banker* p2 = p1->next; p2 != NULL; p2 = p2->next)
{
if (p1->account_num > p2->account_num)//升序排列
{
Banker* p11 = p1->next;
Banker* p22 = p2->next;
Banker t = *p1;
*p1 = *p2;
*p2 = t;
p1->next = p11;
p2->next = p22;
}
}
}
cout << "排序成功!" << endl;
}
break;
case 2:
{
for (; p1->next != NULL; p1 = p1->next)
{
for (Banker* p2 = p1->next; p2 != NULL; p2 = p2->next)
{
if (p1->name > p2->name)//升序排列
{
Banker* p11 = p1->next;
Banker* p22 = p2->next;
Banker t = *p1;
*p1 = *p2;
*p2 = t;
p1->next = p11;
p2->next = p22;
}
}
}
cout << "排序成功!" << endl;
}
break;
case 3:
{
for (; p1->next != NULL; p1 = p1->next)
{
for (Banker* p2 = p1->next; p2 != NULL; p2 = p2->next)
{
if (p1->money > p2->money)//升序排列
{
Banker* p11 = p1->next;
Banker* p22 = p2->next;
Banker t = *p1;
*p1 = *p2;
*p2 = t;
p1->next = p11;
p2->next = p22;
}
}
}
cout << "排序成功!" << endl;
}
break;
case 4:
{
for (; p1->next != NULL; p1 = p1->next)
{
for (Banker* p2 = p1->next; p2 != NULL; p2 = p2->next)
{
if (p1->open_time > p2->open_time)//升序排列
{
Banker* p11 = p1->next;
Banker* p22 = p2->next;
Banker t = *p1;
*p1 = *p2;
*p2 = t;
p1->next = p11;
p2->next = p22;
}
}
}
cout << "排序成功!" << endl;
}
break;
default:
cout << "您的输入有误!" << endl;
}
}
//6、存款
void deposit(BankList& BL)
{
string account_num;//账户
int password;//密码
Banker* p = BL->next;
cout << "请输入需要存款的账户:";
cin >> account_num;
if (account_num_exist(BL, account_num))
{
cout << "请输入需要存款的账户密码:";
cin >> password;
while (p != NULL)
{
if (p->account_num == account_num && p->password == password)
{
cout << "请输入存款金额:";
long long m;
cin >> m;
p->money += m;
cout << "存款成功!" << endl;
return;
}
p = p->next;
}
cout << "密码错误!" << endl;
}
else
{
cout << "此账户不存在!" << endl;
}
}
//7、取款
void withdrawals(BankList& BL)
{
string account_num;//账户
int password;//密码
Banker* p = BL->next;
cout << "请输入需要取款的账户:";
cin >> account_num;
if (account_num_exist(BL, account_num))
{
cout << "请输入需要取款的账户密码:";
cin >> password;
while (p != NULL)
{
if (p->account_num == account_num && p->password == password)
{
cout << "请输入您的取款金额:";
long long m;
cin >> m;
if (p->money >= m)
{
p->money -= m;
cout << "取款成功!" << endl;
cout << "当前账户信息如下:" << endl;
cout << "账户\t\t姓名\t性别\t密码\t金额\t开户日期\t开户状态" << endl;
cout << p->account_num << "\t" << p->name << "\t" << p->sex << "\t" << p->password
<< "\t" << p->money << "\t" << p->open_time << "\t" << p->states << endl;
return;
}
else
{
cout << "余额不足!" << endl;
return;
}
}
p = p->next;
}
cout << "密码错误!" << endl;
}
else
{
cout << "此账户不存在!" << endl;
}
}
void ReadFile(BankList&, string);
void save(BankList& BL, string file);
//8、转账
void transfer(BankList& BL)
{
Banker* p1 = BL->next;
BankList bk;
InitList(bk);
string bank1,bank2,account_num;//银行名,账户
int password;//密码
cout << "请输入转账方所在银行:";
cin >> bank1;
bank1 += ".txt";
cout << "请输入收款方所在银行:";
cin >> bank2;
bank2 += ".txt";
ReadFile(bk, bank2);
Banker* p2 = bk->next;
cout << "请输入转账方账户:";
cin >> account_num;
if (account_num_exist(BL, account_num))
{
cout << "请输入密码:";
cin >> password;
while (p1 != NULL)
{
if (p1->account_num == account_num && p1->password == password)
{
cout << "请输入收款方账户:";
cin >> account_num;
while (p2)
{
if (p2->account_num == account_num)
{
long long m;
cout << "请输入转账金额:";
cin >> m;
if (bank1 == bank2)
{
if (p1->money >= m)
{
p1->money -= m;
p2->money += m;
cout << "转账成功!" << endl;
cout << "当前账户信息如下:" << endl;
cout << "账户\t\t姓名\t性别\t密码\t金额\t开户日期\t开户状态" << endl;
cout << p1->account_num << "\t" << p1->name << "\t" << p1->sex
<< "\t" << p1->password
<< "\t" << p1->money << "\t" << p1->open_time << "\t"
<< p1->states << endl;
save(bk, bank2);
return;
}
else
{
cout << "余额不足!" << endl;
return;
}
}
else
{
cout << "收取手续费:" << m * 0.01 << " 元!" << endl;
if (p1->money >= m + m * 0.01)
{
p1->money -= m;
p2->money += m;
cout << "转账成功!" << endl;
cout << "当前账户信息如下:" << endl;
cout << "账户\t\t姓名\t性别\t密码\t金额\t开户日期\t开户状态" << endl;
cout << p1->account_num << "\t" << p1->name << "\t" << p1->sex
<< "\t" << p1->password
<< "\t" << p1->money << "\t" << p1->open_time << "\t"
<< p1->states << endl;
save(bk, bank2);
return;
}
else
{
cout << "余额不足!" << endl;
return;
}
}
}
p2 = p2->next;
}
cout << "账户不存在" << endl;
}
p1 = p1->next;
}
cout << "密码错误!" << endl;
}
else
{
cout << "账户不存在!" << endl;
}
}
double cal_year(int a, int b)
{
int year1 = a / 10000;
int year2 = b / 10000;
int month1 = a / 100 % 100;
int month2 = b / 100 % 100;
int day1 = a % 100;
int day2 = b % 100;
double year = 0;
if (year1 == year2)
year = 0.5;
else if (month2 == month1 && day1 == day2)
{
year = year2 - year1;
}
else if (month2<month1 || month2 == month1 && day1>day2)
{
year = year2 - year1 - 0.5;
}
else if (month2 > month1 || month2 == month1 && day1 < day2)
{
year = year2 - year1 + 0.5;
}
return year;
}
//9、计算利息
void Calculation_interest(BankList& BL)
{
string account_num;//账户
int password;//密码
Banker* p = BL->next;
cout << "请输入账户:";
cin >> account_num;
if (account_num_exist(BL, account_num))
{
cout << "请输入密码:";
cin >> password;
while (p != NULL)
{
if (p->account_num == account_num && p->password == password)
{
cout << "请输入存款到期时间:";
int end_time;
double rate = 0;
cin >> end_time;
double year = cal_year(p->open_time, end_time);
int year2 = year;
if (p->states == "活期")
{
for (int i = 1; i <= year2; i++)
{
rate += (rate + p->money) * 0.0035;
}
if (year > year2 + 0.1)
rate += (rate + p->money) * 0.0035 * 0.5;
}
else if (p->states == "定期")
{
for (int i = 1; i <= year; i++)
{
if (i == 1)
{
rate += (rate + p->money) * 0.0275;
}
else if (i == 2)
{
rate += (rate + p->money) * 0.0335;
}
else if (i >= 3)
{
rate += (rate + p->money) * 0.04;
}
}
int year2 = year;
if (fabs(year - 0.5) <= 1e-6)
rate += (rate + p->money) * 0.0275 * 0.5;
else if (fabs(year - 1.5) <= 1e-6)
rate += (rate + p->money) * 0.0335 * 0.5;
else if (fabs(year - 2.5) <= 1e-6)
rate += (rate + p->money) * 0.04 * 0.5;
}
cout << "您获得的利息为:" << rate << endl;
return;
}
p = p->next;
}
cout << "密码错误!" << endl;
}
else
{
cout << "账户不存在!" << endl;
}
}
//10、保存账户信息
void save(BankList& BL, string file)
{
ofstream ofs;
ofs.open(file.c_str());
Banker* p = BL->next;
while (p)
{
ofs << p->account_num << "\t" << p->name << "\t" << p->sex << "\t" << p->password
<< "\t" << p->money << "\t" << p->open_time << "\t" << p->states << endl;
p = p->next;
}
ofs.close();
cout << "保存成功!" << endl;
}
void ReadFile(BankList& BL, string file)
{
ifstream ifs;
Banker* p = BL;
ifs.open(file.c_str());
if (!ifs)
return;
while (!ifs.eof())
{
Banker* pt = new Banker;
pt->next = NULL;
ifs >> pt->account_num >> pt->name >> pt->sex >> pt->password
>> pt->money >> pt->open_time >> pt->states;
if (ifs.eof())
break;
p->next = pt;
p = pt;
}
ifs.close();
}
void Menu()//菜单界面
{
system("cls");
system("color F0");
cout << "******************************" << endl;
cout << "* 银行账户管理系统 *" << endl;
cout << "******************************" << endl;
cout << "*1、查询账户信息 *" << endl;
cout << "*2、开户 *" << endl;
cout << "*3、销户 *" << endl;
cout << "*4、修改账户密码 *" << endl;
cout << "*5、账户排序 *" << endl;
cout << "*6、存款 *" << endl;
cout << "*7、取款 *" << endl;
cout << "*8、转账 *" << endl;
cout << "*9、计算利息 *" << endl;
cout << "*10、保存账户信息 *" << endl;
cout << "*0、退出系统 *" << endl;
cout << "******************************" << endl;
}
//选择需要操作的文件
void Choice_a_file(BankList& BL,string &FileName)
{
int ch;
system("color F0");
cout << "1:a.txt" << endl;
cout << "2:b.txt" << endl;
cout << "3:c.txt" << endl;
cout << "4:d.txt" << endl;
cout << "5:e.txt" << endl;
cout << "0:退出" << endl;
while (1)
{
cout << "请选择需要操作的文件:" << endl;
cin >> ch;
if (ch == 1)
{
FileName = "a.txt";
ReadFile(BL, "a.txt");
break;
}
else if (ch == 2)
{
FileName = "b.txt";
ReadFile(BL, "b.txt");
break;
}
else if (ch == 3)
{
FileName = "c.txt";
ReadFile(BL, "c.txt");
break;
}
else if (ch == 4)
{
FileName = "d.txt";
ReadFile(BL, "d.txt");
break;
}
else if (ch == 5)
{
FileName = "e.txt";
ReadFile(BL, "e.txt");
break;
}
else if (ch == 0)
{
exit(0);
}
else
{
cout << "您的输入有误!" << endl;
}
}
}
int main()
{
BankList BL;
InitList(BL);
int choice;
string FileName;
Choice_a_file(BL,FileName);//选择待操作文件
while (1)
{
//菜单调用
Menu();
cout << "请选择您要进行的操作" << endl;
cin >> choice;
switch (choice)
{
case 1: //1、查询账户信息
SelectAccount(BL);
break;
case 2: //2、开户
Open_an_ccount(BL);
break;
case 3: //3、销户
Pin_households(BL);
break;
case 4: //4、修改账户密码
Modify_account_password(BL);
break;
case 5: //5、账户排序
Sort_accountInfo(BL);
break;
case 6: //6、存款
deposit(BL);
break;
case 7: //7、取款
withdrawals(BL);
break;
case 8: //8、转账
transfer(BL);
break;
case 9: //9、计算利息
Calculation_interest(BL);
break;
case 10: //10、保存账户信息
save(BL, FileName);
break;
case 0: //0、退出系统
cout << "欢迎下次使用" << endl;
system("pause");
return 0;
break;
default:
break;
}
system("pause");
}
return 0;
}
这是?项目吗?