cout << "Testing assignment: ":
Classic copy:
copy = c2:
copy. Report ()
return 0:
// copy constructor
// adds b to bottles
// subtracts b from bottles, if available
1:
-
void Bravo (const Cd & disk)
disk.Report ():
2. 完成练习1,但让两个类使用动态内存分配而不是长度固定的数组来记录字符串。
3. 修改baseDMA-lacksDMA-hasDMA类层次,让3个类都从一个ABC派生而来,然后使用与程序清
单13.10相似的程序对结果进行测试。也就是说,它应使用ABC指针数组,并让用户决定要创建的对象类
型。在类定义中添加virtual View()方法以处理数据显示。
4. Benevolent Order of Programmers 用来维护瓶装葡萄酒箱。为描述它,BOP Portmaster 设置了一个
Port类,其声明如下:
Vinclude <iostream>
using namespace std:
class Port
private:
char * brand:
char style[20]: // i.e .. tawny, ruby, vintage
int bottles:
public:
Port (const char * br = "none", const char * st = "none", int b = 0):
Port (const Port & p);
virtual ~Port (){ delete [] brand: )
Port & operator= (const Port & p):
Port & operator+= (int b):
Port & operator -= (int b):
int BottleCount()const { return bottles: }
virtual void Show()const:
friend ostream & operator << (ostream & os, const Port & p);
show()方法按下面的格式显示信息:
Brand: Gallo
Kind: tawny
Bottles: 20
operator << ()函数按下面的格式显示信息(末尾没有换行符):
Gallo, tawny. 20
PortMaster 完成了Port类的方法定义后派生了VintagePort类,然后被解职–-因为不小心将一瓶45
度Cockburn泼到了正在准备烤肉调料的人身上,VintagePort类如下所示:
class VintagePort: public Port // style necessarily - "vintage"
private:
char * nickname:
int year:
public:
VintagePort ():
VintagePort (const char * br. int b, const char * nn, int y);
VintagePort (const VintagePort & vp):
~VintagePort (){ delete (] nickname: }
VintagePort & operator= (const VintagePort & vp);
void Show() const:
// i.e .. "The Noble" or "Old Velvet", etc.
// vintage year

1910




被折叠的 条评论
为什么被折叠?



