Documente Academic
Documente Profesional
Documente Cultură
Objectives
• History of C++
• Features of C++
• Sample C++ program
• Data types
• Variables
• Conditional and looping statement h
Invent
Why C++
History of C++
• 1980:Bjarne Stroustrup of AT&T Bell Laboratories
added the concept of classes of C. The language
is called “C with classes”
• 1983: “C with classes” is called C++
• 1985:AT&T begins Commercial distribution of C++
• 1986:Cfront-apreprocessor that translates C++ to
C is widely available. The C++ Programming
Language by Stroustrup is published
• 1988: The first true C++ compiler becomes
available
h
Invent
Why C++
h
Invent
Why C++
Features of C++
• Data Abstraction
• Reusability
• Reliability h
Invent
Why C++
• Extensibility
OOPS Concepts
• Class and Object
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism etc.
h
Invent
Why C++
h
Invent
Why C++
h
Invent
Why C++
h
Invent
Why C++
long double
bool
12
1 h
16 Digits of precision
0 or 1
float
fnum1,fnum2=99. fnum1 4 -
h
float
62f; fnum2 4 99.62
fnum2=99.62f;
Invent
Why C++
Operators in C++
• Comparison operator like ==,!=,>,<,>=and <= are
present in C++.
• It has arithmetic operators like +,-,*, / and % .
• Logical operator supported by C++ are &&(and) , ||
(or) and !(not).
• Assignment operators =, +=, -=,*=,/= and %= is
supported by it. h
Invent
Why C++
if statement
if(contition)
{
// Executes if condition is true
}
else
{
// Executes if condition is false
}
h
Invent
Why C++
Nested if
if (condition)
{
if (condition)
{
//statements
}//close of inner if
else
{
//statements
}//close of inner else
} //close of outer if
else
{
//statements
h
}//close of outer if
Invent
Why C++
Switch case
Switch (x)
{
case 1: cout<<“Option 1”;
break;
case 2: cout<<“Option 2”;
break;
case 3: cout<<“Option 3”;
break;
default : cout<<“Not a choice”;
}
h
Invent
Why C++
cout<< (a >b)? a : b;
while loop
while (condition)
{
//statements
}
h
Invent
Why C++
do while
{
//statements
}while(expr);
for loop
for(initialzation_expr;test_expr;change_expr)
{
//statements
}
h
Invent
Why C++
Arrays
Arrays in c and c++ are same
Example:
char name[20];
char str[]=“Sandy”;
int amount[4]={4,5,7,2};
float sal[3]={2.4f,3.4f,2.4f};
These arrays can be accepted using for
loops as in c language.
h
Invent
Why C++
Exercise
• Write a program to find out the highest
and lowest values from given 20 input
from user.
h
Invent
Why C++
h
Invent
Why C++
h
Invent