Buscar

C Certified Associate Programmer CPA Dumps

Prévia do material em texto

CPA C++ Certified Associate Programmer exam dumps questions are the best
material for you to test all the related C++ Institute exam topics. By using the
CPA exam dumps questions and practicing your skills, you can increase your
confidence and chances of passing the CPA exam.
Features of Dumpsinfo’s products
Instant Download
Free Update in 3 Months
Money back guarantee
PDF and Software
24/7 Customer Support
Besides, Dumpsinfo also provides unlimited access. You can get all
Dumpsinfo files at lowest price.
C++ Certified Associate Programmer CPA exam free dumps questions are
available below for you to study. 
Full version: CPA Exam Dumps Questions
1.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:
 1 / 16
https://www.dumpsinfo.com/unlimited-access/
https://www.dumpsinfo.com/exam/cpa
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.It prints: float exception.Exception Nr.5.2
B.It prints: int exception.Exception Nr.20
C.It prints: An exception occurred
D.Compilation Error
Answer: B
2.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main() {
float i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4 / 2;
cout << i;
return 0;
}
A.It prints: 0
B.It prints: 1
C.It prints: 2
D.It prints: 0.5
Answer: B
3.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a;
a.setAge(10);
a.Print();
a.setAge();
 2 / 16
https://www.dumpsinfo.com/
a.Print();
return 0;
}
A.It prints: 10
B.It prints: 20
C.It prints: 1020
D.It prints: 2010
Answer: C
4.What happens when you attempt to compile and run the following code?
#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,"o");
cout << s;
}
return( 0 );
}
A.It prints: Hoto
B.It prints: Ho
C.It prints: to
D.It prints: Ht
Answer: A
5.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: 5, 5, 10.00
B.It prints: 5.9, 5, 10
C.It prints: 6, 5, 10
D.It prints: 6, 5, 10.00
Answer: B
 3 / 16
https://www.dumpsinfo.com/
6.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int fun(int x) {
return x<<2;
}
int main(){
int i;
i = fun(1) / 2;
cout << i;
return 0;
}
A.It prints: 0
B.It prints: 1
C.It prints: 2
D.It prints: 4
Answer: C
7.What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
int x;
A() { x=0;}
};
class B {
public:
int x;
B() { x=1;}
};
class C :public A, public B {
public:
int x;
C(int x) {
this?>x = x;
A.:x = x + 1;
}
void Print() { cout << x << A::x << B::x; }
};
int main () {
C c2(1);
c2.Print();
return 0;
}
B.It prints: 1
C.It prints: 121
D.It prints: 111
 4 / 16
https://www.dumpsinfo.com/
E.It prints: 2
Answer: B
8.What happens when you attempt to compile and run the following code?
#include <cstdlib>
#include <iostream>
using namespace std;
inline float sum(float a,float b)
{
return a+b;
}
int main()
{
float a,b;
a = 1.5; b = 3.4;
cout<<sum(a,b);
return 0;
}
A.It prints: 0
B.It prints: 4.9
C.It prints: 5
D.It prints: 4
Answer: B
9.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int i = 5;
cout<<"Hello World" << ++i;
return 0;
}
A.It prints: Hello World6
B.It prints: Hello
C.It prints: World
D.It prints: Hello World5
Answer: A
10.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;
 5 / 16
https://www.dumpsinfo.com/
};
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;
}
A.It prints: Bob5
B.It prints: Bob
C.It prints: 5
D.None of these
Answer: A
11.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;
}
A.1010
B.101010
C.0510
D.None of these
Answer: C
12.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void fun(int);
int main()
{
 6 / 16
https://www.dumpsinfo.com/
int a=0;
fun(a);
return 0;
}
void fun(int n)
{
if(n < 2)
{
fun(++n);
cout << n;
}
}
A.It prints: 21
B.It prints: 012
C.It prints: 0
D.None of these
Answer: A
13.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void print(char *c);
int main (int argc, const char * argv[])
{
print("Test");
return 0;
}
void print(char *c)
{
cout<<c;
}
A.It prints: Test
B.It prints: T
C.It prints: st
D.None of these
Answer: A
14.What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
enum state { ok, error, warning};
enum state s1, s2, s3;
s1 = ok;
s2 = warning;
s3 = error;
s4 = ok;
cout << s1<< s2<< s3;
return 0;
 7 / 16
https://www.dumpsinfo.com/
}
A.It will print:”123”
B.compilation error
C.It will print:”021”
D.It will print:”132”
Answer: B
15.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();
}
A.It prints: from First
B.It prints: from Firstfrom First
C.It prints: from Firstfrom Second
D.It prints: from Secondfrom Second
Answer: B
16.What will happen when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
string fun(string, string);
int main()
{
string s="Hello";
cout << fun(s, " World");
return 0;
}
string fun(string s1, string s2)
 8 / 16
