首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #include <iostream> #include <string> using namespace std; class Y; class X { private: int x;
有以下程序: #include <iostream> #include <string> using namespace std; class Y; class X { private: int x;
admin
2010-03-29
83
问题
有以下程序: #include <iostream> #include <string> using namespace std; class Y; class X { private: int x; char *strx; public: X(int a, char *str) { x=a; strx=new char[strlen(str)+1]; strcpy(strx,str); } void show(Y &ob) ; }; class Y { private: int y; char *stry; public: Y(int b,char *str) { y=b; stry=new char[strlen(str)+1]; strcpy(stry, str); } friend void X: :show(Y &ob) ; }; void X: :show(Y &ob) { cout<<strx<<", "; cout<<ob, stry<<end1; } int main ( ) { X a(10,"X"); Y b (20, "Y"); a. show(B) ; return 0; } 执行后的输出结果是( )。
选项
A、X,Y
B、a,b
C、X,X
D、Y,Y
答案
1
解析
本题考核类的定义和友元函数的应用。
①该程序中,类X的成员函数show()在类Y中说明为友元,因此,在该友元成员 show()中可以访问类Y的私有成员stry。
②成员函数show()的功能就是输出类X的私有成员strx和Y对象ob的私有成员 stry,
③主函数main()中定义了X类的一个对象a和Y类的一个对象b,并且都进行了初始化。然后调用对象a的成员函数show,输出对象a中私有成员strx中的内容和对象b中私有成员stry中的内容,即字符串stringX和stringY。
转载请注明原文地址:https://kaotiyun.com/show/zFjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
数据库技术的根本目标是要解决数据的
下列程序段选项中,使i的运行结果为4的程序段是()。
以下叙述中正确的是
以下叙述中正确的是
fun函数的功能是:通过键盘输入给x所指的整型数组所有元素赋值。在下划线处应填写的是#include<stdio.h>#defineN5Voidfun(intx[N]){intm;for(m=N-l;m>=0;m--)scanf("%d"
由关系R1和:R2得到关系R3的操作是
以下不构成无限循环的语句或语句组是
以下叙述中错误的是
若有以下程序段structst{intn;structst*next;};structsta[3]={5,&a[1],7,&a[2],9,’\0’},*p;p=&a[0];则以下选项中值为6的表达式是
在软件开发中,需求分析阶段产生的主要文档是()。
随机试题
Beautyisacuriousphenomenon,oneofpermeable,shiftingboundaries.Wemaythinkweunderstandit,【C1】______wesenseiteffor
肝细胞分泌胆汁的主要刺激物是
[2011年,第85题]在信号源(uS,RS)和电阻RL之间接入一个理想变压器,如图7.2-33所示,若uS=80sinωtV,RL=10Ω,且此时信号源输出功率最大,那么,变压器的输出电压u2等于()。
以下()不是城市变电所规划选址的要求。
监事会成员不少于3人,由公司职工代表组成,具体比例由公司章程规定。监事的任期每届为3年,监事任期届满,连选可以连任。( )
新增流动资金贷款额度的公式为()。
按题材分类,下列不属于中国画的是()。
Theworkersareracing______timetorepairtheroad.
Althoughdiverse,Africanmusichascertaindistinctivetraits,oneofwhichistheuseofrepetitionasanorganizingprinciple
AlmosteverydaythemediadiscoversanAfricanAmericancommunityfightingsomeformofenvironmentalthreatfromlandfills,g
最新回复
(
0
)