C++学习-Day-21

C++学习-Day-21

一、编程练习

  1. 10_1
#include<iostream>
#include<string>
using namespace std;
class Bankaccount
{
   
private:
    string name;
    string account;
    double crash;
public:
    Bankaccount(){
   };
    Bankaccount(string name,string account,double crash);
    void show() const;
    void input(double cra);
    void get(double cra);
};
Bankaccount::Bankaccount(string name,string account,double crash)
{
   
    this->name=name;
    this->account=account;
    this->crash=crash;
}
void Bankaccount::show() const
{
   
    cout<<"Name: "<<name<<endl
        <<"Account: "<<account<<endl
        <<"Crash::"<<crash;
}
void Bankaccount::input(double cra)
{
   
    this->crash+=cra;
}
void Bankaccount::get(double cra)
{
   
    this->crash-=cra;
}
int main()
{
   
    cout<<"initial information\n";
    Bankaccount ccb;
    ccb.show();
    cout<<"\ncreate a  new account\n";
    Bankaccount icbc("jam","ic",115345.54);
    icbc.show();
    cout<<"\ninput 10000\n";
    icbc.input(10000);
    icbc.show();
    cout<<"\nget 5000\n";
    icbc.get(5000);
    icbc.show();
}

  1. 10_2
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
class Person
{
   
private:
    static const int LIMIT=25;
    string lname;//last name
    char fname[LIMIT];//first name
public:
    Person(){
   lname="";fname[0]='\0';}
    Person(const string &ln,const char * fn="Heyyou");
    //the following methods display lname and fname
    void show() const;//firstname, lastname format
    void formalshow() const;//lastname, firstname format
};
Person::Person(const string &ln,const char * fn)
{
   
    this->lname=ln;
    strcpy(this->fname,fn);
}
void Person::show() const
{
   
    cout<<"First name: "<<fname<<endl
        <<"Last name:"<<lname;
}
void Person::formalshow() const
{
   
    cout<<"Last name: "<<lname<<endl
        <<"First name:"<<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值