Programming Language: University of Basra College of Engineering Department of Mechanical Engineering
Programming Language: University of Basra College of Engineering Department of Mechanical Engineering
Programming Language: University of Basra College of Engineering Department of Mechanical Engineering
College of Engineering
Department of Mechanical Engineering
Programming
language
C++
فراس مطر.د
C++
What is C++?
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”.
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.
C++ is still widely used, and the most popular software is based on C++.
| C++
1
Features of C++ language:
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.
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.
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++.
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:
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.
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.
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
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
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).
/straustrup.html).