Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Programming Language: University of Basra College of Engineering Department of Mechanical Engineering

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

University of Basra

College of Engineering
Department of Mechanical Engineering

Programming
language
C++

‫من قبل طالب‬


‫عباس عبدالك يرم عباس‬
‫الدراسة المسائي‬
A_46 ‫شعبة قورم‬
‫بأشراف‬

‫فراس مطر‬.‫د‬
C++
What is C++?

C++ is a general-purpose, object-oriented programming language. It was created by


Bjarne Stroustrup at Bell Labs around 1980. C++ is very similar to C (which was
invented by Dennis Ritchie in the early 1970s). C++ is so backwards compatible with
C that you can probably compile more than 1,970% of C programs without changing
a line of source code. Although C++ is a well-structured language and is safer than C
because it is based on OOPs.

Some computer languages are written for a specific purpose. For example, Java was
initially designed to control toasters and some other electrical appliances. C was
developed for operating system programming. Pascal is designed to teach proper
programming techniques. But C++ is a general purpose language. It deserves to be
widely recognized and nicknamed “Swiss Language Pocket Knife”.

Is C++ the best programming language?

The answer depends on perspective and requirements. Some tasks can be


performed in C++, but not very quickly. For example, designing GUI screens for
applications.

Other languages such as Visual Basic and Python have graphical user interface
(GUI) design elements built into them. Therefore, it is more suitable for GUI type of
task.

Some scripting languages that provide additional scripting capabilities for


applications. Like MS Word and even Photoshop tend to be variants of Basic, not
C++.

C++ is still widely used, and the most popular software is based on C++.
| C++

1
Features of C++ language:

High performance and efficiency:


Direct Memory Control: C++ allows programmers to directly control memory
management using pointers, which helps improve program performance and
efficiency.
Fast machine code: Code written in C++ is translated into machine instructions very
quickly, making it ideal for applications that require fast response and processing-
intensive.

Object Oriented Programming (OOP):


Encapsulation: C++ allows data and functions to be encapsulated into objects,
enhancing security and organization.
Inheritance: Inheritance facilitates code reuse and reduces redundancy, allowing
complex software structures to be created in more organized ways.
Polymorphism: Allows the creation of functions and classes that operate in different
ways depending on the data used, which increases the flexibility of the program.
Abstraction: It helps hide the internal details of objects and provide simple interfaces
to use.

Compatibility with C language:


C programmers can easily use C libraries and code in C++, promoting smooth
transition between the two languages and reuse of legacy code.

Templates:
Class and function templates: Allow writing generic code that works with multiple
data types, which promotes code reuse and reduces errors.
Standard Template Library (STL): It contains a set of ready-made classes and
templates such as lists, vectors, groups, and maps, which facilitates the development
process.
| C++

2
Generic Programming:
It allows writing algorithms and classes that work with any type of data, enhancing
flexibility and reusability.

Resource Management:
Provides powerful tools such as Smart Pointers to intelligently manage memory and
reduce the possibility of memory leaks.

Portability:
Code written in C++ can be ported to multiple platforms with little or no changes,
making it easier to develop programs that run on different operating systems.

Scalability:
C++ is widely used in developing large and complex software projects due to its
ability to scale efficiently and its support for large project architectures.

Huge community and strong support:


C++ has a large developer community, many educational resources, and forums,
making it easy to find help and solutions to problems.

Wide use in industries:


C++ is used to develop many important software such as operating systems, games,
financial software, embedded software, and high-performance graphics software.

Disadvantages of C++ language:

Complexity and difficulty of learning:


Complex learning: C++ is a complex language and contains many features that may
be difficult for beginners to understand, such as manual memory management,
pointers, and object-oriented programming.
Complex syntax: It has a rich and complex syntax, which makes it difficult to write
clean, error-free code.
| C++

3
Manual memory management:
Possibility of memory leaks: Because of the need to manually manage memory using
pointers, unstructured code can lead to memory leaks or illicit memory access.
Hard errors: Memory errors such as Buffer Overflows and Dangling Pointers can be
difficult to detect and fix.

Complexities in object-oriented programming:


Multiple inheritance: Support for multiple inheritance in C++ can be useful but also
increases design and implementation complexity, leading to diamond problems.
Resource Management: Applying the RAII (Resource Acquisition Is Initialization)
principle requires a deep understanding and mastery of the language, which
increases the complexity of the code.

Long translation time:


Slow compilation: Due to the size and complexity of the code in large C++ projects,
the compile time can be long, which affects the development cycle.

Lack of ready-made libraries:


Compared to some other languages like Python or Java: While C++ has a Standard
Template Library (STL), the variety and large number of ready-to-use libraries is less
compared to modern languages.

Poor relative security:


Vulnerabilities: Due to complexity and manual memory management, C++ programs
can have more vulnerabilities compared to languages that manage memory
automatically like Java and Python.

Lack of support for a strong virtual environment:


Cross-platform development environment: Although C++ supports cross-platform
compatibility, setting up a cross-platform development environment can be complex
and difficult.

Lack of some modern features:


| C++

Modern Features: Despite constant updates, C++ may lack some of the modern
features and simplicity found in newer programming languages like Python and Rust.

4
Who uses C++?

Some of the most visible systems in use today have significant parts written in C++.

Examples include Amadeus (airline tickets).

