What happens when you attempt to compile and run the following code?#include <iostream>#include <string>using namespace std;const int size = 3;class A {public:string name;A() { name = "Bob";}A(string s) { name = s;}A(A &a) { name = a.name;}};class B : public A {public:int *tab;B() { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;} B(string s) : A(s) { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;} ~B() { delete tab; }void Print() {for (int i=0; i<size; i++) cout << tab[i];cout << name;}};int main () {B b1("Alan");B b2;b1.tab[0]=0;b1.Print(); b2.Print();return 0;}
Answer(s): C
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 A {public:virtual void Print(){ cout<< "B";}};class C:public B {public:void Print(){ cout<< "C";}};int main(){A ob1;B ob2;C ob3;B *obj;obj = &ob2;obj?>Print();obj = &ob3;obj?>Print();}
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();
Answer(s): A
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;};class B : private A {string name;public:void set() {x = 1;}void Print() {cout << x;}};int main () {B b;
Answer(s): D
Post your Comments and Discuss C++ Institute CPA-21-02 exam with other Community members:
Subash commented on October 21, 2024 I am planning to take this exam. Are these 257 questions enough to clear it? Also, does each section have a passing percentage, or is it based on the overall ? INDIA upvote
Our website is free, but we have to fight against bots and content theft. We're sorry for the inconvenience caused by these security measures. You can access the rest of the CPA-21-02 content, but please register or login to continue.