-
About the Course 0
CDAC CCAT Study Materials
Crack your CDAC CCAT Exams in first attempt with LMT Study Materials- 📚Complete Study Notes (Concepts & Solved Example)
- 📌 500+ Practice Problems
- 📝 Formula's and tricks
- 👣 Beginner Friendly
- ⭐️ Trusted by 1000+ Students
- 📑 Previous Year Question Papers
- 📚 Section A + Section B + Section C [ All Notes Available ]
The one-stop destination for everything you need for CDAC CCAT Exam Preparations
So let's dive in - Enroll today, Crack the exam & get into top Institute of CDAC and get to work with your Dream CompanyNo items in this section -
Section A [ Quantitative ] 43
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
Lecture2.5
-
Lecture2.6
-
Lecture2.7
-
Lecture2.8
-
Lecture2.9
-
Lecture2.10
-
Lecture2.11
-
Lecture2.12
-
Lecture2.13
-
Lecture2.14
-
Lecture2.15
-
Lecture2.16
-
Lecture2.17
-
Lecture2.18
-
Lecture2.19
-
Lecture2.20
-
Lecture2.21
-
Lecture2.22
-
Lecture2.23
-
Lecture2.24
-
Lecture2.25
-
Lecture2.26
-
Lecture2.27
-
Lecture2.28
-
Lecture2.29
-
Lecture2.30
-
Lecture2.31
-
Lecture2.32
-
Lecture2.33
-
Lecture2.34
-
Lecture2.35
-
Lecture2.36
-
Lecture2.37
-
Lecture2.38
-
Lecture2.39
-
Lecture2.40
-
Lecture2.41
-
Lecture2.42
-
Lecture2.43
-
-
Section A [ Verbal ] 6
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
Lecture3.5
-
Lecture3.6
-
-
Section A [ Logical Reasoning ] 24
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
Lecture4.5
-
Lecture4.6
-
Lecture4.7
-
Lecture4.8
-
Lecture4.9
-
Lecture4.10
-
Lecture4.11
-
Lecture4.12
-
Lecture4.13
-
Lecture4.14
-
Lecture4.15
-
Lecture4.16
-
Lecture4.17
-
Lecture4.18
-
Lecture4.19
-
Lecture4.20
-
Lecture4.21
-
Lecture4.22
-
Lecture4.23
-
Lecture4.24
-
-
Section B 15
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
Lecture5.6
-
Lecture5.7
-
Lecture5.8
-
Lecture5.9
-
Lecture5.10
-
Lecture5.11
-
Lecture5.12
-
Lecture5.13
-
Lecture5.14
-
Lecture5.15
-
-
Section C 6
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
Lecture6.5
-
Lecture6.6
-
-
Quiz 6
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
Lecture7.4
-
Lecture7.5
-
Lecture7.6
-
CPP Programming
1. Introduction To C++
• Limitations Of C Language
• A Brief History of C++ And Characteristics
• C++ Organization
• Object Oriented Programming
• Basic I/O in C++
• Data Types In C++
• Variable
• Escape sequences
• Constants And Keywords
2.
Object Oriented Programming System in C++
• OOPS in C++
• Classes in C++
• Objects in C++
• Abstraction In C++
• Encapsulation In C++
• Inheritance in C++
• Polymorphism in C++
3.
Functions, Constructors, Structures and
Keywords in C++
• Function definition
• Constructors In C++
• Structures in C++
• const Keyword in C++
• static Keyword in C++
4. [Bonus] Extra Topic
• Exception Handling in C++
• Initializer List in C++
• Header Guards in C++
1. Introduction To C++
★ Limitations Of C Language
The limitations of C programming languages are as follows:
• Difficult to debug.
• C allows a lot of freedom in writing code, and that is why you can put an
empty line or white space anywhere in the program. And because there is no
fixed place to start or end the line, so it isn't easy to read and understand the
program.
• C compilers can only identify errors and are incapable of handling exceptions
(run-time errors).
• C provides no data protection.
• It also doesn't feature the reusability of source code extensively.
• It does not provide strict data type checking (for example, an integer value can
be passed for floating datatype).
Categorisation Of High Level Languages
High-level programming languages
The high-level programming languages can be categorized into different types on
the basis of the application area in which they are employed as well as the
different design paradigms supported by them. The high-level programming
languages are designed for use in a number of areas. Each high-level language is
designed by keeping its target application area in mind. Some of the high-level
languages are best suited for business domains, while others are apt in the scientific
domain only. The high-level language can be categorized on the basis of the various
programming paradigms approved by them. The programming paradigms refer to the
approach employed by the programming language for solving the different types of
problem.
1. Categorisation based on Application
On the basis of application area the high level language can be divided into the
following types:
i) Commercial languages
These programming languages are dedicated to the commercial domain and are
specially designed for solving business-related problems. These languages can be
used in organizations for processing handling the data related to payroll, accounts
payable and tax building applications. COBOL is the best example of the commercial
based high-level programming language employed in the business domain.
ii) Scientific languages
These programming languages are dedicated to the scientific domain and are
specially designed for solving different scientific and mathematical problems. These
languages can be used to develop programs for performing complex calculation
during scientific research. FORTRAN is the best example of scientific based
language.
iii) Special purpose languages
These programming languages are specially designed for performing some dedicated
functions. For example, SQL is a high-level language specially designed to interact
with the database programs only. Therefore we can say that the special purpose
high-level language is designed to support a particular domain area only.
iv) General purpose languages
These programming languages are used for developing different types of software
applications regardless of their application area. The various examples of general
purpose high-level programming languages are BASIC, C, C++, and java.
2.
Categorisation based on Design paradigm
On the basis of design paradigms the high level programming languages can be
categorised into the following types:
i) Procedure-oriented languages
These programming languages are also called an imperative programming language.
In this language, a program is written as a sequence of procedures. Each procedure
contains a series of instructions for performing a specific task. Each procedure can be
called by the other procedures during the program execution. In this type of
programming paradigms, a code once written in the form of a procedure can be used
any number of times in the program by only specifying the corresponding procedure
name. Therefore the procedure-oriented language allows the data to move freely
around the system. The various examples of procedure-oriented language are
FORTRAN, ALGOL, C, BASIC, and ADA.
ii) Logic-oriented languages
These languages use logic programming paradigms as the design approach for
solving various computational problems. In this programming paradigm predicate
logic is used to describe the nature of a problem by defining the relationship between
rules and facts. Prolog is the best example of the logic-oriented programming
language.
iii) Object-oriented languages
These languages use object-oriented programming paradigms as the design approach
for solving a given problem. In this programming language, a problem is divided into
a number of objects which can interact by passing messages to each other. C++ and C# are
examples of object-oriented programming languages.
★ A Brief History of C++
• The history of C++ begins with C. The reason for this is easy to understand:
C++ is built upon the foundation of C. Thus, C++ is a superset of C.
• C++ expanded and enhanced the C language to support object-oriented
programming (which is described later in this module).
• C++ also added several other improvements to the C language, including an
extended set of library routines. However, much of the spirit and flavor of C++
is directly inherited from C. Therefore, to fully understand and appreciate C++,
you need to understand the “how and why” behind C.
• C++ is regarded as a middle-level language, as it comprises a combination of
both high-level and low-level language features.
• The C++ programming language was created by Bjarne Stroustrup and his team
at Bell Laboratories (AT&T, USA) to help implement simulation projects in an
object-oriented and efficient way. The earliest versions, which were originally
referred to as “C with classes,” date back to 1980. As the name C++ implies,
C++ was derived from the C programming language: ++ is the increment
operator in C.
Characteristics of C++
C++ is not a purely object-oriented language but a hybrid that contains the
functionality of the C programming language. This means that you have all the
features that are available in C:
• Universally usable modular programs
• Efficient, close to the machine programming
• Portable programs for various platforms.
★ C++ Organization
• C++ is designed as a bridge between the programmer and the raw computer.
• The idea is to let the programmer organize a program in a way that he or she
can easily understand.
• The compiler then translates the language into something the machine can use.
• Computer programs consist of two main parts: data and instructions. The
computer imposes little or no organization on these two parts.
• After all, computers are designed to be as general as possible. The idea is for
the programmer to impose his or her own organization on the computer and
not the other way around.
C++ Compilation Process
It is fundamental to know how C++ compilation works to understand how programs
are compiled and executed. Compiling C++ source code into machine-readable code
consists of the following four processes:
1. Preprocessing the source code.
2. Compiling the source code.
3. Assembling the compiled file.
4. Linking the object code file to create an executable file.
Let's start with a simple C++ program to understand how compilation happens.
#include <iostream>
int main(){
// This is a single line comment
/* This is a multi-line
comment */
std::cout << "Hello Universe" << std::endl;
return 0;
}
Let's demystify the C++ compilation process using the following diagram:
1. When the C++ preprocessor encounters the #include <file> directive, it
replaces it with the content of the file creating an expanded source code file.
2. Then, this expanded source code file is compiled into an assembly language
for the platform.
3. The assembler converts the file that's generated by the compiler into the object
code file.
4. This object code file is linked together with the object code files for any
library functions to produce an executable file.
Difference Between Header and Source Files
Source files contain the actual implementation code. Source files typically have the
extension .cpp, although other extensions such as .cc, .ccx, or .c++ are also quite
common.
On the other hand, header files contain code that describes the functionalities that are
available. These functionalities can be referred to and used by the executable code in
the source files, allowing source files to know what functionality is defined in other
source files.
Compiling And Linking Process
Compilation is a process that ensures that a program is syntactically correct, but it
does not perform any checks regarding its logical correctness. This means that a
program that compiles correctly might still produce undesired results:
Every C++ program needs to define a starting point, that is, the part of the code the
execution should start from. The convention is to have a uniquely named main
function in the source code, which will be the first thing to be executed. This function
is called by the operating system, so it needs to return a value that indicates the status of
the program; for this reason, it is also referred to as the exit status code.
★ Object-Oriented Programming
Central to C++ is object-oriented programming (OOP). As just explained, OOP was
the impetus for the creation of C++. Because of this, it is useful to understand OOP’s
basic principles before you write even a simple C++ program.
Object-oriented programming offers several major advantages to software
development:
• Reduced susceptibility to errors: an object controls access to its own data.
More specifically, an object can reject erroneous access attempts.
• Easy re-use: objects maintain themselves and can therefore be used as
building blocks for other programs.
• Low maintenance requirement: an object type can modify its own internal
data representation without requiring changes to the application.
A First Simple C++ Program
/* This is a simple C++ program. Call this file Sample.cpp. */
#include<iostream>
using namespace std;
// A C++ program begins at main().
int main()
{
cout << "C++ is power programming.";
return 0;
}
Output
/* When run, the program displays the following output:*/
C++ is power programming.
★ Basic I/O in C++
The C++ standard libraries provide an extensive set of input/output capabilities which
we will see in subsequent chapters. This chapter will discuss very basic and most
common I/O operations required for C++ programming.
C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device
like a keyboard, a disk drive, or a network connection etc. to main memory, this is
called input operation and if bytes flow from main memory to a device like a display
screen, a printer, a disk drive, or a network connection, etc., this is called output
operation.
I/O Library Header Files
There are following header files important to C++ programs −
The Standard Output Stream (cout)
The predefined object cout is an instance of ostream class. The cout object is said to
be "connected to" the standard output device, which usually is the display screen. The
cout is used in conjunction with the stream insertion operator, which is written as <<
which are two less than signs as shown in the following example.
#include <iostream>
using namespace std;
int main() {
char str[] = "Hello C++";
cout << "Value of str is : " << str << endl;
}
When the above code is compiled and executed, it produces the following result −
Value of str is : Hello C++
The C++ compiler also determines the data type of variable to be output and selects
the appropriate stream insertion operator to display the value. The << operator is
overloaded to output data items of built-in types integer, float, double, strings and
pointer values.
The insertion operator << may be used more than once in a single statement as shown
above and endl is used to add a new-line at the end of the line.
The Standard Input Stream (cin)
The predefined object cin is an instance of istream class. The cin object is said to be
attached to the standard input device, which usually is the keyboard. The cin is used
in conjunction with the stream extraction operator, which is written as >> which are
two greater than signs as shown in the following example.
#include <iostream>
using namespace std;
int main() {
char name[50];
cout << "Please enter your name: ";
cin >> name;
cout << "Your name is: " << name << endl;
}
When the above code is compiled and executed, it will prompt you to enter a name.
You enter a value and then hit enter to see the following result −
Please enter your name: cplusplus
Your name is: cplusplus
The C++ compiler also determines the data type of the entered value and selects the
appropriate stream extraction operator to extract the value and store it in the given
variables.
The stream extraction operator >> may be used more than once in a single statement.
To request more than one datum you can use the following −
cin >> name >> age;
This will be equivalent to the following two statements −
cin >> name;
cin >> age;
The Standard Error Stream (cerr)
The predefined object cerr is an instance of ostream class. The cerr object is said to
be attached to the standard error device, which is also a display screen but the object
cerr is un-buffered and each stream insertion to cerr causes its output to appear
immediately.
The cerr is also used in conjunction with the stream insertion operator as shown in
the following example.
#include <iostream>
using namespace std;
int main() {
char str[] = "Unable to read
";
cerr << "Error message : " << str << endl;
}
When the above code is compiled and executed, it produces the following result −
Error message : Unable to read
The Standard Log Stream (clog)
The predefined object clog is an instance of ostream class. The clog object is said to
be attached to the standard error device, which is also a display screen but the object
clog is buffered. This means that each insertion to clog could cause its output to be
held in a buffer until the buffer is filled or until the buffer is flushed.
The clog is also used in conjunction with the stream insertion operator as shown in
the following example.
#include <iostream>
using namespace std;
int main() {
char str[] = "Unable to read
";
clog << "Error message : " << str << endl;
}
When the above code is compiled and executed, it produces the following result −
Error message : Unable to read
You would not be able to see any difference in cout, cerr and clog with these small
examples, but while writing and executing big programs the difference becomes
obvious. So it is good practice to display error messages using cerr stream and while
displaying other log messages then clog should be used.
★ Datatypes In C++
There are 4 types of data types in C++ language.
Basic Data Types
The basic data types are integer-based and floating-point based. C++ language
supports both signed and unsigned literals.
The memory size of basic data types may change according to the 32 or 64 bit
operating system.
Let's see the basic data types. Its size is given according to 32 bit OS.
Derived Data Types
The data-types that are derived from the primitive or built-in datatypes are referred to
as Derived Data Types. These can be of four types namely:
1. Function
2. Array
3. Pointer
4. Reference
Abstract or User-Defined Data Types
These data types are defined by user itself. Like, defining a class in C++ or a
structure. C++ provides the following user-defined datatypes:
1. Class
2. Structure
3. Union
4. Enumeration
5. Typedef defined DataType
Datatype Modifiers
As the name implies, datatype modifiers are used with the built-in data types to
modify the length of data that a particular data type can hold.
Data type modifiers available in C++ are:
Signed
• Unsigned
• Short
• Long
Below table summarizes the modified size and range of built-in datatypes when
combined with the type modifiers:
★ Variables
A variable is a name of memory location. It is used to store data. Its value can be
changed and it can be reused many times.
It is a way to represent memory location through symbol so that it can be easily
identified.
Let's see the syntax to declare a variable:
1. int x;
2. float y;
3. char z;
Here, x, y, z are variables and int, float, char are data types.
We can also provide values while declaring the variables as given below:
1. int x=5,b=10; //declaring 2 variable of integer type
2. float f=30.8;
3. char c='A';
Rules for defining variables
1. A variable can have alphabets, digits and underscore.
2. A variable name can start with an alphabet and underscore only. It can't start
with a digit.
3. No white space is allowed within the variable name.
4. A variable name must not be any reserved word or keyword e.g. char, float
etc.
5. Valid variable names:
• int a;
• int _ab;
• int a30;
6. Invalid variable names:
• int 4;
• int x y;
• int double;
Scope Of Variables
In general, the scope is defined as the extent up to which something can be worked
with. In programming also the scope of a variable is defined as the extent of the
program code within which the variable can be accessed or declared or worked with.
There are mainly two types of variable scopes:
1. Local Variables
2. Global Variables
Now let’s understand each of the scope at a greater detail:
Local Variables
Variables defined within a function or block are said to be local to those functions.
• Anything between ‘{‘ and ‘}’ is said to inside a block.
• Local variables do not exist outside the block in which they are declared, i.e.
they can not be accessed or used outside that block.
• Declaring local variables: Local variables are declared inside a block.
// CPP program to illustrate
// usage of local variables
#include<iostream>
using namespace std;
void func(){
// this variable is local to the
// function func() and cannot be
// accessed outside this function
int age=18;
}
int main() {
cout<<"Age is: "<<age;
return 0;
}
Output:
Error: age was not declared in this scope
The above program displays an error saying “age was not declared in this scope”. The
variable age was declared within the function func() so it is local to that function and
not visible to portion of program outside this function.
Rectified Program : To correct the above error we have to display the value of
variable age from the function func() only. This is shown in the below program:
// CPP program to illustrate
// usage of local variables
#include<iostream>
using namespace std;
void func()
{
// this variable is local to the
// function func() and cannot be
// accessed outside this function
int age=18;
cout<<age;
}
int main()
{
cout<<"Age is: ";
func();
return 0;
}
Output:
Age is: 18
Global Variables
As the name suggests, Global Variables can be accessed from any part of the
program.
• They are available throughout the lifetime of a program.
• They are declared at the top of the program outside all of the functions or
blocks.
• Declaring global variables: Global variables are usually declared outside of
all of the functions and blocks, at the top of the program. They can be
accessed from any portion of the program.
// CPP program to illustrate
// usage of global variables
#include<iostream>
using namespace std;
// global variable
int global = 5;
// global variable accessed from
// within a function
void display()
{
cout<<global<<endl;
}
// main function
int main()
{
display();
// changing value of global
// variable from main function
global = 10;
display();
}
Output:
5
10
In the program, the variable “global” is declared at the top of the program outside all
of the functions so it is a global variable and can be accessed or updated from
anywhere in the program.
What if there exists a local variable with the same name as that of global
variable inside a function?
Let us repeat the question once again. The question is : if there is a variable inside a
function with the same name as that of a global variable and if the function tries to
access the variable with that name, then which variable will be given precedence?
Local variable or Global variable? Look at the below program to understand the
question:
// CPP program to illustrate
// scope of local variables
// and global variables together
#include<iostream>
using namespace std;
// global variable
int global = 5;
// main function
int main()
{
// local variable with same
// name as that of global variable
int global = 2;
cout << global << endl;
}
Look at the above program. The variable “global” declared at the top is global and
stores the value 5 whereas that declared within the main function is local and stores a
value 2. So, the question is when the value stored in the variable named “global” is
printed from the main function then what will be the output? 2 or 5?
• Usually when two variable with the same name are defined then the compiler
produces a compile time error. But if the variables are defined in different
scopes then the compiler allows it.
• Whenever there is a local variable defined with same name as that of a global
variable then the compiler will give precedence to the local variable
★ Escape Sequences
Escape sequences are used in the programming languages C and C++ , and their
design was copied in many other languages such as Java and C# . Escape sequences
are the special characters used in control string to modify the format of the output.
These characters are not displayed in output. These characters are used with
combination of backslash \. This backslash \ is called escape character.
Table of Escape sequence of C & C++ are as follows:
★ Constants
Constants refer to fixed values that the program may not alter and they are called
literals.
Constants can be of any of the basic data types and can be divided into Integer
Numerals, Floating-Point Numerals, Characters, Strings and Boolean Values.
Again, constants are treated just like regular variables except that their values cannot
be modified after their definition.
Keywords
This is a list of reserved keywords in C++. Since they are used by the language, these
keywords are not available for re-definition or overloading.