有如下程序: #include <iostream> using namespace std; class sample { private: int x, y; public: sample(int i,int j) { x=i; y=j; } void disp() { cout<<"displ"<<end1; } void disp() const { cout<<"disp2"<<end1; } }; int main () { const sample a(i,2); a.disp (); return 0; } 该程序运行后的输出结果是( )。
A.disp1
B.disp2
C.disp1 disp2
D.程序编译时出错
第1题:
有以下程序 #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
第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)<<endl; return 0; } 执行结果是
A.20
B.30
C.900
D.400
第3题:
第4题:
有以下程序: #include<iostrearn> using namespace std; class sample { private: int x; static int y; public: sample (int A) ; static void print (sample s); }; sample::sample(int A) { x=a; y+=x; }
A.x=10,y=20
B.x=20,y=30
C.x=30,y=20
D.x=30,y=30
第5题:
有以下程序: #include<iostream> using namespace std; Class sample { private: int n; public: sample(){} sample(int m) { n=m; } sample add(sample s1,samplc s2) { this-->n=s1.n+s2.n; return(*this); } void disp(
A.n=10
B.n=5
C.n=20
D.n=15