一、编程练习
- 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();
}
- 10_2
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
class Person
{
private:
static const int LIMIT=25;
string lname;
char fname[LIMIT];
public:
Person(){
lname="";fname[0]='\0';}
Person(const string &ln,const char * fn="Heyyou");
void show() const;
void formalshow() const;
};
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:"<<