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

C++ unit 1

C++ is a cross-platform, object-oriented programming language developed by Bjarne Stroustrup, combining low-level and high-level features. It offers advantages such as modularity, reusability, and encapsulation, making it suitable for various applications including operating systems, game development, and scientific research. The document also covers input/output operations, manipulators, and the structure of C++ programs, including the use of the scope resolution operator.

Uploaded by

kittylite25kk
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)
15 views

C++ unit 1

C++ is a cross-platform, object-oriented programming language developed by Bjarne Stroustrup, combining low-level and high-level features. It offers advantages such as modularity, reusability, and encapsulation, making it suitable for various applications including operating systems, game development, and scientific research. The document also covers input/output operations, manipulators, and the structure of C++ programs, including the use of the scope resolution operator.

Uploaded by

kittylite25kk
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/ 10

UNIT - I

INTRODUCTION TO 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.

EVOUTION OF C++
• The C++ language is an object-oriented programming language & is a combination of
both low-level & high-level language – a Middle-Level Language. The programming
language was created, designed & developed by a Danish Computer Scientist – Bjarne
Stroustrup at Bell Telephone Laboratories (now known as Nokia Bell Labs) in Murray
Hill, New Jersey.
• As he wanted a flexible & a dynamic language which was similar to C with all its
features, but with additionality of active type checking, basic inheritance, default
functioning argument, classes, inlining, etc. and hence C with Classes (C++) was
launched.
• C++ was initially known as “C with classes, ” and was renamed C++ in 1983. ++
is shorthand for adding one to variety in programming;

ADVANTAGES OF OOP
• Modularity: OOP divides complex systems into smaller components, making the
codebase easier to comprehend, create, and maintain.
• Reusability: Inheritance allows code reuse, improving code quality and saving time.
• Encapsulation: Protects data integrity and privacy by restricting direct access and
allowing controlled access through methods.
• Flexibility and Scalability: OOP enables easy addition and modification of features
without impacting the entire codebase.
• Code Organization: OOP promotes a structured approach, enhancing collaboration
and code readability.
• Code Maintenance: Changes and bug fixes can be made to specific objects or classes
without affecting other parts of the system, reducing errors and improving debugging.
• Code Reusability: OOP encourages the development of reusable code elements, saving
time and improving system reliability.
• Better Problem Solving: OOP models real-world systems, allowing developers to
create intuitive solutions that closely mimic real-world circumstances.

REAL LIFE APPLICATIONS OF C++

