Anda di halaman 1dari 15

GENERAL C++ VIVA QUESTIONS

• P is an object pointer to a class student with data member mark. Select the correct
method of accessing from the following list:
a) P.mark
b) P::mark
c) P*mark
d) P→mark

2. Divya wrote a C++ function that allocates memory for100 integers using new operator.
Identify the problems that may arise if she does not use delete operator in it.

3. int a[5] = {10, 5, 18, 14, 16};


cout<<*(a+2);
What will be the output of the above code.

4. For a geometric system discuss the underlying OOP feature in the following operations
a) To combine data and function as a single unit
b) To define a function perimeter that finds perimeter for different shapes.

5. Identify the type of constructor invoked in the following cases.


a) An object is initialised with another object
b) An object is declared with initial values for the data members

6. Distinguish between
a. Call by value and call by reference
b. Global variable and local variable
c. Class and object
d. Structure and Class
e. Data hiding and encapsulation
f. Simple variable & pointer variable
g. Constants and identifiers
h. Library functions and user defined functions
i. Structure & array
j. ‘a’ and “a”
k. a=5 and a = = 5
Copy constructors are called in following cases:
a) when a function returns an object of that class by value
b) when the object of that class is passed by value as an argument to a function
c) when you construct an object based on another object of the same class
d) When compiler generates a temporary object
Diff. bet. Break and continue
A break statement results in the termination of the statement to which it applies (switch, for,
do, or while). A continue statement is used to end the current loop iteration and return control
to the loop statement.

For which statements does it make sense to use label?


The only statements for which it makes sense to use a label are those statements that can
enclose a break or continue statement.
Some Points to Consider
structures are a way of storing many different values in variables of potentially diff types
under under the same name
2. classes and structures make program modular, easier to modify make things compact
3. useful when a lot of data needs to be grouped together
4. struct Tag {?}struct example {Int x;}example ex; ex.x = 33; //accessing variable of
structure
5. members of a struct in C are by default public, in C++ private
6. unions like structs except they share memory ? allocates largest data type in memory
- like a giant storage: store one small OR one large but never both at the same time
7. pointers can point to struct:
8. C++ can use class instead of struct (almost the same thing) - difference: C++ classes
can include functions as members
9. members can be declared as: private: members of a class are accessible only from
other members of their same class; protected: members are accessible from members
of their same class and friend classes and also members of their derived classes; public:
members are accessible from anywhere the class is visible
10. structs usually used for data only structures, classes for classes that have procedures
and member functions.

• What is inheritance?
• Difference between Composition and Aggregation.
• What is Polymorphism?
• Is class an Object? Is object a class?
• Comment: C++ "includes" behavior .
• What is the use of Operator Overloading?
• Every object has : state, behavior and identity – explain.
• Why constructors have no return type?
• Why destructors invoke in reverse order?
• What is role of constructor?
• Why we need constructors?
• What property of OOP is implemented in Constructors?
• Can destructors be overloaded Yes/No & Why?
• Can constructors be overloaded Yes/No & Why?
• What is difference between default constructor and constructor with default
arguments?
• Can constructor use static variables?
• Does any value is returned by Constructors?
• Why the reference of an object is passed in copy constructor?
• When copy constructor is invoked?
• From the given conditions (1) Sample S1=S2; (2) S1=S2 ; When copy constructor
will invoke.
• if a derived class has no parameters for its constructor but a base class has
parameterized constructor , how the constructor for the derived class would defined?
EXPECTED VIVA questions(SOLVED)

• What is a class?
Class is concrete representation of an entity. It represents a group of objects, which hold similar
attributes and behavior. It provides Abstraction and Encapsulations. Classes are generally declared
using the keyword class.
1. What is an Object? What is Object Oriented Programming?

Object represents/resembles a Physical/real entity. An object is simply something you can


give a name. Object Oriented Programming is a Style of programming that represents a
program as a system of objects and enables code-reuse.
1. What is Encapsulation?

