0% found this document useful (0 votes)
30 views43 pages

CS304P Quiz 16 Finals 24-01-2024 Mam Mehwish

The document contains a series of quiz questions and answers related to Object Oriented Programming concepts in C++, including polymorphism, virtual functions, templates, and inheritance. It covers the syntax for defining functions and classes, as well as the behavior of public and private members in inheritance. The quiz format suggests it is intended for students preparing for a final term examination in a programming course.

Uploaded by

faphere579
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views43 pages

CS304P Quiz 16 Finals 24-01-2024 Mam Mehwish

The document contains a series of quiz questions and answers related to Object Oriented Programming concepts in C++, including polymorphism, virtual functions, templates, and inheritance. It covers the syntax for defining functions and classes, as well as the behavior of public and private members in inheritance. The quiz format suggests it is intended for students preparing for a final term examination in a programming course.

Uploaded by

faphere579
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

CS304P

Final Term (Live Quiz)


PAID VU LMS HANDLING by Mam Mehwish
03184148783
Past Papers for Mids./Finals are also Available

Question #1:

Which keyword is used to achieve polymorphism?

poly

virtual ✅

polymorphism

pure virtual

Question #2:

Suppose you have a function: void sum();

Choose correct syntax from the given options which will make this function pure virtual function.

void sum() virtual=0;

sum()=0;

void sum()=0;

virtual void sum()=0; ✅

Question #3:

Virtual functions can be used in ________ ways.

2✅

6
0

Question #4:

A class with pure virtual function is called ________ class.

abstract ✅

normal

solid

concrete

Question #5:

virtual void print(); is an example of_.

template function

virtual function ✅

simple function

pure virtual function

Question 1:

Which of the following is the correct syntax for a function template in C++?

template<class T> void func(T a); ✔

template<type T> func(T a);

func<class T>(T a);

template void func<class T>(T a);

Question 2:

What does a C++ template allow you to do?

Create new data types dynamically at runtime

Write functions or classes that can operate with different data types ✔
Define multiple main functions in a program

None of the given

Question 3:

Suppose you have a function: void sum(); Choose the correct syntax from the given options which will
make this function pure virtual function.

void sum() virtual=0;

void sum()=0;

virtual void sum()=0; ✔

sum()=0;

Question 4:

Virtual functions can be used in ________ ways.

2✔

Question 5:

Which keyword is used to achieve polymorphism?

polymorphism

pure virtual

poly

virtual ✔

Question 6:

virtual void print(); is an example of_.

pure virtual function

template function
simple function

virtual function ✔

Question 7:

A class with pure virtual function is called ________ class.

solid

concrete

abstract ✔

normal

Question 8:

How can you define a class template in C++?

template<class T> MyClass { ... };

template<typename T> class MyClass { ... }; ✔

template<type T> class MyClass { ... };

template<name T> class MyClass { ... };

Question 9:

What is the purpose of explicit specialization in templates?

To avoid the use of templates

To improve runtime performance

To handle specific data types that the template cannot handle successfully ✔

To simplify the template syntax

Question 10:

Which keyword is used to define a template in C++?

template ✔

class
function

typename

cs304p

Question 1:

virtual void print(); is an example of_.

simple function

template function

pure virtual function

virtual function ✔

Question 2:

What does a C++ template allow you to do?

Define multiple main functions in a program

Create new data types dynamically at runtime

Write functions or classes that can operate with different data types ✔

None of the given

Question 3:

Which of the following is the correct syntax for a function template in C++?

template void func<class T>(T a);

template<class T> void func(T a); ✔

func<class T>(T a);

template<type T> func(T a);

Question 4:
Which keyword is used to define a template in C++?

template ✔

typename

function

class

Question 5:

Virtual functions can be used in ________ ways.

2✔

Question 6:

Suppose you have a function: void sum(); Choose the correct syntax from the given options which will
make this function a pure virtual function.

sum()=0;

void sum() virtual=0;

void sum()=0;

virtual void sum()=0; ✔

Question 7:

Which keyword is used to achieve polymorphism?

poly

virtual ✔
pure virtual

polymorphism

Question 8:

How can you define a class template in C++?

template<class T> MyClass { ... };

