数据结构和程序设计真题
obj1.f();
A obj2(15);
obj2.f();
obj1.f();
return 0;
}
}
a=10
b=10
a=15
b=25
a=10
b=25
6.#include<iostream>
Using namespace std
ClassA{
Private:Leabharlann int a;public:
A(){ cout<<”A`s default constactour called.\n”;};
return 0;
}
2.#include<iostream>
Using namespace std
main(){
int a=1,b=2,c=3,d=4,y=10;
switch(y){
case1:a++;break;
default:d=1;
case2:b++;break;//d=1,b=3
case4:c++;break;
A(int i) {a= i; cout<<”A`s constractour called.\n”};
Void print(){ cout<<a<<’’,’’;}
~A() { cout<<”A`s destractor called.\n”}
Int Geta{ return a;}
}
Class B{
}
Cout <<a<<b<<c<<d<<endl;//1331
Return 0;
}
3.#include<iostream>
Using namespace std
Main(){
Int i=0,sum=0;
for(;;){
i+=2;
if(i>10){ cout <<”sum=”<<sum; break;}
Class A{
private:
int a;
static int b;
public:
A(int i){a=i;b+=i;}
Void f();
void A::f(){
cout <<”a=”<<a<<endl;
cout <<”b=”<<b<<endl;
}
Private A::b=0;
Main(){
A obj1(10);//
}
}
if(i==8) continue;
sum+=I;//0+2+4+6+10=22
}
Return 0;
}
4.#include<iostream>
Using namespace std;
Int &f1(int &a);
Int f2 (int b );
Main(){
Int x=10;
Inty=f1(x);
Void print();
Private:
Int b;
A aa;
}
Void B::print(){
A::print();
Cout <<b<<aa.Geta()<<endl;
}
Main(){
B bb[2] = {B(10,15,20),B(1,2,3)};
For(int i=0;i<2;i++){
bb[i].print();
Public:
A
B(){ cout<<”B`s default constactour called.\n”};
B(int i, int j, int k ){ A(i),aa(j)cout <<”B`s constractor called.\n”;}
~B(){ cout <<”B’s destractor called.\n”}
Int z=f2(x);
cout <<x<<endl//20
cout <<y<<endl;//20
cout <<z<<endl;//40
return 0;
}
Int &f1(int &a){
a+=a;
}
Int f2(int b){
b+=b;
}
}
#include<iostream>
Using namespace std
程序设计部分
读程序,写结果
1.#include<iostream>
Using namespace std
Main(){
int i=2,j=4,m,n;
m = ++i + j++;//i=3 j=5 m=3+4=7
n = (++i)+(++j)+m;//i=4,j=6,n=4+6+7=17
cout <<i<<j<<m<<n;//46717