Devices, making C++ ideal for forming the base layer of many important applications.
For these reasons, C++ is an excellent choice for building software that is fast, efficient at
managing system resources, and reliable in performing critical tasks.
What is C++ used for?
C++ can be found in a wide variety of industries. Check out the following list for some
of the most notable, interesting, and even surprising real-world applications of C++.
Operating systems
C++ plays an important part in well-known operating systems, from MacOS and
Windows to mobile operating systems like iOS. In general, operating systems need to be fast
and efficient at managing system resources. With the low-level (close to machine code)
capabilities of C++, developers can structure their code to make even the smallest details of an
operating system fast and energy efficient.
Game development
C++ is one of the most widely-used programming languages in game development. It
has been used to create: games, such as World of Warcraft, Counter-Strike, and StarCraft, game
engines like Unreal Engine, and gaming consoles, including Xbox, PlayStation, and Nintendo
Switch.
Gaming involves lots of resource-intensive functions, whether it’s generating graphics or
facilitating multiplayer sessions. C++ helps in optimizing the use of resources, such as allowing
programmers to adjust exactly how data structures and memory allocation are handled.
IoT devices
IoT (Internet of Things) devices include embedded systems that often rely on C++.
Some examples of these devices are appliances, cars, smartwatches, TVs, and medical devices.
Because the hardware is often embedded inside of an object, these devices have to operate with
limited computing resources and strict power requirements. C++ helps programmers control
how these resources are used in order to run programs more efficiently.
Databases
C++ is used to build popular database tools like MySQL and MongoDB. These
databases form the backbone of many well-known applications, including ones created by
Google, Netflix, YouTube, Adobe, and more. C++ is ideal for helping structure databases to
support efficient storage.
Web browsers
C++ plays a role in web browsers, such as Google Chrome, Mozilla Firefox, Safari, and
Opera. It is used to develop back-end services that retrieve information from databases and
render code into interactive web pages. C++ helps web browsers carry out these tasks with
speed and minimal delays, which means we don’t have to wait long for content to appear on
our screens.
Machine learning tools
Machine learning tools, such as TensorFlow, rely on C++ as a back-end programming
language. Even though data scientists can use TensorFlow with Python, for example, the core
machine learning calculations are carried out with C++ code. In fact, C++ has a large collection
of libraries that power these highly-sophisticated calculations that train machine learning
models.
AR/VR applications
C++ is widely used for developing augmented reality and virtual reality applications.
In fact, many of these applications run on Unreal Engine, which is built using C++. AR/VR
applications need to handle large amounts of data that adjust continuously based on input from
camera sensors and user interactions. C++ is ideal for helping process all of this data while
creating seamless virtual experiences.
Scientific research
C++ plays a notable role in scientific research, from space exploration to high-energy
particle physics. At CERN, scientists use C++ for analyzing data on subatomic particles that
can help answer questions about how our universe originated. At NASA, C++ has been used
to build autonomous driving systems that help the Mars Rovers navigate unknown terrain.
Many parts of the International Space Station are built using C++ as well.
Financial tools
Many banks and financial institutions use C++ to build their software infrastructure,
which powers applications for banking, trading, and financial modeling. The speed and reliable
performance of C++ is ideal for processing millions of daily transactions, facilitating a high
volume and frequency of trades, and creating data simulations for large portfolios.
Flight software
C++ is a commonly-used language for flight software that powers commercial airplanes
and military and defense aircraft (such as the F-16 and F-35 planes). C++ is used to build a lot
of the safety-critical software, which is required to follow strict coding standards to make sure
that the wings, engines, and other critical parts work predictably during each flight.
Google search engine
Google’s search engine relies on C++ to make sure that search results show up quickly
and with minimal response time. C++ also powers the machine learning and other complex
algorithms that make sure we get the best possible results for our search. Google’s crawling
and indexing infrastructure is also implemented in C++.
Medical technology
C++ can be found in a variety of medical applications, from MRI machines to lab
testing equipment to systems that handle patient information. C++ is also used to model data
and run data simulations for bioinformatics research, because many advanced algorithms
written for the medical and biological sciences are implemented in C++.
Telecommunications
C++ is widely used in building telephone, Internet, and other telecommunications
infrastructure. It’s ideal for managing resources to handle tons of simultaneous communication
with speed and efficiency.
Movie production
Many of the graphics and special effects that you see in movies are created with C++.
C++ is great for this role because it can handle large files with high-quality footage and run
many of the advanced calculations that make the special effects possible.

INPUT / OUTPUT IN C++


In C++, a stream refers to a sequence of characters that are transferred between the
program and input/output (I/O) devices. Stream classes in C++ facilitate input and output
operations on files and other I/O devices.
Predefined streams for C++
cin
The standard input stream
cout
The standard output stream
cerr
The standard error stream, unit-buffered such that characters sent to this stream are flushed on
each output operation
clog
The buffered error stream
There are two kinds of console input/output functions :
No. Functions

1 Formatted input/output functions.

2 Unformatted input/output functions.

FORMATTED INPUT/OUTPUT FUNCTIONS


Formatted console input/output functions are used for performing input/output
operations at console and the resulting data is formatted and transformed. For more on
formatted input/output functions, please read formatted input/output functions.
Some of the most important formatted console input/output functions are -
Functions Description

width(int width) Using this function, we can specify the width of a value to be
displayed in the output at the console.

Using this function, we can fill the unused white spaces in a


fill(char ch)
value(to be printed at the console), with a character of our
choice.

