关闭

test4-8(银行系统支持多用户)求助!!!

294人阅读 评论(0) 收藏 举报

程序:

/*
* Copyright(c)2013,
*All right reserved.
*文件名称:test4-8.cpp
*作    者:徐驰
*完成日期:2013-12-05
*版 本 号:v1.2
*
*输入描述:指令
*问题描述:银行系统支持多用户
*程序输出:服务项目
*问题分析:略
*算法分析:略
*/
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
string account[2]={"001","002"};
string pass_word[2]={"000001","000002"};
double sum[2]={10000,10000};
int check_account();
void work(int acc_num);
void drop_out();
void search(int acc_num);
void withdrawals(int acc_num);
void deposit(int acc_num);
void transfer(int acc_num);
void change_password(int acc_num);  
void main()
{
    cout<<"~~~欢迎存钱~~~"<<endl;
	work(check_account());
}
int check_account()
{
	int pass_num=0,i;
	string acc,pass;  
	do
	{
		cout<<"请输入账号:";
		cin>>acc;
		for(i=0;i<2;i++)
		{
			if(acc==account[i])break;
		}
		if(acc!=account[i])cout<<"查无此账号,请重新输入."<<endl; 
	}
	while(acc!=account[i]);
	while(1)  
    {  
		cout<<"请输入密码:";  
        cin>>pass;  
        if(pass==pass_word[i])break;  
        cout<<"输入错误请重新输入。"<<endl;  
        pass_num++;  
        if(pass_num==3)  
        {  
            cout<<"the system has been destroied... "<<endl;  
            exit(1);  
        }  
    }
	return i;
}
void work(int acc_num)
{
	int num;
	while(1)  
    {  
        cout<<"请输入指令:"<<endl;  
        cout<<"*  1.查询"<<endl;      
        cout<<"*  2.取款"<<endl;      
        cout<<"*  3.存款"<<endl;    
        cout<<"*  4.转账"<<endl;
		cout<<"*  5.修改密码"<<endl;
        cout<<"*  0.退出"<<endl;      
        cout<<"*  请输入(0-4):";  
        cin>>num;  
        switch(num)  
        {  
            case 0:drop_out();break; 
            case 1:search(acc_num);break;  
            case 2:deposit(acc_num);break; 
            case 3:withdrawals(acc_num);break;  
            case 4:transfer(acc_num);break; 
			case 5:change_password(acc_num);break;	
            default :cout<<"try it again~~~"<<endl<<endl;  
        }  
    }
}
void drop_out()
{
	cout<<"欢迎下次存钱~~~"<<endl;exit(1);
}
void search(int acc_num)
{
	cout<<"您的余额为:"<<sum[acc_num]<<endl<<endl;
}
void withdrawals(int acc_num)
{
	double sum1;
	int type,time,level;
	cout<<"请输入金额:";
	cin>>sum1;
	cout<<"请输入类型(0.活期;1.定期):";
	cin>>type;
	sum[acc_num]=sum[acc_num]+sum1;
	if(type)
	{
		cout<<"请输入时间(以月为单位):";
		cin>>time;
		level=(time>=3)+(time>=6)+(time>=12)+(time>=24)+(time>=36)+(time>=60);
		switch(level)
		{
			case 0:cout<<"到期本金:"<<sum[acc_num]<<"利息:"<<sum[acc_num]*time/12.0*0.005;break;
			case 1:cout<<"到期本金:"<<sum[acc_num]<<"利息:"<<sum[acc_num]*time/12.0*0.031;break;
			case 2:cout<<"到期本金:"<<sum[acc_num]<<"利息:"<<sum[acc_num]*time/12.0*0.033;break;
			case 3:cout<<"到期本金:"<<sum[acc_num]<<"利息:"<<sum[acc_num]*time/12.0*0.035;break;
			case 4:cout<<"到期本金:"<<sum[acc_num]<<"利息:"<<sum[acc_num]*time/12.0*0.044;break;
			case 5:cout<<"到期本金:"<<sum[acc_num]<<"利息:"<<sum[acc_num]*time/12.0*0.05;break;
			case 6:cout<<"到期本金:"<<sum[acc_num]<<"利息:"<<sum[acc_num]*time/12.0*0.055;break;
		}
	}
	else
	{
		cout<<"您的余额为:"<<sum[acc_num];
	}
	cout<<endl<<endl;
}
void deposit(int acc_num)
{
	double sum1;
	while(1)
	{
		cout<<"请输入金额:";
		cin>>sum1;
		if(sum1<=sum[acc_num])
		{
			sum[acc_num]=sum[acc_num]-sum1;
			cout<<"余额:"<<sum[acc_num];
			break;
		}
		else
		{
			cout<<"余额不足,请重新输入。";
		}
	}
	cout<<endl<<endl;
}
void transfer(int acc_num)
{
	double sum1;
	int i;
	string acc;
	do
	{
		cout<<"请输入账号:";
		cin>>acc;
		if(acc!=account[acc_num])
		{	
			for(i=0;i<2;i++)
			{
				if(acc==account[i])break;
			}
			if(acc!=account[i])cout<<"查无此账号,请重新输入。"<<endl; 
		}
		else cout<<"您不能给自己转账。"<<endl;
	}
	while(acc!=account[i]||acc==account[acc_num]);
	while(1)	
	{
		cout<<"请输入金额:";
		cin>>sum1;
		if(sum1<=sum[acc_num])
		{
			sum[acc_num]=sum[acc_num]-sum1;
			sum[i]=sum[i]+sum1;
			cout<<"已向"<<account[i]<<"转账"<<sum1<<"元。"<<"余额:"<<sum[acc_num];
			break;
		}
		else
		{
			cout<<"余额不足,请重新输入。";
		}
	}
	cout<<endl<<endl;
}
void change_password(int acc_num)
{
	string pass1,pass2;
	int pass_num;
	while(1)  
    {  
		cout<<"请输入旧密码:";  
        cin>>pass1;  
        if(pass1==pass_word[acc_num])break;  
        cout<<"输入错误请重新输入。"<<endl;  
        pass_num++;  
        if(pass_num==3)  
        {  
            cout<<"the system has been destroied... "<<endl;  
            exit(1);  
        }  
    }
	while(1)  
    {  
		cout<<"请输入新密码:";  
        cin>>pass1;  
        cout<<"请再次输入新密码:";
		cin>>pass1;
		if(pass1==pass2)break; 
        cout<<"输入错误请重新输入。"<<endl;    
    }
	pass_word[acc_num]=pass1;
	cout<<"密码已修改。"<<endl;  
}
结果:

求助:

请问各位大神为什么我的这个程序一给自己转账就会出现应用程序错误。。。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:13702次
    • 积分:582
    • 等级:
    • 排名:千里之外
    • 原创:47篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档