Charpter 12

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值