首页/ 题库 / [单选题]以下程序的执行结果是 ( )。 #inc的答案

以下程序的执行结果是 ( )。 #include <iostream> using namespace std; class sample { private: int x; public: sample (int A) { x=a; } friend double square(sample s); }; double square(sample s) {

单选题
2022-01-13 20:21
A、20
B、30
C、900
D、400
查看答案

正确答案
C

试题解析
解析:本题考核友元函数的应用。程序中函数square()是类sample的一个友元函数,它可以直接访问类sample的所有成员。它的功能是返回类sample的私有数据成员x的平方。所以程序的执行结果是:900。注意:友元函数不是类的成员函数,在类外定义时不要加上类名及其作用域运算符(::)。友元函数的调用与一般函数的调用的方式和原理一致,可以在程序的任何地方调用它。

标签:
感兴趣题目
下面程序输出的结果是( )。 #include<iostream> using namespace std; void main() { char ch[][8]={"good","better","best"}; for(int i=1;i<3;++i) { cout<<ch[i]<<endl; } }
有以下程序: #include <iostream> #include <string> using namespace std; int main () { char s[]=" 123\"; cout<<strlen (s) <<", "<<sizeof (s) <<end1; return 0; }
有如下程序: #include <iostream> using namespace std; int main() { int *p; *p = 9; cout << "The value at p: " << *p; return 0; } 编译运行程序将出现的情况是( )。
有如下程序: #include <iostream> using namespace std; int main( ){ int*P; *P=9; cout<<"The value at P:"<<*P: return 0; } 编译运行程序将出现的情况是
有如下程序: #include<iostream> using namespace std; int main() { int *p; *p=9; cout<<"The value at p:"<<*p; return 0; } 编译运行程序将出现的情况是( )
有以下程序: #include 〈iostream〉 using namespace std; #define M 10 #define B4 void setstar(char *a, int n) { int i; for (i=0; i
运行以下的程序代码,结果是( )。 #include<iostream> using namespace std; intmain() { int x=5; int *q=&x; int &y=x; y++; tout<<(*q)++<<end1; return 0; }
有以下程序: #include <iostream> using namespace std; int main() { int x=15; while(x>10&&x<50) { x++; if(x/3) { x++; break; } } cout<<x<<end1; return 0; } 执行后的输出结果是
有以下程序: #include<iostream> using namespace std; int main() { int x=15; while(x>10&&x<50) { x++; if(x/3) { x++;break; } } cout<<x<<endl; return 0; } 执行后的输出结果是( )。
有以下程序: #inclyde<iOStream> using namespace std; int main() { int x=15; while(x>10&&x<50) { x++; if(x/3) { x++;break; } } cout<<x<<endl; return 0; } 执行后的输出结果是
有以下程序: #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base ( ) { strcpy (baseName, "Base"); } virtual char *myName() {
有如下程序: #include<iostream> using namespace std; classA { public: A(){cout<<"A";} }; class B{public:B(){cout<<"B";}}; class C:public A { B b; public: C(){cout<<"C";} }; int main(){C obj;return 0;} 执行后的输出结果是( )
相关题目
下面程序的执行结果为 #include" iostream" using namespace std; class A { int a; public: void Seta(int x) { a=x;} void Display_a( ) { cout < < a < < end1;} }; class B { int b; public: void Setb(int x) { b=x;} void D
下面程序的执行结果为 #includ"iostream" using namespace std; class A { int a; public: void Seta(int x){a=x;} void Display_a(){cout<<a<<endl;} }; class B { int b; public: void Setb(int x){b=x;} void
下面程序的运行结果为( )。 #include <iostream> using namespace std; class A{ public: A(){cout<<" ";} ~A(){cout<<" ";} } class B:public A{ public: B(){cout<<" ";} ~B(){cout<<" ";} } void main(){ B b; }
下面程序的输出结果是( )。 #include<iostream> using namespace std; void main() { int a=18; int * p=&a; cout<<* p;}
下面程序的执行结果为 #includ"iostream" using namespace std; class A { int a; public: void Seta(int x){a=x;} void Display_a(){cout<<a<<endl;} }; class B { int b; public: void Setb(int x){b=x;} void
如下程序的输出结果是 #include<iostream> using namespace std: int main( ){ int sum: for(inti=O;i<6;i+=3){ sunl=i: for(intj=i;j<6;j++)suitL+=j; } cout<<sum<<endl: retuIn 0:
若有以下程序: #include <iostream> using namespace std; class point { private: int x, y; public: point ( ) { x=0; y=0; } void setpoint(int x1,int y1) { x=x1; y=y1;
有如下程序: #include<iostream> using namespace std; class A { public: A(){cout<<"A";} }; class B<public:B(){cout<<"B";)); class C:public A { B b; public: C(){cout<<"C";} }; int main(){Cobj;retum 0;} 执行后的输出结果是
下列程序的输出结果为( )。 #include (iostream) using namespace std; void main( ) char,a[ ] = { "hello" ," the" ," world" }; char * * pa = a: pa + +; cout << * pa << ENDL; }
以下程序的输出结果是( )。 #include<iostream> using namespace std; void fun(char**q) { ++q; cout<<*q<<end1; } main() { static char*s[]={"HI","HELL0","TEST"}; char**p; p=s; fun(p); system("PAUSE"); return 0; }
执行下列程序的结果是( )。 #include<iostream.h> void main() { char *str; str="test!"; cout<<str[5]; }
关于语句#include<iostream>using namespace std;void main(){cout<<100.8989663<<';com<<fixed<<100.8989663<<';cout<<scientific<<100.8989663<<';}的输出结果为( )
以下程序的执行结果是 ( )。 #include <iostream> using namespace std; class sample { private: int x; public: sample (int A) { x=a; } friend double square(sample s); }; double square(sample s) {
有以下程序#include <iostream>using namespace std;class sample{private: int x;public: sample(int a) { x=a; } friend double square(sample s);};double square(sample s){ return s. x*s. x;}int main(){ sample s1(20),s2(30); cout<<square(s2)<<end1; return 0;}执行结果是( )。
有以下程序 #include <iostream> using namespace std; class sample { private: int x; public: sample(int a) { x=a; } friend double square(sample s); }; double square(sample s) { return s.x*s.x; } int main() { sample s1 (20),s2(30); cout<<square(s2)<<end1; return 0; } 执行结果是
下面程序的运行结果为( )。 #include <iostream> using namespace std; class A{ public: A(){cout<<" ";} ~A(){cout<<" ";} } class B:public A{ public: B(){cout<<" ";} ~B(){cout<<" ";} } void main(){ B b; }
设程序如下: #include<iostream> using namespace std; int main() { int **p,*q,r=10; q=&r; p=&q; cout<<**p+1<<end1; return 0; } 以上程序的输出结果是( )
在下列程序的横线处填上适当的内容,使程序执行后的输出结果为ABCD。 #include<iostream> using namespace std; class A { public:A(){cout<<‘A’;} }; Class B: { public:B(){cout<<‘B’;} }; class C:virtual public A { public:C(){cout<<‘C’;} }; class D:p
下面程序的输出结果是( )。 #include <iostream> using namespace std; void main( ) { int i=8,*p=0; p = &i; coat<<p; }
有下列的程序: #include<cstring.h> #include<iostream.h> using namespace std; class MyString { public: MyString(const char*s); ~MyString()<delete[]data;} protected: unsigned len; char*data; };
广告位招租WX:84302438

免费的网站请分享给朋友吧