题目内容 (请给出正确答案)
[主观题]

若有以下程序: include <iostream> using namespace std; class sample { int x; public: sample

若有以下程序:

include <iostream>

using namespace std;

class sample

{

int x;

public:

sample(){}

void setx(int i)

{

x=i;

}

friend iht fun(sample B[],int n)

{

int m=0;

for{int i=0;i<n;i++)

if(B[i].x>m)

m=B[i].x;

return.m;

}

};

int main ()

{

sample A[10];

int arr[]={90,87,42,78,97,84,60,55,78,65};

for(int i=O;i<10;i++)

A[i].setx(arr[i]);

cout<<fun(A, 10)<<end1;

return 0;

}

该程序运行后的输出结果是【 】。

查看答案
如搜索结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能会需要:
您的账号:
发送账号密码至手机
发送
更多“若有以下程序: include <iostream> usi…”相关的问题

第1题

在类中定义和实现的函数可以称为【】。

在类中定义和实现的函数可以称为【 】。

点击查看答案

第2题

使用VC6打开考生文件夹下的工程test7_1,此工程包含一个源程序文件test7_1.cpp,但该程序运行有问

题,请改正程序中的错误,使程序的输出结果如下:

Constructor1

Constructor1

Constructor1

Destructor

Constructor2

Destructor

x=0

x=5

Destructor

Destructor

源程序文件test1_1.cpp清单如下:

include<iostream.h>

class B

{

int X;

public:

B(){X=0;cout<<"Constructorl"<<endl;}

B(int i){x=i;cout<<"Constructor2"<<endl;}

~B(){cout<<"Destructor"<<endl;}

/**********found*********/

~B(int i){cout<<i<<"be Destructor"<<endl;}

void print(){cout<<"x="<<x<<endl;}

};

void main()

{

B *ptr;

ptr=new B[2];

/**********found*********/

ptr[0]=B(0);

ptr[1]=B(5);

/**********found********/

for(int i=0; i<2;)

ptr[i].print();

delete []ptr;

}

点击查看答案

第3题

使用VC6打开考生文件夹下的工程test42_3。此工程包含—个test42_3.cpp,其中定义了类Cpolygon、COutp

ut和CTriangle,其中CTriangle类由Cpolygon和COutput类public派生,但三个类的定义并不完整。请按要求完成下列操作,将程序补充完整。

(1)定义类CPolygon的保护数据成员width和height,它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。

(2)完成类CPolygon的成员函数set_values(int a,int b),使参数a和b分别赋值给保护数据成员width和height,请在注释“//**2**”之后添加适当的语句。

(3)完成类Coutput的成员函数output(int)的定义,将传入的参数为血型的i输出到屏幕并换行,请在注释“//**3**”之后添加适当的语句。

(4)完成派生类CTriangle的声明,它由Cpolygon和COutput类public派生,请在注释“//**4**”之后添加适当的语句。

源程序文件test42_3.cpp清单如下:

include <iostream.h>

class CPolygon

{

protected:

// ** 1 **

public:

void set_values(int a, int b)

{

// ** 2 **

}

};

class COutput

{

public:

void output(int i);

};

void COutput::output(int i)

{

// ** 3 **

}

// ** 4 **

{

public:

int area (void)

{

return (width * height / 2);

}

}

int main ()

{

CTriangle trgl;

trgl.set_values (4,5);

trgl.output (trgl.area());

return 0;

}

点击查看答案

第4题

若有以下程序段: include <iostream> using namespace std; int main() {char*p="abcdefgh",*r;l

若有以下程序段:

include <iostream>

using namespace std;

int main()

{

char*p="abcdefgh",*r;

long*q;

q=(long*)p;q++;

r=(char*)q;

cout<<r<<end1;

return 0;

}

该程序的输出结果是【 】。

点击查看答案

第5题

下面程序的预设功能是:统计文件abc.txt中的字符个数。 include <iostream.h> include <fstream.h>

下面程序的预设功能是:统计文件abc.txt中的字符个数。

include <iostream.h>

include <fstream.h>

include <stdlib.h>

void main()

{

fstream file;

file.open( "abc.txt", ios::in);

if ( !file )

{

cout<<"Can not open abc.txt"<<end1;

abort();

}

char ch;

int i = O;

while (______________)

{

file.get(ch);

i++;

}

cout<<"Characters : "<<i<<end1;

file.close();

}

则程序中空白处应该填入的语句是【 】。

点击查看答案

第6题

基类的【】不能被派生类的成员访问,基类的【】在派生类中的性质和继承的性质一样,而基类的【】在私有继

基类的【 】不能被派生类的成员访问,基类的【 】在派生类中的性质和继承的性质一样,而基类的【 】在私有继承时在派生类中成为私有成员,在公有和私有保护继承时在派生类中仍为保护成员。

点击查看答案

第7题

以下程序执行后输出的结果是【】。 include<iostream> include<fstream> using namespace std; int

以下程序执行后输出的结果是【 】。

include<iostream>

include<fstream>

using namespace std;

int main(){

ofstream ofile("D:\\temp.txt");

if(!ofile){

cout<<"temp.txt cannot open"<<endl;

return 0;

}

ofile<<"This is a book" <<" " <<54321<<endl;

ofile.close();

ifstream ifile("D:\\temp.txt");

if(!ifile){

cout<<"temp.txt cannot open" <<endl;

return 0;

}

charstr[40];

ifile >> str;

ifile.close();

cout<<Str<<endl;

return 1;

}

点击查看答案

第8题

在C++中,设置虚基类的目的是【】。

在C++中,设置虚基类的目的是【 】。

点击查看答案

第9题

假定一个二维数组的定义为“int a[3][5];”,则该数组所含元素的个数为【】,所占字节存储空间的字节数

假定一个二维数组的定义为“int a[3][5];”,则该数组所含元素的个数为【 】,所占字节存储空间的字节数为【 】。

点击查看答案

第10题

表达式float(25)/4int(14.4)%5的值分别为【】和【】。

表达式float(25)/4 int(14.4)%5的值分别为【 】和【 】。

点击查看答案
热门考试 全部 >
相关试卷 全部 >
账号:
你好,尊敬的上学吧用户
发送账号至手机
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
谢谢您的反馈

您认为本题答案有误,我们将认真、仔细核查,
如果您知道正确答案,欢迎您来纠错

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
上学吧
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反上学吧购买须知被冻结。您可在“上学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
上学吧
点击打开微信