
CPA別格な問題集をダウンロードして無料で最新の(CPAテスト問題集をゲット2022年01月22日)
CPA問題集は合格保証します合格できるCPA試験問題2022年更新
質問 112
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class BaseClass
{
public:
int *ptr;
BaseClass(int i) { ptr = new int(i); }
~BaseClass() { delete ptr; delete ptr;}
void Print() { cout << *ptr; }
};
void fun(BaseClass x);
int main()
{
BaseClass o(10);
fun(o);
o.Print();
}
void fun(BaseClass x) {
cout << "Hello:";
}
- A. Runtime error.
- B. It prints: Hello:1
- C. It prints: Hello:
- D. It prints: 10
正解: A
解説:
Section: Volume A
質問 113
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
float i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2;
cout << i;
return 0;
}
- A. It prints: 2
- B. It prints: 0
- C. It prints: 1
- D. It prints: 0.5
正解: C
質問 114
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int f(int a, int b);
int main()
{
float b;
b = f(20,10);
cout << b;
return 0;
}
int f(int a, int b)
{
return a/b;
}
- A. It prints: 5
- B. It prints: 0
- C. It prints: 2
- D. It prints: 10
正解: C
質問 115
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
protected:
int y;
public:
int x;
int z;
A() { x=1; y=2; z=3; }
A(int a, int b) : x(a), y(b) { z = x * y;}
void Print() {
cout << z;
}
};
int main () {
A a(2,5);
a.Print();
return 0; }
- A. It prints: 5
- B. It prints: 2
- C. It prints: 10
- D. It prints: 6
正解: C
質問 116
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int x,y;
union t
{
char tab[2];
int i;
};
union t u;
u.tab[0] = 1;
u.tab[1] = 2;
u.i = 0; x = u.tab[0];
y = u.tab[1];
cout << x << "," << y << "," << u.i;
return 0;
}
- A. compilation fails
- B. It prints: 0,0,0
- C. It prints: 1,2,0
- D. None of these
正解: B
質問 117
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
string s;
A(string s) { this->s = s; }
};
class B {
public:
string s;
B (A a) { this->s = a.s; }
void print() { cout<<s; }
};
int main()
{
A a("Hello world");
B b=a;
b.print();
}
- A. It prints: Hello
- B. It prints: Hello world
- C. Compilation error
- D. None of these
正解: B
質問 118
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1[]= {"H" , "t" };
string s;
for (int i=0; i<2; i++) {
s = s1[i];
s.insert(1,"o");
cout << s; } return( 0 ); }
- A. It prints: to
- B. It prints: Hoto
- C. It prints: Ho
- D. It prints: Ht
正解: B
質問 119
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{
First FirstObject;
FirstObject.Print();
Second SecondObject;
SecondObject.Print();
}
- A. It prints: from Firstfrom Second
- B. It prints: from Secondfrom Second
- C. It prints: from First
- D. It prints: from Firstfrom First
正解: A
解説:
Section: Volume A
質問 120
Which code, inserted at line 10, generates the output "2?1"?
#include <iostream>
#include <string>
using namespace std;
class A {
protected:
int y;
public:
int z;
};
//insert code here
public:
void set() {
y = 2;
z = 3;
}
void Print() { cout << y << z; }
};
int main () {
B b;
b.set();
b.z
= ?1; b.Print(); return 0; }
- A. class B : public A {
- B. class B : protected A {
- C. class B {
- D. class B : private A {
正解: A
質問 121
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
float i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2;
cout << i;
return 0;
}
- A. It prints: 2
- B. It prints: 0
- C. It prints: 1
- D. It prints: 0.5
正解: C
解説:
Section: Volume A
質問 122
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int *t;
t = new int[2];
for (int i=0; i<2; i++) {
t[i] = i;
}
cout << t[1];
}
- A. It prints: ?1
- B. It prints: 0
- C. It prints: 1
- D. It prints: 10
正解: C
質問 123
Which code, inserted at line 10, generates the output "2?1"?
#include <iostream>
#include <string>
using namespace std;
class A {
protected:
int y;
public:
int z;
};
//insert code here
public:
void set() {
y = 2;
z = 3;
}
void Print() { cout << y << z; }
};
int main () {
B b;
b.set();
b.z = ?1;
b.Print();
return 0;
}
- A. class B : public A {
- B. class B : protected A {
- C. class B {
- D. class B : private A {
正解: A
質問 124
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int min(int a, int b);
int main()
{
int min(int,int);
int b;
b = min(10,20);
cout << b;
return 0;
}
int min(int a, int b)
{
return(b);
}
- A. It prints: 20
- B. It prints: 2010
- C. It prints: 1020
- D. It prints: 10
正解: A
質問 125
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1[]= {"Hello" , "World" };
for (int i=0; i<2; i++) {
cout << s1[i];
}
return( 0 );
}
- A. It prints: World
- B. It prints: Hello
- C. It prints: HelloWorld
- D. It prints: WorldHello
正解: C
質問 126
Which of the following structures are correct?
1:
struct s1{ int x; char c;
};
2:
struct s2{ float f; struct s2 *s;
};
3:
struct s3{ float f; in i;
}
- A. All of these
- B. 0
- C. 1
- D. 2
正解: B,D
質問 127
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int op(int x, int y);
int main()
{
float *pf;
float f=0.9;
pf=&f;
cout << op(1, *pf);
return 0;
}
int op(int x, int y)
{
return x*y;
}
- A. It prints: ?1
- B. It prints: 0
- C. It prints: 1
- D. It prints: 0.5
正解: B
解説:
Section: Volume A
質問 128
What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const char *s;
char str[] = "Hello ";
s = str;
while(*s) {
cout << *++s;
*s++;
}
return 0;
}
- A. The code will not compile.
- B. It will print:"Hello "
- C. It will print:"el "
- D. It will print garbage value
正解: C
解説:
Section: Volume A
質問 129
What happens when you attempt to compile and run the following code?
#include <iostream> #include <string>
using namespace std;
class A {
protected:
int y;
public:
int x, z;
A() : x(1), y(2), z(0) {}
A(int a, int b) : x(a), y(b) { z = x * y;}
void Print() { cout << z; }
};
class B : public A {
public:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};
int main () {
A b(2,5);
b.Print();
return 0;
}
- A. It prints: 5
- B. It prints: 2
- C. It prints: 10
- D. It prints: 1
正解: C
質問 130
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main(){
int *i;
i = new int;
*i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4;
cout << *i;
return 0;
}
- A. It prints: 0
- B. It prints: 2
- C. It prints: 1
- D. It prints: 0.5
正解: B
質問 131
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int x,y=10;
float f;
f = 5.20;
x=(int) f;
cout << x <<", ";
f=float (y);
cout << f;
return 0;
}
- A. It prints: 5.2, 10
- B. It prints: 5.20, 10.0
- C. It prints: 5, 10
- D. It prints: 5.2, 10.00
正解: C
解説:
Section: Volume A
質問 132
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int x=2, *y, z=3;
y = &z;
cout<<x**y*x***y;
return 0;
}
- A. It prints: 14
- B. Compilation error
- C. It prints: 16
- D. It prints: 36
正解: B
解説:
Section: Volume A
質問 133
What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input?
#include <iostream>
#include <string>
using namespace std;
void f();
int main()
{
f();
return 0;
}
void f()
{
char c;
c = cin.get();
cout << c;
if(c != '\n')
f();
}
- A. It prints: h
- B. It prints: o
- C. It prints: hello
- D. It prints: olleh
正解: C
質問 134
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B {
public:
int x;
B() { x=1;}
};
class C :public A, public B {
public:
int x;
C(int x) {
this->x = x;
- A. It prints: 2
- B. :x = x + 1;
}
void Print() { cout << x << A::x << B::x; }
};
int main () {
C c2(1);
c2.Print(); return 0; } - C. It prints: 111
- D. It prints: 121
- E. It prints: 1
正解: E
質問 135
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << " " << im;}
};
int main(){
complex c1;
double i=2;
c1 = i; c1.print(); return 0; }
- A. It prints: 0 0
- B. It prints: 2 0
- C. It prints: 1 1
- D. It prints: 2 2
正解: D
質問 136
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class B;
class A {
int age;
public:
A () { age=5; };
friend class B;
};
class B {
string name;
public:
B () { name="Bob"; };
void Print(A ob) {
cout << name << ob.age;
}
};
int main () {
A a;
B b;
b.Print(a);
return 0;
}
- A. It prints: 5
- B. It prints: Bob
- C. It prints: Bob5
- D. None of these
正解: C
質問 137
......
C++ Institute CPA 認定試験の出題範囲:
| トピック | 出題範囲 |
|---|---|
| トピック 1 |
|
| トピック 2 |
|
| トピック 3 |
|
| トピック 4 |
|
| トピック 5 |
|
検証済みのCPA問題集で問題と解答で合格保証試験問題集テストエンジン:https://jp.fast2test.com/CPA-premium-file.html