Encapsulation is binding of attributes and behaviors. Hiding the actual implementation and
exposing the functionality of any object. Encapsulation is the first step towards OOPS, is
the procedure of covering up of data and functions into a single unit (called class). Its
main aim is to protect the data from out side world
1. What is Abstraction?

Hiding the complexity. It is a process of defining communication interface for the


functionality and hiding rest of the things.
1. What is Overloading?

Adding a new method with the same name in same/derived class but with different
number/types of parameters. It implements Polymorphism.
1. What is Inheritance?

It is a process in which properties of object of one class acquire the properties of object of
another class.
1. What is an Abstract class?

An abstract class is a special kind of class that cannot be instantiated. It normally contains
one or more abstract methods or abstract properties. It provides body to a class.
1. What is Polymorphism? And its type?
• What do you mean by iostream.h?
· What is inheritance and its type?
· What is the difference b/n public, private and protected?
• Public: The data members and methods having public as access outside the class.
• Protected: The data members and methods declared as protected will be accessible to
the class methods and the derived class methods only.
• Private: These data members and methods will be accessibl not from objects created
outside the class.
1. What is a void return type?
A void return type indicates that a method does not return a value.
1. What is the difference between a while statement and a do statement?
A while statement checks at the beginning of a loop to see whether the next loop
iteration should occur. A do statement checks at the end of a loop to see whether
the next loop iteration should occur..
1. What is a nested class? Why can it be useful?
A nested class is a class enclosed within the scope of another class. For example:
// Example 1: Nested class // class Outer Class {class Nested Class {// …}; //...
1. What is inline function?
Normally, a function call transfers the control from the calling program to the function
and after the execution of the program returns the control back to the calling
program after the function call. These concepts of function saved program space and
memory space are used because the function is stored only in one place and is only
executed when it is called. This concept of function execution may be time consuming
since the registers and other processes must be saved before the function gets called.

