0% found this document useful (0 votes)
0 views

Download

The document outlines the similarities and differences between C and C++, highlighting that C++ is a superset of C with added features like Object-Oriented Programming (OOP), Exception Handling, and a more extensive standard library. It explains key OOP concepts such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction. Additionally, it discusses the main() function as the entry point of C++ programs and the role of header files in including predefined functions.

Uploaded by

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

Download

The document outlines the similarities and differences between C and C++, highlighting that C++ is a superset of C with added features like Object-Oriented Programming (OOP), Exception Handling, and a more extensive standard library. It explains key OOP concepts such as classes, objects, inheritance, polymorphism, encapsulation, and abstraction. Additionally, it discusses the main() function as the entry point of C++ programs and the role of header files in including predefined functions.

Uploaded by

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

23CS101 - Problem Solving Using C++

Study Materials
Similarities between C and C++:
• Both the languages have a similar syntax.
• Code structure of both the languages are same.
• The compilation of both the languages is similar.
• They share the same basic syntax. Nearly all of C’s operators and keywords are
also present in C++ and do the same thing.
• C++ has a slightly extended grammar than C, but the basic grammar is the same.
• Basic memory model of both is very close to the hardware.
• Same notions of stack, heap, file-scope and static variables are present in both
the languages.
Differences between C and C++ are:
• C++ is often viewed as a superset of C.
• C++ is also known as a C with class This was very nearly true when C++ was originally
created, but the two languages have evolved over time with C picking up a number of
features that either weren’t found in the contemporary version of C++ or still haven’t
made it into any version of C++.
• That said, C++ is still mostly a superset of C adding Object-Oriented Programming,
Exception Handling, Templating, and a more extensive standard library
C VS C++:
C VS C++:
C VS C++:
Object Oriented Programming:

• Object-Oriented Programming or OOPs refers to languages that use objects in


programming.
• 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.
OOPs Concepts:

• Class
• Objects
• Data Abstraction
• Encapsulation
• Inheritance
• Polymorphism
1. Class:
• A class is a user-defined data type. It consists of data members and member
functions, which can be accessed and used by creating an instance of that class.
• It represents the set of properties or methods that are common to all objects of
one type.
• A class is like a blueprint for an object.
• For Example: Consider the Class of Cars. There may be many cars with different
names and brands but all of them will share some common properties like all of
them will have 4 wheels, Speed Limit, Mileage range, etc. So here, Car is the class,
and wheels, speed limits, mileage are their properties.
2. Object:

• It is a basic unit of Object-Oriented Programming and represents the real-life


entities.
• An Object is an instance of a Class. When a class is defined, no memory is
allocated but when it is instantiated (an object is created) memory is allocated.
• An object has an identity, state, and behavior.
• Each object contains data and code to manipulate the data. Objects can interact
without having to know details of each other’s data or code, it is sufficient to
know the type of message accepted and type of response returned by the
objects.
• For example: Dog is a real-life Object, which has some characteristics like color,
Breed, Bark, Sleep, and Eats.
3.Inheritance:

• Inheritance is a mechanism in which one object acquires all the properties and
behaviors of a parent object.
• It is an important part of OOPs (Object Oriented programming system).
• The idea behind inheritance is that you can create new classes that are built upon
existing classes. There are 5 types of inheritance
• Single-level inheritance
• Multi-level Inheritance
• Hierarchical Inheritance
• Multiple Inheritance
• Hybrid Inheritance.
4.Polymorphism:

• Polymorphism is considered one of the important features of Object-Oriented


Programming.
• Polymorphism allows us to perform a single action in different ways.
• In other words, polymorphism allows you to define one interface and have
multiple implementations. The word “poly” means many and “morphs” means
forms, So it means many forms.

Types of Polymorphism:
• Compile-time Polymorphism
• Runtime Polymorphism
5. Encapsulation:

• Encapsulation is a fundamental concept in object-oriented programming (OOP)


that refers to the bundling of data and methods that operate on that data within
a single unit.
• Encapsulation is a way of hiding the implementation details of a class from
outside access and only exposing a public interface that can be used to interact
with the class.
6. Abstraction:
• Data Abstraction may also be defined as the process of identifying only the
required characteristics of an object ignoring the irrelevant details.
• The properties and behaviours of an object differentiate it from other objects of
similar type and also help in classifying/grouping the objects.
• Consider a real-life example of a man driving a car. The man only knows that
pressing the accelerators will increase the speed of a car or applying brakes will
stop the car, but he does not know how on pressing the accelerator the speed is
actually increasing, he does not know about the inner mechanism of the car or
the implementation of the accelerator, brakes, etc in the car
main() Function:
• main() function is the entry point of any C++ program.
• It is the point at which execution of program is started.
• When a C++ program is executed, the execution control goes directly to the
main() function.
• Every C++ program have a main() function.
Syntax:
main() function:
• void: is a keyword in C++ language, void means nothing, whenever we use void as
a function return type then that function nothing return. here main() function no
return any value.
• In place of void we can also use int return type of main() function, at that time
main() return integer type value.
• main: is a name of function which is predefined function in C++ library.
Example:
Header File:

• These are those files that store predefined functions.


• It contains definitions of functions that you can include or import using a
preprocessor directive #include.
• This preprocessor directive tells the compiler that the header file needs to be
processed prior to the compilation.
• For example, the <iostream> header file in C++ contains the definition of input-
output functions.
Header File:
Types of Header Files:

• Standard library header files


• User-defined header files
• Standard library header files: These are those header files that are already
present in the compiler of C++; you just need to import them to use them.
• User-defined header files: These are those header files defined by the user and
can be used by including them in the program using #include.

You might also like