Text Material Preview
CPA-21-02 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-21-02 exam dumps questions and practicing your skills, you can increase your confidence and chances of passing the CPA-21-02 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. CPA – C++ Certified Associate Programmer CPA-21-02 exam free dumps questions are available below for you to study. Full version: CPA-21-02 Exam Dumps Questions 1.Which of the following statements are correct about an array? int tab[10]; A. The array can store 10 elements. B. The expression tab[1] designates the very first element in the array. C. The expression tab[9] designates the last element in the array. D. It is necessary to initialize the array at the time of declaration. Answer: A, C 2.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void fun(int &i); 1 / 20 https://www.dumpsinfo.com/unlimited-access/ https://www.dumpsinfo.com/exam/cpa-21-02 int main() { int i=2; fun(i); cout<<i; return 0; } void fun(int &i) { i+=2; } A. It prints: 2 B. It prints: 0 C. It prints: 4 D. It prints: 16 Answer: C 3.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; #define DEF_A 0 #define DEF_B DEF_A+1 #define DEF_C DEF_B+1 int main(int argc, char *argv[]) { cout << DEF_C; return 0; } A. It prints: 2 B. It prints: 10 C. It prints: 0 D. It prints: 1 Answer: A 4.How many times will the program print "HELLO" ? #include <iostream> using namespace std; int main() { cout<<"HELLO"; main(); return 0; } A. 65536 B. 32769 C. 1 D. Till stack overflows Answer: D 5.What happens when you attempt to compile and run the following code? 2 / 20 https://www.dumpsinfo.com/ #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; } A. It prints: A no parametersA no parametersB string parameter B. It prints: A string parameterA no parametersB int parameterA object A parameter C. It prints: A no parametersB string parameter D. It prints: A no parametersA no parameters Answer: B 6.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 3 / 20 https://www.dumpsinfo.com/ B. It prints: AA C. It prints: BA D. It prints: BB Answer: A 7.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 { string z; public: void set() { y = 4; z = "John"; } void Print() { cout << y << A::z; } }; int main () { B b; b.set(); b.Print(); return 0; } A. It prints: 4John B. It prints: 2John C. It prints: 23 D. It prints: 43 Answer: D 8.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; } 4 / 20 https://www.dumpsinfo.com/ 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 9.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; }; 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 10.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; } A. It prints: 20 5 / 20 https://www.dumpsinfo.com/ B. It prints: 10 C. Compilation error at line 8 D. It prints address of ptr Answer: C 11.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 12.What happens when you attempt to compile and run the following code? 6 / 20 https://www.dumpsinfo.com/ A. It prints: 3 B. It prints: 4 C. It prints: 0 D. It prints: 6 Answer: D 13.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; class First { public: First() { cout << "Constructor";} ~First() { cout << "Destructor";} void Print(){ cout<<"from First";} }; int main() { First FirstObject; FirstObject.Print(); } 7 / 20 https://www.dumpsinfo.com/ A. It prints: Constructorfrom First B. It prints: Constructorfrom FirstDestructor C. It prints: Constructorfrom FirstDestructorDestructor D. Compilation error at line 16 Answer: B 14.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 15.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]; if (i==0) s.insert(1,"ow"); else s.push_back('o'); cout << s; } return (0); } A. It prints: Hoto 8 / 20 https://www.dumpsinfo.com/ B. It prints: Ht C. It prints: toHo D. It prints: Howto Answer: D 16.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main(){ int i = 1; if (--i==1) { cout << i; } else { cout << i-1; } return 0; } A. It prints: 0 B. It prints: 1 C. It prints: -1 D. It prints: 2 Answer: C 17.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void fun(int); int main() { 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 18.What happens when you attempt to compile and run the following code? #include <iostream> 9 / 20 https://www.dumpsinfo.com/ #include <string> using namespace std; class A { public: string s; A(string s) { this?>s = s; } }; class B { public: string s; B (A a) { this?>s = a.s; } void print() { cout<<s; } }; int main() { A a("Hello world"); B b=a; b.print(); } A. It prints: Hello world B. It prints: Hello C. Compilation error D. None of these Answer: A 19.What is the output of the program? #include <iostream> #include <string> using namespace std; class First { stringname; public: First() { name = "Alan"; } 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 10 / 20 https://www.dumpsinfo.com/ Answer: B 20.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; } 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 21.Analyze the code below. If it contains an error, indicate its place in the program. 11 / 20 https://www.dumpsinfo.com/ A. Error in the for loop B. Error in the break statement C. No error D. Error in the if statement Answer: C 22.What happens when you attempt to compile and run the following code? A. It prints: 10 B. It prints: 2+32+3 C. It prints: 7 D. It prints: 22+3 Answer: D 23.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 12 / 20 https://www.dumpsinfo.com/ Answer: C 24.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main (int argc, const char * argv[]) { int x,y; union t { char tab[2]; int i; }; union t u; u.tab[0] = 1; u.tab[1] = 2; u.i = 0; x = u.tab[0]; y = u.tab[1]; cout << x << "," << y << "," << u.i; return 0; } A. compilation fails B. It prints: 0,0,0 C. It prints: 1,2,0 D. None of these Answer: B 25.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: 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; } 13 / 20 https://www.dumpsinfo.com/ 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 26.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; c1.print(); return 0; } A. It prints: 1 0 B. It prints: 1 1 C. It prints: 0 0 D. Compilation error Answer: C 27.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 14 / 20 https://www.dumpsinfo.com/ B. It prints: 6 C. It prints: 2 D. It prints: 3 Answer: B 28.Which of the following statements are true? (Choose two.) A. Class A's friend's friend is also a friend of class A B. Friendship is inherited C. A class may be a friend of many classes D. A class may have many friends Answer: C, D 29.What will happen 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; *s++; } return 0; } A. It will print:"el " B. The code will not compile. C. It will print:"Hello " D. It will print garbage value Answer: A 30.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; } A. It will print:”123” B. compilation error C. It will print:”021” 15 / 20 https://www.dumpsinfo.com/ D. It will print:”132” Answer: B 31.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[2]; for (int i=0; i<2; i++) t[i].Print(); } A. It prints: 30 B. It prints: John C. It prints: John 31 D. It prints: John 30John 30 Answer: D 32.If a function, which is not a method, needs to save any value between its subsequent invocations, this can be done by: (Choose two.) A. setting a variable declared inside the function with the static modifier B. setting a parameter of the function C. setting a variable declared outside the function D. setting a variable declared inside the function without the static modifier Answer: A, C 33.What is the output of the program? #include <iostream> #include <string> using namespace std; int main() { 16 / 20 https://www.dumpsinfo.com/ string s1="World"; string s2; s2="Hello" + s1; cout << s2; return (0); } A. It prints: HelloWorld B. It prints: Hello C. It prints: World D. Compilation error Answer: A 34.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; void fun(char*); int main() { char t[4]={'0', '1', '2', '3'}; fun(&t[2]); return 0; } void fun(char *a) { cout << *a; } A. It prints: 2 B. It prints: 21 C. It prints: 00 D. It prints: 02 Answer: A 35.Which code, inserted at line 18, generates the output "AB" #include <iostream> using namespace std; class A { public: void Print(){ cout<< "A";} void Print2(){ cout<< "a";} }; class B:public A { public: void Print(){ cout<< "B";} void Print2(){ cout<< "b";} }; int main() { B ob2; 17 / 20 https://www.dumpsinfo.com/ //insert code here ob2.Print(); } A. ob2?>A::Print(); B. ob2.B::Print(); C. ob2?>B::Print(); D. ob2.A::Print(); Answer: D 36.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int main() { int i=2; switch(i) { case 1: cout<<"Hello"; break; case 2: cout<<"world"; break; case 3: printf("End"); break; } return 0; } A. It prints: Hello B. It prints: world C. It prints: End D. It prints: E Answer: B 37.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int fun(int x); int main() { cout << fun(0); return 0; } int fun(int x) { if(x > 0) return fun(x-1); else return 100; } A. It prints: 0 18 / 20 https://www.dumpsinfo.com/ B. It prints: 10 C. It prints: 100 D. It prints: -1 Answer: C 38.What happens when you attempt to compile and run the following code? #include <iostream> using namespace std; int op(int x, int y); int main() { int i=2, j=2, k; float f=0.3; k = op(i, j); cout<< k << "," << op(1, f); return 0; } int op(int x, int y) { return x+y; } A. It prints: 4,1 B. It prints: 4,0.7 C. It prints: 4,0 D. It prints: 0,4 Answer: A 39.1.What will the variable "age" be in class B? class A { int x; protected: int y; public: int age; A () {age=5;}; }; class B: public A { string name; public: B () {name="Bob";}; void Print () { cout << name << age; } }; A. public B. private C. protected D. None of these Answer: A 19 / 20 https://www.dumpsinfo.com/ Powered by TCPDF (www.tcpdf.org) 20 / 20 https://www.dumpsinfo.com/ http://www.tcpdf.org