Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

oops qb sem 3

Uploaded by

VIJAY
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

oops qb sem 3

Uploaded by

VIJAY
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

PANIMALAR ENGINEERING COLLEGE

DEPARTMENT OF CSBS
23CB1301-OBJECT ORIENTED PROGRAMMING
UNIT-I: INTRODUCTION TO C
PART A
1. Define identifier in C. [Remember]
In C programming, an identifier is a name used to identify a variable, function, array,
structure, union, label, or any other user-defined item. Identifiers are fundamental to the
program as they provide a way to refer to data and functions in the code.

Examples of Valid Identifiers

● variable
● sum1
● _count
● TotalAmount
● data_array

2. Define keyword. [Remember]


Keywords are predefined; reserved words used in programming that have special meanings to
the compiler.
Keywords are part of the syntax and they cannot be used as an identifier. Ex: auto, break,
case, char, do, default.

Examples of Keywords in C

● int: Defines an integer variable.


● float: Defines a floating-point variable.
● char: Defines a character variable.
● if: Starts a conditional statement.
● else: Specifies the alternative block of code in a conditional statement.
● for: Starts a for loop.
● while: Starts a while loop.
● return: Returns a value from a function.
● void: Specifies that a function does not return a value.
● struct: Defines a structure.
3. What are data types. [Understand]
A data type in programming is a classification that specifies which type of value a variable
has and what type of mathematical, relational or logical operations can be applied to it
without causing an error. Ex: String, int, float, Boolean.
A data types define the type of data that a variable can hold. They determine the size, layout,
and range of values that the variable can store, as well as the operations that can be performed
on the variable.
4. List out any ten data types. [Apply]
Int
Char
Float
Double
Enum, pointer. array, structure, union, void

5. What is meant by constants? [Understand]


Constants are also like normal variables. But, only difference is their values cannot be
modified by the program once they are defined. Constants refer to fixed values. They are
also called as literals.

Constants can be defined using several methods:

1. #define Preprocessor Directive:

Used to define constant values that can be used throughout the program.

2. const Keyword:

Used to define constant variables whose values cannot be changed after initialization.

6. Define Variables. [Remember]


A variable is a named storage location in memory that holds a value. Variables are used to
store data that can be modified during program execution.
Example:
int age = 25; float temperature = 36.5; char grade = 'A';
In this example, age, temperature, and grade are variables of types int, float, and char,
respectively.
7. How to declare Variables. [Apply]
A variable declaration provides assurance to the compiler that there exists a variable with the
given type and name so that the compiler can proceed for further compilation without
requiring the complete detail about the variable. To declare a variable, you specify the data
type followed by the variable name. Optionally, you can also initialize the variable with a
value during the declaration.
Syntax: Data type Variable name;
8. What is meant by expressions. [Remember]
An expression is any legal combination of symbols that represent a value. Each expression
consists of at least one operand and can have one or more operators. An expression is a
combination of variables, constants, operators, and function calls that produces a value.
Expressions are used to perform computations and assign values to variables.
Example: int result = (a + b) * c;
In this example, (a + b) * c is an expression that calculates the value by adding a and b, then
multiplying the result by c, and assigns this value to the variable result.

9. Define Statements.[ Remember]


a statement is a complete instruction that performs a specific action. Statements form the
building blocks of a C program and include declarations, assignments, function calls, and
control flow commands.
Example: int a = 5; // Declaration statement
a = a + 1; // Assignment statement
printf("%d", a); // Function call statement.
In this example, each line is a statement performing a specific action: declaring a
variable, assigning a value, and calling a function.
10. What is meant by operators.[ Understand]
An operators are symbols that perform operations on one or more operands to produce a
result. These operations can include arithmetic, comparison, logical, bitwise, and assignment
operations.
Examples of operators :"+", "-", "*", "/", "==", "&&", "||", "&", "|", "=", etc..

11. Define Arithmetic operator.[ Remember]


An arithmetic operator performs mathematical operations such as addition, subtraction and
multiplication on numerical values. Ex: +, -, *, /, %.
Examples:
1.Addition (+):int result = 10 + 5; // result is 15
2. Subtraction (-):int result = 10 - 5; // result is 5
3. Multiplication (*):int result = 10 * 5; // result is 50
4. Division (/):int result = 10 / 5; // result is 2
5. Modulus (%):int result = 10 % 3; // result is 1 (remainder of 10 divided by 3)

12. Define logical operator. [Remember]


