Oop 1

Download as pdf
Download as pdf
You are on page 1of 18
1272972020 (00P using G++ Exam Duration: 20 Min. OOP using C++ Exam Duration : 90 Min. * Required 1.Name * Enter your answer 2. Track * Open Source 3. class Point { float x, y; Point (float a, float b) { x=a; y=b;} Point () { x=0; y=0; } } To write copy constructor to class point, what would be its signature? (3 Points) O Point (Point) 4B Point (Point &) © Point & Point (Point 8). O Point & Point (Point) hitpslformsoffce.com/Pages!ResponsePage aspx?ié=CDEmgpygXU-OFU_OFmnd_UguVFgCHSFkhOmgYPbWniIUOVFIVzBaRecxWTkeVFVWO... 1/18 ‘12972020 (00° vsing C+ Exam Duration 80 Min, O void Point (Point) O void Point (Point & © None of the above 4. class Nice { inta; 19 public: Nice(){a=0;} Nice(Nice & myN) { this-> a= myNaa; cout<<"I am the copy constructor " ; } void setA(int m) {a = m;} int getA() { return a ;} i void show(Nice &obj) { cout<<"I am the show function, value is: " << obj.getAQ ; } void main() { Nice nt; n1.setA(15); — show(n1) ; } (3 Points) WW an the show function, value is: 15. O 1am the show function, value is: 15. 1 am the copy constructor. © 1am the copy constructor. | am the show function, value is: 15. © 1am the copy constructor. 5. The Destructor of a class is responsible for removing the object from the memory (1 Point) @ te htpslforms.offce.com/Pages!ResponsePage.aspx?i¢=CDEmgpygXU-OFU_OFmnd_UguVFgCHSFkhOmgYPbWniIUOVFIVzBaRecxWTkVFVWO... 2/18 1212972020 {00° usng C+ Exam Duraton: 20 Min O False 6.When overloading a certain function, it is obligatory that we specify a different number of parameters for the new function. (1 Point) 7. What will be the output when you compile and run the following piece of code? class Test { int x; public: Test(){ x=0; } Test(int y) { x= y++;} Test(Test &ir) { x= ++rx; } void print() {cout< Child 3,4); cout <<" } "ccexe<"ys"< wien steps will allow Sub to compile? (3 Points) (J Class Sub compile successfully. LX Comment tine 2 WF in ine 1 and 4 to, use (*this).a instead of this.a; (© change Line 1 and 4 to, this(a); LZ change Line 3 to, Subp: Super(5) (J change Line 3 to, Sub): this(5) O) alithe above. hitpslforms.offce.com/Pages!ResponsePage.aspx?i¢=CDEmgpygXU-OFU_OFmnd_UguVFgCHSFkKhOmgYPbWniIUOVFIVzBaRecxWTkVFVWA... 7/8 1212972020 (00P using G++ Exam Duration: 20 Min. 15. What will be the output when you compile and run the following piece of code? class Base { public: Base() { cout<<"Welcome he class Derived : public Base { public: Derived() { cout<<"Hello ";} i void main() { Base myBase ; Derived myDerived ; } (3 Points) © Welcome Hello O Hello Welcome O Welcome Hello Welcome F welcome Welcome Hello 16. In order to turn a class into an abstract class, which of the following do we need to do? (3 Points) © Write the abstract keyword before the name of the class. O Make the class a pure virtual class. WR write one or mare pure virtual functions inside the class. O Aande. © None of the above hitpslfrmsoffce.com/Pages!ResponsePage.aspx?ié=CDEmgpygXU-OFU_OFmnd_UguVFgCHSFkKhOmgYPbWniIUOVFIVzBaRzcxWTkVFVWO... a8 1212972020 (00P using G++ Exam Duration: 20 Min. 17. If a certain function is made friend for class A, then that function can access only the private members of class A. (1 Point) O Tne WF False 18. A protected member of a class can be directly accessed by its name inside another class if and only if that other class is a child of that class. (1 Point) 19. Which of the following most closely describes the process of overriding? (3 Points) © Ass withthe same name replaces the functionality of a class defined earlier in the hierarchy. > ‘A function with the same name replaces the functionality of a function defined earlier in the inheritance hierarchy. © A function with the same name but diferent parameters gives multiple uses forthe same function name. O Making a class abstract so that no objects can be declared from it 20. Assume you have a class M that contains a pointer to an object of class N. Assume that we declare an object of M in the main( ) function. When will the body of the constructor of class N be executed? @ Points) X When any member function of the class M is called. htpslfrmsoffce.com/Pages!ResponsePage.aspx?ié=CDEmgpygXU-OFU_OFmnd_UguVFgCHSFkKhOmgYPbWniIUOVFIV2BaRecxWTkVFVWO... 9/18 1212972020 (00P using G++ Exam Duration: 20 Min. O After the body of the constructor of class M is executed, © Before the body of the constructor of class M is executed, WZ None of the above 21.class Parent { public: int x; Parent(intm) {x =m ;} \ class Child : protected Parent { public: int y; Child(int m, int n) : Parent(m) {_ y =n; } i class GrandChild : public Child { intz; public: GrandChild(int a, int b, int c) : Child(a,b) { z= ¢;} i void main( ) { GrandChild obj(3,5,7); cout<<"Value of x is: "< powerTwo(); //Linet myPtr->powerThree(); //Line 2 } (3 Points) O48 razr O 927 O98 © Compilation Error at Linet htps:formsaffice.comIPages/ResponsePage.aspx?i¢=CD8mgpyeXU-OFU_OFmg_UguVFgCHS#khOmgYPbWniUOVFIV2BaRzcxWTRAVFVW. rene 1212972020 (00P using G++ Exam Duration: 20 Min. © Compilation Error at Line2 35. What will be the output when you compile and run the following piece of code? class Parent { inty; static int z; public: Parent ) { // inet } Parent (int a=5) Z/Line 2 { 1 i void main() { Parent d(4); //Line 3 Parent dAine4 AL (3 Points) © Compilation Error at Line 1, an object member function cannot access a static member © Compitation Error at Line 2, constructor should initialize static member (z=0;) © Compilation Error at Line 3 (L@& compilation Error at Line 4. © The code compiles successfully. Never give out your password, Report abuse hitpslformsoffce.com/Pages!ResponsePage.aspx?i¢=CDEmgoyeXU-OFU_OFmnd_UguVFgCHSFkKhOmgYPbWniIUOVFIVzBaRecxWTkeVFVW.... 17/18 1212972020 (00P using G++ Exam Duration: 20 Min. This content is created by the owner of the form. The data you submit wil be sent to the form owner. Microsoft is not responsible for the privacy or security practices of its customers, including those of this form owner, Never give out your password, Powered by Microsoft Forms |Privacy and cookies | Terms of use hitpslformsoffce.com/Pages!ResponsePage.aspx?i¢=CDEmgpygXU-OFU_OFmnd_UguVFgCHSFKhOmgYPBWniIUOVFIVzBaRzcxWTkVFVW.... 18/18

You might also like