首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #inc1ude<iostream> using namespace std; class Boat; class Car{ public: Car(int i):weight(i){}
有如下程序: #inc1ude<iostream> using namespace std; class Boat; class Car{ public: Car(int i):weight(i){}
admin
2020-07-30
43
问题
有如下程序:
#inc1ude<iostream>
using namespace std;
class Boat;
class Car{
public:
Car(int i):weight(i){}
friend int Total(const Car&c,const Boat&b); //①
private:
int weight;
};
class Boat{
public:
Boat(int i):weight(i){}
friend int Total(const Car &c,const Boat &b);
private:
int weight;
};
int Total(const Car&c,const Boat &b){ //②
return c.weight+b.weight;
}
int main(){
Car c(10),
Boat b(8);
cout<<"The total weight is "<<Total(c,b)<<endl;//③
return 0:
}
下列关于程序的描述中,正确的是( )。
选项
A、程序编译正确
B、程序编译时语句①出错
C、程序编译时语句②出错
D、程序编译时语句③出错
答案
A
解析
程序中定义了类Car和类Boat,在两个类中分别定义他们的构造函数和友元函数friend。程序在VC6.0中编译通过。
转载请注明原文地址:https://kaotiyun.com/show/3Xyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下类定义:classPa{intk;public:Pa():k(0){//①Pa(intn):k(11){}//②Pa(Pa&p):k(p.k){}//③
有如下程序:#includeusingnamespacestd;classXX{protected:intk:public:XX(intn=5):k(n){};
下列叙述中,不属于设计准则的是()。
下列有关C++流的叙述中,错误的是()。
在类中重载赋值运算符时,应将其声明为类的()。
有如下函数定义:voidfunc(inta,int&b){a++;b++;)若执行代码段:intx=0,y=1;func(x,y);则变量X和y的值分别是()。
当派生类继承一个基类时,默认的继承方式为()。
数据流图用于抽象描述一个软件的逻辑模型,数据流图由一些特定的图符构成。下面图符名标识的图符不属于数据流图合法图符的是()。
软件按功能可以分为应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是()。
下列给定程序中函数fun的功能是:根据整型形参m,计算如下公式的值:例如,若m的值为5,则应输出1.463611。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序
随机试题
痄腮主要病变的经脉是
硫脲类抗甲状腺药物的不良反应不包括
下列基坑工程中,可判定为一级基坑的有()。
非织造(无纺、针刺)土工布的功能主要有()。
在社会主义初级阶段,公有制经济包括()。
下列关于税务机关行使税务检查权的表述中,符合税法规定的有()。(2009年新制度)
Itisanastonishingfactthattherearelawsofnature,rulesthatsummarizeconveniently(1)_____qualitativelybutquantitati
ObesityCausesGlobalWarmingThelistofillsattributabletoobesitykeepsgrowing:Eastweek,obesepeoplewereaccusedo
A、Takeabus.B、Onfoot.C、Takeataxi.D、Takethesubway.D地铁可以直达,而乘坐公交车需要换乘,出租车也不经过博物馆的,因此推知女士最有可能选择乘坐地铁。故D为本题答案。
A、Theuseofhands.B、Differentwaysofexpressingpoliteness.C、Customsofancienttimes.D、Themeaningofthehandanditsact
最新回复
(
0
)