C++ Institute C++ Certified Associate Programmer - CPA FREE EXAM DUMPS QUESTIONS & ANSWERS
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;
}
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout<<i;
}
cout<<i;
return 0;
}
Correct Answer: C
Vote an answer
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
struct Person {
string name;
int age;
};
class First
{
Person *person;
public:
First() {person = new Person;
person->name = "John";
person->age = 30;
}
void Print(){
cout<<person->name << " "<< person->age;
}
};
int main()
{
First t;
t.Print();
}
#include <iostream>
#include <string>
using namespace std;
struct Person {
string name;
int age;
};
class First
{
Person *person;
public:
First() {person = new Person;
person->name = "John";
person->age = 30;
}
void Print(){
cout<<person->name << " "<< person->age;
}
};
int main()
{
First t;
t.Print();
}
Correct Answer: A
Vote an answer
What happens when you attempt to compile and run the following code?
#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 {
public:
void set() {
y = 4; z = 2;
}
void Print() {
cout << y << z;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
#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 {
public:
void set() {
y = 4; z = 2;
}
void Print() {
cout << y << z;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}
Correct Answer: A
Vote an answer
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; }
#include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a[2][2]; fun(a); return 0; }
Correct Answer: C
Vote an answer
Which code, inserted at line 15, generates the output "5 Bob"?
#include <iostream>
#include <string>
using namespace std;
class B;
class A {
int age;
public:
A () { age=5; };
friend void Print(A &ob, B &so);
};
class B {
string name;
public:
B () { name="Bob"; };
//insert code here
};
void Print(A &ob, B &so) {
cout<<ob.age << " " << so.name;
}
int main () {
A a;
B b;
Print(a,b);
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class B;
class A {
int age;
public:
A () { age=5; };
friend void Print(A &ob, B &so);
};
class B {
string name;
public:
B () { name="Bob"; };
//insert code here
};
void Print(A &ob, B &so) {
cout<<ob.age << " " << so.name;
}
int main () {
A a;
B b;
Print(a,b);
return 0;
}
Correct Answer: B
Vote an answer
What is the output of the program?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.setAge();
b->setAge(20);
a.Print();
b->Print();
return 0;
}
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.setAge();
b->setAge(20);
a.Print();
b->Print();
return 0;
}
Correct Answer: B
Vote an answer
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";}
B(int s) { cout << "B int parameter";}
};
int main () {
A a2("Test");
B b1(10);
B b2(b1);
return 0;
}
#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";}
B(int s) { cout << "B int parameter";}
};
int main () {
A a2("Test");
B b1(10);
B b2(b1);
return 0;
}
Correct Answer: D
Vote an answer
How many times will "HELLO" be printed?
#include <iostream>
using namespace std;
int main()
{
for(int i=?1; i<=10; i++)
{
if(i < 5)
continue;
else
break;
cout<<"HELLO";
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
for(int i=?1; i<=10; i++)
{
if(i < 5)
continue;
else
break;
cout<<"HELLO";
}
return 0;
}
Correct Answer: D
Vote an answer
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();
}
#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();
}
Correct Answer: D
Vote an answer
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
protected:
int y;
public:
int x;
int z;
A() { x=2; y=2; z=3; }
A(int a, int b) : x(a), y(b) { z = x ? y;}
void Print() {
cout << z;
}
};
int main () {
A a(2,5);
a.Print();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class A {
protected:
int y;
public:
int x;
int z;
A() { x=2; y=2; z=3; }
A(int a, int b) : x(a), y(b) { z = x ? y;}
void Print() {
cout << z;
}
};
int main () {
A a(2,5);
a.Print();
return 0;
}
Correct Answer: B
Vote an answer
Which code, inserted at line 10, generates the output "Hello World"?
#include <iostream> #include <string>
using namespace std;
string fun(string, string);
int main()
{
string s="Hello";
string *ps;
ps = &s;
//insert code here
return 0;
}
string fun(string s1, string s2)
{
return s1+s2;
}
#include <iostream> #include <string>
using namespace std;
string fun(string, string);
int main()
{
string s="Hello";
string *ps;
ps = &s;
//insert code here
return 0;
}
string fun(string s1, string s2)
{
return s1+s2;
}
Correct Answer: D
Vote an answer
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this->s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o->Print();
}
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this->s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o->Print();
}
Correct Answer: C
Vote an answer
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const int x=20;
const int *ptr;
ptr = &x;
*ptr = 10;
cout<<*ptr;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
const int x=20;
const int *ptr;
ptr = &x;
*ptr = 10;
cout<<*ptr;
return 0;
}
Correct Answer: B
Vote an answer
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;
}
#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;
}
Correct Answer: D
Vote an answer
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;
}
#include <iostream>
using namespace std;
int main()
{
int i=0;
for(; i<=5; i++)
cout << i;
return 0;
}
Correct Answer: A
Vote an answer