};
class Computer{ public:
Computer(int i,char c): 【11】{} void Print()const
{cout<<“The computer is”<<id<<endl;mon.Print();} private: int id;
Monitor mon; };
const Computer myComputer(101,'B‘); myComputer .Print(); return 0; }
请将程序补充完整,使程序在运行时输出: The computer is 101
'The type of monitor i.s 8
(12)有如下程序: #include <iostream> using namespace std class Animal{ public:
virtual char* getType()const { return “Animal”;} virtual char* getVoice()const { return “Voice”;} };
Class Dog : public Animal { public:
char* getType ( ) const {return “Dog”;} char* getVoice ( ) const {return “Woof”} };
void type(Animal& a) {cout<<a.getType();} void speak(Animal a) {cout<<a.getVoice();} int main( ) {
Dog d; type (d);cout<<“ speak”;speak(d);cout<<endi; return 0; }
运行时的输出结果是【12】。 (13)补充完整下面的类定义: const double PI=3 .14;
class Circle{ //圆形物体的抽象基类 protected:
double r; //半径 public: