首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> using namespace std; class Monitor{ public: Monitor(char t):type(t){ } void Pr
有如下程序: #include<iostream> using namespace std; class Monitor{ public: Monitor(char t):type(t){ } void Pr
admin
2012-01-20
68
问题
有如下程序:
#include<iostream>
using namespace std;
class Monitor{
public:
Monitor(char t):type(t){ }
void Print( )const
{cout<<"The type of monitor is"<<type< private:
char type;
};
class Computer{
public:
Computer(int i,char C) :______{}
void Print( )const
{eout<<"The computer is"<<id<<endl;mort.Print( );}
private:
int id;
Monitor mon;
};
int main( ){
const Computer myComputer(101,’B’);
myComputer.Print( );
return 0;
}
请将程序补充完整,使程序在运行时输出:
The computer is 101
The type of monitor is B
选项
答案
id(I),mon(C)
解析
带参构造函数的定义格式(在类外部声明)为:
类名::构造函数名([参数表]):数据成员名1(初始值1),数据成员名2(初始值2)……在类中声明为:
构造函数名([参数表]):数据成员名1(初始值1),数据成员名2(初始值2)……
在compute中有两个数据成员,所以在构造函数中应该对这两个数据成员id和mon初始化,初始化mon创建一个对象,参数为构造函数的形参c。
转载请注明原文地址:https://kaotiyun.com/show/dXVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include#includestruetA{inta;eharb[10];doublec;};struetAf(struetAt);main(){struetAa={10
以下定义语句中正确的是()。
有如下程序#include<stdio.h>intconvert(int*data){return(*data)++;}main(){intdata=56;convert(&data);
下面程序段的输出结果是()。#includemain(){floatx=1.236547;printf("%f\n",(int)(x*1000+0.5)/(float)1000);}
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是
有如下程序:#include#defineD(x)4*x+1main(){inti=2,j=4;printf("%d\n",D(i+j));}程序运行后的输出结果是(
以下叙述中正确的是()。
下列说法不正确的是()。
下列叙述中错误的是()。
在数据库系统的组织结构中,下列()映射把用户数据库与概念数据库联系了起来。
随机试题
怎样确定和刃磨刻线刀的几何角度?
下列选项中,引起牙周脓肿最常见的病原菌是
A.麻疹B.风疹C.猩红热D.幼儿急疹E.水痘
下列()的成功标准是项目管理团队能够高效率运转并能对其实现有效的领导。
下列有关现金日记账的格式和登记方法的说法中,正确的有()。
运输企业为用户提供的赔付业务属于运输产品的()。
【B1】【B9】
以债的标的有无选择性为标准,债可以分为()
有以下程序:#include<stdio.h>struetS{intn;inta[20];};voidf(int*a,intn){inti;for(i=0;i<n-1;i++)a[i]+=i;}main(){inti;
Fragmentsofcharredantelopebonehaverecentlybeenfoundatamillion-year-oldsettlementofHomoerectus,anearlyhumanspe
最新回复
(
0
)