SlideShare a Scribd company logo
C++ Character Set:
ī¯ The valid set of characters that a C++ language can
recognizes includes the following.
13
C++ Introduction
Tokens:
ī¯ Smallest individual
token.
unit in a program is known as
1.
2.
3.
4.
Identifiers
Keywords
Operators
Punctuators / Delimiters
14
C++ Introduction
Identifiers is a name given to programming elements such as
variables, functions, arrays, objects, classes, etc.,
ī¯ The following are some valid identifiers:
Student Reg101 a1e2r3
creating identifiers:
_dos
ī¯ Rules to be followed while
īƒŧ Identifiers are a sequence of characters which should begin with
the alphabet either from A-Z (Uppercase) or a-z (lowercase) or
(underscore).
īƒŧ C++ treats uppercase and lowercase characters differently
īƒŧ No Special character is allowed except underscore “_”.
īƒŧ Identifier should be single words i.e. blank spaces cannot be
included in identifier.
īƒŧ Reserved Keywords should not be used as identifiers.
īƒŧ Identifiers should be of reasonable length.
_
15
Identifiers
Keywords: are predefined word that gives special
meaning to the complier.
16
Keywords
.
ī¯ C++ Operators:
īƒŧ Operators are used to perform operations on variables
values.
īƒŧ Example: int x = 100 + 50;
ī¯ C++ Operators Types:
and
īƒŧ C++ divides the operators into
ī¯ Arithmetic operators
ī¯ Assignment operators
ī¯ Comparison operators
ī¯ Logical operators
ī¯ Bitwise operators
the following groups.
22
C++ Operators
ī¯ Arithmetic operators are used to perform common
mathematical operations.
23
Arithmetic Operators
ī¯ Assignment operators are used to assign values to variables.
24
Assignment Operators
ī¯ Comparison operators are used to compare two values.
ī¯ The return value of a comparison is either true (1) or false (0).
25
Relational Operator
ī¯ Logical operators are used to determine the logic between
variables or values.
26
Logical Operators
ī¯ A Bitwise operators
programming.
are used in bit level
27
Bitwise Operators
28
ī¯ Operators may also be classified
operands they act on either:
īƒŧ Unary Operators
īƒŧ Example: a++
īƒŧ Binary Operators
īƒŧ Example: x = y– z;
on the number of
C++ Operators
Special Operator :
ī¯ An expression is a combination of opcode and operand.
ī¯ Some special operators used in C++ programming are:
29
C++ Operators
ī¯ Punctuators in C++ have syntactic and semantic meaning
to the compiler.
30
Punctuators
Data Types:
ī¯ Data Types can be defined as the set of values, which can be
stored in a variable along with the operations that can be
performed on those values.
ī¯ C++ defines several types of data and each type has
characteristics.
ī¯ C++ data types can be classified as:
unique
1.
2.
3.
The fundamental data type(built-in
Derived Data type
User-defined data type
data)
31
Data Types
Data Types:
ī¯ C++ defines several types of data and
characteristics.
each type has unique
ī¯ C++ data types can be classified as:
32
Data Types
Input & Output Operators
ī¯ The input output operations are done using library functions
cin and cout objects of the class iostream.
ī¯ Using the standard input and output library, we will able to
interact with the user by printing message on the screen and
getting the user’s input from the keyboard.
īƒŧ A stream is an object where a program can either
insert/extract characters to/from it.
īƒŧ The standard C++ library includes the header file iostream,
where the standard input and output stream objects are
declared.
35
Input & Output Operators
Input Operators:
ī¯ Input Operator “>>”: The standard input device is usually the
keyboard.
ī¯ Input in C++ is done by using the
the cin stream.
“stream extraction” (>>) on
ī¯ “cin” stands for “console input”.
ī¯ Example: int age;
cin>>age;
36
Input & Output Operators
Output Operator:
ī¯ Output Operator “<<”: The standard output device is the
screen (Monitor).
ī¯ Outputting in C++ is done by using the object followed by
“stream insertion” (<<).
ī¯ “cout” stands for console output
the
ī¯ Example: cout<<”sum”; //prints sum
cout<<sum; //prints the content of the variable sum;
37
Input & Output Operators
Cascading of I/O Operators:
ī¯ If a program requires more than
possible to input these variables
multiple stream extraction “>>”
one input variable then it is
in a single cin statement using
operators.
ī¯ Example: cout<<”Enter the two number”;
cin>>a>>b;
ī¯ If a program requires more than one output result then this can
be done using a single cout statement with multiple stream
insertion “<<“ operators.
ī¯ This is called cascading of input & output operators.
ī¯ Example: cout<<”Entered the two number”<<a<<b<<endl;
cout<<”The sum of two number is”<<sum<<endl;
38
Input & Output Operators
Introduction:
ī¯ Control statements are statements that alter the sequence
of flow of instructions.
ī¯ The order in which statements are executed in a program
is called flow of control.
ī¯ Types of control statements:
control statements.
īƒŧ Selection statements
īƒŧ Iteration statements
C++ supports two basic
41
Control Statements
Selection Statements:
This statement allows us to select a statement or set of
statements for execution based on some condition.
It is also known as conditional statement.
ī¯
ī¯
This structure helps the programmer
decision.
The different selection statements:
īƒŧ if statement
īƒŧ if – else statement
īƒŧ Nested – if statement
īƒŧ switch statement
to take appropriate
ī¯
ī¯
42
Control Statements
.:
43
if
ī¯
statement:
This
This
This
is the simplest form of Selection statement.
statement is also called as one-way branching.
statement is used to decide whether a statement
ī¯
or
ī¯
set of statements should be executed
The decision is based on a condition
evaluated to TRUE or FALSE
Syntax:
if (Test Condition) // is true
Statement 1;
Statement 2;
or not.
which can be
ī¯
ī¯
Selection Statements
if
ī¯
– else statement:
This statement is also called as two-way branching.
This structure helps to select one
executed from two sets.
set of statements to be
ī¯
Syntax of if – else
if (Test Condition)
statement is:
ī¯
Statement 1;
else
Statement 2;
44
Selection Statements
Nested if statement :
ī¯ If the statement of an if statement is another if statement
then such an if statement is called as Nested-if Statement.
ī¯ The general form of
if (Test Condition 1)
Statement 1;
else if (Test Condition 2)
Statement 2;
else
â€Ļâ€Ļâ€Ļ..
else if( test Condition N)
Statement N;
else Default Statement;
if – else – if statement is:.
45
Selection Statements
Switch Statement :
ī¯ C++ has built in multiple-branch selection statement
ī¯ If there are more than two alternatives to
selection construct is used.
be selected, multiple
ī¯ The general form of Switch statement
Switch ( Expression )
is:
{ Case Label-1: Statement 1;
Break;
Case Label-2: Statement 1;
Break;
â€Ļâ€Ļâ€Ļâ€Ļ..
Case Label-N: Statement N;
Break;
Default : Default- Statement;
} 46
Selection Statements
Iterative Constructs or Looping:
ī¯ The process of repeated execution of a sequence of
statements until some condition is satisfied is called as
iteration or loop.
ī¯ Iterative statements are also called as repetitive statement
or looping statements.
ī¯ There are three types
īƒŧ while loop
īƒŧ do while loop
īƒŧ for loop
of looping structures in C++:
47
Iteration statements
while loop:
ī¯ This is a pre-tested loop structure.
ī¯ This structure checks the condition at the beginning of the
structure.
ī¯ The set of statements are executed again
the condition is true.
and again until
ī¯ The general form of while
while ( Test Condition)
structure is
{ Statement
Statement
â€Ļâ€Ļ..
Statement
1
2
N
} //End of While 48
Iteration statements
do-while loop:
ī¯ This is a post-tested loop structure.
ī¯ This structure checks the condition at the end of the structure.
ī¯ The set of statements are executed again
condition is true.
and again until the
ī¯ The general form
do
of while structure is
{ Statement
Statement
â€Ļâ€Ļ..
Statement
1
2
N
} //while ( Test Condition);
49
Iteration statements
for loop:
ī¯ This structure is the fixed execution structure.
ī¯ Usually used when we know in advance exactly how
many times a set of statements to be executed repeatedly.
ī¯ This structure can be used as increment looping
decrement looping structure.
or
ī¯ The general form of for structure is as follows:
for ( Expression 1; Expression 2; Expression 3)
{ Statement
Statement
Statement
1;
2;
N;
}
50
Iteration statements
Introduction:
ī¯ An array is collection of elements where all the elements are
same data type under the same name.
ī¯ The elements are numbered as 0, 1, 2â€Ļ.n-1.
ī¯ These numbers called as indices or subscripts.
ī¯ These numbers are used to locate the positions of elements
within the array.
ī¯ If a is the name of
accessed as
a[0], a[1],
the array, the elements can be directly
a[2],â€Ļâ€Ļ, a[n-1].
56
Arrays
.
ī‚§Why need to use array type?
ī‚§Consider the following issue:
"We have a list of 1000 students' marks of
an integer type. If using the basic data
type (int), we will declare something like
the followingâ€Ļ"
int studMark0, studMark1, ...studMark999
#include<iostream>
using namespace std;
int main()
{
int i,sum=0,a[5];
cout<<"enter Numbers ";
for(i=0;i<5;i++)
{
cin>>a[i];
}
for(i=0;i<5;i++)
{
sum=sum+a[i];
}
cout<<" Sum= "<<sum;
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int i,a[5],max, min;
cout<<"enter value ";
for(i=0;i<5;i++)
{
cin>>a[i];
}
max=a[0];
min=a[0];
for(i=1;i<5;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
cout<<" max="<<max<<endl;
cout<< " min ="<<min<<endl;
return 0;
}
Introduction:
ī¯ A function is a named group of statements developed to solve
a sub-problem and returns a value to other functions when it is
called.
ī¯ Types of functions:
īƒŧ Library functions
A standard library is a collection of pre-defined functions and
other programming elements, which are accessed through
header files
īƒŧ User-defined functions
ī¯
We can create our own functions or sub-programs to solve our
problem. Such functions are normally referred to as user-
defined functions
ī¯
58
Functions
User-defined functions:
User-defined function is a function defined by the user to solve
his/her problem.
The purpose of using a function is to make the program design
process easy, understandable and thereby avoiding ambiguity.
Types of functions:
ī¯
ī¯
ī¯
īƒŧ Function
īƒŧ Function
īƒŧ Function
īƒŧ Function
with
with
with
with
no arguments and no return values.
arguments and with no return values.
no arguments and with return values.
arguments and with return values.
īƒŧ Recursive function.
59
Functions
Function with no argument and no return
#include<iostream>
using namespace std;
void sum();
int main()
{
sum();
return 0;
}
void sum()
{
int a,b;
cout<<" enter a and b :- ";
cin>>a>>b;
cout<<" Sum="<<a+b;
}
Function with argument and no return
#include<iostream>
using namespace std;
void sum(int, int);
int main()
{
int a,b;
cout<<" enter a and b :- ";
cin>>a>>b;
sum(a,b);
return 0;
}
void sum(int a, int b)
{
cout<<" Sum="<<a+b;
}
Function with no argument and return
#include<iostream>
using namespace std;
int sum();
int main()
{
int x;
x=sum();
cout<<" Sum="<<x;
return 0;
}
int sum()
{
int a,b;
cout<<" enter a and b :- ";
cin>>a>>b;
return(a+b);
}
Function with argument and return
#include<iostream>
using namespace std;
int sum(int, int);
int main()
{
int x,a,b;
cout<<" enter a and b :- ";
cin>>a>>b;
x=sum(a,b);
cout<<" Sum="<<x;
return 0;
}
int sum(int a, int b)
{
return(a+b);
}
ī¯ Objects are basic building blocks for designing programs.
ī¯ An object is a collection of data members and associated
member functions.
ī¯ An object may represent a person, place or a table of data.
ī¯ Each object is identified by a unique name. Each object
must be a member of a particular class.
62
Objects
ī¯ A class is a collection of objects that have identical
properties, common behavior and shared relationship.
ī¯ A class binds the data and its related functions together.
ī¯ A class is a user-defined data type that we
program.
can use in a
ī¯ To create a class, use the
ī¯ Example:
class MyClass
{
// The class body
};
class keyword.
īƒŧ Where class keyword is used to create a class called MyClass
63
Class
Definition and Declaration of Classes
ī¯ A class definition is a process of naming a class and data
variables, and interface operation of the class.
ī¯ The variables declared inside a class are known as data
members.
ī¯ The functions declared inside a class are known as member
functions.
ī¯ A class declaration specifies the representation of objects of
the class and set of operations that can be applied to such
objects.
64
Class in C++
Definition and Declaration of Classes
ī¯ Class body is enclosed in a pair of brackets. Class body
contains the declaration of its members (data and functions).
ī¯ The functions declared inside a class are known
functions.
as member
ī¯ The general syntax of the class declaration
class User_Defined_Name
{
private :
Data Member;
Member functions;
};
is:
65
Class in C++
Access Specifiers
Access specifiers define how the members (attributes and
function) of a class can be accessed.
ī¯
Every data member of a class is specified by three levels
access protection for hiding data and function members
internal to the class.
of
ī¯
They help in controlling the access
Different access specifiers are:
īƒŧ private
īƒŧ public
īƒŧ protected
of the data members.
ī¯
ī¯
66
Access Specifiers
private:
ī¯ private access means a member data can only be accessed by
the class member function or friend function.
ī¯ The data members or member functions declared private
cannot be accessed from outside the class.
ī¯ The objects of the class can access the private members
through the public member functions of the class.
ī¯ By default data members in a class are private.
ī¯ Example:
private:
int x;
float y;
only
67
Access Specifiers
protected:
ī¯ The members which are declared using protected can be
accessed only by the member functions, friend of the class
also the member functions derived from this class.
ī¯ The members cannot be accessed from outside the class.
and
ī¯ The protected access
specifiers.
ī¯ Example:
protected:
int x;
float y;
specifier is similar to private access
68
Access Specifiers
public:
ī¯ public access means that member can be accessed any function
inside or outside the class.
ī¯ Some of the public functions of a class provide interface for
accessing the private and protected members
ī¯ Example:
class MyClass
{
public: // Public access specifier
of the class.
int x;
private:
int y;
};
// Public attribute
// Private access specifier
// Private attribute
69
Access Specifiers
Member Function:
ī¯ Member functions are functions that are included
within a class (Member functions are also called
Methods).
ī¯ Member functions can be defined
īƒŧ Inside class definition
īƒŧ Outside class definition
in two places.
70
Member Function
Inside class definition:
ī¯ To define member function inside a class the function declaration
within the class is replaced by actual function definition inside
class.
the
ī¯ Only small functions are
ī¯ Example:
class rectangle
{
defined inside class definition.
void compute( )
{
area = length * breadth;
}
void display( )
{
int length, breadth,
public:
void get_data( )
{
area;
cout<< ” Enter the values for Length and
Breadth”;
cin>>length>>breadth;
}
cout<<” The area of rectangle is”<<area;
}
};
71
Member Function
Outside class definition:
ī¯ To define member function outside the class, the class name
must be linked with the name of member function.
ī¯ Scope resolution operator (::) is used to define the member
function outside the class.
ī¯ Syntax of a member function defined outside the class is:
return_type class_name : : member_function_name( arg1, ..., argnN)
{
function body;
}
72
Member Function
Program to use member
class definition:
#include<iostream.h>
class item
{
private:
int numbers;
float cost;
public:
functions inside and outside
};
void item : : getdata(int a, float b)
{
number = a;
cost = b;
}
void getdata(int a,
void putdata( )
{
cout<<”Number:
float b); int main( )
{
item x;
x. getdata( 250, 10.5);
x.putdata( );
return 0;
}
“<<number<<endl;
cout<<”Cost:”<<cost<<endl;
}
73
Member Function
Object of a class:
ī¯ An object is a real world element which is identifiable entity
with some characteristics (attributes) and behavior (functions).
ī¯ An object is an instance of a class.
ī¯ An object is normally defined in the main ( ) function.
ī¯ The syntax for defining objects of a class as follows:
class Class_Name
{
private : //Members
public : //Members
};
class Class_Name Object_name1, Object_name2,â€Ļâ€Ļ;
īƒŧ where class keyword is optional.
74
Defining object of a class
Dot operator (.):
ī¯ The public data members of objects of a class can be accessed
using direct member access operator (.).
ī¯ Private and protected members of the class can be accessed
only through the member functions of the class.
ī¯ No functions outside a class can include statements to access
data directly.
ī¯ The syntax of accessing member (data and functions) of a class
is:
a) Syntax for accessing a data member of the class:
Object_Name . data_member;
b) Syntax for accessing a member function of the class:
Object_Name . member_function(arguments); 75
Accessing member of the class

