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

01_01_Intro

The document provides a comprehensive overview of C++, including its history, features, and applications. It highlights C++ as a middle-level, object-oriented programming language that supports various programming paradigms and emphasizes its use in system programming, game development, and software engineering. Key topics covered include data types, keywords, input/output operations, and the Standard Template Library (STL).

Uploaded by

ASK 011
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

01_01_Intro

The document provides a comprehensive overview of C++, including its history, features, and applications. It highlights C++ as a middle-level, object-oriented programming language that supports various programming paradigms and emphasizes its use in system programming, game development, and software engineering. Key topics covered include data types, keywords, input/output operations, and the Standard Template Library (STL).

Uploaded by

ASK 011
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Index

1. Intro

2. History

3. C vs CPP

4. Datatypes

5. Keywords

6. Input/output

7. Basic programs
What is C++
 case-sensitive(Hello" and "hello" would be considered different)

 free-form programming language that supports object-oriented,

 procedural and generic programming.

 middle-level language, both high and low level language features.


 C++ is a superset of the C language.

Call by user explicitly eg Function.


Automatic compiler calls implicitly e.g default Constructor.

Standard Template Library (STL) many functions are available that help in quickly
writing code.
like sets, maps, hash tables, etc.

memory allocated at run time is known as Dynamic Memory Allocation.


The allocation and deallocation of the memory can be done using the new and delete
operators respectively.

Procedure : typically refers to a function that performs a specific task or a


series of actions without returning a value.

Procedures are sometimes called "void functions, indicating that they do not return
any value. Instead, they carry out a sequence of actions or operations.

History

developed by Bjarne Stroustrup at Bell Labs circa 1980.(1979) AT&T (American


Telephone & Telegraph), located in U.S.A.
The Need of C++

C++ is used in developing browsers, operating systems, and applications ,in-


game programming, software engineering, data structures, etc.

 Performance: C++ is known for its high performance and efficiency. This includes
real-time systems, game development, scientific computing, and high-frequency
trading platforms.

 Systems Programming: It's commonly used in the development of operating


systems, device drivers, and embedded systems.

 Game Development: C++ is a popular choice for game development due to its
performance, control over hardware, and the availability of game development
libraries and engines like Unreal Engine, which is primarily written in C++.

 Security: In security-critical applications, C++ can be used with care to write


secure and robust code.

Uses of C++ (With Real-World Applications)

The uses of C++ can be found in almost all applications today. Here are some
interesting areas where C++ is popularly used.

1. Operating Systems
Mac OS X has large amounts written in C++.
Microsoft like Windows, Microsoft Office, IDE Visual Studio, and Internet
Explorer are also written in C++.

2. Games

3D games and multiplayer networking.

3. Web Browsers
Mozilla Firefox totally build using CPP, Also software like Chrome and google file.

4. GUI Based Applications

Adobe such as Photoshop, Illustrator, etc. are developed using C++.


1) Simple: structured approach (to break the problem into parts), a rich set of
library functions, data types, etc.

2) Abstract Data types: complex data types called Abstract Data Types (ADT) can
be created using classes.

3) Portable : Can be run on different machines.

4) Mid-level / Intermediate programming language: C++ includes both low-level


programming and high-level language so it is known as a mid-level and intermediate
programming language.
It is used to develop system applications such as kernel, driver, etc.

5) Structured programming language: Divide the program into several parts


using functions.

6) Rich Library: It provides inbuilt functions that make the development fast
<iostream>
<cmath>
<cstdlib>
<fstream>

7) Memory Management: Operators are new, delete etc.

8) Quicker Compilation, Compiler base

12) Object-Oriented: concepts like data hiding, encapsulation, and data


abstraction can easily be implemented using keyword class, private, public, and
protected access specifiers.

14) Reusability: Inheritance.

15) National Standards: ANSI.

16) Errors are easily detected: exception handling to support error handling in
your program.

Many compilers and interpreters for other languages such as FORTRAN, PERL,
Python, PASCAL, BASIC, LISP, etc., have been written in C++.
C C++

procedural style programming. supports both procedural and object


oriented.
Data is less secured in C. In C++, you can use modifiers for class
members to make it inaccessible for
outside users.
top-down approach. bottom-up approach.

does not support function supports function overloading.


overloading.
you can't use functions in you can use functions in structure.
structure.
does not support reference supports reference variables.
variables.
Operator overloading is not Operator overloading is possible
possible
programs are divided programs are divided into functions and
into procedures and modules classes.
does not provide the feature of supports the feature of namespace.
namespace.
Exception handling is not easy in provides exception handling using Try and
C. It has to perform using other Catch block.
functions.
C does not support the C++ supports inheritance.
inheritance.
Namespace feature
A namespace is a feature that groups the entities like classes, objects, and
functions under some specific name.
namespace feature that avoids the name collisions.
“std” is for standard liblary.