The extra time needed and the process of saving is valid for larger functions. If the
function is short, the programmer may wish to place the code of the function in the
calling program in order for it to be executed. This type of function is best handled by
the inline function. In this situation, the programmer may be wondering “why not write
the short code repeatedly inside the program wherever needed instead of going for
inline function?” Although this could accomplish the task, the problem lies in the loss of
clarity of the program. If the programmer repeats the same code many times, there will
be a loss of clarity in the program. The alternative approach is to allow inline functions
to achieve the same purpose, with the concept of functions.
1. What is preprocessor?
The preprocessor is used to modify your program according to the preprocessor
directives in your source code. Preprocessor directives (such as #define) give the
preprocessor specific instructions on how to modify your source code. The
preprocessor reads in all of your include files and the source code you are
compiling and creates a preprocessed version of your source code. This
preprocessed version has all of its macros and constant symbols replaced by
their corresponding code and value assignments. If your source code contains
any conditional preprocessor directives (such as #if), the preprocessor evaluates
the condition and modifies your source code accordingly.
The preprocessor contains many features that are powerful to use, such as
creating macros, performing conditional compilation, inserting predefined
environment variables into your code, and turning compiler features on and off.
For the professional programmer, in-depth knowledge of the features of the
preprocessor can be one of the keys to creating fast, efficient programs.
1. What is the difference between overloading and overriding?
Overloading - Two functions having same name and return
Type, but with different type and/or number of arguments.
Overriding - When a function of base class is re-defined in
the derived class.
1. C++ Memory Management operators
The concept of arrays has a block of memory reserved. The disadvantage with the
concept of arrays is that the programmer must know, while programming, the size
of memory to be allocated in addition to the array size remaining constant. In
programming there may be scenarios where programmers may not know the
memory needed until run time. In this case, the programmer can opt to reserve as
much memory as possible, assigning the maximum memory space needed to tackle
this situation. This would result in wastage of unused memory spaces. Memory
management operators are used to handle this situation in C++ programming
language.
1. What are memory management operators?
There are two types of memory management operators in C++:
• new
• delete
1. What is array and its type?
2. What is the difference b/n array and pointer?
Pointer –pointer is a variables that hold the address of another variable .It is used to
manipulate data using the address, pointer use the * operator to access the data
pointed by them.
Array –array use subscripted [] variable to access and manipulate the data ,array
variables can be equivalently written using pointer expression.
A special function Always called whenever an instance of the class is created.
• Same name as class name
• No return type
• Automatically call when object of class is created
• Used to initialize the members of class
• class Test
{ int a,b;
Test()
{ a=9;b=8; } };

Here Test() is the constructor of Class Test.

1. What is copy constructor?

Constructor which initializes it's object member variables ( by shallow copying) with
another object of the same class. If you don't implement one in your class then compiler
implements one for you.
for example:
• Test t1(10); // calling Test constructor
Test t2(t1); // calling Test copy constructor
Test t2 = t1;// calling Test copy constructor
• Copy constructors are called in following cases:
• when a function returns an object of that class by value
• when the object of that class is passed by value as an argument to a function
• when you construct an object based on another object of the same class

1. What is default Constructor?

Constructor with no arguments or all the arguments has default values. In Above Question
Test() is a default constructor
1. What is friend function?

As the name suggests, the function acts as a friend to a class. As a friend of a class, it can
access its private and protected members. A friend function is not a member of the class.
But it must be listed in the class definition.
1. What is a scope resolution operator?

A scope resolution operator (::), can be used to define the member functions of a class
outside the class.
1. What do you mean by pure virtual functions?

A pure virtual member function is a member function that the base class forces derived
classes to provide. Normally these member functions have no implementation. Pure virtual
functions are equated to zero. class Shape
{ public: virtual void draw() = 0;}
1. What are the advantages of inheritance?
It permits code reusability. Reusability saves time in program development. It encourages
the reuse of proven and debugged high-quality software, thus reducing problem after a
system becomes functional
1. What are virtual functions? Describe a circumstance in which virtual functions would be
appropriate

Virtual functions are functions with the same function prototype that are defined
throughout a class hierarchy. At least the base class occurrence of the function is preceded
by the keyword virtual. Virtual functions are used to enable generic processing of an entire
class hierarchy of objects through a base class pointer. For example, in a shape hierarchy,
all shapes can be drawn. If all shapes are derived from a base class Shape which contains
a virtual draw function, then generic processing of the hierarchy can be performed by
calling every shape’s draw generically through a base class Shape pointer.

1. Distinguish between virtual functions and pure virtual functions

A virtual function must have a definition in the class in which it is declared. A pure virtual
function does not provide a definition. Classes derived directly from the abstract class
must provide definitions for the inherited pure virtual functions in order to avoid becoming
an abstract base class

1. What is the difference between parameter and arguments?

Parameter –While defining method, variable passed in the method are


called parameters.
Arguments-While using those methods value passed to those variables
are called arguments.
Viva-Voice, It is not just the presentation of your project but also the representation of
your professional skills. We will provide you detailed study(in the form of questioner
asked by different professors) on various viva-voices conducted, which will help you to
face viva and score more in your final year project report.
A Person who is taking your viva-voice is completely depends on your explanation about
your project means he/she does not do any home work for taking your viva. They start
studying your project just before 10 minutes of your viva. If your report has some
problem related to index, content, coding don't worry about that you can remove it just
by showing confidence and doing professional talk in front of your professor. We can
classify the all viva questions into four category viz. ABOUT PROJECT TITLE &
PROJECT REPORT, DOCUMENTATION i.e. THEORATICAL KNOWLEDGE,
TESTING OF SOFTWARE AND ABOUT PROGRAMMING.
1. In the first category i.e. “about project title” the few questions are:
a) What is the significance of this title?
b) Why you choose this title?
c) Are you think that this title is suitable for Class XII ?
d) Can you give any other title to your project work?
e) Can you explain your title of the project in 100 words?
h) What does your project do?
i) How much time you taken in Analysis, Coding and Testing
k) What are the uses of the project?
Question-Answers for Viva

Classes:

1. What are inline member functions?

Ans. Functions defined inside a class are inline.

2. What is the difference between ordinary functions and inline functions?

Ans. No function call is made to inline functions as the source code is copied to the program during
compilation whereas in ordinary functions, the control is switched over to the function block when
function is called.

3. What are the situations where the inline functions do not work?

Ans. Inline functions does not work in the following situations

a. functions with return values,or having switch, goto, or loop

b. functions containing static variables

c. a recursive function

d. function having return statement (even if it does not return values)

4. What are the basic differences between a structure and a class?


Ans. Structure has only data members whereas class has both data member and member functions.
By default all members of a structure are public whereas all members of a class are private by
default.

5. What is a friend of a class?

Ans. Any ordinary function (non-member of a class) which has access privileges to the private
members of a class are called friends of a class.

6. Which are the three types of (categories of ) a class function?

Ans. Accessor function – which can only access the data members(not edit it), mutator function –
which can manipulate the data members (getdata(),calculate()), manager function – specific
functions (constructor, destructor)

7. Explain Encapsulation, Data hiding, Data Abstraction with reference to classes.

8. What must be done to make the static data member of a class work?

Ans. Declaration within class and definition outside the class

9. What is the difference between static member function and ordinary member functions:

Ans. Static function of a class can access only the other static members of a class. Static function of a
class is invoked by using the class name instead of object name.

10. How does the memory allocation for member functions and data members take place?

Ans. Member functions are created and placed in memory only once when the class is defined. The
memory is allocated for objects’data members when the objects are declared. All objects share the
same member functions.
11. Name the methods through which polymorphism is exhibited in C++?

Ans. Through operator overloading, function overloading and virtual functions.

12. What are overloaded functions?

Ans. Functions having the same name but which differs in number of type of arguments is called
overloaded functions. It has nothing to do with return types( data type of functions)

13. What contributes to function overloading – function signatures or return type of function – Ans.
function signature

14. Name the various types of constructors- default , parameterized, copy constructor

15. How is a copy constructor called ? Ans – It is called by call by reference only.

16. What is default constructor ?

Ans. A constructor with no arguments or all arguments having default values.

17. What are the uses of scope resolution?

Ans- used to defined methods of a class outside the class, to unhide global variable having the same
name as the local variable in a block

18. What do you mean by temporary instance of a class?

Ans. Objects created for the purpose of execution only. …..

19. The differences between constructors and destructor are:

Ans. constructors can take arguments but destructor can't , constructors can be overloaded but
destructors can't be overloaded.

20. Write a statement in C++ to prove that even primitive data types have constructors . Ans – int
k(2).

21. What are the privileges of friend function of a class- to access the private and protected
members of a class

22. What happens when constructor functions are invoked – objects are create

Revision

23. How many ways of representing an integer – decimal, octal and hexadecimal

24. Which is the standard library –iostream.h

25. Difference between goto and gotoxy – goto is C++ statement and gotoxy () is a function defined
in conio.h

26. Why is char treated as integer? –memory represents char in ASCII codes(numeric)
27. What is the length of escape sequences ? – 1 byte.

28. Name the only data type of which we cannot declare any variables?

Ans. Void

29. Name the fundamental data types of C++

Ans. Int, char, float, double, void.

30. What is the difference between Union and Enumeration?

Ans. Union is when two variables usually of different types sharing the same memory location ( any
one occupies memory at a time). Enumeration is a way of declaring integer constants. Eg. Union
share { int x, char y;};

Enum p{F, S, T};

31. Name an exit controlled and an entry controlled loop.

