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

NIIT Vile Parle

C++ is a widely used programming language with applications in systems software, applications, and games. It uses variables to store values in memory locations identified by names. Variables must follow naming rules and have defined data types like char, int, and float. Classes define attributes using member variables and allow accepting and storing values. C++ programs include header files, the main function, object creation, and return values. Other concepts include arrays, abstraction, encapsulation, access specifiers, friend functions, inheritance, operators, and loops. While powerful, C++ is criticized for complexity and lacking features like built-in threading compared to other languages.

Uploaded by

GauravMakhecha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

NIIT Vile Parle

C++ is a widely used programming language with applications in systems software, applications, and games. It uses variables to store values in memory locations identified by names. Variables must follow naming rules and have defined data types like char, int, and float. Classes define attributes using member variables and allow accepting and storing values. C++ programs include header files, the main function, object creation, and return values. Other concepts include arrays, abstraction, encapsulation, access specifiers, friend functions, inheritance, operators, and loops. While powerful, C++ is criticized for complexity and lacking features like built-in threading compared to other languages.

Uploaded by

GauravMakhecha
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

NIIT Vile Parle

As one of the most popular programming languages


ever created, C++ is widely used in the software
industry. Some of its application domains include
systems software, application software, device drivers,
entertainment software such as video games ,etc.
Variables -
A variable is a location in memory that has a name and may
contain a value.

Variable names should not have any embedded space or


symbols
Variable name must be unique.
A variable can have number of characters
A variable name must begin with a letter or underscore
Keywords cannot be used as variable names
Data types-
A data type defines the type of data that can be stored in a
variable.
Built-in data types in C++

char- for characters and strings


int- for integers
float- for numbers with decimal.
Member variables
We can implement attributes in c++ by using member variables.
Member variables are declared inside the class body.
Example :

Class car
{
Float Example
price;
};
In the above example, the variable price of type float is
declared inside the class car.
Accepting and storing values in member variables
Example

Class car
{
float price;
public:
void acceptprice()
{
cout << “enter price :”;
cin >> price;
}
};

In case of the above code, the message “enter price” is displayed. The
cursor blinks on the screen and waits for the user to enter data in the
variable
Components of c++ program

The iostream Header File


#include<iostream.h>

This statement is called a preprocessor directive. The


preprocessor directive are the statements that are
processed before the program is compiled
The main() function
Example:

#include<iostream.h>
int main()
{
return 0;
}

The operating system considers the number 0 that is


returned to it to imply that the program has completed
execution without any errors.
Creating Objects

A class declaration does not reserve memory at the time


of declaration. The memory is allocated when an
instance of class is created. An instance of a class is
called an object.
Introduction to arrays
An array is a collection of elements of single data type stored in
adjacent memory locations.
 
All elememt of an array must be of the same data type.

 Before any array variable can be initialized, its data type and
size must be defined.

Declaring and initializing arrays,


This is how an array variable is declared:
 
<data_type><variable_name>[<dimension_size>];
 
Abstraction and encapsulation
 
“ An Abstraction denotes the essential
characteristics of an object that distinguishes it from
all other kinds of objects and thus provides crisply
defined conceptual boundries, relative to prospective
of the viewer.” – Grady Booch.

“Encapsulation is the process of hiding all of the


details of an object that do not contribute to its
essential characteristic.” – Grady Booch
Access specifiers.
The public access specifier
The public access specifier allows a class to expose its member
variables and member functions to other functions and objects.
 
The private access specifier
The private access specifier allows to hide its member variable and
member functions from other functions and objects. This
feature of insulated data from direct access by other parts of the
program is called data hiding.
 
The protected access specifier
Like the private access specifier, The protected access specifier
allows to hide its member variable and member functions from
other functions and objects. The significant use of the protected
access specifier is while implementing inheritance
Friend functions

In order to access the non-public member of a class,


C++ provides the friend keyword.
Any non-member function may be declared a friend
by a class, in which case the function may directly
access the private member attributes of class object.
Inheritance

Inheritance allows one data type to acquire properties


of other data types.
 Inheritance from a base class may be declared as
public, protected, or private. This access specifier
determines whether unrelated and derived classes
can access the inherited public and protected
members of the base class.
Operators
Operators are used to compute and compare values and test condition .
Arithmetic operators
Assignment operators
Unary operators
Comparison operators
Logical operators
Conditional operators
Arithmatic operators

We can use Arithmatic operators to perform


arithmetic operations, such as addition, subtraction,
multiplication and division.
Arithmatic Assignment operators

We can use the Arithmatic assignment operators ‘=’ to


assign the value of the right operand to the left. For
example, the statement x=y assigns the value of y to x.
Unary operators

operators description example Explanation

An increment operator x++ Equivalent to x = x+1


++ increases the value of operand
by one.
An decrement operator x-- Equivalent to x = x-1
-- decreases the value of operand
by one.
Comparison operators
Also called relational operators, are used to compare
two values.
operator description
s
== Evaluates whether or not the operands are equal
!= Evaluates whether or not the operands are not
equal
> Evaluates whether or not the left operand is
greater than the right operand
< Evaluates whether or not the left operand is less
than the right operand
>= Evaluates whether or not the left operand is
greater than or equal to the right operand
<= Evaluates whether or not the left operand is less
than or equal to the right operand
Logical operators
Logical operators are used to combine two or more
expressions.
C++ provides the AND(&&), the OR(||) ant the
NOT(!) logical operators.
Operators Description

&& Evaluates to true, if both the conditions evaluate to true,


false otherwise

|| Evaluates to true, if at least one of the conditions


evaluates to true, and false if none of the condition
evaluates to true.
! The effect of the ! operator is that the logical value of its
operand is reversed.
Loop construct

Causes a section of a program to be repeated a certain


number of times.
The repetition continues while the condition set for
the loop remains true.
 Example;

#include <iostream>
Class loops Output
{
int num1;
int num2; 1
public; 1
void fibonacci() 2
{
num1=num2=1; 3
cout <<num1 << endl; 5
while (num2 < 200) 8
{
13
cout <<num2 << endl;
num2+= num1; 21
num1 = num2 – num1; 34
} 55
}
};
89
int main() 144
{
Loop l1;
L1.fibonacci ();
Return 0;
}
Criticism
First, since C++ includes most of C as a subset, it
inherits many of the criticisms leveled at C. For its
large feature set, it is criticized as being over-
complicated, and difficult to fully master.
Other criticism stems from what is missing from C++.
For example, the current version of Standard C++
provides no language features to create multi-
threaded software. These facilities are present in some
other languages including Java and C#.
THANK YOU

You might also like