首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: using namespace std; class Boat; class Car{ public: Car(int i):weight(i){} friend int Total(const Car &c,const Boat&b);//
有如下程序: using namespace std; class Boat; class Car{ public: Car(int i):weight(i){} friend int Total(const Car &c,const Boat&b);//
admin
2018-12-04
91
问题
有如下程序:
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/rrAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序完成从文件读取文件显示的同时写入第二个文件,则在程序中划线部分应该出现的语句是______。#include<iostream.h>#include(fstream.h)voidmain(){fstreamfi
下列关于构造函数和析构函数的描述,错误的是()。
有以下类定义classMyClass{private:intid;Chargender;Char*phone;public:MyClass():id(0),gender(‘#’),pho
下列是软件调试技术的是()。
设有基类定义:classCbase{private:inta;protected:intb;public:intc;};派生类采用何种继承方式可以使成员变量b成为自己的私有
下面程序的结果为______。#include<iostream.h>voidmain(){int3=1,b=2;boolc=1;if(a>b)||c)cout<<“true”<<endl;else
下列选项中不属于结构化程序设计方法的是()。
以下使用不当会破坏面向程序设计特性的是
下述关于数据库系统的叙述中正确的是
有关析构函数的说法中错误的是
随机试题
某家电企业是一家拥有300多亿资产的巨型企业,在目前产品多样化和高科技化的市场需求面前,你认为该企业最适宜的组织结构形式是()
婴幼儿易发生尿路感染的解剖特点不包括哪一项
地籍按功能可分为()。
经济法是调整()的法。
某票据的出票日期为“2015年2月15日”,其规范写法是()。
对于一个批处理系统,大部分是内部处理过程,这时用原型方法是一个理想选择。
鲜花∶塑料花
恐怖症是指病人持续地和非理性地害怕某一特定物体、活动或情境,这种恐惧相对于实际的威胁来说是夸大的和非理性的。根据上述定义,下列不属于恐怖症的是()。
在不兑现的货币制度下,本(位)币一定是()。[重庆大学2016研]
MigrantWorkersInthepasttwentyyears,therehasbeenanincreasingtendencyforworkerstomovefromonecountrytoanot
最新回复
(
0
)