template<typename T> class MyClass { ... }; ✔

template<type T> class MyClass { ... };

template<name T> class MyClass { ... };

Question 9:

What is the purpose of explicit specialization in templates?

To improve runtime performance

To avoid the use of templates

To simplify the template syntax

To handle specific data types that the template cannot handle successfully ✔

Question 10:

A class with pure virtual function is called ________ class.

solid

abstract ✔

concrete

normal

cs304p

Question 1:

What is the purpose of explicit specialization in templates?


⬜ To avoid the use of templates

⬜ To simplify the template syntax

✅ To handle specific data types that the template cannot handle successfully

⬜ To improve runtime performance

Question 2:

How can you define a class template in C++?

⬜ template<type T> class MyClass { ... };

✅ template<typename T> class MyClass { ... };

⬜ template<name T> class MyClass { ... };

⬜ template<class T> MyClass { ... };

Question 3:

Virtual functions can be used in ________ ways.

⬜8

⬜0

⬜6

✅2

Question 4:

Which of the following is the correct syntax for a function template in C++?

⬜ func<class T>(T a);

⬜ template void func<class T>(T a);

✅ template<class T> void func(T a);

⬜ template<type T> func(T a);

Question 5:

virtual void print(); is an example of_.


⬜ pure virtual function

⬜ simple function

⬜ template function

✅ virtual function

Question 6:

A class with pure virtual function is called ________ class.

⬜ solid

⬜ concrete

✅ abstract

⬜ normal

Question 7:

What does a C++ template allow you to do?

⬜ Define multiple main functions in a program

⬜ Create new data types dynamically at runtime

⬜ None of the given

✅ Write functions or classes that can operate with different data types

Question 8:

Suppose you have a function: void sum();

Choose correct syntax from the given options which will make this function pure virtual function.

⬜ void sum() virtual=0;

⬜ void sum()=0;

⬜ sum()=0;

✅ virtual void sum()=0;

Question 9:
Which keyword is used to achieve polymorphism?

✅ virtual

⬜ poly

⬜ pure virtual

⬜ polymorphism

Question 10:

Which keyword is used to define a template in C++?

✅ template

⬜ typename

⬜ class

⬜ function

cs304p

Question # 1:

How can you define a class template in C++?

template<type T> class MyClass { ... };

template<class T> MyClass { ... };

✅ template<typename T> class MyClass { ... };

template<name T> class MyClass { ... };

Question # 2:

Which keyword is used to define a template in C++?

✅ template

class

typename

function
Question # 3:

virtual void print(); is an example of_.

simple function

✅ virtual function

template function

pure virtual function

Question # 4:

What does a C++ template allow you to do?

Define multiple main functions in a program

None of the given

✅ Write functions or classes that can operate with different data types

Create new data types dynamically at runtime

Question # 5:

Which keyword is used to achieve polymorphism?

pure virtual

polymorphism

✅ virtual

poly

Question # 6:

Suppose you have a function: void sum();

Choose correct syntax from the given options which will make this function pure virtual function.

void sum() virtual=0;

void sum()=0;

✅ virtual void sum()=0;


sum()=0;

Question # 7:

Which of the following is the correct syntax for a function template in C++?

template void func<class T>(T a);

template<type T> func(T a);

✅ template<class T> void func(T a);

func<class T>(T a);

Question # 8:

A class with pure virtual function is called ________ class.

✅ abstract

concrete

normal

solid

Question # 9:

What is the purpose of explicit specialization in templates?

✅ To handle specific data types that the template cannot handle successfully

To improve runtime performance

To simplify the template syntax

To avoid the use of templates

Question # 10:

Virtual functions can be used in ________ ways.

✅2

0
8cs304p

In the given class, the method Test is_.

Overloaded

Overridden ✔

Both

None of the given options

What will be the output of the following program?

cpp

Copy code

#include<iostream>

using namespace std;

class FirstNumber {

private:

int x;

public:

int y;

FirstNumber () { x = 0; y = 10; }

};