Ans. Exit controlled – do{…..}while(); Entry controlled – while(){….}

32. Which of the following is not a jump statement? Switch, goto, break, exit.

n. Switch.

33. Which of the following will work only in a loop – break, goto, continue, exit.

Ans. Continue and break.

34. Which is the default data type of C++? – Ans. Int

35. If a function does not have a data type specified which will be its datatype by default ? – Ans. Int

36. What is the default value of a static variable or global variable?

Ans – zero

37. Which are the storage class specifiers in C++?

Ans. Auto, register, extern, static.

38. A function that calls itself for its processing is known as – recursive function

39. Strings are character arrays. The last index of it contains the null-terminated character – ‘\0’.

40. What is the only function all C++ programs must contain? – main()

41. The directives for the preprocessors begin with - #


42. Differences between ‘a’ and “a”- ‘a’ is character of I byte whereas “a” is a string of 2 bytes.

43. What is the difference between int K[2] and int K(2) ? – first is in integer array of size 2 whereas
second is declaring a variable K with initial value 2.

44. Differences between abort() and exit() – abort()- aborts “abnormal termination” exit()- closes all
files and writes the buffered output before termination.

45. biggest number that can be represented by – int (32,767) and unsigned int (65,535)

47. What is the difference between a structure and an array?

Ans. Structures are heterogeneous collection of data whereas arrays are homogenous collection of
data. Members of a structure are referred to by dot operator whereas array elements are referred
to by subscript values.

48. What is the condition of assigning one structure to another?

Ans. Both structures must be of the same type ( same tag name)

49. What is the difference between typedef and reference variable?

Ans. Typedef creates an alternative name for a standard data type whereas reference creates an
alternative name for a variable.

50. What is the function of #define?

Ans. Used to declare symbolic constants and macros.

Inheritance :

51. What is the default inheritance visibility mode? - private (if no visibility is specified it is private)
52. Can a derived class access the private members of the base class? If Yes, how? – can only access
them through the nonprivate members.

53. What is inheritance graph? – derivation form multiple base classes.

54. what is order of constructor and destructor invocation in case of inheritance.?

When object of derived is inherited first the constructor of base class and then the derived class but
for destructor first the destructor of derived class and then the base class is invoked.

55. What is the difference between protected and private members of class –

Ans. protected members are inheritable –private members are not.

56. What is the size of a class without any data member?

1 byte.

57. Which operator can be used prove that the private members of the base class are actually
hidden in the derived (visible ) but not accessible?

ans. Sizeof() operator on the object of the derived class will prove this.

58. What is Virtual Base classes?

Ans. In multiple bases classes are inherited.

59. What is containership or aggregation or containment?

Ans. When a class contains objects of other class types as its members it is called containership

60. Explain Has- A relationship, Is – A relationship.

Ans. When a class inherits from another class, the derived has a IS-A relationship with the base class.
When a class contains the object of another class type – then the class containing the object has a
HAS –A relationship with the contained class.

61. When a subclass is a base class of another class it is – multilevel inheritance.

62. What is function overriding ?

Ans. When a function of base class is re-defined in derived class – it is called function overriding.

63. What is the advantage of inheritance ? Ans – code reusability and saving of programming time.

64. Differentiate between ‘IS-A’ , ‘HAS-A’ and ‘HOLDS-A’ relationship in inheritance.

65. What are visibility modes ? Differentiate between them.

Ans. Private, protected, public.


File handling:

66. by default all files are treated as – text files in C++ ( not binary)

67. explain the file modes – ios::ate, ios::app, ios::noncreate….

68. difference between get() and getline().

69. use of seekg, seekp , tellg, tellp.

70. What is a stream ?

Ans. A sequence of bytes – flow of bytes into or out of a program.

71. Name the stream classes in C++ for I/O – ofstream, ifstream, fstream.

72. Name the member functions belonging to fstream class – get(), seekp(), seekg()

