Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views8 pages

UNIT1-C

C++ is a cross-platform, high-performance programming language developed as an extension of C, featuring object-oriented programming principles that enhance modularity, reusability, and maintainability. It has undergone five major updates since its inception, making it widely used in various applications, including operating systems and embedded systems. Key concepts in C++ include abstraction, encapsulation, and modularity, which collectively facilitate the development of complex software systems.

Uploaded by

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

UNIT1-C

C++ is a cross-platform, high-performance programming language developed as an extension of C, featuring object-oriented programming principles that enhance modularity, reusability, and maintainability. It has undergone five major updates since its inception, making it widely used in various applications, including operating systems and embedded systems. Key concepts in C++ include abstraction, encapsulation, and modularity, which collectively facilitate the development of complex software systems.

Uploaded by

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

UNIT1:

What is C++?
C++ is a cross-platform language that can be used to create high-performance
applications.

C++ was developed by Bjarne Stroustrup, as an extension to the C language.

C++ gives programmers a high level of control over system resources and
memory.

The language was updated 5 major times in 2011, 2014, 2017, 2020, and 2023
to C++11, C++14, C++17, C++20, and C++23.

Why Use C++


C++ is one of the world's most popular programming languages.

C++ can be found in today's operating systems, Graphical User Interfaces, and
embedded systems.

C++ is an object-oriented programming language which gives a clear structure


to programs and allows code to be reused, lowering development costs.

C++ is portable and can be used to develop applications that can be adapted to
multiple platforms.

C++ is fun and easy to learn!

As C++ is close to C, C# and Java, it makes it easy for programmers to switch to


C++ or vice versa.

Difference between C and C++


C++ was developed as an extension of C, and both languages have almost the
same syntax.

The main difference between C and C++ is that C++ supports classes and
objects, while C does not.

Complexity in software:

Software complexity in C++ refers to how difficult a program or a part of it is to


understand, modify, and maintain. This complexity can be broadly categorized
into two main types:
 Algorithmic Complexity (Time and Space Complexity): This measures how the
execution time and memory usage of an algorithm scale with the size of its input. It is
typically expressed using Big O notation.
o Time Complexity: Quantifies the number of operations an algorithm performs as a
function of the input size.

 Example (Linear Search - O(N)):


example, linearSearch iterates through the arr vector. In the worst case, it
might need to check every element, making its time complexity O(N), where N
is the size of the vector.
 Space Complexity: Quantifies the amount of memory an algorithm requires as a
function of the input size.

Example (Storing a copy - O(N)):

The createCopy function creates a new std::vector that is a copy of the


input original vector. The memory used by copy_vector is proportional to the
size of original, resulting in O(N) space complexity.
 Structural/Maintainability Complexity: This relates to the design and organization of
the code, affecting its readability, testability, and ease of modification.

Example (High Cyclomatic Complexity): A function with many nested if-


else statements or complex loops can have high cyclomatic complexity, indicating many
possible execution paths and making it harder to test and understand.
This processValue function has several conditional branches, increasing its
cyclomatic complexity and potentially making it harder to reason about all
possible execution scenarios compared to a simpler function.

The need for object- Orientation:


The need for object-oriented programming (OOP) in C++ arises from its ability
to address challenges in software development, particularly for complex and
large-scale projects. OOP provides a structured and efficient approach to
building applications through its core principles:
 Modularity and Reusability:
OOP promotes breaking down complex systems into smaller, self-contained units
called objects. These objects encapsulate data and the functions that operate on that
data. This modularity allows for easier development, testing, and maintenance of
individual components. Furthermore, objects and classes can be reused across
different parts of a project or even in entirely new projects, reducing development time
and effort.
 Data Hiding and Security:
Encapsulation, a key OOP concept, bundles data and methods within a class and
controls access to that data. This mechanism allows for data hiding, where internal
details of an object are protected from external access and modification, enhancing
data integrity and security.
 Maintainability and Scalability:
The modular nature of OOP makes code easier to maintain and debug. Changes or
updates to one part of the system are less likely to impact other parts, simplifying the
maintenance process. Additionally, OOP's principles like inheritance and
polymorphism facilitate the creation of scalable applications that can be easily
extended and adapted to evolving requirements.
 Modeling Real-World Entities:
OOP provides a natural way to model real-world entities and their relationships within
a program. Objects can represent tangible things like cars or people, or abstract
concepts like bank accounts or transactions, making the design and implementation of
complex systems more intuitive and understandable.
 Flexibility and Extensibility:
Polymorphism, another core OOP concept, allows objects of different classes to be
treated as objects of a common type, enabling flexible and extensible code. This
allows for dynamic behavior and the ability to add new functionalities without
significant modifications to existing code.

Abstraction:
Abstraction in C++ is a fundamental concept in object-oriented programming
(OOP) that involves simplifying complex systems by showing only essential
information while hiding unnecessary details. It focuses on what an object
does rather than how it does it.

Key aspects of Abstraction in C++:


 Hiding Implementation Details:
Abstraction conceals the internal workings and complexities of a class or system from
the user. The user interacts with a simplified interface without needing to understand
the underlying implementation.
 Focus on Essential Features:
It emphasizes presenting only the relevant attributes and behaviors of an object,
making it easier to use and manage.
 Achieved through Classes and Access Specifiers:
C++ uses classes to define data and functions, and access specifiers
(like public, private, and protected) to control visibility and enforce
abstraction. Private members hide implementation details, while public members
expose the interface.
 Abstract Classes and Pure Virtual Functions:
Abstraction can also be implemented using abstract classes, which are classes
containing at least one pure virtual function. A pure virtual function is declared with =
0 and has no implementation in the base class; it must be implemented by derived
classes. This forces derived classes to provide their own specific implementations for
certain behaviors.

 Benefits:
Abstraction promotes code reusability, simplifies maintenance, enhances security by
restricting access to sensitive data, and reduces the overall complexity of a program.
Encapsulation:

Encapsulation in C++ is a fundamental principle of Object-Oriented


Programming (OOP) that involves bundling data (member variables) and the
methods (member functions) that operate on that data into a single unit,
known as a class. It is primarily concerned with controlling access to the
internal state of an object and promoting data hiding.

Key aspects of Encapsulation in C++:


 Bundling Data and Methods:
Encapsulation combines related data members and member functions within a class,
creating a self-contained unit. This promotes organization and modularity, as all
relevant components for a specific entity are grouped together.
 Data Hiding:
A core aspect of encapsulation is data hiding, achieved through access specifiers
(e.g., private, protected, public). By declaring data members as private, direct
access from outside the class is restricted, preventing unintended modification or
corruption of the object's internal state.
 Controlled Access through Interfaces:
While data members are often kept private, public member functions (like "getter" and
"setter" methods) are provided to allow controlled access to and modification of the
private data.
Modularity:

Modularity in C++ refers to the practice of organizing code into independent,


self-contained units called modules. This approach aims to enhance code
organization, maintainability, reusability, and collaboration in software
development.

Key aspects of modularity in C++:


 Functions:
Functions are the most fundamental unit of modularity. They encapsulate specific
tasks and can be called from various parts of the program, promoting code reuse and
readability.
 Classes and Objects:
Object-Oriented Programming (OOP) in C++ heavily relies on classes to define
blueprints for objects. Classes encapsulate data and behavior, promoting modularity
through data hiding (encapsulation) and clear interfaces.
 Namespaces:
Namespaces help organize code by grouping related functions, classes, and other
entities, preventing naming collisions in larger projects.
 Header and Implementation Files:
The traditional C++ approach to modularity involves separating class declarations
(interfaces) into header files ( .h or .hpp) and their definitions (implementations) into
source files (.cpp). This separation allows for independent compilation of modules and
reduces compilation times.
 C++20 Modules:
A significant advancement in C++20 introduced native support for modules. This
feature aims to overcome limitations of traditional header files, such as slow
compilation times and issues with macro definitions, by providing a more efficient and
robust way to manage dependencies.
 Shared Libraries (DLLs/SOs):
For larger-scale modularity, C++ allows the creation of shared libraries or Dynamic
Link Libraries (DLLs on Windows, Shared Objects/SOs on Linux). These libraries
contain compiled code that can be linked with multiple programs at runtime, enabling
code reuse across different applications.
Benefits of modularity:
 Improved maintainability:
Smaller, independent modules are easier to understand, debug, and modify without
affecting other parts of the system.
 Enhanced reusability:
Modules can be reused in different projects or within the same project, reducing
development time and effort.
 Better collaboration:
Teams can work on different modules concurrently, facilitating parallel development.
 Reduced complexity:
Breaking down a large system into smaller, manageable modules simplifies the overall
design and understanding.
 Faster compilation times:
With C++20 modules, incremental builds can be significantly faster as changes in one
module do not necessarily require recompiling its dependents.

Hierarchy:
The hierarchy of classes in Java has one root class, called Object , which is superclass of any
class. Instance variable and methods are inherited down through the levels. In general, the
further down in the hierarchy a class appears, the more specialized its behavior.

You might also like