Cause all that matters here is passing the C++ Institute CPA exam. Cause all that you need is a high score of CPA C++ Certified Associate Programmer exam. The only one thing you need to do is downloading Testking CPA exam study guides now. We will not let you down with our money-back guarantee.
Q17. - (Topic 1)
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 A
B. It prints: B B
C. It prints: A B
D. It prints: B A
Answer: A
Q18. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A {
public:
virtual void Print()=0;
};
class B:public A {
public:
virtual void Print() { cout<< "B"; }
};
class C:public A {
public:
virtual void Print() { cout<< "C"; }
};
int main()
{
B ob2;
C ob3;
A *obj;
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}
A. It prints: BC
B. It prints: CB
C. It prints: CC
D. It prints: BB
Answer: A
Q19. - (Topic 2)
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;
}
A. It prints: 0
B. It prints: 2
C. It prints: 1
D. It prints: 10
Answer: C
Q20. - (Topic 1)
Which statement should be added in the following program to make work it correctly?
using namespace std;
int main (int argc, const char * argv[])
{
cout<<"Hello";
}
A. #include<stdio.h>
B. #include<stdlib.h>
C. #include <iostream>
D. #include<conio.h>
Answer: C
Q21. - (Topic 1)
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();
}
A. void Print(){ cout<<"A";}
B. virtual void Print(){ cout<<"A";}
C. virtual void Print(string s){ cout<<s;}
D. None of these
Answer: B
Q22. - (Topic 2)
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1[]= {"H" , "t" };
string s;
for (int i=0; i<2; i++) {
s = s1[i];
s.insert(1,"ow");
cout << s;
}
return( 0 );
}
A. It prints: How
B. It prints: Ht
C. It prints: Hoto
D. It prints: Howtow
Answer: D
Q23. - (Topic 2)
What is the output of the program given below?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
enum state { ok, error, warning};
enum state s1, s2, s3, s4;
s1 = ok;
s2 = warning;
s3 = error;
s4 = ok;
cout << s1<< s2<< s3<< s4;
return 0;
}
A. 1234
B. compilation fails
C. 0210
D. 1322
Answer: C
Q24. - (Topic 2)
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
void fun(int i);
int main()
{
int i=0;
i++;
for (i=0; i<=5; i++)
{
fun(i);
}
return 0;
}
void fun(int i)
{
if (i==3)
return;
cout << i;
}
A. It prints: 05
B. It prints: 012345
C. It prints: 01245
D. It prints: 0
Answer: C
Q25. - (Topic 1)
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;
}
{
i=5;
cout << i;
}
cout<<i;
return 0;
}
A. 1010
B. 101010
C. 055
D. None of these
Answer: C
Q26. - (Topic 1)
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; } cout<<i; return 0; }
A. 1010
B. 100
C. 010
D. None of these
Answer: C
Q27. - (Topic 2)
What will be the output of the program? #include <iostream>
using namespace std;
int main()
{
const int y = 5;
const x = ?10;
cout<<x<<" "<<y;
return 0;
}
A. ?10 5
B. 5 ?10
C. Compilation error
D. None of these
Answer: C
Q28. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class complex{
double re, im;
public:
complex() : re(1),im(0.4) {}
complex operator+(complex &t);
void Print() { cout << re << " " << im; }
};
complex complex::operator+ (complex &t){
complex temp;
temp.re = this?>re + t.re;
temp.im = this?>im + t.im;
return temp;
}
int main(){
complex c1,c2,c3;
c3 = c1 + c2;
c3.Print();
}
A. It prints: 1 0.4
B. It prints: 2 0.8
C. It prints: 0 0
D. Garbage value
Answer: B
Q29. - (Topic 1)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << " " << im;}
};
int main(){
complex c1;
double i=2;
c1 = i;
c1.print();
return 0;
}
A. It prints: 0 0
B. It prints: 1 1
C. It prints: 2 0
D. It prints: 2 2
Answer: D
Q30. - (Topic 2)
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const char *s;
char str[] = "Hello";
s = str;
while(*s) {
cout << *s++;
}
return 0;
}
A. It prints: el
B. It prints: Hello
C. It prints: H
D. It prints: o
Answer: B
Q31. - (Topic 2)
What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
int fun(int);
int main()
{
int *x = new int;
*x=10;
cout << fun(*x);
return 0;
}
int fun(int i)
{
return i*i;
}
A. It will print: 100
B. It will print: 101
C. It will print: 10
D. It will print: 1
Answer: A
Q32. - (Topic 1)
What is the output of the program if character 4 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'
default:
cout<<"No exception";
}
}
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. It prints: float exception. Exception Nr.
B. It prints: int exception. Exception Nr.
C. It prints: An exception occurred
D. It prints: No exception
Answer: D