An expression containing logical operator returns either 0 or 1 depending upon whether
expression results true or false. Logical operators are commonly used in decision making in
C programming. Logical operators in C are used to perform logical operations on boolean
values. They include "&&" (logical AND), "||" (logical OR), and "!" (logical NOT).
Ex: && ||!
13.Define Assignment operator.[ Remember]
An assignment operator is used for assigning a value to a variable.
The most common assignment operator is = Ex: = =+ -= *= /= %=
14.Define Conditional operator.[ Remember]
A conditional operator is a ternary operator that is it works on 3 operands.
Syntax: ConditionalExpression?expression1: expression2
15. Define Branching.[ Remember ]
The C language programs follow a sequential form of execution of statements. Many times it
is required to alter the flow of sequence of instructions. C language provides statements that
can alter the flow of a sequence of instructions. These statements are called as control
statements.
16. List out the types of branching. [Apply]
If Statement The If else Statement Compound Relational tests Nested if Statement Switch
Statement
17. Define Looping. [Remember]
A loop statement allows us to execute a statement or group of statements multiple times.
Looping in C is a programming construct that allows executing a block of code repeatedly
until a specified condition is met. It helps in automating repetitive tasks and iterating over
data structures.
18. List out the types of Looping. [Apply]
1.While loop
2.Do...while loop
3. For loop
4. Nested loops
19. Write down the syntax of if-else statement. [Remember]
If (condition)
Program statement 1;
Else Program statement 2;
20. Define Switch Statement. [Remember]
A switch statement allows a variable to be tested for equality against a list of values. Each
value is called a case, and the variable being switched on is checked for each switch case.
The switch statement in C is a control flow statement used to select one of many code blocks
to be executed based on the value of a variable or expression.
Syntax for a switch statement in C :
witch (expression)
{ case constant1: // code to be executed if expression matches constant1 break;
case constant2: // code to be executed if expression matches constant2 break; // add more
cases as needed
default: // code to be executed if expression doesn't match any constant }

21. Define goto statement. [Remember]


goto statement is highly discouraged in any programming language because it makes difficult
to trace the control flow of a program, making the program hard to understand and hard to
modify. The goto statement in C is a control flow statement used to transfer control to a
labeled statement within the same function.
Syntax: goto label;
//...
label:
// statement(s);

22. Define comma operator. [Remember]


Comma operator represented by ‘,’ ensures the evaluation from left to right, one by one, of
two or more expressions, separated with commas, and result of entire expression is value of
rightmost expression.
Example: int a = 10, b = 20, c = 30;
23. What is the purpose of continue statement : [Understand]
The continue statement in C programming works somewhat like the break statement. Instead
of forcing termination, it forces the next iteration of the loop to take place, skipping any code
in between.
24. Write the syntax of While loop. [Remember]
while(condition) { statement(s); }
25. Define Functions. [Remember]
A function is a group of statements together perform a task. Every C program has at least one
function, which is main ( ), and all the most trivial programs cab define additional functions.
Functions in C are named blocks of code that perform a specific task. They allow
modularizing code, making it more organized, reusable, and easier to maintain.
Syntax: return_type function_name(parameter_list)
{ // Function body
// Statements
return value; // Optional return statement }
27. Write the general form of functions. [Remember]
return _type function_ name( parameter list) { body of the function }
28. List out the parts of function. [Apply]
1.Return type
2.Function name
3.Parameter List
4.Function Body
29. Define return type. [Remember]
A function may return a value. The return_type is the data type of the value the function
returns. Some functions perform the desired operations without returning a value.
Syntax: return_type function_name(parameters) { // Function body }
30.Define Function Prototype. [Remember]
A function prototype in C declares the function before it is defined or used in the program. It
specifies the function's return type, name, and parameter list. Function prototypes enable the
compiler to check the correctness of function calls and ensure consistency between function
declarations and definitions.
Syntax for a function prototype:
return_type function_name(parameter_list);

31. Define Storage Classes. [Remember]


A storage class defines the scope (visibility) and life-time of variables and/or functions within
a C Program. They precede the type that they modify.
We have four different storage classes in a C program − auto
register static extern
32. Define Static Variables.[ Remember]
Static variables have a property of preserving their value even after they are out of their
scope. static variables preserve their previous value in their previous scope and are not
initialized again in the new scope
33. What is meant by Local variables. [Understand]
Variables that are declared inside a function or block are called local variables. They can be
used only by statements that are inside that function or block of code.
Local variables are not known to functions outside their own local variable declaration int
main(){ int a, b; int c;}
34. What is meant by global variables. [Understand]
Global variables are defined outside a function, usually on top of the program. Global
variables hold their values throughout the lifetime of your program and they can be accessed
inside any of the functions defined for the program.
A global variable can be accessed by any function global variable declaration int a, b; int c;
int main(){ }

35.Define Recursion.[ Remember]


Recursion is the process of repeating items in a self-similar way. In programming languages,
if a program allows you to call a function inside the same function, then it is called a
recursive call of the function. S
Syntax: void recursion() { recursion(); } int main() { recursion(); }
36. Define Array.[ Remember]
Arrays a kind of data structure that can store a fixed-size sequential collection of elements of
the same type. An array is used to store a collection of data, but it is often more useful to
think of an array as a collection of variables of the same type.
37. List out the types of array. [Apply]
One Dimensional Arrays
Two Dimensional Arrays
Multi-dimensional Arrays Dynamic Arrays
38. How to pass arrays to functions [Apply]
void myFunction(intparam[10]) { . . . }
39. Define multi-dimensional array. [Remember]
The simplest form of multidimensional array is the twodimensional array. A two-
dimensional array is, in essence, a list of onedimensional arrays. To declare a two-
dimensional integer array of size [x][y]
40. Define Structure.[ Remember]
Structure is another user defined data type available in C that allows combining data items of
different kinds. Structures are used to represent a record.
In C, a structure is a user-defined data type that allows bundling together different types of
data under a single name. Each piece of data within a structure is called a member.
Syntax:
struct structure_name { // member1 declaration // member2 declaration // ... };
41. Define user defined data types. [Remember]
User-defined data types in C are created by the programmer to define a new type that is not
built into the C language. Structures and typedefs are common ways to define user-defined
data types.
Examplee: Typedef: typedef existing_data_type new_data_type;
.42. What is meant by union.[ Understand]
A union is a special data type available in C that allows storing different data types in the
same memory location. You can define a union with many members, but only one member
can contain a value at any given time. Unions provide an efficient way of using the same
memory location for multiple-purpose.
Syntax: union union_name { // member1 declaration // member2 declaration // ... };
43. Define bitwise operator. [Understand]
To perform bit-level operations in C programming, bitwise operators are used.
44. Write the syntax for declaring array. [Understand]
type arrayName [ arraySize ];
EX: double balance[10];
45. Define pointers. [Remember]
Pointers in C are easy and fun to learn. Some C programming tasks are performed more
easily with pointers, and other tasks, such as dynamic memory allocation, cannot be
performed without using pointers
46. Write the syntax of pointers.[ Remember]
data_type * pt_name; * - pointer variable pt_name - name of the variable which needs a
memory location
47. Define File.[ Remember]
A file represents a sequence of bytes, regardless of it being a text file or a binary file. C
programming language provides access on high level functions as well as low level (OS
level) calls to handle file on your storage devices.
48. How to use pointers.[Apply]
define a pointer variable assign the address of a variable to pointer access the value at the
address available in the pointer variable
49. Define Null pointer[Remember]
A pointer that is assigned NULL is called a null pointer EX: intmain( ) { int *ptr =NULL;
Printf("The value of pointer is:", ptr); return 0; }
50. Define pointer to pointer [Remember]
A pointer to pointer is a form of multiple indirections, or a chain of pointers.
51. List out the modes of opening file [Apply]
r, w, a, r+, w+, a+
52. Write the syntax for fclose( ) and fputc ( ) function. [Remember]
intfclose( File *fp ) intfputc ( int c, FILE *fp)
53. Write the operations of file. [Remember]
Create OPen Process Delete Close.
54.What is a command line argument? [Understand]
Command line arguments are a powerful way to pass parameters to a program when it is
executed. They allow users to customize the behavior of the program without modifying its
source code.
Syntax: int main(int argc, char *argv[])
argc: Integer value representing the number of command line arguments passed to the
program, including the name of the program itself.
argv: Array of strings (character pointers) containing the actual command line arguments
passed to the program.

55.How to pass two arguments in command line? [Apply]


Each argument on the command line is separated by one or more spaces, and the operating
system places each argument directly into its own null-terminated string. The second
parameter passed to main() is an array of pointers to the character strings containing each
argument (char *argv[]).

56.What is a preprocessor directive? [Understand]


Preprocessor directives are lines of the source file where the first non-whitespace character is
# , which distinguishes them from other lines of text. The effect of each preprocessor
directive is a change to the text and the result is a transformation of the text that does not
contain the directives nor comments. Preprocessor directives are used for tasks such as
including header files, defining macros, and conditional compilation.

13marks:

1. Write a C program for Arithmetic operators. [Understand]


2. Explain in detail about the Data types in C language with examples. [Understand]
3. Explain in detail about the String functions with its examples. [Understand]
4. Explain in detail about the error handling in C with its example. [Understand]
5. Explain in detail about the pointers in C with its example. [Understand]
UNIT-II:PROGRAMMING IN C++:
2Marks:

1.What is a single line comment in C? [Understand]

"//print Hello World to the screen" is a single-line comment which is ignored by the compiler.
The comment line explains to the user that the 'printf()' function is used to print 'Hello world.
A single-line comment in C is used to add explanatory text or notes within the code. It starts
with // and extends to the end of the line. Single-line comments are ignored by the compiler
and do not affect the program's execution.
Example: #include <stdio.h> int main()
{ // This is a single-line comment
printf("Hello, world!\n"); // This line prints "Hello, world!" return 0; }

2.What are the two types of comments? [Understand

1. Single-line comments: Single-line comments start with // and extend to the end of the
line. They are used to add explanatory text or notes within the code.

Example:

#include <iostream>

int main() { // This is a single-line comment

std::cout << "Hello, world!" << std::endl; // This line prints "Hello, world!" return 0; }

2. Multi-line comments: Multi-line comments start with /* and end with */. They can
span across multiple lines and are used to comment out blocks of code or add longer
explanations.

Example: int main()

{ /* This is a multi-line comment It can span across multiple lines and is useful for
commenting out blocks of code */
std::cout << "Hello, world!" << std::endl; // This line prints "Hello, world!" return 0; }

3.What is scope in C++ with example? [Understand]


In C++, scope refers to the region of the program where a variable or function is accessible.
Variables declared within a certain scope are only accessible within that region and cannot be
used outside of it.
Syntax:
Global Scope: Variables declared outside of all functions
int globalVar; // Global scope
Local Scope: Variables declared within a function or a block.
void someFunction() { int localVar; // Local scope }
When you declare a program element such as a class, function, or variable, its name can only
be "seen" and used in certain parts of your program. The context in which a name is visible is
called its scope. For example, if you declare a variable x within a function, x is only visible
within that function body.

4.What is the scope of a variable name in C++? [Understand]

The scope of a variable in C++ refers to where in the program it can be accessed. It can be
local, limited to a specific block or function; class, accessible within a class definition; or
global, available throughout the entire program.

SYNTAX:

1. Local Scope: void functionName() { // Local variable declaration data_type


variable_name;
2. Class Scope: class ClassName { public: // Class member variable declaration
data_type variable_name; };
3. Global Scope: // Global variable declaration data_type variable_name;

5.What is function declaration &definition in C++ with an example? [Understand]


In C++, a function declaration (or function prototype) specifies the function's name, return
type, and parameters without providing the function's body. It tells the compiler about a
function's existence before its actual definition.
The syntax for a function declaration is: return_type function_name(parameter_list); In this
example, int is the return type of the function, add is the name of the function, and (int x, int
y) is the parameter list that specifies two integer parameters called “x” and “y.”

6.What is ‘this’ function in C++? [Understand]


The 'this' pointer is passed as a hidden argument to all nonstatic member function calls and is
available as a local variable within the body of all nonstatic functions. 'this' pointer is not
available in static member functions as static member functions can be called without any
object (with class name).

7. What is an example of a local variable declaration?


Declaration of Local Variable:

We can also declare the local variables in the header of a “for” statement. In this case it is
executed in the same manner as if it were part of a local variable declaration statement. For
example: for(int i=0;i<=5;i++){……} In above example int i=0 is a local variable
declaration.

8.What are the four parts of a function in C++? [Understand]


The main part of functions is return_type, function_name, parameter and functions body.

9.What are the data types in C++ function? [Understand]

In C++, there are five basic data types: int, float, char, bool, and double. Integers, floating-
point numbers, characters, Boolean values, & double-precision floating-point numbers are
each represented by one of these data types

10.What are the four types of User-defined Function Types in C++. [Understand]
● Function with no argument and no return value.
● Function with no argument but return value.
● Function with argument but no return value.
● Function with argument and return value.

11.What is function overloading in C++ in detail? [Understand]

Overloading is about the same function having different signatures. Overriding is about the
same function, and same signature but different classes connected through inheritance.
Overloading is an example of compiler time polymorphism and overriding is an example of
run time polymorphism.

12.What is function overriding in C++ . [Understand]


Function Overriding in C++

A function is a block of statements that together performs a specific task by taking some
input and producing a particular output. Function overriding in C++ is termed as the
redefinition of base class function in its derived class with the same signature i.e. return type
and parameters.
What is the difference between function overloading and function overriding with an
example?
13.what is the main difference between function overloading and function overridding
in C++. [Understand]
The main difference between overloading and overriding is that overloading occurs when
methods in the same class have the same method name but different parameters, whereas
overriding occurs when two methods have the same method name and parameters.

14.What is type checking in C++? [Understand]


A compiler, or interpreter, performs type checking when it ensures that operations are applied
to data of the correct type. C++ has stronger type checking than C, though not as strong as
that provided by Pascal, which always prohibits attempts to use data of the wrong type.

15.What is the Reference variable in C++.[ Understand]


A reference variable is one that refers to the address of another variable. It represents the
name of another variable, location, or value. Once you initialize the variable references, that
variable will be referred to using the variable name or reference name.
16.What is the passing parameter varaiable in C++. [Understand]
Parameter Passing in C++There are three parameter-passing modes in C++: by value, by
pointer, and by reference. When a parameter is passed by value, the changes made to the
parameter within the function do not affect the value of the actual argument used in the
function call.
17. What is overloading and overriding in C++? [Understand]
Function overloading allows multiple functions to share the same name, but they must have
different parameters. Function overriding allows a method to be redefined with the same
name and signature. 2. Inheritance is not a prerequisite for function overloading.

18. What is type checking in C++? [Understand]


A compiler, or interpreter, performs type checking when it ensures that operations are applied
to data of the correct type. C++ has stronger type checking than C, though not as strong as
that provided by Pascal, which always prohibits attempts to use data of the wrong type.

19. What are the two types of type checking?[ Understand]


The first rule confirms that a variable has a given type if the context maps that variable to that
type. The second rule manipulates the context: first, it typechecks the let-binding itself in the
original context Γ.
20.What is a reference variable with an example? [Understand]
A parameter or variable is an area of storage. In some cases, the variable contains a value, for
example, a particular name or employee ID. In other cases, the variable is a reference variable
, and contains an address that holds the value at run time.

21. What is reference operator in C++ with example? [Understand]


Reference can be created by simply using an ampersand (&) operator. When we create a
variable, then it occupies some memory location. We can create a reference of the variable;
therefore, we can access the original variable by using either name of the variable or
reference.

22. How many types of parameters passed into a function? [Understand]


There are two kinds of parameters: input parameters. the most common kind; they pass
values into functions. Depending on the programming language, input parameters can be
passed in several ways (e.g., call-by-value, call-by-address, call-by-reference).

28.How to pass a parameter by value in C++? [Apply]


Passing values in C++
1. call by value. int triple(int number) { number=number*3; return number; } int main() { i=7;
int j = triple(i) } ...
2. call by reference. Sometimes you want to change a variable by passing it to a function. ...
3. Using const. ...
4. Using const with pointers.
23.What is parameter passing in C++ . [Understand]

Parameter Passing in C++There are three parameter-passing modes in C++: by value, by


pointer, and by reference. When a parameter is passed by value, the changes made to the
parameter within the function do not affect the value of the actual argument used in the
function call.
30. What is the difference between parameter by value and reference? [Understand]

Pass-by-reference: When a method is called, the method arguments reference the same
variable in memory as the caller. Pass-by-value: When a method is called, the caller passes a
copy of the argument variables to the method resulting in two values in memory.12 Jul 2022
24.How to call a pointer in C++? [Apply]
Passing the variable address from the calling function and using them as a pointer inside the
function is called the call-by-pointer. This method allows clearer visibility of functions in
which the value of the passed variables may change.

25.Why do we use the new operator in C++? [Apply]


The new operator denotes a request for memory allocation on the Free Store. If sufficient
memory is available, a new operator initializes the memory and returns the address of the
newly allocated and initialized memory to the pointer variable

26. What is the use of typecast? [Understand]


Type casting, also known as type conversion, is an important concept in Java that allows us to
convert one data type into another. It is useful when we need to perform operations on
different data types or when you want to store a value of one data type into a variable of
another data type.11 Apr 2024

27. What are the 4 casts in C++? [Understand]


Four different cast operators apply to Windows Runtime types: static_cast Operator,
dynamic_cast Operator, safe_cast Operator, and reinterpret_cast Operator. safe_cast and
static_cast throw an exception when the conversion can't be performed; static_cast Operator
also performs compile-time type checking
28.What is the difference between type casting and type conversion? [Understand]
Type casting is a mechanism in which one data type is converted to another data type using a
casting () operator by a programmer. Type conversion allows a compiler to convert one data
type to another data type at the compile time of a program or code.
29.What is an inline function in C++ with an example? [Understand]
An inline function is a function that is expanded in line when it is called. When the inline
function is called whole code of the inline function gets inserted or substituted at the point of
the inline function call. This substitution is performed by the C++ compiler at compile time.
30.What is an inline function in C++ with examples? [Understand]
An inline function is a function that is expanded in line when it is called. When the inline
function is called whole code of the inline function gets inserted or substituted at the point of
the inline function call. This substitution is performed by the C++ compiler at compile time.
31.What is the default value of an argument in C? [Understand]
A C++ default argument is a value in the C++ function declaration automatically assigned by
the compiler if the calling function does not pass any value to that argument. However, if
arguments are passed when the function is called, the default arguments are ignored.
32.What is an example of a default argument? [Understand]
Default arguments are overwritten when calling function provides values for them. For
example, calling of function sum(10, 15, 25, 30) overwrites the value of z and w to 25 and 30
respectively. During calling of function, arguments from calling function to called function
are copied from left to right.

PART B

1. Explain in detail about the function overloading in c++ with examples. . [Understand]
2.Explain in detail about the new and Delete operator with its examples. [Understand]
3.Explain in detail about the inline function in C++ with its examples. [Understand]

PART C
1.Difference between the Passing by value and passing by reference in C++. [Apply]
2.Difference between the Function overloading and function overriding with its examples.
[Apply]
UNIT-3 :OOPs Concepts
PART A
1.What is the essentials for OOPs? [Understand]
There are four fundamental concepts of Object-oriented programming – Inheritance,
Encapsulation, Polymorphism, and Data abstraction.

2.What is the main aim of OOPs?[ Understand]

Object-oriented programming aims to implement real-world entities like inheritance, hiding,


polymorphism etc. in programming. The main aim of OOP is to bind together the data and
the functions that operate on them so that no other part of the code can access this data except
that function.

3.what is Data hiding? [Understand]


Data hiding is an object-oriented programming (OOP) technique specifically used to hide
internal object details (i.e., data members). Data hiding guarantees exclusive data access to
class members only and protects and maintains object integrity by preventing intended or
unintended changes and intrusions.

4.What is abstraction and data hiding? [Understand]


Abstraction is the concept of hiding internal implementation details and expose only the
necessary functionalities or apis to the end users. Data Hiding is the concept of restricting
access to class and instance variables to improve the security aspect of the applications.

5.Why is encapsulation called data hiding? [Understand]


Data encapsulation leads to the very important concept of data hiding. In short, encapsulation
is a method of binding the data and functions together in a capsule to hide the complexity of a
class. In encapsulation, the members inside a class can be public, protected, or private.

6.What is meant by information hiding? [Understand]


Information hiding is a technique to achieve secret communication by embedding
confidential data into public mediums, which is useful for intellectual property protection,
public information protection, and so on.
7.What is meant by encapsulation? [Understand]
Encapsulation is a way to restrict the direct access to some components of an object, so users
cannot access state values for all of the variables of a particular object. Encapsulation can be
used to hide both data members and data functions or methods associated with an instantiated
class or object.

8.Which is data abstraction? [Understand]


Data Abstraction is a process of hiding unwanted or irrelevant details from the end user. It
provides a different view and helps in achieving data independence which is used to enhance
the security of data. The database systems consist of complicated data structures and
relations.

9.What are two differences between data hiding and encapsulation? [Understand]
Two differences between Data Hiding and Encapsulation are as follows: Data hiding focuses
more on data security whereas, encapsulation focuses more on hiding the complexity of the
system. Data hiding focuses on restricting the use of data whereas, encapsulation deals with
wrapping of data and functions.

10.What is procedural abstraction? [Understand]

Procedural abstraction is the process of breaking down a complex problem into smaller, more
manageable steps. By identifying the essential actions that need to be taken in order to solve a
problem, procedural abstraction can help to make the problem-solving process more efficient
and effective.

11.What is the difference between procedural and data abstraction? [Understand]


Data Abstraction refers to the act of representing essential features without including the
background details or explanations whereas whenever the same operations are performed in
different places in a program, there is a chance of Procedural abstraction.

12.What is class and object in C++? [Understand]


Class is a user-defined datatype that has its own data members and member functions
whereas an object is an instance of class by which we can access the data members and
member functions of the class.
Syntax:
class ClassName { public: // data members // member functions };
ClassName objectName;
13.What is the difference between object and instance of a class? [Understand]
The object is an instance of a class. A class is a blueprint or template that describes the
behavior and properties of the objects of the class. When we create an object in Java, we
create an instance of that class that has its own set of properties and can perform actions
based on the behavior defined in the class.

14.What are the difference between classes and objects in C++? [Understand]

Key differences between Class and object


Classes are used to define the structure and behavior of objects, while objects are used to
represent specific entities in a program. Classes are typically defined once and can be used to
create multiple objects, while each is a unique class instance.

15.what is Scope of class in C++? [Understand]


Class scope Names of class members have class scope, which extends throughout the class
definition regardless of the point of declaration. Class member accessibility is further
controlled by the public , private , and protected keywords.

16.What is the scope resolution operator in C++? [Understand]


The Scope Resolution Operator (::) in C++ enables us to access variables, functions, or
classes defined in different scopes. It helps disambiguate identifiers, making code more
organized and manageable. Working with classes allows us to access class members and
methods, even outside the class definition.
17.What does :: in C++ mean? [Understand]
scope resolution operator
Two colons (::) are used in C++ as a scope resolution operator. This operator gives you more
freedom in naming your variables by letting you distinguish between variables with the same
name.

18.what is member function of class in C++. [Understand]

In C++, a member function is a function that is associated with a specific class or object.
These functions are defined within the class definition and provide the ability to perform
operations on the class's data members and interact with other objects of the same class.

19.How many member functions are there in C++? [Understand]

There are 5 types of member functions that are generally provided in C++. Namely, simple,
static, const, inline and friend member functions. Member functions are specific to classes.

20.What is a class member function or method? [Understand]


Class is a blueprint of an object, which has data members and member functions also known
as methods. A method is a procedure or function in the oops concept. A method is a function
that belongs to a class.

21.What is member function in class in C++? [Understand]


Member functions are operators and functions that are declared as members of a class.
Member functions do not include operators and functions declared with the friend specifier.
These are called friends of a class. You can declare a member function as static ; this is called
a static member function.
22.what are the three types of access specifier? [Understand]
In C++, there are three access specifiers:
● public - members are accessible from outside the class.
● private - members cannot be accessed (or viewed) from outside the class.
● protected - members cannot be accessed from outside the class, however, they can be
accessed in inherited classes.

24.What is called access specifier? [Understand]

● Access modifiers (or access specifiers) are keywords in object-oriented languages that set the
accessibility of classes, methods, and other members. Access modifiers are a specific part of
programming language syntax used to facilitate the encapsulation of components.

25.How to access class members in C++? [Apply]


● Accessing data members and member functions: The data members and member functions of
the class can be accessed using the dot('.') operator with the object. For example, if the name
of the object is obj and you want to access the member function with the name printName()
then you will have to write obj.printName().

26.What is the default access specifier in C++ inheritance? [Understand]
If you do not choose an inheritance type, C++ defaults to private inheritance (just like
members default to private access if you do not specify otherwise). That gives us 9
combinations: 3 member access specifiers (public, private, and protected), and 3 inheritance
types (public, private, and protected).

27.What is this keyword in C++? [Understand]


The 'this' keyword in C++ allows you to navigate to the object that is currently running inside
a member function of a class or struct. This enables you to call the member functions and
variables of the object from a function.

28.Why is this pointer used? [Understand]


The pointer which denotes the object calling the member function is known as this pointer.
The this pointer is usually used when there are members in the function with same name as
those of the class members.

29.What is a constructor and destructor in C++? [Understand]


Constructor is called by the compiler whenever the object of the class is created, it allocates
the memory to the object and initializes class data members. A destructor is called by the
compiler when the object is destroyed and its main function is to deallocate the memory of
the object.
30.What is constructor with example? [Understand]
A constructor in Java is similar to a method that is invoked when an object of the class is
created. Here, Test() is a constructor. It has the same name as that of the class and doesn't
have a return type.
31.What is destructor example? [Understand]
A destructor is a member function that is invoked automatically when the object goes out of
scope or is explicitly destroyed by a call to delete or delete[] . A destructor has the same
name as the class and is preceded by a tilde ( ~ ). For example, the destructor for class String
is declared: ~String() .
32.What is an abstract class in C++?
An abstract class is a class that is designed to be specifically used as a base class. An abstract
class contains at least one pure virtual function. You declare a pure virtual function by using
a pure specifier ( = 0 ) in the declaration of a virtual member function in the class declaration.
33.What is friend class in C++ ? [Understand]
Friend Classes in C++

Friend classes are those classes that have permission to access private members of the class in
which they are declared. The main thing to note here is that if the class is made friend of
another class then it can access all the private members of that class.

34.What is friend class with example in C++? [Understand]

C++ Friend class


A friend class can access both private and protected members of the class in which it has
been declared as friend. Let's see a simple example of a friend class. int x =5; friend class B;
// friend class.

35.What is error handling in C++?[Understand]

Exception Handling in C++ is a process to handle runtime errors. We perform exception


handling so the normal flow of the application can be maintained even after runtime errors. In
C++, exception is an event or object which is thrown at runtime. All exceptions are derived
from std::exception class.
36.What are the types of exception handling in C++?[Understand]
Exception handling in C++ consist of three keywords: try , throw and catch : The try
statement allows you to define a block of code to be tested for errors while it is being
executed. The throw keyword throws an exception when a problem is detected, which lets us
create a custom error.

37.What is error handling and its types? [Understand]


What is Error Handling? Error Handling refers to the process of detecting, managing, and
resolving errors and exceptions that occur during data processing and analytics. It involves
implementing mechanisms and strategies to handle unexpected events and ensure data
integrity and reliability.

38.What is the difference between exception and error? [Understand]


Key Differences Between Errors and Exceptions:

Errors indicate unrecoverable system issues beyond program control. In contrast, exceptions
represent unexpected events within the program that can often be handled gracefully.

39.How many types of error are there in C++?[Understand]


There are different types of errors in programming including syntax errors, run-time errors,
linker errors, logical errors, and semantic errors. Syntax errors are the most common type of
error, while run-time errors are often the most challenging to detect.
40.What is error handling and its types? [Understand]
Error Handling refers to the process of detecting, managing, and resolving errors and
exceptions that occur during data processing and analytics. It involves implementing
mechanisms and strategies to handle unexpected events and ensure data integrity and
reliability.

PART-B

1.Explain in detail about the OOPS Concepts. [Understand]


2.Explain in detail about the Classes and Objects in C++. [Understand]
3.Difference between the Constructors and Destructors in C++ with its Example.
[Understand]

PART-C

1.Explain in detail about the Member function of class with its examples. [Understand]
2.Explain in detail about the error handling in C++ with its examples. [Understand]
UNIT-IV: INHERITANCE AND POLYMORPHISM

PART A

1.What is operator overloading in C++ with example? [Understand]


C++ has the ability to provide the operators with a special meaning for a data type, this
ability is known as operator overloading. Operator overloading is a compile-time
polymorphism. For example, we can overload an operator '+' in a class like String so that we
can concatenate two strings by just using +.
2.What is function overloading and operator overloading? ?[Understand]
Function overloading means using a single name and giving more functionality to it. Operator
overloading means adding extra functionality for a certain operator. When an operator is
overloaded, the operator has different meanings, which depend on the type of its operands.

3.What is the difference between operator overloading and overriding in C++?


?[Understand]
The main difference between overloading and overriding is that overloading occurs when
methods in the same class have the same method name but different parameters, whereas
overriding occurs when two methods have the same method name and parameters.

4.What is inheritance in C++ example? ?[Understand]

It allows us to create a new class (derived class) from an existing class (base class). The
derived class inherits the features from the base class and can have additional features of its
own. For example, class Animal { // eat() function // sleep() function }; class Dog : public
Animal { // bark() function };

5.What are the types of inheritance in C++ with example? ?[Understand]


They are as follows:
● Single Inheritance.
● Multiple Inheritance.
● Multilevel Inheritance.
● Hierarchical Inheritance.
● Hybrid Inheritance.
6.What is an example of inheritance? ?[Understand]
What is inheritance in C++ diagram?

Inheritance in C++ refers to the process wherein new classes can inherit properties (objects
and methods) from pre-existing classes. There are multiple benefits to this, like inducing code
reusability, modularity, easier maintenance, and more.

7.What is an example of a single level inheritance in C++??[Understand]


C++ Single Inheritance Example
High speed of the Lamborghini supercar is 275 km/hr. In the above code, we have a class Car
as a base class from which we have derived a subclass Super_Car. Class Super_Car inherits
all the members of the Car class and can be extended to include its properties, as seen from
the output.

8.What is inheritance syntax? ?[Understand]

Syntax of Inheritance in C++

The Basic Syntax for defining the child class and parent class in all types of inheritance in
C++ is as follows: class parent_class{ //class definition of the parent class }; class child_class
: visibility_modeparent_class { //class definition of the child class };

9.What is multiple inheritance in C++ with an example? ?[Understand]


Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes.
The constructors of inherited classes are called in the same order in which they are inherited.
For example, in the following program, B's constructor is called before A's constructor.30 Jun
2023
10.What is a real life example of multiple inheritance? ?[Understand]

A real-time example of multiple inheritance is a class that inherits from both a "Vehicle"
class and an "Electricity-Powered" class, to create a new class called "Electric Vehicle". This
class would have access to both the properties and methods of its parent classes.
11.What is an example of inheritance?
Inheritance is a way of representing real-world relationships between the two. Here's an
example – car, bus, bike – all of these come under a broader category called Vehicle. That
means they've inherited the properties of class vehicles, i.e., all are used for transportation.
12.What is class hierarchy with an example? [Understand]
A class hierarchy or inheritance tree in computer science is a classification of object types,
denoting objects as the instantiations of classes (class is like a blueprint, the object is what is
built from that blueprint) inter-relating the various classes by relationships such as "inherits",
"extends", "is an ...
13.What is an example of hierarchical inheritance? [Understand]
In hierarchical inheritance, all features that are common in child classes are included in the
base class. For example, Physics, Chemistry, Biology are derived from Science class.
Similarly, Dog, Cat, Horse are derived from Animal class.

14.What is a class hierarchy in C++?[Understand]


A class hierarchy represents a set of hierarchically organized concepts. Base classes act
typically as interfaces. They are two uses for interfaces. One is called implementation
inheritance and the other interface inheritance.
15.What is pointer in C++ with example?
Pointers: Pointers in C++ are basically variables that store the memory address of another
variable. intvar=10; int *ptr = &var; References: References work like the alias, which is
another name for a variable that was declared previously with another name.
16.What is pointers and its types? [Understand]
A pointer is a variable whose value is the address of another variable of the same type. The
value of the variable that the pointer points to by dereferencing using the * operator. The
different types of pointers are void, null, dangling, wild, near, far, huge.
17.What is the syntax of pointer? [Understand]

The syntax of declaring a pointer is to place a * in front of the name. A pointer is associated
with a type (such as int and double ) too.
18.What are examples of objects in C++?[Understand]
C++ Object

In C++, Object is a real world entity, for example, chair, car, pen, mobile, laptop etc. In other
words, object is an entity that has state and behavior. Here, state means data and behavior
means functionality. Object is a runtime entity, it is created at runtime.
19.How to initialize a pointer to an object in C++?[Understand]
You need to initialize a pointer by assigning it a valid address. This is normally done via the
address-of operator ( & ). The address-of operator ( & ) operates on a variable, and returns
the address of the variable. For example, if number is an int variable, &number returns the
address of the variable number .
20.What is the syntax for declaring pointer to object? [Understand]
The syntax of declaring a pointer is to place a * in front of the name. A pointer is associated
with a type (such as int and double) too. Naming Convention of Pointers: Include a "p" or
"ptr" as prefix or suffix, e.g., iPtr, numberPtr, pNumber, pStudent.
21.What is an object explain with an example in C++?[Understand]
In C++, an object is an instance of a class that encapsulates data and functionality pertaining
to that data. Suppose a class named MyClass was created, so now it can be used to create
objects. To create an object of MyClass , specify the class name, followed by the object
name.
22.Can we assign one object to another object in C++?[Understand]
In C++, you can assign one object to another using the assignment operator ( = ) if the objects
have the same data type.
23.How to assign a class to another class in C++?[Understand]
Through class conversion, one can assign data that belongs to a particular class type to an
object that belongs to another class type. where '=' has been overloaded for objects of class
type 'B'. Class conversion can be achieved by conversion function which is done by the use of
operator overloading.
24.What is dynamic polymorphism in C++ with an example? [Understand]
Run-time polymorphism, also known as dynamic polymorphism, is achieved through
inheritance and virtual functions. Inheritance is the process of creating a new class from an
existing class, which inherits all the data members and member functions of the base class.
25.What is dynamic binding in C++ with an example? [Understand]

Dynamic binding in C++ is a practice of connecting the function calls with the function
definitions by avoiding the issues with static binding, which occurred at build time. Because
dynamic binding is flexible, it avoids the drawbacks of static binding, which connected the
function call and definition at build time.
26.What is a real life example of polymorphism in C++?[Understand]
Polymorphism in C++

Real life example of polymorphism, a person at the same time can have different
characteristic. Like a man at the same time is a father, a husband, an employee. So the same
person posses different behavior in different situations. This is called polymorphism.
27.What is static and dynamic binding polymorphism in C++?[Understand]
What is the difference between static binding and dynamic binding in C++? In static binding,
the function is bound at the compile time, whereas in dynamic binding, the function is bound
at run time. Static binding is also known as early binding or compile-time polymorphism.
28.What is a virtual function in C++ with example? [Understand]

A virtual function is a member function in the base class that we expect to redefine in derived
classes. For example, class Base { public: void print() { // code } }; class Derived : public
Base { public: void print() { // code } }; The print() method in the Derived class shadows the
print() method in the Base class.
29.What is a virtual base class in C++ with an example? [Understand]

Virtual Class is defined by writing a keyword “virtual” in the derived classes, allowing only
one copy of data to be copied to Class B and Class C (referring to the above example). It
prevents multiple instances of a class appearing as a parent class in the inheritance hierarchy
when multiple inheritances are used.
30.What is a virtual class in OOP? [Understand]
In object-oriented programming, a virtual base class is a nested inner class whose functions
and member variables can be overridden and redefined by subclasses of an outer class.
Virtual classes are analogous to virtual functions.
PART-B

1.Explain in detail about the operator overloading in C++ with its examples.[Understand]
2.Explain in detail about the types of inheritance and with its examples.[Understand]
3.Explain in detail about the Error handling in C++.[Understand]
PART-B

1.Explain in detail about the ponters to objects in C++ with its examples.[Understand]
2.Difference between the Overloading and Overridding in C++ with its
examples.[Understand]
UNIT-V
GENERIC PROGRAMMING AND I/O STREAMS:
PART-A

1.What is the concept of template in C++? [Understand]


Templates in C++ allow you to write generic and reusable code. They enable functions and
classes to operate with generic types, making it possible to create a function or class to work
with any data type.
Syntax: template <typename T> T functionName(T parameter) { // Function body }
2.What is the concept of function template in C++? [Understand]
Function templates are similar to class templates but define a family of functions. With
function templates, you can specify a set of functions that are based on the same code but act
on different types or classes.
Syntax:
template <typename T> return_type functionName(T parameter1, T parameter2) { //
Function body }

3.What is the use of a template in C++?[Understand]


Templates are pre-formatted documents designed to create commonly used document types
such as letters, fax forms, or envelopes. Some of the advantages of using templates are:
Templates simplify the creation of documents.
4.What type of template function in C++?[Understand]
In C++, there are several types of template functions that you can create to handle different
scenarios. Here are the main types:
Function Template:
This is a basic template function that works with any data type specified at the time of the
function call.
Non-Type Template Parameter:
This template uses non-type parameters (like integers or pointers) along with type
parameters.
Template Specialization:
This allows you to provide a specific implementation of a template for a particular type.
1. Function Template
Syntax:
template <typename T> T functionName(T parameter1, T parameter2) { // Function body }
2. Non-Type Template Parameter
Syntax: template <typename T, int size>

5.What is Template in C++?[Understand]


In C++, a template is a feature that allows functions and classes to operate with generic types.
This enables you to create a function or a class to work with any data type without being
rewritten for each type.
Types of Templates
Function Templates
Class Templates
1. Function Templates
A function template works with any data type. You define a template using the template
keyword followed by template parameters inside angle brackets.
Syntax:
cpp
Copy code
template <typename T>
return_type functionName(T parameter) {
// Function body
}
2. Class Templates
A class template allows you to create a class that can operate with any data type.
Syntax:
cpp
Copy code
template <typename T>
class ClassName {
public:
T data;
// Member functions
};

6.How Do Templates Work? [Apply]


Templates are expanded at compiler time. This is like macros. The difference is, that the
compiler does type-checking before template expansion. The idea is simple, source code
contains only function/class, but compiled code may contain multiple copies of the same
function/class.

7.What is a class template in C++? [Understand]


A class template describes a set of related classes or data types that differ only by types, by
integral values, by pointers or references to variables with global linkage, or by a
combination thereof. Class templates are particularly useful in describing generic, but type-
safe, data structures.
8.What is template function in C++ with example? [Understand]

A template is a simple yet very powerful tool in C++. The simple idea is to pass the data type
as a parameter so that we don't need to write the same code for different data types. For
example, a software company may need to sort() for different data types.
9.What are class templates also called? [Understand]
Generic programming is an approach where generic data types are used as parameters in
algorithms so that they work for variety of suitable data types. Templates are sometimes
called parameterized classes or functions.
10.What is a function in C++ with an example? [Understand]
A function definition provides the actual body of the function. The C++ standard library
provides numerous built-in functions that your program can call. For example, function
strcat() to concatenate two strings, function memcpy() to copy one memory location to
another location and many more functions.
11.What is a function template in class? [Understand]
A class template definition must declare the class data and function members, as in the
following examples. template <class Elem> class Array { Elem* data; int size; public: Array(
intsz ); intGetSize(); Elem& operator[]( intidx ); }; template <unsigned Size> class String {
char data[Size];
12.What is a template specialization in C++?[Understand]
Template Specialization (C++)

A template has multiple types and only some of them need to be specialized. The result is a
template parameterized on the remaining types. A template has only one type, but a
specialization is needed for pointer, reference, pointer to member, or function pointer types.
13.How to declare a template? [Apply]
Class Template Declaration

A class template starts with the keyword template followed by template parameter(s) inside
<> which is followed by the class declaration. template <class T> class className{ private:
T var; ... .. ... public: T functionName(T arg); ... .. ... };
14.What is typename in C++ template? [Understand]
In template definitions, typename provides a hint to the compiler that an unknown identifier
is a type. In template parameter lists, it's used to specify a type parameter.
15. what is the Stream Class Hierarchy in C++.[Understand]
istream is a general purpose input stream. cin is an example of an istream.
ostream is a general purpose output stream. cout and cerr are both examples of ostreams.
ifstream is an input file stream. ...
ofstream is an output file stream.
16.What is a file stream in C++? [Understand]
A stream is an abstraction that represents a device on which operations of input and output
are performed. A stream can be represented as a source or destination of characters of
indefinite length depending on its usage. In C++ we have a set of file handling methods.
These include ifstream, ofstream, and fstream
17.What is stream in Oops? [Understand]
A stream is a general name given to a flow of data. Each stream has a source and a
destination. For output stream, the source is always memory variable and the destination is
the file in which the data is to be written. For input stream, it is the reverse.
16.What are the advantages of streams in C++?[Understand]
C++ stream objects provide two advantages over their C counterparts: The C++ compiler
determines the type of variable being read or written and the stream I/O operators
automatically convert an input value to the appropriate type and automatically convert an
output value to an appropriate printed string.
18.What is a stream and a file? [Understand]
A file stream is a sequence of bytes used to hold file data. Usually a file has only one file
stream, namely the file's default data stream. However, on file systems that support multiple
data streams, each file can have multiple file streams. One of these streams is the default data
stream, which is unnamed.
19.What is stream class in C++ with an example? [Understand]

A C++ stream is a flow of data into or out of a program, such as the data written to cout or
read from cin. For this class we are currently interested in four different classes: istream is a
general purpose input stream. cin is an example of an istream.
20. what are the library functions in C++.[Understand]

Function Description Example(s)

iostream Input/output Controls for input and output

cstring Functions for strings Create string variables\compare strings

cstdlib Miscellaneous utilities Memory allocation\numeric string conversion\process control

ctime Date and time running time\clock\time calculations/conversions


21.What is the type of library in C++?[Understand]

We learned the basics of C++ libraries: There are 2 types of libraries: static library and
dynamic(shared) library. Static libraries are copied into the executable at compile time.
Dynamic libraries are not copied, but loaded and linked at runtime.
22.What is formatted Input and formatted output in C++?[Understand]
Formatting Output in C++

cout<< "M = " << M << " and " G = " << G; In each case, the value of the string or variable
is printed using a default format.

Formatted Input Method

In this method the variables are read from a fixed starting point until a space is encountered.
As every variable has a fixed starting point, the number of columns between any pair of
variables becomes the width of the first variable.

PART-B

1.Explain in detail about the Template function in C++ with its examples.[Understand]
2.Explain in detail about the Class Template in C++ with its examples.[Understand]
3.Difference between the Function Template and Class Template in C++ with its
examples.[Understand]
PART-C

1.Explain in detail about the Streams in C++ with its examples.[Undersatand]


2. Explain in detail about the Formatted Input function and Formatted output function in
C++ with its examples[Understand].

You might also like