基类中被说明为______的成员只能被其派生类的成员函数访问,不能被外界函数访问。
查看答案
请将横线处缺失部分补充完整。#include using namespace std;class base{private:int x;public:base(int a){x=a;}int get(){return x;}void showbase() {cout<<"x="<showbase();d.showderived();b.showbase();}输出结果如下:x=3x=6,y=7x=6x=6x=6x=6,y=7x=6
有如下程序:#includeusing namespace std;class Pet{char name[10];public:Pet(char *name){ strcpy(this->name,name);}const char *getName()const{return name;}virtual void call()const=0;};class Dog: public Pet{public:Dog(char *name):Pet(name){}void call()const{ cout<<"汪汪叫";}};class Cat:public Pet{public:Cat(char *name):Pet(name){}void call()const{ cout<<"喵喵叫";}};int main(){Pet *pet1=new Dog("哈克"), *pet2=new Cat("吉米");cout<getName();pet1->call();cout<
如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。#include#includeusing namespace std;class TwoDShape{ //二维图形类.char name[20];public:TwoDShape(char *n="unknown"){strcpy(name,n);}char *getName(){return name;}__________________________=0;};class Rec:public TwoDShape{double width,height;public:Rec(double w=0.0,double h=0.0):TwoDShape("rectangle"){width=w;height=h;}double getWidth(){return width;}double getHeight(){return height;}double area(){return width*height;}};int main(){TwoDShape *shape;shape=new Rec(2.1,3.0);cout<<"object is "<getName()<<"\n",cout<<"Area is "<area()<<"\n";return 0;}请将程序补充完整,使程序在运行时输出:object is triangleArea is 6.3
有如下程序:#includeusing namespace std;class Base{int b;public:Base(int i){b=i;}void disp(){cout<<"Base:b="<