class SecondNumber: public FirstNumber {

int z;

public:

int w;

SecondNumber () : FirstNumber () {

z = 20;

w = y + z;
cout<<w;

};

int main() {

SecondNumber Obj;

return 0;

40

10

30 ✔

20

Consider the code below,

cpp

Copy code

class class1{

public:

void func1();

};

class class2 : public class1 { };

Function func1 of class1 is ______ in class2.

Private

Hidden

Public ✔

Protected

What is the name of the Base class in the line below?


cpp

Copy code

class Truck : public Vehicle

None of the given options

Vehicle ✔

Truck

Public

For the given class definition, which one is correct?

cpp

Copy code

#include<iostream>

using namespace std;

class A{

int x, y;

public:

int Add(int a, int b) { return a + b; }

int Add(int c) { return c; }

};

Function Add has an error

None of the given options

Function Add is overloaded ✔

Function Add is overridden

If the programmer does not specify the type of inheritance, then the default type of inheritance is
____________.

Protected
None of the given

Private ✔

Public

In the case of public inheritance, private members of the base class will be _____________ in the
derived class.

Hidden ✔

Public

Private

Protected

What will be the output of the following program?

cpp

Copy code

#include<iostream>

using namespace std;

class House{

private:

int rooms;

public:

House() { cout << "Entering the house" << endl; }

House(int R) { rooms = R; }

~House() { cout << "Leaving the house" << endl; }

};

class Kitchen : public House {

double size;
public:

Kitchen() : House() { cout << "Entering the kitchen"; }

};

int main() {

Kitchen Obj;

return 0;

Entering the kitchen Entering the house Leaving the house

Entering the house Leaving the house Entering the kitchen

Leaving the house Entering the house Entering the kitchen

Entering the house Entering the kitchen Leaving the house ✔

In inheritance, polymorphism is done by ______.

None of the given options

Copy Constructor

Method Overloading

Method Overriding ✔

In Dev C++, _____________ keeps track of the virtual functions and calls them correctly according to the
nature of the object for which they are being called.

Query Analyzer

Compiler ✔

Interpreter

Debugger

cs304p

1. In the case of private inheritance, public members of the base class will be ____________ in the
derived class.
Private ✓

Protected

Public

Hidden

2. Virtual functions can be used in ____________ ways.

2✓

3. In the case of public inheritance, private members of the base class will be ____________ in the
derived class.

Private ✓

Hidden

Protected

Public

4. In Dev C++, ____________ keeps track of the virtual functions and calls them correctly according to
the nature of the object for which they are being called.

Compiler

Query Analyzer

Interpreter ✓

Debugger

**5. Consider the code below:

class base1{ public: void fun1(); }

class base2{ public: void fun2(); }

class derived: public base1, public base2{}


function fun() { /* ... / }

Function fun() is _____________ in class derived.*

Public ✓

Private

Protected

Hidden

6. In the above code, does the method test() is ____________.

None of the given options

Overloaded

Overridden ✓

Both

7. Which of the following members of base class can be accessed in the derived class?

All (Public, Protected and Private)

Both Protected and Public ✓

Both Public and Private

Both Protected and Private

8. What will be the output of the following program?

#include<iostream>

using namespace std;

class house{

public:

house(){ cout<<"entering the house"<<endl; }

~house(){ cout<<"leaving the house"<<endl; }

};
class kitchen: public house{

public:

kitchen(){ cout<<"entering the kitchen"<<endl; }

~kitchen(){ cout<<"leaving the kitchen"<<endl; }

};

int main(){

kitchen obj;

Entering the kitchen

Entering the house

Leaving the house

Leaving the house

Entering the house

Entering the kitchen

9. What will be the output of the following program?

#include<iostream>

using namespace std;

class house{

public:

house(){ cout<<"entering the house"<<endl; }

~house(){ cout<<"leaving the house"<<endl; }

};

class kitchen: public house{


public:

kitchen(){ cout<<"entering the kitchen"<<endl; }

~kitchen(){ cout<<"leaving the kitchen"<<endl; }

};

int main(){

kitchen obj;

Entering the kitchen

Entering the house

Leaving the house

Leaving the house

Entering the house

Entering the kitchen

10. In the case of protected inheritance, public members of the base class will be ____________ in the
derived class.

Protected ✓

Public

Private

Hidden

11. In inheritance, polymorphism is done by ____________.

Copy Constructor

None of the given options

Method Overriding ✓

Method Overloading
Subject Code: CS304P - Object Oriented Programming (Practical)

Question # 1

virtual void print(); is an example of_.

pure virtual function

template function

simple function

virtual function

Question # 2

A class with pure virtual function is called ________ class.

concrete

abstract

normal

solid

Question # 3

Which keyword is used to achieve polymorphism?

virtual

polymorphism

poly

pure virtual

Question # 4

Suppose you have a function: void sum();

Choose correct syntax from the given options which will make this function pure virtual function.

void sum()=0;

virtual void sum()=0;


sum()=0;

void sum() virtual=0;

Question # 5

Virtual functions can be used in ________ ways.

Subject Code: CS304P - Object Oriented Programming (Practical)

Question 1:

Which keyword is used to achieve polymorphism?

poly

virtual ✅

pure virtual

polymorphism

Question 2:

Suppose you have a function: void sum();

Choose correct syntax from the given options which will make this function pure virtual function.

void sum()=0;

virtual void sum()=0; ✅

void sum() virtual=0;

sum()=0;

Question 3:

A class with pure virtual function is called ________ class.


normal

solid

concrete

abstract ✅

Question 4:

virtual void print(); is an example of_.

template function

simple function

virtual function ✅

pure virtual function

Question 5:

Virtual functions can be used in ________ ways.

2✅

Subject Code: CS304P - Object Oriented Programming (Practical)

Question 1: Which of the following is not the correct type of inheritance in C++?

 secret

 private

 protected

 public

Correct Option:
✅ secret
Question 2: In case of public inheritance between Base class A and Derived class B, which of the
following data members of Base class will be hidden in Derived class?

 both public and private

 protected

 public

 private

Correct Option:
✅ private

Question 3: For the given class definition, which one is correct?

cpp

Copy code

#include<iostream>

using namespace std;

class A{

int x,y;

public:

int Add(int a,int b){return a+b;}

int Add(int c){return c;}

};

 Function Add is overloaded

 None of the given options

 Function Add has an error

 Function Add is overridden

Correct Option:
✅ Function Add is overloaded

Question 4: There are ________ types of inheritance in C++.

 3

 4
 2

 1

Correct Option:
✅4

Question 5: In the above class, the method Test is_______.

cpp

Copy code

class A {

public:

int Test(int x) {return x*x;}

int Test(int x, int y) {return x*y;}

};

class B : public A {

public:

int Test(int x) { return x*x*x;}

};

 Overridden

 Overloaded

 Both

 None of the given options

Correct Option:
✅ Overridden

Subject Code: EDU406 - Critical Thinking and Reflective Practice

Question # 1:
What are the four steps involved in Socratic method?

 ❌ design, discuss, apply, reflect

 ❌ question, clarify, experience, review


 ✅ elicit, clarify, test, decide

 ❌ plan, formulate, implement, evaluate

Question # 2:
Which of the following is the lowest level of cognitive domain in Bloom's Taxonomy?

 ✅ Knowledge

 ❌ Synthesis

 ❌ Analysis

 ❌ Reflection

Question # 3:
In Socratic method, how many types of questions are used to develop thinking from lower to higher
order?

 ❌ Five

 ❌ Four

 ❌ Three

 ✅ Six

Question # 4:
In terms of goal setting, what does the acronym SMARTER stand for?

 ✅ specific, measurable, action-oriented, realistic, time-bound, energizing and relevant

 ❌ specific, meaningful, applicable, realistic, transferable, energizing and relevant

 ❌ specific, measurable, action-oriented, repeatable, time-bound, energizing and relevant

 ❌ specific, measurable, achievable, realistic, thoughtful, energizing and relevant

Question # 5:
Socratic method focuses on ___________.

 ❌ Problem solving

 ❌ Brainstorming
 ✅ Questioning

 ❌ Inquiry

Question # 6:
How many parts Ghayle's process of development can be divided into?

 ❌ Four parts

 ✅ Five parts

 ❌ Two Parts

 ❌ Three parts

Question # 7:
Which one of the following terms is used for memory improvement techniques and strategies?

 ❌ Chunking

 ✅ Mnemonic

 ❌ Heuristic

 ❌ Acronym

Question # 8:
‘Does this all make sense together? This question belongs to which type of Socratic questioning?

 ❌ Relevance

 ❌ Equity

 ❌ Precision

 ✅ Logic

Question # 9:
What does learning from day to day chaos means?

 ❌ Learning throughout the year

 ❌ Learning alone

 ✅ Learning from day to day experience


 ❌ Learning from others

Question # 10:
In Socratic method, questions of assumption force the reflective practitioner to look at the information
and ___________ it.

 ❌ Analyze

 ✅ Evaluate

 ❌ Understand

 ❌ Remember

Question #1
For the given class definition, which one is correct?

cpp

Copy code

#include<iostream>

using namespace std;

class A{

int x, y;

public:

int Add(int a, int b) { return a + b; }

int Add(int c) { return c; }

};

 Function Add has an error

 Function Add is overridden

 None of the given options

 Function Add is overloaded ✅


Question #2
In case of public inheritance between Base class A and Derived class B, which of the following data
members of Base class will be hidden in Derived class?

 both public and private

 public

 private ✅

 protected

Question #3
There are ________ types of inheritance in C++.

 4✅

 1

 3

 2

Question #4
In the above class, the method Test is_______.

cpp

Copy code

class A {

public:

int Test(int x) { return x*x; }

int Test(int x, int y) { return x*y; }

};

class B : public A {

public:

int Test(int x) { return x*x*x; }

};

 Overridden ✅
 Overloaded

 Both

 None of the given options

Question #5
Which of the following is not the correct type of inheritance in C++?

 secret

 public

 private

 protected

 secret ✅

Question 1:
virtual void print(); is an example of_________________.

 virtual function ✔️

 pure virtual function

 simple function

 template function

Question 2:
What does a C++ template allow you to do?

 None of the given

 Define multiple main functions in a program

 Create new data types dynamically at runtime

 Write functions or classes that can operate with different data types ✔️

Question 3:
A class with pure virtual function is called ________ class.

 solid

 concrete
 normal

 abstract ✔️

Question 4:
How can you define a class template in C++?

 template<class T> MyClass { ... };

 template<typename T> class MyClass { ... }; ✔️

 template<name T> class MyClass { ... };

 template<type T> class MyClass { ... };

Question 5:
Which keyword is used to define a template in C++?

 function

 typename

 class

 template ✔️

Question 6:
What is the purpose of explicit specialization in templates?

 To improve runtime performance

 To simplify the template syntax

 To handle specific data types that the template cannot handle successfully ✔️

 To avoid the use of templates

Question 7:
Virtual functions can be used in ________ ways.

 8

 0

 6

 2 ✔️
Question 8:
Which of the following is the correct syntax for a function template in C++?

 template void func<class T>(T a);

 func<class T>(T a);

 template<class T> void func(T a); ✔️

 template<type T> func(T a);

Question 9:
Which keyword is used to achieve polymorphism?

 pure virtual

 virtual ✔️

 polymorphism

 poly

Question 10:
Suppose you have a function: void sum();
Choose correct syntax from the given options which will make this function pure virtual function.

 sum()=0;

 virtual void sum()=0; ✔️

 void sum() virtual=0;

 void sum()=0;

Question 1:
Which of the following members of base class can be accessed in the derived class?

 ⬜ Both Public and Private

 ✅ Both Protected and Public

 ⬜ All (Public, Protected, and Private)

 ⬜ Both Protected and Private


Question 2:
If the programmer does not specify the type of inheritance then the default type of inheritance is
____________.

 ⬜ Private

 ⬜ None of the given

 ⬜ Protected

 ✅ Public

Question 3:
In the case of protected inheritance, public members of the base class will be _____________ in the
derived class.

 ⬜ Private

 ✅ Protected

 ⬜ Hidden

 ⬜ Public

Question 4:
What will be the output of the following program?

cpp

Copy code

#include<iostream>

using namespace std;

class FirstNumber

private:

int x;

public:

int y;

FirstNumber () { x = 0; y = 10; }
};

class SecondNumber: public FirstNumber

int z;

public:

int w;

SecondNumber () : FirstNumber ()

z = 20;

w = y + z;

cout<<w;

};

int main()

SecondNumber Obj;

return 0;

 ⬜ 30

 ⬜ 20

 ✅ 40

 ⬜ 10

Question 5:
Consider the code below,

cpp

Copy code
class class1{

public:

void func1();

};

class class2 : public class1 { };

Function func1() of class1 is ______ in class2.

 ⬜ Private

 ⬜ Hidden

 ⬜ Protected

 ✅ Public

Question 1:
If the programmer does not specify the type of inheritance then the default type of inheritance is
____________.

 ⬜ Protected

 ⬜ Private

 ✔ Public

 ⬜ None of the given

Question 2:
Which of the following members of the base class can be accessed in the derived class?

 ⬜ All (Public, Protected, and Private)

 ⬜ Both Public and Private

 ⬜ Both Protected and Private

 ✔ Both Protected and Public

Question 3:
In the case of private inheritance, public members of the base class will be _____________ in the
derived class.
 ⬜ Protected

 ⬜ Public

 ✔ Private

 ⬜ Hidden

Question 4:
Consider the code below,

cpp

Copy code

class class1{ public: void func1(); };

class class2 : public class1 { };

Function func1() of class1 is ______ in class2.

 ⬜ Hidden

 ✔ Public

 ⬜ Private

 ⬜ Protected

Question 5:
In the case of public inheritance, private members of the base class will be _____________ in the
derived class.

 ⬜ Public

 ⬜ Protected

 ⬜ Private

 ✔ Hidden

Question # 1:

Which of the following members of base class can be accessed in the derived class?

 Both Protected and Public ✅


 Both Protected and Private

 All (Public, Protected, and Private)

 Both Public and Private

Question # 2:

What will be the output of the following program?

cpp

Copy code

#include<iostream>

using namespace std;

class FirstNumber

private:

int x;

public:

int y;

FirstNumber () { x = 0; y = 10; }

};

class SecondNumber: public FirstNumber

int z;

public:

int w;

SecondNumber () : FirstNumber ()

z = 20;
w = y + z;

cout<<w;

};

int main()

SecondNumber Obj;

return 0;

 30 ✅

 10

 20

 40

Question # 3:

In the case of public inheritance, private members of the base class will be _____________ in the
derived class.

 Protected

 Private

 Hidden

 Public ✅

Question # 4:

Consider the code below,

cpp

Copy code

class class1{

public:
void func1();

};

class class2 : public class1 { };

Function func1() of class1 is ______ in class2.

 Private

 Protected

 Public ✅

 Hidden

Question # 5:

If the programmer does not specify the type of inheritance then the default type of inheritance is
____________.

 Private ✅

 Protected

 Public

 None of the given

Question #1
If the programmer does not specify the type of inheritance then the default type of inheritance is
____________.

 Protected

 Private

 None of the given

 Public ✅

Question #2
What is the name of the Base class in the line below?

cpp

Copy code
class Truck : public Vehicle;

 Truck

 Vehicle ✅

 Public

 None of the given options

Question #3
In the case of public inheritance, private members of the base class will be _____________ in the
derived class.

 Public

 Protected

 Private

 Hidden ✅

Question #4
Which of the following members of the base class can be accessed in the derived class?

 Both Public and Private

 All (Public, Protected, and Private)

 Both Protected and Public ✅

 Both Protected and Private

Question #5
What will be the output of the following program?

cpp

Copy code

#include<iostream>

using namespace std;

class FirstNumber {

private:
int x;

public:

int y;

FirstNumber () { x = 0; y = 10; }

};

class SecondNumber: public FirstNumber {

int z;

public:

int w;

SecondNumber () : FirstNumber () {

z = 20;

w = y + z;

cout << w;

};

int main() {

SecondNumber Obj;

return 0;

 20

 30 ✅

 40

 10
🔥🔥 Paid Vu Lms Handling 🔥🔥
♦ 1 GDB= Rs 100
♦ 1 Quiz= Rs 200
♦ 1 Assignment=Rs 250

💎Agr complete handling krwatey hain 1 subject ki with all activities= Rs 500 (Half
Semester) 💎

LECTURES Play Service Available In Very Low Price. 🖥

🎊🎉80-100% Marks Guaranteed 🎉🎊

🔥 Miss Mehwish:03184148783🔥

You might also like