What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class Test {
float i,j;
};
class Add {
public:
int x,y;
Add (int a=3, int b=3) { x=a; y=b; }
int result() { return x+y;}
};
int main () {
Test test;
Add * padd;
padd = &test;
cout << padd?>result();
return 0;
}
A. It prints: 9
B. Compilation error
C. It prints: 6
D. It prints: 33
正解:B
質問 2:
Which of the following expressions decrement variable i by 2? (Choose two.)
A. --i; i--;
B. i &= 0x03;
C. --i--;
D. i -= 2;
正解:A,D
質問 3:
Which of the following statements are true? (Choose two.)
A. Class A's friend's friend is also a friend of class A
B. A class may be a friend of many classes
C. A class may have many friends
D. Friendship is inherited
正解:B,C
質問 4:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class BaseC
{
int *ptr;
public:
BaseC() { ptr = new int(10);}
BaseC(int i) { ptr = new int(i); }
~BaseC() { delete ptr; }
void Print() { cout << *ptr; }
};
int main()
{
BaseC *o = new BaseC(5);
o?>Print();
}
A. It prints: 0
B. It prints: 5
C. It prints: 1
D. It prints: 10
正解:B
質問 5:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A {
public:
void Print(){ cout<<"A";}
};
class B:public A {
public:
virtual void Print(){ cout<< "B";}
};
class C:public B {
public:
void Print(){ cout<< "C";}
};
int main()
{
A ob1;
B ob2;
C ob3;
B *obj;
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}
A. It prints: BC
B. It prints: AA
C. It prints: AB
D. It prints: BB
正解:A
質問 6:
Which of the following is a logical operator?
A. !
B. ||
C. &&
D. &
正解:A,B,C
質問 7:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(1),im(0.4) {}
bool operator==(complex &t);
};
bool complex::operator == (complex &t){
if((this?>re == t.re) && (this?>im == t.im))
return true;
else
return false;
}
int main(){
complex c1,c2;
if (c1==c2)
cout << "OK";
else {
cout << "ERROR";
}
}
A. Compilation error
B. It prints: OK
C. It prints: ERROR
D. Runtime error.
正解:B
質問 8:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void fun(char*);
int main()
{
char t[4]={'0', '1', '2', '3'};
fun(&t[2]);
return 0;
}
void fun(char *a)
{
cout << *a;
}
A. It prints: 2
B. It prints: 02
C. It prints: 21
D. It prints: 00
正解:A
Komesu -
先日、御社のC++ Institute CPA-21-02問題集を購入させていただきました。
受験して、合格の結果を取りました。
本当に高い質がある対応資料です。感謝します。