More Related Content

Similar to Introduction to C++.pptx learn c++ and basic concepts of OOP

PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
ArshiniGubbala3
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Pranali Chaudhari
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
madhurij54
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Ajeet Kumar
 
C++ rajan
C++ rajanC++ rajan
C++ rajan
Deep Rajan
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
AkshhayPatel
 
C introduction
C introductionC introduction
C introduction
AswathyBAnil
 
chapter-2.ppt
chapter-2.pptchapter-2.ppt
chapter-2.ppt
XanGwaps
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plusRalph Weber
 
C intro
C introC intro
C intro
SHIKHA GAUTAM
 
C program
C programC program
C program
AJAL A J
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
jatin batra
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
Don Dooley
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
1HK19CS090MOHAMMEDSA
 
C operators
C operatorsC operators
C operators
GPERI
 

Similar to Introduction to C++.pptx learn c++ and basic concepts of OOP (20)

PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
C++ rajan
C++ rajanC++ rajan
C++ rajan
 
Unit 1
Unit 1Unit 1
Unit 1
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
Pc module1
Pc module1Pc module1
Pc module1
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 
C introduction
C introductionC introduction
C introduction
 
chapter-2.ppt
chapter-2.pptchapter-2.ppt
chapter-2.ppt
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
C intro
C introC intro
C intro
 
