SlideShare a Scribd company logo
1 of 30
Download to read offline
UNIT - I
INTRODUCTION TO C++:
•C++ (pronounced "see plus plus") is a programming language began as an
expanded version of C.
•The C++ were first invented by Bjarne Stroustrup in 1979 at Bell
Laboratories in Murray Hill, New Jersey.
•Bjarne Stroustrup initially called the new language "C with Classes."
However, in 1983 the name was changed to C++.
•C++ is a middle-level programming language.
•C++ is a statically typed, compiled, general purpose, case -sensitive, free-
form programming language that supports procedural, object-oriented, and
generic programming.
•C++ is an intermediate level language, as it comprises a confirmation of both
high level and low level language features.
KEY CONCEPTS OF OOPs:
•Object Oriented Programming is a paradigm that provides many concepts such
as inheritance, data binding, polymorphism etc.
•Object means a real word entity such as pen, chair, table etc.
•Object-Oriented Programming is a methodology or paradigm to design a program
using classes and objects. It simplifies the software development and maintenance by
providing some concepts: Object, Class, Inheritance, Polymorphism, Abstraction,
Encapsulation.
1. Object - Any entity that has state and behavior is known as an object. For
example: chair, pen, table, keyboard, bike etc. It can be physical and logical.
Class - Collection of objects is called class. It is a logical entity.
2. Inheritance - When one object acquires all the properties and behaviours of parent
object i.e. known as inheritance. It provides code reusability. It is used to achieve
runtime polymorphism.
3. Polymorphism - When one task is performed by different ways i.e. known as
polymorphism. For example: to convince the customer differently, to draw something
e.g. shape or rectangle etc.
In C++, we use Function overloading and Function overriding to achieve
polymorphism.
4. Abstraction - Hiding internal details and showing functionality is known as
abstraction. For example: phone call, we don't know the internal processing.
In C++, we use abstract class and interface to achieve abstraction.
5. Encapsulation - Binding (or wrapping) code and data together into a single unit is
known as encapsulation. For example: capsule, it is wrapped with different
medicines.
ADVANTAGES OF OOPs
• OOPs makes development and maintenance easier where as in
Procedure-oriented programming language it is not easy to manage
if code grows as project size grows.
• OOPs provide data hiding whereas in Procedure-oriented
programming language a global data can be accessed from
anywhere.
• OOPs provide ability to simulate real-world event much more
effectively. We can provide the solution of real word problem if we
are using the Object-Oriented Programming language.
OBJECT-ORIENTED LANGUAGE (OOL):
• Object-oriented language was primarily designed to reduce complexity in typical
procedural languages through data binding and encapsulation techniques. In
object-oriented language, the objects created provide limited or no access to
other functions or methods within the program. This enables only authorized or
inherited methods/functions to access a particular object.
• Object-oriented language typically supports the following features, at minimum:
• The ability to create classes and their associated objects
• Encapsulation
• Inheritance
• Java, C++ and Smalltalk are popular examples of object-oriented languages
INPUT/OUTPUT IN C++:
• C++ I/O operation is using the stream concept. Stream is the sequence of
bytes or flow of data. It makes the performance fast.
• If bytes flow from main memory to device like printer, display screen, or
a network connection, etc, this is called as output operation.
• If bytes flow from device like printer, display screen, or a network
connection, etc to main memory, this is called as input operation.
I/O Library Header Files
Standard input stream (cin)
The cin is a predefined object of istream class. It is connected with the
standard input device, which is usually a keyboard. The cin is used in
conjunction with stream extraction operator (>>) to read the input from a
console.
Standard output stream (cout)
The cout is a predefined object of ostream class. It is connected with the
standard output device, which is usually a display screen. The cout is used
in conjunction with stream insertion operator (<<) to display the output on
a console
Standard end line (endl)
The endl is a predefined object of ostream class. It is used to insert a new
line characters and flushes the stream.
#include <iostream>
using namespace std;
int main( ) {
int age;
cout << "Enter your age: ";
cin >> age;
cout << "Your age is: " << age << endl;
}
Output: Enter your age: 22
Your age is: 22
C++ DECLARATIONS:
#include <iostream> using namespace std; //
main() is where program execution begins.
int main()
{
cout << "Hello World"; // prints Hello World return 0;
}
Let us look at the various parts of the above program −
The C++ language defines several headers, which contain information that is either
necessary or useful to your program.
For this program, the header <iostream> is needed.
The line using namespace std; tells the compiler to use the std namespace.
Namespaces are a relatively recent addition to C++.
The next line '// main() is where program execution begins.' is a single-line
comment available in C++. Single-line comments begin with // and stop at the end
of the line.
The line int main() is the main function where program execution begins.
The next line cout << "Hello World"; causes the message "Hello World" to be
displayed on the screen.
The next line return 0; terminates main( )function and causes it to return the value
0 to the calling process.
C++ Identifiers
A C++ identifier is a name used to identify a variable, function, class, module, or any other user-
defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by
zero or more letters, underscores, and digits (0 to 9).
C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is a case-
sensitive programming language. Thus, Manpower and manpower are two different identifiers
in C++.
Here are some examples of acceptable identifiers −
mohd zara abc move_name a_123 myname50
_temp j a23b9 retVal
C++ Keywords
The following list shows the reserved words in C++. These reserved words may not be used as
constant or variable or any other identifier names.
Asm else new this auto enum operator throw bool explicit
private true break export try case extern public goto typedef
catch false register typeid char float typename do if signed
class for unsigned friend delete using switch long int continue
return union const short sizeof virtual default inline static volatile
struct while double void mutable template wchar_t dynamic_cast
Namespace protected static_cast reinterpret_cast const_cast
Trigraphs
A few characters have an alternative representation, called a trigraph sequence. A trigraph is a
three-character sequence that represents a single character and the sequence always starts with
two question marks.
Trigraphs are expanded anywhere they appear, including within string literals and character
literals, in comments, and in preprocessor directives.
Following are most frequently used trigraph sequences −
Whitespace in C++
A line containing only whitespace, possibly with a comment, is known as a blank line, and C++
compiler totally ignores it.
Whitespace is the term used in C++ to describe blanks, tabs, newline characters and comments.
Whitespace separates one part of a statement from another and enables the compiler to
identify where one element in a statement, such as int, ends and the next element begins.
Control Structures:
1. Decision Making Statements - C++ if-else
In C++ programming, if statement is used to test the condition. The various types are as follows
•if statement
The C++ if statement tests the condition. It is executed if condition is true.
if(condition){
//code to be executed
}
C++ IF-else Statement
The C++ if-else statement also tests the condition. It executes if block if condition is true
otherwise else block is executed.
if(condition){
//code if condition is true
}else{
//code if condition is false
}
nested if statement
if(condition1){
//code to be executed if condition1 is true
}if(condition2){
//code to be executed if condition2 is true
} else{
//code to be executed if all the conditions are false
}
#include <iostream>
using namespace std;
int main () {
int num, std,sec;
cout<<"Enter your Standard:"; cin>>std ;
if (std >0 || std <13)
{ if( sec >0|| sec<3){
cout<<“You are a CBSE Students"; }
else if (sec >= 4 && std >11)
{ cout<<“You are a State Board Students"; }
else
{ cout<<“You are a Tamil Medium Students"; }
if-else-if ladder
if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}
#include <iostream>
using namespace std;
int main () {
int num;
cout<<"Enter a number to check grade:";
cin>>num;
if (num <0 || num >100)
{ cout<<"wrong number"; }
else if(num >= 0 && num < 50){
cout<<"Fail"; }
else if (num >= 50 && num < 60)
{ cout<<"D Grade"; }
else if (num >= 60 && num < 70)
{ cout<<"C Grade"; }
else if (num >= 70 && num < 80)
{ cout<<"B Grade"; }
else if (num >= 80 && num < 90)
{ cout<<"A Grade"; }
else if (num >= 90 && num <= 100)
{ cout<<"A+ Grade"; } }
C++ switch
The C++ switch statement
executes one statement from
multiple conditions. It is like
if-else-if ladder statement.
switch(expression){
case value1:
//code to be executed;
break;
case value2:
//code to be executed;
break;
......
default:
//code to be executed if all
cases are not matched;
break; }
BREAK
C++ Continue Statement
The C++ continue statement is used to continue loop. It continues the current
flow of the program and skips the remaining code at specified condition. In
case of inner loop, it continues only inner loop. jump-statement & Continue;
C++ Goto Statement
The C++ goto statement is also known as jump statement. It is used to transfer
control to the other part of the program. It unconditionally jumps to the
specified label.
It can be used to transfer control from deeply nested loop or switch case label.
#include <iostream>
int main () {
int num;
cout<<"Enter a number to check grade:";
cin>>num; switch (num) {
case 10: cout<<"It is 10"; break; continue;
case 20: cout<<"It is 20"; break;
case 30: cout<<"It is 30"; break; goto case 10
default: cout<<"Not 10, 20 or 30"; break; } }
Output:Enter a number: 10 It is 10
C++ Comments
The C++ comments are statements that are not executed by the compiler. The
comments in C++ programming can be used to provide explanation of the code,
variable, method or class. By the help of comments, you can hide the program
code also.
There are two types of comments in C++.
Single Line comment - The single line comment starts with // (double
slash). Let's see an example of single line comment in C++
Multi Line comment - The C++ multi line comment is used to comment
multiple lines of code. It is surrounded by slash and asterisk (/∗ ..... ∗/).
#include <ostream>
int main()
{
/* declare and
print variable in C++. */
int x = 35; // x is a variable
cout<<x<<"n";
}
C++ For Loop
The C++ for loop is used to iterate a part of the program several times. If the number of iteration
is fixed, it is recommended to use for loop than while or do-while loops.
The C++ for loop is same as C/C#. We can initialize variable, check condition and
increment/decrement value.
for(initialization; condition; incr/decr){
//code to be executed
}
C++ While loop
In C++, while loop is used to iterate a part of the program several times. If the
number of iteration is not fixed, it is recommended to use while loop than for
loop.
while(condition){
//code to be executed
}
Do-While Loop
The C++ do-while loop is used to iterate a part of the program several times. If
the number of iteration is not fixed and you must have to execute the loop at
least once, it is recommended to use do-while loop.
The C++ do-while loop is executed at least once because condition is checked
after loop body.
do{
//code to be executed
}while(condition);
C++ Functions
The function in C++ language is also known as procedure or subroutine in other
programming languages.
To perform any task, we can create function. A function can be called many
times. It provides modularity and code reusability.
Advantage of functions in C
1) Code Reusability -By creating functions in C++, you can call it many times.
So we don't need to write the same code again and again.
2) Code optimization-It makes the code optimized, we don't need to write
much code.Suppose, you have to check 3 numbers (531, 883 and 781) whether
it is prime number or not. Without using function, you need to write the prime
number logic 3 times. So, there is repetition of code. Types of Functions
There are two types of functions in C programming:
1. Library Functions: are the functions which are declared in the C++ header
files such as ceil(x), cos(x), exp(x), etc.
2. User-defined functions: are the functions which are created by the C++
programmer, so that he/she can use it many times. It reduces complexity of a
big program and optimizes the code.
C++ Recursion
When function is called within the same function, it is known as
recursion in C++. The function which calls the same function, is known
as recursive function.
A function that calls itself, and doesn't perform any task after function
call, is known as tail recursion. In tail recursion, we generally call the
same function with return statement.
Let's see a simple example of recursion.
recursionfunction(){
recursionfunction(); //calling self function
}
THANK YOU……

More Related Content

Similar to C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps concepts

Similar to C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps concepts (20)

C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Survey of programming language getting started in C
Survey of programming language getting started in CSurvey of programming language getting started in C
Survey of programming language getting started in C
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
C programming language
C programming languageC programming language
C programming language
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Learning c++
Learning c++Learning c++
Learning c++
 
C++ basics
C++ basicsC++ basics
C++ basics
 
c.ppt
c.pptc.ppt
c.ppt
 
c programming session 1.pptx
c programming session 1.pptxc programming session 1.pptx
c programming session 1.pptx
 

More from ANUSUYA S

Digital Old Question Paper for Reference (Bharathiyar University)
Digital Old Question Paper for Reference (Bharathiyar University)Digital Old Question Paper for Reference (Bharathiyar University)
Digital Old Question Paper for Reference (Bharathiyar University)ANUSUYA S
 
C Old Question Paper for Reference (Bharathiyar University)
C Old Question Paper for Reference (Bharathiyar University)C Old Question Paper for Reference (Bharathiyar University)
C Old Question Paper for Reference (Bharathiyar University)ANUSUYA S
 
C++ Old Question Paper for Reference (Bharathiyar University)
C++ Old Question Paper for Reference (Bharathiyar University)C++ Old Question Paper for Reference (Bharathiyar University)
C++ Old Question Paper for Reference (Bharathiyar University)ANUSUYA S
 
C++ 260 MCQ Question with Answer for all Units
C++ 260 MCQ Question with Answer for all UnitsC++ 260 MCQ Question with Answer for all Units
C++ 260 MCQ Question with Answer for all UnitsANUSUYA S
 
C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File ConceptsANUSUYA S
 
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...ANUSUYA S
 
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...ANUSUYA S
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersANUSUYA S
 

More from ANUSUYA S (8)

Digital Old Question Paper for Reference (Bharathiyar University)
Digital Old Question Paper for Reference (Bharathiyar University)Digital Old Question Paper for Reference (Bharathiyar University)
Digital Old Question Paper for Reference (Bharathiyar University)
 
C Old Question Paper for Reference (Bharathiyar University)
C Old Question Paper for Reference (Bharathiyar University)C Old Question Paper for Reference (Bharathiyar University)
C Old Question Paper for Reference (Bharathiyar University)
 
C++ Old Question Paper for Reference (Bharathiyar University)
C++ Old Question Paper for Reference (Bharathiyar University)C++ Old Question Paper for Reference (Bharathiyar University)
C++ Old Question Paper for Reference (Bharathiyar University)
 
C++ 260 MCQ Question with Answer for all Units
C++ 260 MCQ Question with Answer for all UnitsC++ 260 MCQ Question with Answer for all Units
C++ 260 MCQ Question with Answer for all Units
 
C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File Concepts
 
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...
C++ - UNIT_-_II.pptx which used to contain breif description about classes & ...
 
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...
C++ - UNIT_-_III.pptx which contains detail description of Operator & Overloa...
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 

Recently uploaded

9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi NcrSapana Sha
 
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiFULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiMalviyaNagarCallGirl
 
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call GirlsFaridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
Strip Zagor Extra 322 - Dva ortaka.pdf
Strip   Zagor Extra 322 - Dva ortaka.pdfStrip   Zagor Extra 322 - Dva ortaka.pdf
Strip Zagor Extra 322 - Dva ortaka.pdfStripovizijacom
 
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | DelhiFULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | DelhiMalviyaNagarCallGirl
 
Turn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel JohnsonTurn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel Johnsonthephillipta
 
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call GirlsBurari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiMalviyaNagarCallGirl
 
FULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | DelhiFULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | DelhiMalviyaNagarCallGirl
 
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...anilsa9823
 
Call Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call GirlsCall Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call GirlsAyesha Khan
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiMalviyaNagarCallGirl
 
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857delhimodel235
 
FULL ENJOY - 9953040155 Call Girls in Moti Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Moti Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Moti Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Moti Nagar | DelhiMalviyaNagarCallGirl
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000Sapana Sha
 
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad EscortsIslamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escortswdefrd
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubaidajasot375
 
Karachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in KarachiKarachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in KarachiAyesha Khan
 
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiMalviyaNagarCallGirl
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Parkjosebenzaquen
 

Recently uploaded (20)

9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
 
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiFULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
 
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call GirlsFaridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girls
 
Strip Zagor Extra 322 - Dva ortaka.pdf
Strip   Zagor Extra 322 - Dva ortaka.pdfStrip   Zagor Extra 322 - Dva ortaka.pdf
Strip Zagor Extra 322 - Dva ortaka.pdf
 
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | DelhiFULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
 
Turn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel JohnsonTurn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel Johnson
 
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call GirlsBurari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
 
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gtb Nagar | Delhi
 
FULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | DelhiFULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | Delhi
 
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
Lucknow 💋 Virgin Call Girls Lucknow | Book 8923113531 Extreme Naughty Call Gi...
 
Call Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call GirlsCall Girl Service in Karachi +923081633338 Karachi Call Girls
Call Girl Service in Karachi +923081633338 Karachi Call Girls
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
 
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
 
FULL ENJOY - 9953040155 Call Girls in Moti Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Moti Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in Moti Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in Moti Nagar | Delhi
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
 
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad EscortsIslamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
Islamabad Call Girls # 03091665556 # Call Girls in Islamabad | Islamabad Escorts
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
 
Karachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in KarachiKarachi Escorts | +923070433345 | Escort Service in Karachi
Karachi Escorts | +923070433345 | Escort Service in Karachi
 
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Park
 

C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps concepts

  • 1. UNIT - I INTRODUCTION TO C++: •C++ (pronounced "see plus plus") is a programming language began as an expanded version of C. •The C++ were first invented by Bjarne Stroustrup in 1979 at Bell Laboratories in Murray Hill, New Jersey. •Bjarne Stroustrup initially called the new language "C with Classes." However, in 1983 the name was changed to C++. •C++ is a middle-level programming language. •C++ is a statically typed, compiled, general purpose, case -sensitive, free- form programming language that supports procedural, object-oriented, and generic programming. •C++ is an intermediate level language, as it comprises a confirmation of both high level and low level language features.
  • 2. KEY CONCEPTS OF OOPs: •Object Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism etc. •Object means a real word entity such as pen, chair, table etc. •Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts: Object, Class, Inheritance, Polymorphism, Abstraction, Encapsulation. 1. Object - Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical. Class - Collection of objects is called class. It is a logical entity. 2. Inheritance - When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism. 3. Polymorphism - When one task is performed by different ways i.e. known as polymorphism. For example: to convince the customer differently, to draw something e.g. shape or rectangle etc. In C++, we use Function overloading and Function overriding to achieve polymorphism. 4. Abstraction - Hiding internal details and showing functionality is known as abstraction. For example: phone call, we don't know the internal processing. In C++, we use abstract class and interface to achieve abstraction. 5. Encapsulation - Binding (or wrapping) code and data together into a single unit is known as encapsulation. For example: capsule, it is wrapped with different medicines.
  • 3. ADVANTAGES OF OOPs • OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grows. • OOPs provide data hiding whereas in Procedure-oriented programming language a global data can be accessed from anywhere. • OOPs provide ability to simulate real-world event much more effectively. We can provide the solution of real word problem if we are using the Object-Oriented Programming language.
  • 4. OBJECT-ORIENTED LANGUAGE (OOL): • Object-oriented language was primarily designed to reduce complexity in typical procedural languages through data binding and encapsulation techniques. In object-oriented language, the objects created provide limited or no access to other functions or methods within the program. This enables only authorized or inherited methods/functions to access a particular object. • Object-oriented language typically supports the following features, at minimum: • The ability to create classes and their associated objects • Encapsulation • Inheritance • Java, C++ and Smalltalk are popular examples of object-oriented languages
  • 5. INPUT/OUTPUT IN C++: • C++ I/O operation is using the stream concept. Stream is the sequence of bytes or flow of data. It makes the performance fast. • If bytes flow from main memory to device like printer, display screen, or a network connection, etc, this is called as output operation. • If bytes flow from device like printer, display screen, or a network connection, etc to main memory, this is called as input operation. I/O Library Header Files
  • 6. Standard input stream (cin) The cin is a predefined object of istream class. It is connected with the standard input device, which is usually a keyboard. The cin is used in conjunction with stream extraction operator (>>) to read the input from a console. Standard output stream (cout) The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console Standard end line (endl) The endl is a predefined object of ostream class. It is used to insert a new line characters and flushes the stream. #include <iostream> using namespace std; int main( ) { int age; cout << "Enter your age: "; cin >> age; cout << "Your age is: " << age << endl; } Output: Enter your age: 22 Your age is: 22
  • 7. C++ DECLARATIONS: #include <iostream> using namespace std; // main() is where program execution begins. int main() { cout << "Hello World"; // prints Hello World return 0; } Let us look at the various parts of the above program − The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, the header <iostream> is needed. The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++. The next line '// main() is where program execution begins.' is a single-line comment available in C++. Single-line comments begin with // and stop at the end of the line. The line int main() is the main function where program execution begins. The next line cout << "Hello World"; causes the message "Hello World" to be displayed on the screen. The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process.
  • 8. C++ Identifiers A C++ identifier is a name used to identify a variable, function, class, module, or any other user- defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9). C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is a case- sensitive programming language. Thus, Manpower and manpower are two different identifiers in C++. Here are some examples of acceptable identifiers − mohd zara abc move_name a_123 myname50 _temp j a23b9 retVal C++ Keywords The following list shows the reserved words in C++. These reserved words may not be used as constant or variable or any other identifier names. Asm else new this auto enum operator throw bool explicit private true break export try case extern public goto typedef catch false register typeid char float typename do if signed class for unsigned friend delete using switch long int continue return union const short sizeof virtual default inline static volatile struct while double void mutable template wchar_t dynamic_cast Namespace protected static_cast reinterpret_cast const_cast
  • 9. Trigraphs A few characters have an alternative representation, called a trigraph sequence. A trigraph is a three-character sequence that represents a single character and the sequence always starts with two question marks. Trigraphs are expanded anywhere they appear, including within string literals and character literals, in comments, and in preprocessor directives. Following are most frequently used trigraph sequences − Whitespace in C++ A line containing only whitespace, possibly with a comment, is known as a blank line, and C++ compiler totally ignores it. Whitespace is the term used in C++ to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins.
  • 10. Control Structures: 1. Decision Making Statements - C++ if-else In C++ programming, if statement is used to test the condition. The various types are as follows •if statement The C++ if statement tests the condition. It is executed if condition is true. if(condition){ //code to be executed }
  • 11. C++ IF-else Statement The C++ if-else statement also tests the condition. It executes if block if condition is true otherwise else block is executed. if(condition){ //code if condition is true }else{ //code if condition is false }
  • 12. nested if statement if(condition1){ //code to be executed if condition1 is true }if(condition2){ //code to be executed if condition2 is true } else{ //code to be executed if all the conditions are false } #include <iostream> using namespace std; int main () { int num, std,sec; cout<<"Enter your Standard:"; cin>>std ; if (std >0 || std <13) { if( sec >0|| sec<3){ cout<<“You are a CBSE Students"; } else if (sec >= 4 && std >11) { cout<<“You are a State Board Students"; } else { cout<<“You are a Tamil Medium Students"; }
  • 13.
  • 14. if-else-if ladder if(condition1){ //code to be executed if condition1 is true }else if(condition2){ //code to be executed if condition2 is true } else if(condition3){ //code to be executed if condition3 is true } ... else{ //code to be executed if all the conditions are false }
  • 15. #include <iostream> using namespace std; int main () { int num; cout<<"Enter a number to check grade:"; cin>>num; if (num <0 || num >100) { cout<<"wrong number"; } else if(num >= 0 && num < 50){ cout<<"Fail"; } else if (num >= 50 && num < 60) { cout<<"D Grade"; } else if (num >= 60 && num < 70) { cout<<"C Grade"; } else if (num >= 70 && num < 80) { cout<<"B Grade"; } else if (num >= 80 && num < 90) { cout<<"A Grade"; } else if (num >= 90 && num <= 100) { cout<<"A+ Grade"; } }
  • 16. C++ switch The C++ switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement. switch(expression){ case value1: //code to be executed; break; case value2: //code to be executed; break; ...... default: //code to be executed if all cases are not matched; break; }
  • 17. BREAK
  • 18. C++ Continue Statement The C++ continue statement is used to continue loop. It continues the current flow of the program and skips the remaining code at specified condition. In case of inner loop, it continues only inner loop. jump-statement & Continue; C++ Goto Statement The C++ goto statement is also known as jump statement. It is used to transfer control to the other part of the program. It unconditionally jumps to the specified label. It can be used to transfer control from deeply nested loop or switch case label. #include <iostream> int main () { int num; cout<<"Enter a number to check grade:"; cin>>num; switch (num) { case 10: cout<<"It is 10"; break; continue; case 20: cout<<"It is 20"; break; case 30: cout<<"It is 30"; break; goto case 10 default: cout<<"Not 10, 20 or 30"; break; } } Output:Enter a number: 10 It is 10
  • 19. C++ Comments The C++ comments are statements that are not executed by the compiler. The comments in C++ programming can be used to provide explanation of the code, variable, method or class. By the help of comments, you can hide the program code also. There are two types of comments in C++. Single Line comment - The single line comment starts with // (double slash). Let's see an example of single line comment in C++ Multi Line comment - The C++ multi line comment is used to comment multiple lines of code. It is surrounded by slash and asterisk (/∗ ..... ∗/). #include <ostream> int main() { /* declare and print variable in C++. */ int x = 35; // x is a variable cout<<x<<"n"; }
  • 20. C++ For Loop The C++ for loop is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use for loop than while or do-while loops. The C++ for loop is same as C/C#. We can initialize variable, check condition and increment/decrement value. for(initialization; condition; incr/decr){ //code to be executed }
  • 21.
  • 22. C++ While loop In C++, while loop is used to iterate a part of the program several times. If the number of iteration is not fixed, it is recommended to use while loop than for loop. while(condition){ //code to be executed }
  • 23. Do-While Loop The C++ do-while loop is used to iterate a part of the program several times. If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use do-while loop. The C++ do-while loop is executed at least once because condition is checked after loop body. do{ //code to be executed }while(condition);
  • 24. C++ Functions The function in C++ language is also known as procedure or subroutine in other programming languages. To perform any task, we can create function. A function can be called many times. It provides modularity and code reusability. Advantage of functions in C 1) Code Reusability -By creating functions in C++, you can call it many times. So we don't need to write the same code again and again. 2) Code optimization-It makes the code optimized, we don't need to write much code.Suppose, you have to check 3 numbers (531, 883 and 781) whether it is prime number or not. Without using function, you need to write the prime number logic 3 times. So, there is repetition of code. Types of Functions There are two types of functions in C programming: 1. Library Functions: are the functions which are declared in the C++ header files such as ceil(x), cos(x), exp(x), etc. 2. User-defined functions: are the functions which are created by the C++ programmer, so that he/she can use it many times. It reduces complexity of a big program and optimizes the code.
  • 25.
  • 26.
  • 27. C++ Recursion When function is called within the same function, it is known as recursion in C++. The function which calls the same function, is known as recursive function. A function that calls itself, and doesn't perform any task after function call, is known as tail recursion. In tail recursion, we generally call the same function with return statement. Let's see a simple example of recursion. recursionfunction(){ recursionfunction(); //calling self function }
  • 28.
  • 29.