首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class Boat; class Car{ public: Car(int i):weight(i){}
有如下程序: #include<iostream> using namespace std; class Boat; class Car{ public: Car(int i):weight(i){}
admin
2019-06-12
22
问题
有如下程序:
#include<iostream>
using namespace std;
class Boat;
class Car{
public:
Car(int i):weight(i){}
Mend int Total(const Car&c,const Boat&b);//①
private:
int weight;
};
class Boat{
public:
Boat(int i):weight(i){}
Mend 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/LL8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面对对象概念描述正确的是()。
有如下程序:#includeusingnamespacestd;classBase{public:Base(){cout
在C++程序中,如果要求通过函数来实现一种简单的功能,并且要求尽可能加快程序执行速度,则应该选用()。
以下程序段是函数返回a所指数组中最大的值所在的下标值,横线处的语句为()。fun(int*a,intn){inti,j=0,k;k=j;for(i=j;ia[k])______
函数swap(a,n)可完成对a数组从第1个元素到第n个元素两两交换。其中b[0]=1;b[1]=2;swap(b,2)。在运行调用函数中的语句后,b[0]和b[1]的值分别为()。
有以下程序:#includeusingnamespacestd;inta;intfun();intmain(){externinta;intb;
以下程序的正确运行结果是()。#includeimfun(int);voidmain(){inta=2,i;for(i=0;i
有如下程序:#includevoidmain(){charstr[2][5]={“1234”,“5678”},*p[2];imij,s=0;for(i=0;i
在下面函数的横线处填上适当的内容,使该函数能够利用递归方法求解字符串str的长度(不得使用系统提供的字符串处理函数)。intGetLen(char*str){if(___________)return0;
随机试题
BeautyisbigbusinessinChina.Thecountry’scosmeticsmarketisworth$26billionayear,makingitthethird-biggestinthe
新世纪人们医学模式和健康观念的改变是由于
患者吐泻腹痛,烦闷欲绝,头目昏晕,不省人事。治宜首选
女性,35岁。便血并排不尽感半个月就诊,既往有内痔病史,首选的检查方法是
临产观察先露下降程度的标志是
下列关于个人汽车消费贷款的有关规定叙述正确的是()。
泰国第二大城市是()。[2014年云南真题]
“听君一席话,胜读十年书”指的是()。
阅读现代诗歌,要多选些好诗歌,从中接受美的__________,__________自己的情操。填入划横线部分最恰当的一项是()。
利用对话框提示用户输入参数的查询过程称为()。
最新回复
(
0
)