CPA-21-02 試験問題 41
次のコードをコンパイルして実行しようとするとどうなりますか?
#include <iostream>
#include <文字列>
名前空間 std を使用します。
クラス 2 番目。
クラスベース{
年齢;
公共:
Base () { 年齢 = 5; };
友人 void set(Base &ob, Second &so);
void Print() { cout << age;}
};
クラス 2 番目 {
文字列名;
公共:
友人 void set(Base &ob, Second &so);
void Print() { cout << name;}
};
void set(Base &ob, Second &so) {
年齢 = 0; so.name = "ビル";
}
int main () {
基数 a;
2番目のb;
セット(a,b);
a.Print();
b.Print();
0を返します。
}
#include <iostream>
#include <文字列>
名前空間 std を使用します。
クラス 2 番目。
クラスベース{
年齢;
公共:
Base () { 年齢 = 5; };
友人 void set(Base &ob, Second &so);
void Print() { cout << age;}
};
クラス 2 番目 {
文字列名;
公共:
友人 void set(Base &ob, Second &so);
void Print() { cout << name;}
};
void set(Base &ob, Second &so) {
年齢 = 0; so.name = "ビル";
}
int main () {
基数 a;
2番目のb;
セット(a,b);
a.Print();
b.Print();
0を返します。
}
CPA-21-02 試験問題 42
次のコードをコンパイルして実行しようとするとどうなりますか?
#include <iostream>
名前空間 std を使用します。
int main()
{
const char *s;
char str[] = "こんにちは";
s = 文字列;
while(*s) {
cout << *s++;
}
0を返します。
}
#include <iostream>
名前空間 std を使用します。
int main()
{
const char *s;
char str[] = "こんにちは";
s = 文字列;
while(*s) {
cout << *s++;
}
0を返します。
}
CPA-21-02 試験問題 43
次のコードをコンパイルして実行しようとするとどうなりますか?
#include <iostream>
#include <文字列>
名前空間 std を使用します。
クラスA {
保護されています:
int y;
公共:
int x,z;
A() : x(1)、y(2)、z(0) { z = x + y; }
A(int a, int b) : x(a), y(b) { z = x + y;}
void Print() { cout << z; }
};
クラス B : パブリック A {
公共:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};
int main () {
A b;
b.Print();
0を返します。
}
#include <iostream>
#include <文字列>
名前空間 std を使用します。
クラスA {
保護されています:
int y;
公共:
int x,z;
A() : x(1)、y(2)、z(0) { z = x + y; }
A(int a, int b) : x(a), y(b) { z = x + y;}
void Print() { cout << z; }
};
クラス B : パブリック A {
公共:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};
int main () {
A b;
b.Print();
0を返します。
}
CPA-21-02 試験問題 44
次のコードをコンパイルして実行しようとするとどうなりますか?
#include <iostream>
#include <文字列>
名前空間 std を使用します。
構造体 {
文字列名;
年齢;
};
クラスファースト
{
人 *人;
公共:
First() {人 = 新しい人;
人?>名前 = "ジョン";
人?> 年齢 = 30;
}
void Print(){
cout<<人?>名前<< " "<<人?>年齢;
}
};
int main()
{
最初の t[2];
for (int i=0; i<2; i++)
t[i].Print();
}
#include <iostream>
#include <文字列>
名前空間 std を使用します。
構造体 {
文字列名;
年齢;
};
クラスファースト
{
人 *人;
公共:
First() {人 = 新しい人;
人?>名前 = "ジョン";
人?> 年齢 = 30;
}
void Print(){
cout<<人?>名前<< " "<<人?>年齢;
}
};
int main()
{
最初の t[2];
for (int i=0; i<2; i++)
t[i].Print();
}
CPA-21-02 試験問題 45
プログラムの間違いを指摘してください。
#include <iostream>
名前空間 std を使用します。
int main()
{
const int x=1;
int const *y=&x;
cout<<*y;
0を返します。
}
#include <iostream>
名前空間 std を使用します。
int main()
{
const int x=1;
int const *y=&x;
cout<<*y;
0を返します。
}