C program
C programC program
C program
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
C operators
C operatorsC operators
C operators
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
ricssacare
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
Special education needs
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
parmarsneha2
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 

Recently uploaded (20)

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 

Introduction to C++.pptx learn c++ and basic concepts of OOP

  • 1. C++ Character Set: ī¯ The valid set of characters that a C++ language can recognizes includes the following. 13 C++ Introduction
  • 2. Tokens: ī¯ Smallest individual token. unit in a program is known as 1. 2. 3. 4. Identifiers Keywords Operators Punctuators / Delimiters 14 C++ Introduction
  • 3. Identifiers is a name given to programming elements such as variables, functions, arrays, objects, classes, etc., ī¯ The following are some valid identifiers: Student Reg101 a1e2r3 creating identifiers: _dos ī¯ Rules to be followed while īƒŧ Identifiers are a sequence of characters which should begin with the alphabet either from A-Z (Uppercase) or a-z (lowercase) or (underscore). īƒŧ C++ treats uppercase and lowercase characters differently īƒŧ No Special character is allowed except underscore “_”. īƒŧ Identifier should be single words i.e. blank spaces cannot be included in identifier. īƒŧ Reserved Keywords should not be used as identifiers. īƒŧ Identifiers should be of reasonable length. _ 15 Identifiers
  • 4. Keywords: are predefined word that gives special meaning to the complier. 16 Keywords
  • 5. . ī¯ C++ Operators: īƒŧ Operators are used to perform operations on variables values. īƒŧ Example: int x = 100 + 50; ī¯ C++ Operators Types: and īƒŧ C++ divides the operators into ī¯ Arithmetic operators ī¯ Assignment operators ī¯ Comparison operators ī¯ Logical operators ī¯ Bitwise operators the following groups. 22 C++ Operators
  • 6. ī¯ Arithmetic operators are used to perform common mathematical operations. 23 Arithmetic Operators
  • 7. ī¯ Assignment operators are used to assign values to variables. 24 Assignment Operators
  • 8. ī¯ Comparison operators are used to compare two values. ī¯ The return value of a comparison is either true (1) or false (0). 25 Relational Operator
  • 9. ī¯ Logical operators are used to determine the logic between variables or values. 26 Logical Operators
  • 10. ī¯ A Bitwise operators programming. are used in bit level 27 Bitwise Operators
  • 11. 28 ī¯ Operators may also be classified operands they act on either: īƒŧ Unary Operators īƒŧ Example: a++ īƒŧ Binary Operators īƒŧ Example: x = y– z; on the number of C++ Operators
  • 12. Special Operator : ī¯ An expression is a combination of opcode and operand. ī¯ Some special operators used in C++ programming are: 29 C++ Operators
  • 13. ī¯ Punctuators in C++ have syntactic and semantic meaning to the compiler. 30 Punctuators
  • 14. Data Types: ī¯ Data Types can be defined as the set of values, which can be stored in a variable along with the operations that can be performed on those values. ī¯ C++ defines several types of data and each type has characteristics. ī¯ C++ data types can be classified as: unique 1. 2. 3. The fundamental data type(built-in Derived Data type User-defined data type data) 31 Data Types
  • 15. Data Types: ī¯ C++ defines several types of data and characteristics. each type has unique ī¯ C++ data types can be classified as: 32 Data Types
  • 16. Input & Output Operators ī¯ The input output operations are done using library functions cin and cout objects of the class iostream. ī¯ Using the standard input and output library, we will able to interact with the user by printing message on the screen and getting the user’s input from the keyboard. īƒŧ A stream is an object where a program can either insert/extract characters to/from it. īƒŧ The standard C++ library includes the header file iostream, where the standard input and output stream objects are declared. 35 Input & Output Operators
  • 17. Input Operators: ī¯ Input Operator “>>”: The standard input device is usually the keyboard. ī¯ Input in C++ is done by using the the cin stream. “stream extraction” (>>) on ī¯ “cin” stands for “console input”. ī¯ Example: int age; cin>>age; 36 Input & Output Operators
  • 18. Output Operator: ī¯ Output Operator “<<”: The standard output device is the screen (Monitor). ī¯ Outputting in C++ is done by using the object followed by “stream insertion” (<<). ī¯ “cout” stands for console output the ī¯ Example: cout<<”sum”; //prints sum cout<<sum; //prints the content of the variable sum; 37 Input & Output Operators
  • 19. Cascading of I/O Operators: ī¯ If a program requires more than possible to input these variables multiple stream extraction “>>” one input variable then it is in a single cin statement using operators. ī¯ Example: cout<<”Enter the two number”; cin>>a>>b; ī¯ If a program requires more than one output result then this can be done using a single cout statement with multiple stream insertion “<<“ operators. ī¯ This is called cascading of input & output operators. ī¯ Example: cout<<”Entered the two number”<<a<<b<<endl; cout<<”The sum of two number is”<<sum<<endl; 38 Input & Output Operators
  • 20. Introduction: ī¯ Control statements are statements that alter the sequence of flow of instructions. ī¯ The order in which statements are executed in a program is called flow of control. ī¯ Types of control statements: control statements. īƒŧ Selection statements īƒŧ Iteration statements C++ supports two basic 41 Control Statements
  • 21. Selection Statements: This statement allows us to select a statement or set of statements for execution based on some condition. It is also known as conditional statement. ī¯ ī¯ This structure helps the programmer decision. The different selection statements: īƒŧ if statement īƒŧ if – else statement īƒŧ Nested – if statement īƒŧ switch statement to take appropriate ī¯ ī¯ 42 Control Statements
  • 22. .: 43 if ī¯ statement: This This This is the simplest form of Selection statement. statement is also called as one-way branching. statement is used to decide whether a statement ī¯ or ī¯ set of statements should be executed The decision is based on a condition evaluated to TRUE or FALSE Syntax: if (Test Condition) // is true Statement 1; Statement 2; or not. which can be ī¯ ī¯ Selection Statements
  • 23. if ī¯ – else statement: This statement is also called as two-way branching. This structure helps to select one executed from two sets. set of statements to be ī¯ Syntax of if – else if (Test Condition) statement is: ī¯ Statement 1; else Statement 2; 44 Selection Statements
  • 24. Nested if statement : ī¯ If the statement of an if statement is another if statement then such an if statement is called as Nested-if Statement. ī¯ The general form of if (Test Condition 1) Statement 1; else if (Test Condition 2) Statement 2; else â€Ļâ€Ļâ€Ļ.. else if( test Condition N) Statement N; else Default Statement; if – else – if statement is:. 45 Selection Statements
  • 25. Switch Statement : ī¯ C++ has built in multiple-branch selection statement ī¯ If there are more than two alternatives to selection construct is used. be selected, multiple ī¯ The general form of Switch statement Switch ( Expression ) is: { Case Label-1: Statement 1; Break; Case Label-2: Statement 1; Break; â€Ļâ€Ļâ€Ļâ€Ļ.. Case Label-N: Statement N; Break; Default : Default- Statement; } 46 Selection Statements
  • 26. Iterative Constructs or Looping: ī¯ The process of repeated execution of a sequence of statements until some condition is satisfied is called as iteration or loop. ī¯ Iterative statements are also called as repetitive statement or looping statements. ī¯ There are three types īƒŧ while loop īƒŧ do while loop īƒŧ for loop of looping structures in C++: 47 Iteration statements
  • 27. while loop: ī¯ This is a pre-tested loop structure. ī¯ This structure checks the condition at the beginning of the structure. ī¯ The set of statements are executed again the condition is true. and again until ī¯ The general form of while while ( Test Condition) structure is { Statement Statement â€Ļâ€Ļ.. Statement 1 2 N } //End of While 48 Iteration statements
  • 28. do-while loop: ī¯ This is a post-tested loop structure. ī¯ This structure checks the condition at the end of the structure. ī¯ The set of statements are executed again condition is true. and again until the ī¯ The general form do of while structure is { Statement Statement â€Ļâ€Ļ.. Statement 1 2 N } //while ( Test Condition); 49 Iteration statements
  • 29. for loop: ī¯ This structure is the fixed execution structure. ī¯ Usually used when we know in advance exactly how many times a set of statements to be executed repeatedly. ī¯ This structure can be used as increment looping decrement looping structure. or ī¯ The general form of for structure is as follows: for ( Expression 1; Expression 2; Expression 3) { Statement Statement Statement 1; 2; N; } 50 Iteration statements
  • 30. Introduction: ī¯ An array is collection of elements where all the elements are same data type under the same name. ī¯ The elements are numbered as 0, 1, 2â€Ļ.n-1. ī¯ These numbers called as indices or subscripts. ī¯ These numbers are used to locate the positions of elements within the array. ī¯ If a is the name of accessed as a[0], a[1], the array, the elements can be directly a[2],â€Ļâ€Ļ, a[n-1]. 56 Arrays
  • 31. . ī‚§Why need to use array type? ī‚§Consider the following issue: "We have a list of 1000 students' marks of an integer type. If using the basic data type (int), we will declare something like the followingâ€Ļ" int studMark0, studMark1, ...studMark999
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. #include<iostream> using namespace std; int main() { int i,sum=0,a[5]; cout<<"enter Numbers "; for(i=0;i<5;i++) { cin>>a[i]; } for(i=0;i<5;i++) { sum=sum+a[i]; } cout<<" Sum= "<<sum; return 0; }
  • 40. #include<iostream> using namespace std; int main() { int i,a[5],max, min; cout<<"enter value "; for(i=0;i<5;i++) { cin>>a[i]; } max=a[0]; min=a[0]; for(i=1;i<5;i++) { if(max<a[i]) max=a[i]; if(min>a[i]) min=a[i]; } cout<<" max="<<max<<endl; cout<< " min ="<<min<<endl; return 0; }
  • 41.
  • 42.
  • 43. Introduction: ī¯ A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. ī¯ Types of functions: īƒŧ Library functions A standard library is a collection of pre-defined functions and other programming elements, which are accessed through header files īƒŧ User-defined functions ī¯ We can create our own functions or sub-programs to solve our problem. Such functions are normally referred to as user- defined functions ī¯ 58 Functions
  • 44. User-defined functions: User-defined function is a function defined by the user to solve his/her problem. The purpose of using a function is to make the program design process easy, understandable and thereby avoiding ambiguity. Types of functions: ī¯ ī¯ ī¯ īƒŧ Function īƒŧ Function īƒŧ Function īƒŧ Function with with with with no arguments and no return values. arguments and with no return values. no arguments and with return values. arguments and with return values. īƒŧ Recursive function. 59 Functions
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50. Function with no argument and no return #include<iostream> using namespace std; void sum(); int main() { sum(); return 0; } void sum() { int a,b; cout<<" enter a and b :- "; cin>>a>>b; cout<<" Sum="<<a+b; }
  • 51. Function with argument and no return #include<iostream> using namespace std; void sum(int, int); int main() { int a,b; cout<<" enter a and b :- "; cin>>a>>b; sum(a,b); return 0; } void sum(int a, int b) { cout<<" Sum="<<a+b; }
  • 52. Function with no argument and return #include<iostream> using namespace std; int sum(); int main() { int x; x=sum(); cout<<" Sum="<<x; return 0; } int sum() { int a,b; cout<<" enter a and b :- "; cin>>a>>b; return(a+b); }
  • 53. Function with argument and return #include<iostream> using namespace std; int sum(int, int); int main() { int x,a,b; cout<<" enter a and b :- "; cin>>a>>b; x=sum(a,b); cout<<" Sum="<<x; return 0; } int sum(int a, int b) { return(a+b); }
  • 54. ī¯ Objects are basic building blocks for designing programs. ī¯ An object is a collection of data members and associated member functions. ī¯ An object may represent a person, place or a table of data. ī¯ Each object is identified by a unique name. Each object must be a member of a particular class. 62 Objects
  • 55. ī¯ A class is a collection of objects that have identical properties, common behavior and shared relationship. ī¯ A class binds the data and its related functions together. ī¯ A class is a user-defined data type that we program. can use in a ī¯ To create a class, use the ī¯ Example: class MyClass { // The class body }; class keyword. īƒŧ Where class keyword is used to create a class called MyClass 63 Class
  • 56. Definition and Declaration of Classes ī¯ A class definition is a process of naming a class and data variables, and interface operation of the class. ī¯ The variables declared inside a class are known as data members. ī¯ The functions declared inside a class are known as member functions. ī¯ A class declaration specifies the representation of objects of the class and set of operations that can be applied to such objects. 64 Class in C++
  • 57. Definition and Declaration of Classes ī¯ Class body is enclosed in a pair of brackets. Class body contains the declaration of its members (data and functions). ī¯ The functions declared inside a class are known functions. as member ī¯ The general syntax of the class declaration class User_Defined_Name { private : Data Member; Member functions; }; is: 65 Class in C++
  • 58. Access Specifiers Access specifiers define how the members (attributes and function) of a class can be accessed. ī¯ Every data member of a class is specified by three levels access protection for hiding data and function members internal to the class. of ī¯ They help in controlling the access Different access specifiers are: īƒŧ private īƒŧ public īƒŧ protected of the data members. ī¯ ī¯ 66 Access Specifiers
  • 59. private: ī¯ private access means a member data can only be accessed by the class member function or friend function. ī¯ The data members or member functions declared private cannot be accessed from outside the class. ī¯ The objects of the class can access the private members through the public member functions of the class. ī¯ By default data members in a class are private. ī¯ Example: private: int x; float y; only 67 Access Specifiers
  • 60. protected: ī¯ The members which are declared using protected can be accessed only by the member functions, friend of the class also the member functions derived from this class. ī¯ The members cannot be accessed from outside the class. and ī¯ The protected access specifiers. ī¯ Example: protected: int x; float y; specifier is similar to private access 68 Access Specifiers
  • 61. public: ī¯ public access means that member can be accessed any function inside or outside the class. ī¯ Some of the public functions of a class provide interface for accessing the private and protected members ī¯ Example: class MyClass { public: // Public access specifier of the class. int x; private: int y; }; // Public attribute // Private access specifier // Private attribute 69 Access Specifiers
  • 62. Member Function: ī¯ Member functions are functions that are included within a class (Member functions are also called Methods). ī¯ Member functions can be defined īƒŧ Inside class definition īƒŧ Outside class definition in two places. 70 Member Function
  • 63. Inside class definition: ī¯ To define member function inside a class the function declaration within the class is replaced by actual function definition inside class. the ī¯ Only small functions are ī¯ Example: class rectangle { defined inside class definition. void compute( ) { area = length * breadth; } void display( ) { int length, breadth, public: void get_data( ) { area; cout<< ” Enter the values for Length and Breadth”; cin>>length>>breadth; } cout<<” The area of rectangle is”<<area; } }; 71 Member Function
  • 64. Outside class definition: ī¯ To define member function outside the class, the class name must be linked with the name of member function. ī¯ Scope resolution operator (::) is used to define the member function outside the class. ī¯ Syntax of a member function defined outside the class is: return_type class_name : : member_function_name( arg1, ..., argnN) { function body; } 72 Member Function
  • 65. Program to use member class definition: #include<iostream.h> class item { private: int numbers; float cost; public: functions inside and outside }; void item : : getdata(int a, float b) { number = a; cost = b; } void getdata(int a, void putdata( ) { cout<<”Number: float b); int main( ) { item x; x. getdata( 250, 10.5); x.putdata( ); return 0; } “<<number<<endl; cout<<”Cost:”<<cost<<endl; } 73 Member Function
  • 66. Object of a class: ī¯ An object is a real world element which is identifiable entity with some characteristics (attributes) and behavior (functions). ī¯ An object is an instance of a class. ī¯ An object is normally defined in the main ( ) function. ī¯ The syntax for defining objects of a class as follows: class Class_Name { private : //Members public : //Members }; class Class_Name Object_name1, Object_name2,â€Ļâ€Ļ; īƒŧ where class keyword is optional. 74 Defining object of a class
  • 67. Dot operator (.): ī¯ The public data members of objects of a class can be accessed using direct member access operator (.). ī¯ Private and protected members of the class can be accessed only through the member functions of the class. ī¯ No functions outside a class can include statements to access data directly. ī¯ The syntax of accessing member (data and functions) of a class is: a) Syntax for accessing a data member of the class: Object_Name . data_member; b) Syntax for accessing a member function of the class: Object_Name . member_function(arguments); 75 Accessing member of the class