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

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 is the output of the program given below?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout<<i;
}
{
int i=5;
cout << i;
}
cout<<i;
return 0;
}

解説: (JPNTest メンバーにのみ表示されます)
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;
}

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

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

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 First
{
public:
void Print(){ cout<< "from Second";}
};
void fun(First *obj);
int main()
{
First FirstObject;
fun(&FirstObject);
Second SecondObject;
fun(&SecondObject);
}
void fun(First *obj)
{
obj->Print();
}

Which code, inserted at line 19, generates the output "23"?
#include <iostream>
#include <string>
using namespace std;
class A {
int x;
protected:
int y;
public:
int z;
A() { x=1; y=2; z=3; }
};
class B : public A {
string z;
public:
int y;
void set() { y = 4; z = "John"; }
void Print() {
//insert code here
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}

What is the output of the program?
#include <iostream> #include <string>
using namespace std;
struct t { int tab[2];
};
class First
{
struct t u;
public:
First() {
u.tab[0] = 1;
u.tab[1] = 0;
}
void Print(){
cout << u.tab[0] << " " << u.tab[1];
}
};
int main()
{
First t;
t.Print();
}

What happens if you try to compile and run this program?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
print("Test");
return 0;
}
void print(int c[])
{
cout<<c;
}

What is the output of the program?
#include <iostream> #include <string>
using namespace std;
int main()
{
string s1="Wo";
string s2;
s2 = s1;
string s3;
s3 = s2.append("rldHello");
cout << s3;
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 a=0;
fun(a);
return 0;
}
void fun(int n) { if(n < 2) { fun(++n); cout << n; } }

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[0]);
return 0;
}
void fun(char *a)
{
cout << *a;
}

What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main () {
string s1 = "Hello", s2 = "World";
s2 = s1 + s2;
cout << s2;
return 0;
}

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

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

What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class Base {
int age;
public:
class C {
int b;
void PrintC() { cout << b; }
};
Base () {age=5;};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};
int main () {
Base a;
a.setAge(10);
a.Print();
return 0;
}

弊社を連絡する

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

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

サポート:現在連絡