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

Point out an error in the program.
#include <iostream>
using namespace std;
int main()
{
const int x=1;
int const *y=&x;
cout<<*y;
return 0;
}

Which code, inserted at line 5, generates the output "ABC"?
#include <iostream>
using namespace std;
class A {
public:
//insert code here
};
class B:public A {
public:
void Print(){ cout<< "B"; }
};
class C:public B {
public:
void Print(){ cout<< "C"; }
};
int main()
{
A ob1;
B ob2;
C ob3;
A *obj;
obj = &ob1;
obj->Print();
obj = &ob2;
obj->Print();
obj = &ob3;
obj->Print();
}

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

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

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int compare(int, int);
int main()
{
int x = compare(10, 20);
cout << x;
return 0;
}
int compare(int i, int j)
{
return i<j;
}

If there is one, point out an error in the program
#include <iostream>
using namespace std;
int main()
{
int i=1;
for(;;)
{
cout<<i++;
if(i>5)
break;
}
return 0;
}

What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this->s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o->Print();
}

What happens when you attempt to compile and run the following code?
#include <cstdlib>
#include <iostream>
using namespace std;
float* sum(float a,float b);
float* sum(float a,float b)
{
float *f = new float;
*f = a+b;
return f;
}
int main()
{
float a,b,*f;
a = 1.5; b = 3.4;
f = sum(a,b);
cout<<*f;
return 0;
}

What happens if characters 'w', 'o', 'r', 'l' and 'd' are entered as input?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1 = "Hello";
string s2;
getline( cin, s2 );
cout << s1 + s2;
return( 0 );
}

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

What will be the output of the program?
#include <iostream>
using namespace std;
int main()
{
int i=0;
for(; i<=5; i++)
cout << i;
return 0;
}

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;
A *obj;
obj = &ob1;
obj->Print();
obj = &ob2;
obj->Print();
obj = &ob3;
obj->Print();
}

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int x=5;
static int y;
int i=0;
void static myFunction()
{
y=x++ + ++i;
}
int main (int argc, const char * argv[])
{
x++;
myFunction();
cout<<y<<" "<<x<< " " << i;
}

What is the output of the program?
#include <iostream>
using namespace std;
#define PRINT(i) cout<<i;
int main()
{
int y=2, z=3;
PRINT(y);
PRINT(z);
return 0;
}

Point out an error in the program.
#include <iostream>
using namespace std;
int main()
{
char s1[] = "Hello";
char s2[] = "world";
char *const ptr = s1;
*ptr = 'a';
ptr = s2;
return 0;
}

正解:B、C 解答を投票する
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int *a= new int;
*a=100;
cout << *a;
delete a;
}

What is the output of the program?
#include <iostream>
using namespace std;
#define SQR(x)(x*x)
int main(int argc, char *argv[]) {
int x, y=2;
x = SQR(y);
cout << x << ", " <<y;
return 0;
}

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";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1; obj->Print(); B ob2; obj = &ob2; obj->Print(); }

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main(){
int i = 1;
for(i=10; i>-1; i/=2) {
if(!i)
break;
}
cout << i;
return 0;
}

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

弊社を連絡する

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

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

サポート:現在連絡