网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。 include include

如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。

include<iostream>

include<string>

using namespaee 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"<<shape->getName()<<"\n";

cout<<"Area is"<<shape->area()<<"\n";

return 0

}

请将程序补充完整,使程序在运行时输出:

abject is triangle

Area is 6.3


参考答案

更多 “ 如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。 include include 如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。include<iostream>include<string>using namespaee 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, heightpublic: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"<<shape->getName()<<"\n";cout<<"Area is"<<shape->area()<<"\n";return 0}请将程序补充完整,使程序在运行时输出:abject is triangleArea is 6.3 ” 相关考题
考题 执行如下程序后的输出结果是【】。include include using namespace std;int ma 执行如下程序后的输出结果是【 】。include <iostream>include <fstream>using namespace std;int main ( ){char s[25];ofstream fl("data.txt");f1<<"C++ Programming";f1.close ();ifstream f2 ("data.txt");

考题 有如下程序:include include using namespace std;int main(){cout.fill(' 有如下程序:#include <iostream>#include <iomanip>using namespace std;int main(){cout.fill('*');cout<<left<<setw(4)<<123<< "OK"<<end1;return 0;}执行这个程序的输出结果是( )。A.123*OKB.123*OK**C.*123OKD.*123**OK

考题 如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<<,以便于电话号码的输出。请将程序补充完整。include<iostream>include<iomanip>include<string>using namespace std;class PhoneNumber{public:void setNumber(string number) {this-->number = number;}//重载流插入操作符friend【 】(ostream output,const PhoneNumber num){ output<<num. number; return output; }private:string number;};int main() {PhoneNumber phone;phone. setNumber("8008100598");cout<<"The phone number is:"<<phone<<endl;return 0;}

考题 有如下的程序: include using namespace std; class AT{friend ostream operato 有如下的程序:include<iostream>using namespace std;class AT{friend ostream operator<<(ostream,AT);}at;ostream operator<<(ostream os,AT){return os<<'@';}int main(){cout<<"MyHome"<<at<<"isHere.com";}执行上面的程序将输出

考题 有如下程序:includeincludeusing namespace std;class BASE{char c;public 有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)A.XYB.YXC.XD.Y

考题 有如下程序:include using namespace std;class AA{public: virtual void f() {cout 有如下程序: #include <iostream> using namespace std; class AA { public: virtual void f() { cout<< "AA"; } }; class BB : public AA { public: BB() { cout << "BB"; } }; claA.AAB.AABBCCC.BBAABBCCD.BBBBAACC

考题 有如下程序: include include using namespace std; int ma 有如下程序: #include <iostream> #include <iomanip> using namespace std; int main() { cout.fill('*'); cout << left << setw(4) << 123 << "OK" << endl; return 0; }A.123*OKB.123*OK**C.*123OKD.*123**OK

考题 请在如下程序中的空格处填写正确的语句: include using namespace std; class Base { 请在如下程序中的空格处填写正确的语句:include <iostream>using namespace std;class Base {public:void fun() {cout<<"Base fun"<<endl; }};class Derived: public Base {public:void fun() {【 】; //调用基类的函数fun()cout<<"Derived fun "<<endl;}};

考题 阅读如下程序,输入“3”运行程序,结果为____。 #include <iostream.h> void main() { int i; cin>>i; cout<<i++<<endl; }