首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
以下程序运行后的输出结果是______。 #include <iostream> #include <string> using namespace std; class Y;
以下程序运行后的输出结果是______。 #include <iostream> #include <string> using namespace std; class Y;
admin
2010-12-16
23
问题
以下程序运行后的输出结果是______。
#include <iostream>
#include <string>
using namespace std;
class Y;
class X
{
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
{
prlvate:
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<<endl;
}
int main{
{
X a (10, "stringX");
Y b (20, "stringY");
a. show (b);
renurn 0;
}
选项
答案
stringX stringY
解析
本题考核友元函数的应用。该程序中,类X的成员函数show()在类Y中说明为类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/C1Vp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<stdio.h>main(){intt;scanf("%d",&t);if(t++<6)printf("%d、n",t);elseprintf("%d\n",t--);printf("\n");}执行时输
以下选项中不能在C语言程序中用作用户标识符的是()。
已知下列函数定义:fun(int*b,intc,intd){intk;for(k=0;k
在数据库设计中,有三张关于学生选课的数据表,分别是学生信息表Stu(其中包括:学生的学号,姓名,性别,年龄,身份证号),课程信息表Cou(其中包括:课程代号,课程名称),选课信息表SC(其中包括:学生的学号,课程代号,课程成绩),则表SC的关键字(键或码)
将E-R图转换到关系模式时,实体与联系都可以表示成()。
规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:使字符串的前导术号不得多于n个,若多于n个,则删除多余的*号;若少于或等于n个,则不做处理。字符串中间和尾部的*号不删除。例如,字符串中的内容为“*******A木BC*DEF*G*
在一棵二叉树上,第5层的结点数最多是()。
关于计算机软件程序的生命周期,以下叙述正确的是()。
请编写函数fun,其功能是:将一个数字字符串转换为一个整数(不得调用C语言提供的将字符串转换为整数的函数)。例如,若输入字符串“一1234”,则函数把它转换为整数值一1234。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在
若有如下说明,且int类型占两个字节,则正确的叙述为()。structst{inta;intb[2];}a.
随机试题
我国中小学常用的教学原则有()个,分别是:()性原则、()联系()原则、()性原则、()原则、()性原则、(
下列关于现代作家、作品的说法,正确的一项是()。
,临床婴幼儿最常见的贫血类型是
下列可使心输出量增加的情况是
关于口服短效避孕药的不良反应,正确的是( )
下列有关票据记载事项的说法中,正确的是:
输入种用大宗家畜的,应当在国家动植物检疫局设立的动物隔离检疫场所隔离检疫45日;输入其他动物的应当在口岸检疫机关指定的动物检疫隔离场所隔离30日。( )
,2,3,25,()。
中国跨过资本主义发展阶段直接进入社会主义社会后,在社会主义建设问题上,中国人民经过反复实践和探索,又走上了建设中国特色社会主义的成功之路。这一事实说明
党的十八届五中全会提出了全面建成小康社会新的目标。其中:农业现代化取得明显进展,人民生活水平和质量普遍提高,我国()
最新回复
(
0
)