What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int x,y=10;
float f;
f = 5.90;
cout << f << ", ";
x=f;
cout << x <<", ";
f=y;
cout << f;
return 0;
}
A. It prints: 6, 5, 10
B. It prints: 5.9, 5, 10
C. It prints: 5, 5, 10.00
D. It prints: 6, 5, 10.00
正解:B
質問 2:
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class First
{
public:
First() { cout << "Constructor";}
void Print(){ cout<<"from First";}
};
int main()
{
First FirstObject;
FirstObject.Print();
}
A. It prints: Constructorfrom First
B. None of these
C. It prints: from First
D. It prints: Constructor
正解:A
質問 3:
What is the output of the program?
#include <iostream> #include <string>
using namespace std;
int main()
{
string s1="Hello";
string s2="World";
s1+=s2;
cout << s1;
return( 0 );
}
A. It prints: World
B. It prints: HelWorld
C. It prints: HelloWorld
D. It prints: Hello
正解:C
質問 4:
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 :
void print() {
cout << "B ";
}
};
int main() {
B sc[2];
A *bc = (A*)sc;
for (int i=0; i<2;i++)
(bc++)->print();
return 0;
}
A. It prints: A B
B. It prints: A A
C. It prints: B B
D. It prints: B A
正解:B
質問 5:
Which of the following is a user defined data type?
1: struct person { char name[20]; int age; };
2: int l=2;
3:
enum color {red,blue, green};
D.char c;
A. 4
B. 1
C. 3
D. 2
正解:B,C
質問 6:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <cstdarg>
using namespace std;
int mult(int f, int s, int t);
int main()
{
cout << mult(1,2,3);
return 0;
}
int mult(int f, int s, int t) { int mult_res; mult_res = f*s*t; return mult_res; }
A. It prints: 0
B. It prints: 2
C. It prints: 6
D. It prints: 3
正解:C
質問 7:
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A() { cout << "A no parameters";}
A(string s) { cout << "A string parameter";}
A(A &a) { cout << "A object A parameter";}
};
class B : public A {
public:
B() { cout << "B no parameters";}
B(string s) { cout << "B string parameter";}
};
int main () {
A a1;
A a2("Test");
B b1("Alan");
return 0;
}
A. It prints: B no parameter
B. It prints: A no parametersB string parameter
C. It prints: A no parametersA string parameterA no parametersB string parameter
D. It prints: B string parameter
正解:C
質問 8:
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;
}
A. Compilation error
B. It prints: 0
C. It prints: 1
D. It prints: -1
正解:B
Matsuzawa -
この度は御社Pass4Testの製品を利用させてもらいますので、
合格できました!かなりのCPA的中率でした。ありがとうございました。