Bloomberg(Financial Formation),
Amazon (web commerce), Google (web search)
Facebook (social media)
Many programming languages rely on the performance and reliability of C++ for their
implementation. Examples include:

Java virtual machines


JavaScript interpreters (e.g. Google V8)
Browsers (such as Internet Explorer, Mozilla's Firefox, Apple's Safari, and Google
Chrome)
Application and web frameworks (for example, Microsoft's .NET Web Services
Framework).
Applications involving local and wide area networks, user interaction, digital access,
graphics, and databases rely heavily on C++.

Five Basic Concepts of C++

1. C++ Language Variables


Variables are the backbone of any programming language. A variable is a way to
store information for later use. We can retrieve this value or data by referring to a
“word” that describes this information. Once declared and defined, it can be used
multiple times within the scope in which it is declared.

2. Control Structures in C++


When running a program, the compiler reads the code line by line (from top to
bottom, most often from left to right). This is known as "code flow." When reading
| C++

code from top to bottom, there may be points where it needs to make decisions.

5
Depending on the decision, the program may move to a different piece of code, rerun
a certain part, or skip a block of code entirely. This process is similar to choosing
different courses from a list and navigating through the content.

3. C++ Data Structures


Consider a list of courses. If there are many courses and different users may register
for different courses, creating a different variable for each user isn't practical. For
example, if we need to keep track of 10 cycles, defining 10 variables is inefficient.
Instead, data structures like arrays are used to store them efficiently. C++ provides
various built-in data structures to handle such scenarios.

4. C++ Syntax
Syntax is the layout of words, expressions, and symbols. Just like an email address
follows a well-defined syntax, programming languages have rules that need to be
followed to create functional software. If these rules or syntax are not adhered to,
errors will occur.

5. C++ Tools
In programming, a tool is software that helps accomplish tasks more efficiently. One
of the most important tools is the IDE (Integrated Development Environment), which
makes programming easier by organizing files and folders and providing a clean
interface. There are thousands of tools available across different programming
languages that aid in coding.

Using the C++ Programming Language

Here are some of the main uses of the C++ programming language:

Operating Systems
Many operating systems, including Microsoft Windows, Mac OSX, and Linux, have
parts programmed in C++. Its efficiency makes it an ideal choice for developing
operating systems.
| C++

6
Games
C++ is widely used in game development engines due to its speed and ability to
handle hardware resources effectively. It provides procedural programming for CPU-
intensive functions.

Browsers
The rendering engines of various web browsers are programmed in C++ because of
the speed it offers.

Libraries
Many high-level libraries, particularly in machine learning, use C++ as their primary
language due to its speed.

Graphics
C++ is used in graphics applications that require fast rendering, image processing,
real-time physics, and portable sensors.

Banking Applications
Core banking systems, such as Infosys Finacle, use C++ as the back-end
programming language due to the need for high concurrency and low-latency
support.

Cloud/Distributed Systems
Cloud storage systems use scalable file systems that operate close to hardware,
making C++ a preferred choice for cloud systems.

Embedded Systems
Many embedded systems, such as medical devices and smartwatches, use C++ as
their primary programming language.

Assemblers
Compilers of various programming languages use C++ as the backend programming
language.
| C++

7
Example of C++ language

#include <iostream> // Include the core I/O library

int main() {
std::cout << "Hello, World!" << std::endl; // Print text on the screen
return 0; // Returning 0 means that the program finished successfully
}

Code explanation:
Include library:
#include <iostream>
This line includes the basic I/O library in C++, allowing us to use functions like
std::cout.

main function:
int main() {
main is the main function in a C++ program, and execution starts from it.

Print text:
std::cout << "Hello, World!" << std::endl;
std::cout is an object used to print text on the screen.
<< is an output parameter used to send data to std::cout.
"Hello, World!" It is the text that will be printed.
std::endl is used to add a new line after text.

Return value:
return 0;
This line returns the value 0, indicating that the program finished successfully.

This example is simple and gives an idea of how to write a basic program in C++.
You can develop it to include more complex features and functionality depending on
your needs.
| C++

8
References about the C++ language

1. ISO/IEC 14882:2020 Programming languages — C++


- [Reference link](https://api.github.com/repos/cplusplus/draft)
- Accessed: December 8, 2018.

2. History of the invention of C++


- When was C++ invented (in English), most frequently asked questions on Bjarne
Stroustrup's website.
- [Archived copy 2012-07-16 in Wayback
Machine](https://web.archive.org/web/20120716040411/http://www.stroustrup.com/b
s_faq.html).

3. TIOBE Programming Community Index


- [Archived copy 2016-02-13 in Wayback
Machine](https://web.archive.org/web/20160213171056/https://www.tiobe.com/tiobe-
index/).

4. The Transparent Language Popularity Index


- [Archived copy 2018-06-29 in Wayback
Machine](https://web.archive.org/web/20180629101156/http://www.transparent.com/l
anguage-resources/tools/frequency-lists.html) .

5. C++ applications
- Bjarne Stroustrup website.
- [Archived copy 2018-07-02 in Wayback
Machine](https://web.archive.org/web/20180702164845/http://www.stroustrup.com/a
pplications.html).

6. Interview with Bjarne Stroustrup


- app2us.com, August 2008.
- [Archived copy 2017-07-06 in Wayback
Machine](https://web.archive.org/web/20170706091208/http://app2us.com/interviews
| C++

/straustrup.html).

You might also like