https://www.dumpsinfo.com/
{
return s1+s2;
}
A.It will print: Hello World
B.It will print: Hello
C.It will print: World
D.It will print: HW
Answer: A
17.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void set(struct person*);
struct person
{
char name[25];
int age;
};
int main()
{
struct person e = {"Steve", 30};
set(&e);
cout<< e.name << " " << e.age;
return 0;
}
void set(struct person *p)
{
p?>age = p?>age + 1;
}
A.Error: in prototype declaration unknown struct person
B.Error: in structure
C.It prints: Steve 31
D.None of these
Answer: C
18.What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are supplied as input?
#include <iostream>
#include <string>
using namespace std;
void f();
int main()
{
f();
return 0;
}
void f()
{
char c;
c = cin.get();
cout << c;
 9 / 16
https://www.dumpsinfo.com/
if(c != '\n')
f();
}
A.It prints: hello
B.It prints: olleh
C.It prints: h
D.It prints: o
Answer: A
19.Given:
#include <iostream>#include <exception>
using namespace std;
int main () {
try
{
int * myarray= new int[1000];
}
catch (bad_alloc&)
{
cout << "Error allocating memory";
}
catch (exception& e)
{
cout << "Standard exception";
}
catch (...)
{
cout << "Unknown exception";
}
return 0;
}
What will happen if we use the operator “new” and the memory cannot be allocated?
A.It prints: Error allocating memory
B.It prints: Standard exception
C.It prints: Unknown exception
D.Compilation error
Answer: A
20.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)
 10 / 16
https://www.dumpsinfo.com/
{
return i<j;
}
A.It prints: 0
B.It prints: 2
C.It prints: 1
D.It prints: 10
Answer: C
21.What is the output of the program?
#include <iostream>
using namespace std;
#define SQR(x)(x*x)
int main(int argc, char *argv[]) {
int x, y=2;
x = SQR(y);
cout << x << ", " <<y;
return 0;
}
A.It prints: 3, 2
B.It prints: 4, 2
C.It prints: 3, 3
D.It prints: 9, 2
Answer: B
122
What will be the output of the program?
#include <iostream>
using namespace std;
int main()
{
int i=0;
for(; i<=5; i++)
cout << i;
return 0;
}
A.012345
B.0123
C.5
D.6
Answer: A
22.Which code, inserted at line 8, generates the output "100"?
#include <iostream>
using namespace std;
int fun(int);
int main()
{
int *x = new int;
*x=10;
 11 / 16
https://www.dumpsinfo.com/
//insert code here
return 0;
}
int fun(int i)
{
return i*i;
}
A.cout << fun(*x) ;
B.cout << fun(10);
C.cout << fun(5) ;
D.cout << fun(y) ;
Answer: A,B
23.Which of the following is a correct way to define the function fun() in the program below?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int a[2][2];
fun(a);
return 0;
}
A.void fun(int *p[2]) {}
B.void fun(int *p[2][2]) {}
C.void fun(int *p[][2]) {}
D.void fun(int p[][2]) {}
Answer: D
24.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main(){
int i, j;
for(i = 0, j = 1; j < 2, i < 4; i++, j++);
cout << i << " " << j;
return 0;
}
A.It prints: 4 5
B.It prints: 2 3
C.It prints: 3 2
D.It prints: 4 3
Answer: A
25.What happens when you attempt to compile and run the following code?
#include <cstdlib>
#include <iostream>
using namespace std;
 12 / 16
https://www.dumpsinfo.com/
float* sum(float a,float b);
float* sum(float a,float b)
{
float *f = new float;
*f = a+b;
return f;
}
int main()
{
float a,b,*f;
a = 1.5; b = 3.4;
f = sum(a,b);
cout<<*f;
return 0;
}
A.It prints: 0
B.It prints: 4.9
C.It prints: 5
D.It prints: 4
Answer: B
26.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int *t;
t = new int[2];
for (int i=0; i<2; i++) {
t[i] = i;
}
cout << t[1];
}
A.It prints: 0
B.It prints: 1
C.It prints: 10
D.It prints: ?1
Answer: B
27.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;
 13 / 16
https://www.dumpsinfo.com/
}
int min(int a, int b)
{
return(b);
}
A.It prints: 20
B.It prints: 10
C.It prints: 1020
D.It prints: 2010
Answer: A
28.What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A
{
public:
virtual 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();
}
A.It prints: AB
B.It prints: AA
C.It prints: BA
D.It prints: BB
Answer: A
29.What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
class First
{
string name;
public:
First() {
name = "Alan";
 14 / 16
https://www.dumpsinfo.com/
}
void Print(){
cout << name;
}
};
int main()
{
First ob1,*ob2;
ob2 = new First();
ob1.Print();
ob2?>Print();
}
A.Garbage value
B.It prints: AlanAlan
C.It prints: Alan
D.It prints: Al
Answer: B
30.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
31.What will happen when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#define A 1
int main()
{
#if A
cout<<"Hello";
#endif
cout<<"world";
return 0;
}
A.It will print: Helloworld
B.It will print: Hello
C.It will print: world
D.It will print: 0
Answer: A
32.What happens when you attempt to compile and run the following code?
 15 / 16
https://www.dumpsinfo.com/
#include <iostream>
using namespace std;
int main()
{
int i = 0;
i++;
goto lab;
i++;
lab:
cout<<i;
return 0;
}
A.It prints: 0
B.It prints: 34
C.It prints: 1
D.It prints: 3
Answer: C
33.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.It prints: 1 0.8
Answer: C
Powered by TCPDF (www.tcpdf.org)
 16 / 16
https://www.dumpsinfo.com/
http://www.tcpdf.org

Continue navegando