CPA-21-02 無料問題集「C++ Institute CPA - C++ Certified Associate Programmer」

What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class complex{
double re, im;
public:
complex() : re(1),im(0.3) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
complex operator+(complex &t);
void Print() { cout << re << " " << im; }
};
complex complex::operator+ (complex &t){
complex temp;
temp.re = this?>re + t.re;
temp.im = this?>im + t.im;
return temp;
}
int main(){
complex c1(1),c2(2),c3;
c3 = c1 + c2;
c3.Print();
}

What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
class First
{
string name;
public:
First() {
name = "Alan";
}
void Print(){
cout << name;
}
};
int main()
{
First ob1,*ob2;
ob2 = new First();
ob1.Print();
ob2?>Print();
}

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;
}

What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int fun(int);
int main()
{
int *x = new int;
*x=10;
cout << fun(*x);
return 0;
}
int fun(int i)
{
return i*i;
}

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#define DEF_A 0
#define DEF_B DEF_A+1
#define DEF_C DEF_B+1
int main(int argc, char *argv[]) {
cout << DEF_C;
return 0;
}

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 tab[5]={1,2,3};
for (int i=0; i<5; i++)
cout <<tab[i];
return 0;
}

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:";
}

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B : public A {
public:
B() { x=1;}
};
class C : private B {
public:
C() { x=2;}
};
int main () {
C c1;
cout << c1.x;
return 0;
}

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 );
}

Which of the following is a correct way to define the function fun() in the program below?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int a[2][2];
fun(a);
return 0;
}

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";
}
}

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int i = 5;
do {
i??;
cout<<i;
}
while(i >= 0);
return 0;
}

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void fun(int*);
int main()
{
int *x;
int i=2;
x=&i;
fun(x);
cout<<i;
return 0;
}
void fun(int *i)
{
*i = *i * *i;
}

What will be the output of the program?
#include <iostream>
using namespace std;
int main()
{
const int y = 5;
const x = ?10;
cout<<x<<" "<<y;
return 0;
}

弊社を連絡する

我々は12時間以内ですべてのお問い合わせを答えます。

オンラインサポート時間:( UTC+9 ) 9:00-24:00
月曜日から土曜日まで

サポート:現在連絡