关闭

test4-7(银行系统用组织函数)

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

程序:

/*
* Copyright(c)2013,
*All right reserved.
*文件名称:test4-7.cpp
*作    者:徐驰
*完成日期:2013-12-05
*版 本 号:v1.1
*
*输入描述:指令
*问题描述:银行系统用组织函数
*程序输出:服务项目
*问题分析:略
*算法分析:略
*/
#include<iostream>
#include<cstdlib> 
using namespace std;
void password();
void work();
void drop_out();
void search(double sum);
double withdrawals(double sum);
double deposit(double sum);
double transfer(double sum);  
void main()
{
    cout<<"欢迎存钱~~~"<<endl;
	password();
	work();
}
void password()
{
	int pass_num=0;  
    long pass;
	while(1)  
    {  
        cout<<"请输入密码:";  
        cin>>pass;  
        if(pass==123456)break;  
        cout<<"输入错误请重新输入。"<<endl;  
        pass_num++;  
        if(pass_num==3)  
        {  
            cout<<"the system has been destroied... "<<endl;  
            exit(1);  
        }  
    }
}
void work()
{
	int num;
	double sum=10000;
	while(1)  
    {  
        cout<<"请输入指令:"<<endl;  
        cout<<"*  1.查询"<<endl;      
        cout<<"*  2.取款"<<endl;      
        cout<<"*  3.存款"<<endl;    
        cout<<"*  4.转账"<<endl;    
        cout<<"*  0.退出"<<endl;      
        cout<<"*  请输入(0-4):";  
        cin>>num;  
        switch(num)  
        {  
            case 0:drop_out();break; 
            case 1:search(sum);break;  
            case 2:sum=deposit(sum);break; 
            case 3:sum=withdrawals(sum);break;  
            case 4:sum=transfer(sum);break;  
            default :cout<<"try it again~~~"<<endl<<endl;  
        }  
    }
}
void drop_out()
{
	cout<<"欢迎下次存钱~~~"<<endl;exit(1);
}
void search(double sum)
{
	cout<<"您的余额为:"<<sum<<endl<<endl;
}
double withdrawals(double sum)
{
	double sum1;
	int type,time,level;
	cout<<"请输入金额:";
	cin>>sum1;
	cout<<"请输入类型(0.活期;1.定期):";
	cin>>type;
	sum=sum+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<<"利息:"<<sum*time/12.0*0.005;break;
			case 1:cout<<"到期本金:"<<sum<<"利息:"<<sum*time/12.0*0.031;break;
			case 2:cout<<"到期本金:"<<sum<<"利息:"<<sum*time/12.0*0.033;break;
			case 3:cout<<"到期本金:"<<sum<<"利息:"<<sum*time/12.0*0.035;break;
			case 4:cout<<"到期本金:"<<sum<<"利息:"<<sum*time/12.0*0.044;break;
			case 5:cout<<"到期本金:"<<sum<<"利息:"<<sum*time/12.0*0.05;break;
			case 6:cout<<"到期本金:"<<sum<<"利息:"<<sum*time/12.0*0.055;break;
		}
	}
	else
	{
		cout<<"您的余额为:"<<sum;
	}
	cout<<endl<<endl;
	return sum;
}
double deposit(double sum)
{
	double sum1;
	while(1)
	{
		cout<<"请输入金额:";
		cin>>sum1;
		if(sum1<=sum)
		{
			cout<<"余额:"<<sum-sum1;
			break;
		}
		else
		{
			cout<<"余额不足,请重新输入。";
		}
	}
	cout<<endl<<endl;
	return sum-sum1;
}
double transfer(double sum)
{	
	double sum1;
	while(1)
	{
		cout<<"请输入金额:";
		cin>>sum1;
		if(sum1<=sum)
		{
			cout<<"余额:"<<sum-sum1;
			break;
		}
		else
		{
			cout<<"余额不足,请重新输入。";
		}
	}
	cout<<endl<<endl;
	return sum-sum1;
}
结果:


0
0

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