setf(arg1, arg2) Using this function, we can set the flags, which allow us to
display a value in a particular format.

unsetf(char ch)
Using this function, we could clear the flag specified fixed by
the function setf().

Using this function, we can specify the number of


precision(int num_of_digts)
digits(num_of_digits) to the right of decimal, to be printed in
the output.

In C++, we can read the input entered by a user at console using an object cin of istream class
and we can write the output at console using an object cout of ostream class. Through
the cin and cout objects, we can access the formatted I/O functions.

UNFORMATTED INPUT/OUTPUT FUNCTIONS


Unformatted console input/output functions are used for performing input/output
operations at console and the resulting data is left unformatted and untransformed i.e. it is left
in its raw and original form.

• In C++, we can read the input entered by a user at console using an


object cin of istream class and through this object we can access the functions
of istream class, such as - get(char *), get(void) and getline().
• In C++, we can write the output at console using an object cout of ostream class and
through this object we can access the functions of ostream class, such as - put(), write().

Some of the most important formatted console input/output functions are -


Functions Description

Reads a single character from the user at the console and


get(char *)
assigns it to the char array in its argument, but needs
an Enter key to be pressed at the end..

get() Reads a single character from the user at the console, and
returns it.

getline(char* arr, int size) Reads a line of characters, entered by the user at the console
which ends with a newline character or until the size of .
put(char ch)
Writes a single character at the console.

write(char *arr, int num)


Writes a number of characters in a char array to the console.

C++ MANIPULATORS

In C++ programming, language manipulators are used in the formatting of output.


These are helpful in modifying the input and the output stream. They make use of the insertion
and extraction operators to modify the output.
Here’s a list of a few manipulators:
Manipulators Description
Endl It is used to enter a new line with a flush.
setw(a) It is used to specify the width of the output.
setprecision(a) It is used to set the precision of floating-point values.
setbase(a) It is used to set the base value of a numerical number.
STRUCTURE OF C++ PROGRAM

C++ program structure is divided into various sections, namely, headers, class
definition, member functions definitions and main function.

• Comments are a vital element of a program that is used to increase the readability of a
program and to describe its functioning. Comments are not executable statements and
hence, do not increase the size of a file.
• Headers: Generally, a program includes various programming elements like built-in
functions, classes, keywords, constants, operators, etc., that are already defined in the
standard C++ library.
Eg: #inc1ude<iostream>, it includes the contents of iostream in the program. This enables the
programmer to use standard input, output and error facilities that are provided only through
the standard streams defined in <iostream>.
• Main Function: The main () is a startup function that starts the execution of a c++
program. All C++ statements that need to be executed are written within main ( ). The
compiler executes all the instructions written within the opening and closing curly
braces' {}' that enclose the body of main ( ).
SCOPE RESOLUTION OPERATOR IN C++
• Scope resolution operator (::) in C++ is used to define a function outside a class or when
we want to use a global variable but also has a local variable with the same name.
Syntax of Scope Resolution Operator
The scope resolution operator follows this general syntax:
scope_name :: identifier
where scope_name is the name of the scope where identifier is defined.

Uses of the scope resolution Operator


1. It is used to access the hidden variables or member functions of a program.
2. It defines the member function outside of the class using the scope resolution.
3. It is used to access the static variable and static function of a class.
4. The scope resolution operator is used to override function in the Inheritance.

Example:
#include <iostream>
using namespace std;
char c = 'a'; // global variable (accessible to all functions)
int main()
{
char c = 'b'; // local variable (accessible only in main function)
cout << "Local variable: " << c << "\n";
cout << "Global variable: " << ::c << "\n"; // Using scope resolution operator
return 0;
}
Output of program:

Scope resolution operator in class:


#include <iostream.h>

class Game
{
public:
void play(); // Function declaration
};
// function definition outside the class
void Game::play()
{
cout << "Function defined outside the class.\n";
}
int main()
{
Game g;
g.play();
return 0;
}
Output of program:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy