您的位置:首页 > 教育 > 培训 > C++编程逻辑讲解step by step:存折和信用卡类。

C++编程逻辑讲解step by step:存折和信用卡类。

2024/10/6 17:22:04 来源:https://blog.csdn.net/workflower/article/details/139987182  浏览:    关键词:C++编程逻辑讲解step by step:存折和信用卡类。

题目

存折和信用卡类,信用卡是一种存折,可以透支,可以存款。

代码

#include<iostream>
#include<string>
using namespace std;
class passbook
{public:
passbook(string nam,int n,float m)
{name=nam;
num=n;
balance=m;
}
void get_value()
{cin>>name>>num>>balance;}
void display()
{cout<<name<<" "<<num<<" "<<"余额:"<<balance<<" ";}
void deposit();
void withdraw();
protected:string name;int num;float balance;};void passbook::deposit(){float sav;cout<<"存入金额:";cin>>sav;balance=balance+sav;}void passbook::withdraw(){float withdraw;int i;cout<<"取款金额:";for(i=0;i<2;i++){cin>>withdraw;if(balance-withdraw<0){cout<<"余额不足,重新输入"<<endl;continue;}else{balance=balance-withdraw;}}}class credit:public passbook{public:credit(string nam,int n,float m,float a):passbook(nam,n,m){arrears=a;}void show(){display();cout<<"透支:"<<arrears<<endl;}void out(){float sd;
cout<<"取款金额:";cin>>sd;if(arrears+balance-sd<0){arrears=arrears+balance-sd;balance=0;}else{balance=balance-sd;}}private:float arrears;};int main(){credit studl("小陈",3423132,1000,0);studl.show();studl.deposit();studl.show();studl.out();studl.show();passbook stul2("马云",43842238,100);stul2.display();stul2.deposit();stul2.display();stul2.withdraw();stul2.display();return 0;}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com