CPA 無料問題集「C++ Institute C++ Certified Associate Programmer」
What is the output of the program if character "1" is supplied as input?
#include <iostream>
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}
#include <iostream>
using namespace std;
int main () {
int c;
cin >> c;
try
{
switch (c)
{
case 1:
throw 20;
case 2:
throw 5.2f;
case 3:
throw 'a';
}
}
catch (int e)
{ cout << "int exception. Exception Nr. " << e; }
catch (float e)
{ cout << "float exception. Exception Nr. " << e; }
catch (...)
{ cout << "An exception occurred."; }
return 0;
}
正解:A
解答を投票する
What happens when you attempt to compile and run the following code?
#include <iostream> #include <string> using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
};
class B : private A {
string name;
public:
void set() {
x = 1;
}
void Print() {
cout << x;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
#include <iostream> #include <string> using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
};
class B : private A {
string name;
public:
void set() {
x = 1;
}
void Print() {
cout << x;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
正解:D
解答を投票する
Which code, inserted at line 18, generates the output "AB"
#include <iostream>
using namespace std;
class A
{
public:
void Print(){ cout<< "A";}
void Print2(){ cout<< "a";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
void Print2(){ cout<< "b";}
};
int main()
{
B ob2;
//insert code here ob2.Print(); }
#include <iostream>
using namespace std;
class A
{
public:
void Print(){ cout<< "A";}
void Print2(){ cout<< "a";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
void Print2(){ cout<< "b";}
};
int main()
{
B ob2;
//insert code here ob2.Print(); }
正解:B
解答を投票する
What is the output of the program?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.setAge();
b->setAge(20);
a.Print();
b->Print();
return 0;
}
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.setAge();
b->setAge(20);
a.Print();
b->Print();
return 0;
}
正解:D
解答を投票する