If we don’t want to use this line of code, we can use the things in this namespace like
this. std::cout, std::endl.

#include<iostream> #include<iostream>

Using namespace std; Int main

Int main {

{ Std::cout<<”HW”;

cout<<”HW”; return 0;

return 0; }

}
C++ Data Types

Data type specifies which type of data a variable or object can hold.
Variables are containers for storing data values.
A variable is a name of memory location. It is used to store data. Its value can be
changed and it can be reused many times.
Identifiers is a name given to a programming construct such as a variable, function,
class,arrays, or other user-defined data types created by the programmer

There are 4 types of data types

Types Data Types

Basic Data Type int, char, float, double, etc

Derived Data Type array, pointer, etc

Enumeration Data Type enum

User Defined Data Type structure


C++ Keywords

total 95 reserved words in C++


A list of 32 Keywords in C++ Language which are also available in C language are
given below.

auto break case char const continue default do

double else enum extern float for goto if

int long register return short signed sizeof static

struct switch typedef union unsigned void volatile while

A list of 30 Keywords in C++ Language which are not available in C language


are given below.

asm dynamic_cast namespace reinterpret_cast bool

explicit new static_cast false catch

operator template friend private class

this inline public throw const_cast

delete mutable protected true try

typeid typename using virtual wchar_t


C++ Basic Input/Output
I/O operation is using stream concept.
Stream is the sequence of bytes or flow of data. It makes the performance fast.
Bytes flow from main memory  to device like (printer, screen, etc) this is called
as output operation.
Bytes flow from device like (printer, screen, etc)  to main memory, this is called
as input operation.

<iostream> cout, cin and cerr objects,

<fstream> file processing.

 cout :

 It is predefined object of ostream class.

 insertion operator (<<)

 cin :

 It predefined object of istream class.

 extraction operator (>>)

 endl  predefined object of ostream class.

 It is used to insert a new line


Day 1 Lab:

1.Print Hello World

2.Add two numbers

binary numbers
Characters

Calculate compound interest

Calculate power of a number


Swap two numbers
2 Call by reference
3 Swap by temp integer

4 Swap by Arithmetic
5 Using Bitwise Operator

6 Using swap function


6 Area of Rectangle
C++ Program Structure
C++ Arrays
Like other programming languages, array in C++ is a group of similar types of
elements that have contiguous memory location.

In C++ std::array is a container that encapsulates fixed size arrays. In C++, array
index starts from 0. We can store only fixed set of elements in C++ array.

A collection of related data items stored in adjacent memory(nest to) places is


referred to as an array in the C/C++ programming language or any other
programming language for that matter.

They can be used to store a collection of any type of primitive data type, including int,
float, double, char, etc. An array in C/C++ can also store derived data types like
structures, pointers, and other data types, which is an addition. The array
representation in a picture is provided below.
C++ Passing Array to Function
Passing Array to Function: Print minimum number
Passing Array to Function: Print maximum number
C++ Multidimensional Arrays

two dimensional or three dimensional. The data is stored in tabular form (row ∗
The multidimensional array is also known as rectangular arrays in C++. It can be

column) which is also known as matrix.


Declaration and initialization at same time
Math Library Functions

Max and min

The max(x,y) function can be used to find the highest value of x and y:

#include<cmath>
max(x,y) function can be used to find the highest value of x and y
min(x,y) function can be used to find the lowest value of x and y
pow(x,y) It computes x raised to the power y.
sqrt(x) It computes the square root of x.
cbrt(x) cube root of x
round(2.6) Round up value to nearest.

round(2.0) 2

round(2.1) 2

round(2.2) 2

round(2.3) 2

round(2.4) 2

round(2.5) 3

round(2.6) 3

round(2.7) 3

round(2.8) 3

round(2.9) 3

round(2.10) consider as (2.1) -> 2


Ceil(2.5) ceil(2.0) 2
ceil(2.1) 3

ceil(2.2) 3

ceil(2.3) 3

ceil(2.4) 3

ceil(2.5) 3

ceil(2.6) 3

ceil(2.7) 3

ceil(2.8) 3

ceil(2.9) 3

hypot(x,y) It finds the hypotenuse of a right angled triangle.

sizeof() operator in C++

OP-4 4 8 1
OP-4

OP-8

OP-12
OP-20

The fun() would return the size of the integer pointer, i.e., int*, and the size of the
int* is 8 bytes in the 64-bit operating system.
O/P 8 bytes

Structure Binding

Structured binding is one of the newest features of C++17 that binds the specified
names to subobjects or elements of initializer.

This feature simplifies code and improves readability when working with complex
data structures, such as tuples, pairs, or user-defined structures

In simple words, Structured Bindings give us the ability to declare multiple


variables initialized from a tuple or struct.

The main purpose is to make the code clean and easy to understand.

You might also like