#include<iostream>
#include<string>
using namespace std;
//12.1 - 12.4
class Person{
public:
Person(const string &nm,const string &ad):
name(nm),address(ad)
{
}
string getName() const
{
return name;
}
string getAddress() const
{
return address;
}
private:
string name;
string address;
};
//12.9
class Screen{
public:
typedef string::size_type index;
Screen(index he,index wi,const string &co):
contents(co),cursor(0),height(he),width(wi)
{
}
private:
string contents;
index cursor;
index height,width;
};
//12.11
class Y;
class X
{
Y *ptr;
};
class Y
{
X obj;
};
//12.20
class Date{
public:
Date(void)
{
}
Date(int syear,int smonth,int sday)
{
year=syear;
month=smonth;
day=sday;
}
private:
int year;
int month;
int day;
};
//12.21
class Melo{
public:
Melo():red("Melo"){}
private:
const string red;
int blue;
double *fish;
};
//12.37
class Account
{
public:
//constructor
Account(string own,double amnt)
{
owner=own;
amount=amnt;
}
//计算余额
void applyint()
{
amount+=amount*interestRate;
}
//返回当前利率
static double rate()
{
return interestRate;
}
//设置利率
static void rate(double newRate)
{
interestRate=newRate;
}
//存款
double deposit(double amnt)
{
amount+=amnt;
return amount;
}
//取款
bool withdraw(double amnt)
{
if(amount<amnt)
{
return false;
}
else
{
amount+=amnt;
return true;
}
}
//查询当前余额
double getBalance()
{
return amount;
}
private:
string owner;
double amount;
static double interestRate;
};
double Account::interestRate=2.5;
//12.38--12.40
class Foo{
public:
Foo(int x)
{
value=x;
}
int get()
{
return value;
}
private:
int value;
};
class Bar{
public:
Foo FooVal()
{
callFooVal++;
return fval;
}
private:
static int ival;
static Foo fval;
static int callFooVal;
};
int Bar::ival=0;
Foo Bar::fval(10);
int Bar::callFooVal=0;
int main()
{
return 0;
}
Charpter 12
最新推荐文章于 2025-04-03 23:26:49 发布
