CS201 Final Term Short Notes
CS201 Final Term Short Notes
#define PI 3.1415926
Directive:
Directive is a language construct that specifies how a compiler should process its
input
Macro:
Memory Allocation:
Dangling Pointers:
Dangling pointer occurs at the time of the object destruction when the object is
deleted or de-allocated from memory without modifying the value of the pointer.
History of C/C++:
C language was developed by scientists of Bell Labs in 1970s. It is very lean and
mean language, very concise but with lot of power. C conquered the programming
world and took it by storm. Major operating systems e.g., Unix was written in C
language.
Structured programming:
Inline functions:
This is also one of the facilities provided by C++ over C. In our previous lectures,
we discussed and wrote macros few macros like max and circlearea. Inline
functions also work more or less in the same manner as macros.
Lecture 26 to 45
Q.1. What is OOP(Object Oriented Programming)
Ans. The core of the pure object oriented programming is to create an object. In
code, that has certain properties and method.
Ans. A class is a user defined data type, which holds its own data members and
member functions, which can be accessed and used by creating an instance of that
class
Ans. Not object is made, Only inheritance can be used that have abstract and
concrete methods, real words existence are not found. Abstract class can not be
instantiated using new keyword. Abstract class may or may not have abstract
method
Ans. Object is made and used, derived and child classes from abstract classes ,
real words existence are found. Concrete class can be instantiated using new
keyword. Concrete class can not have an abstract method
Ans. Data abstraction refers to provide essential information to the outside the
world but hide their background details. i.e to represent the information needed to
the program without presentation the details
For Example: The data base system hides detials how data is stored and created
and maintained.
Ans. Encapsulation is placing the data and function work on that data in the same
place. Only works with procedural languages.
It is not always clear which works on which variables but object oriented
programming provides you framework to place the data that works together in the
same object.
Ans. One of the most useful aspects of object oriented programming is code
reusability. Inheritance is the process of forming a new class from an existing class
that is:
New class is called as derived class and Existing class is called as base class.
Q.10. What is the features to reduce the code size in OPP?
Public inheritance
Protected
Private
Function overloading
Operator overloading
Overloading vs overloading
Ans. We have written a function named Date(int, int, int). This is in the public
section in our class. It has no return type having the name as that of class. Such
function are called constructor.
Ans. A friend function that can access protected, private and public member of a
class. The friend function is declared using friend keyword inside the body of a
class.
Ans. Friend class is a class that can access to private and protected member of a
class which is declared as friend.
For example: This is needed we want to allow particular class to access the private
and protected member of a class.
Q.16. What is reference data type?
Ans. Unlimited numbers of reference data types, as they are defined by the user.
Consists of Boolean and numeric data type, Int, float, long, short and double
Ans. A constructor can have two arguments. They are used to initialize member
objects. If default values are supplied, the trailing arguments can be omitted in the
expression list of the constructor.
Example: Defines a class with one constructor and two default constructor.
A) Unary
B) Binary
Unary: Unary operator requires only ones to the left of the operand on single
operator.
Example: ^, &, !
Binary: Binary operator requires two operands on both side of the operator.
Example: +, -, *, /
In all of these situations, the compiler performs the conversion implicitly. The
conversion explicit is possible by using a cast expression.
Ans. Yes, if we go to the basic definition of a class, it is nothing but a user defined
data type. A class is a user defined data type, we can also define conversion on it.
Ans. New is called before the constructor and Delete is called after the destructor.
A global array called pool that can store all the Name object expected.
Ans: Copying a file in the reverse order means the last byte of the input file will
be the first byte of the output file, second byte of the input file will be the second
byte of the output file until the first byte of the input file becomes the last byte of
the output file.
Ans. A C++ stream is a flow of data into or out of program such as the data written
to cout or read from cin.
All these functions (getline, get read, unget and peek) are implemented as member
function of the input class.
E.g std::cout<<std::setw(10)
Ans. Manipulators are helping functions that can modify the input/output stream. It
does notnot mean that we change the value of variable, it modifies the I/O stream
using insertion(<<) and extraction(>>) operators.
Q.29. What is Non-Parameterized Manipulators and Parameterized
manipulators?
Ans. Insertion operator(<<) is used for output and extraction operators(>>) is used
for input. These operators must be overloaded as a global function.
operator << returns a value of type ostream & and operator >> returns a
value of type istream & to support cascaded operations.
For operator >>, the second parameter must also be passed by reference.
Stream insertion ( << ) and extraction operators ( >> ) are always
implemented as non-member functions.
The second parameter to operator << is an object of the class that we are
overloading the operator for. Similar is the case for operator >>.
Ans. Manipulators are special stream functions that are used to change certain
characteristics of the input and output.
Q.32. What is static keyword and Static objects and Static data members of a
class?
Ans. In java, static keyword is mainly used for memory management. It can be
used with variables, methods, blocks and nested classes. It is a keyword which is
used to share same variable or method of a given class.
Ans. The call by value method of passing arguments to a function copies the actual
value of an argument into the formal parameter of the function.
Ans. The call by reference method of passing arguments to a function copies the
address of an argument into the formal parameter. It means the changes made to
the parameter affect the passed argument.
The use of call by reference is also important for the sake of efficiency
malloc()
calloc()
realloc()
free()
Ans: Initialization gives a variable an initial value at the point when it is created.
Assignment a variable a value at the some point after the variable is created.
Usage: we want to copy a complex object that has several fields. We want to make
a deep copy of an existing object.
Advantages:
Class template can make use of another kind of template parameter known
as non-type parameter.
Non-type parameter is a special type of parameter that does not substitute
for a type, but is instead replaced by a value.
Ans. A template function instantiated with one set of template arguments may
friend to one template class instantiated with the same set of template arguments.
Ans. Mathematics is a good domain to develop different classes and programs. E.g
solutions for complex numbers, Matrices and Quadratic equations can be sought
for developing our own classes.
Design recipe is a roadmap for defining function, which programmers use to
make sure code they write does what they want it to do.
Program analysis is the process of looking at an organization’s intended
social and behavior change communication program and then identifying
enabling.
Ans. A matrix can have a number of rows and columns and each cell of a matrix
can be represented by their combination
A matrix constructor is a special ‘member function having the same name as that
of its class which is used to initialize some valid values to the data members of an
object.
Ans: A destructor is called for a class object. Destructor are usually used to de-
allocate memory and do other cleanup for a class object and its class members
when the object is destroyed.
Q.46. What is addition operator function and minus operator function and
multiplication operator function?
Ans. A utility function transforms an outcome into a numerical value and measure
the worth of an outcome.
1. Input function
2. Transpose function
Transpose function returns a vertical range of cells as a horizontal range or
vice versa.
Input function is used to ask the user of the program a question, and then
wait for a typed response
Most useful operator function in C++ for mcqs
Operator Meaning
=__________Assignment
+__________Concatenation
+=_________Concatenation assignment
==________Equality
!=___________Inequality
<____________Greater than
<=____________Greater than or equal to
>__________less than
>=__________ less than or equal to
>>_________ Reads
>>_________Prints
______________________________________________