73. What is the difference between binary and text files?

74. Which functions can be used to manage binary files in C++ ?

Ans. Read and Write functions.

75. While writing class objects what is written to files data members or member functions?

Ans. Only data members.

76. How random access is is managed in C++?

Ans. Random access is managed by using seekg(), seekp(), tellg(), tellp() functions.

Pointers:

77. What is the difference between constant pointers and pointer to a constant?

78. What is the disadvantage of calling a function by reference?

Ans. When a function is called by reference method only variables can be passed not constants or
expressions as in call by value method.

79. Which operator is used to refer to the object pointers(class and structure) ?

Ans. Arrow operators ->

80. What is this pointer? - explain

81. State two situations in which this pointer is not used in classes?

Ans. static member functions do not have this pointer and friend functions are not passed this
pointer
82. Which are the two memory management operators in C++.

Ans. New and delete.

83. What is Static memory allocation and dynamic allocation ? static- at compilation time and
dynamic at run time(using NEW operator)

84. What is life time of dynamically allocated memory variable ? – till it is de-allocated.

85. What is memory leak – if the no. of dynamically allotted memory variable are not deleted using
delete –

Arrays ;

86. How are arrays passed to a function? – by reference/pointers and not by value method

87. What do you mean by traversal – processing all data elements of an array is called traversal.

88. What is the size of an array A [-10…..20] ? – 31

89. What is a vector – a numeric one dimensional array.

90. Which are the two ways of memory allocation of a 2-D array – row and column major

91. What is the precondition for a binary search ? – array should be sorted.

92. Stack is – LIFO and Queue is FIFO.

93. Which are the two types of queues ? circular and dequeue

94. Differentiate between arrays, stacks and queues.

95. Merits and demerits of linear and binary search.

Ans. Linear search – demerits takes more iterations to find an element especially if it is towards the
end of array. Array need not be sorted.

96. If arr is an array of integer – is arr++ expression legal – why? (no- base address of a array cannot
be changed)

VIVA-VOCE QUESTIONS FOR C++ CLASS XII


VIVA_VOCE QUESTIOS FOR BOARD PRACTICAL EXAMS
UNIT –I : PROGRAMMING IN C++
Q.1 Define following terms Array, Structure, Class, data-hiding, data abstraction, polymorphism,
inheritance, pointers, constructor, destructor, parameterized constructor, default constructor, copy
constructor, temporary instance, library functions and their header files.
Q.2 Differentiate between ‘IS-A’ , ‘HAS-A’ and ‘HOLDS-A’ relationship in inheritance .
Q.3 What are visibility modes ? Differentiate between them.
Q.4 Define various types of inheritance .
Q.5 How is memory allocated to data members and member function?
Q.6 What is static data member and static member function. What is its use ?
Q.7 How are constructor and destructor executed in inheritance ?
Q.8 How are data-hiding, data-abstraction, encapsulation, polymorphism implemented in c++.
Q.9 What contributes to function overloading – function signatures or return type of function.
Q.10 Difference between array and structures, array and classes
Q.11 Pre-processor directives- #include and #define. NOTE : REVISE CLASS XI
C++ PROGRAMMING DATA FILE HANDLING
Q.1 Use of data-files.
Q.2 Definition of stream, different stream classes, member functions of these stream classes.
Significance of ios flags.
Q.3 difference between text and binary files, get() and read() functions, put() and write() functions
Q.4 use and significance of seekg(),seekp(),tellg(),tellp(),
Q.5 how does eof() works.
UNIT –II : DATA STRUCTURES
Q.1 Differentiate between arrays, stacks and queues.
Q.2 Application of stacks and queues.
Q.3 Merits and demerits of linear and binary search, bubble, selection and insertion sort.
Q.4 Allocation and de-allocation operator new and delete.
Q.5 Linked list, linked stack, linked queue, circular queue, doubly linked queue.

Anda mungkin juga menyukai