以下程序的执行结果是 ( )。 #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) {
A.20
B.30
C.900
D.400
第1题:
以下程序的执行结果是______。
include<iostream.h>
class CSample
{
private:
int n;
static int k:
public:
CSample (int i) {n=i;k++;};
voiddisp();
} ;
void CSample::disp()
{
cout <<"n="<<n<<",k="<<k<<endl
}
int CSample:
第2题:
有以下程序 #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; } 执行结果是
A.20
B.30
C.900
D.400
第3题:
有以下程序: #include <iostream> using namespace std; class sample { private: int n; public: sample(){} sample(int m) { n=m; } void addvalue(int m) { sample s; s.n=n+m; *this=s; } void disp () { cout<<"n="<<n<<endl; } }; int main() { sample s (10); s.addvalue(5); s.disp(); return 0; } 程序运行后的输出结果是
A.n=10
B.n=5
C.n=15
D.n=20
第4题:
若有以下程序:
include <iostream>
using namespace std;
class Sample
{
private:
const int n;
public:
Sample(int i) :n(i) {)
void print()
{
cout<<"n="<<n<<end1;
}
};
int main()
{
sample a(10);
a.print();
return 0;
}
上述程序运行后的输出结果是【 】。
第5题:
有以下程序 #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)<<endl; return 0; } 执行结果是
A.20
B.30
C.900
D.400