SlideShare a Scribd company logo
1 of 31
Overview of C++ language
Lecture’s outline

 What is C++?
 Identifiers.
 Constant
 Semicolons & Blocks in C++
 Data type
 Comments
 Operator
 Declaration of variables
 Giving value to variable
 C++ statements

                prepared by Taif.A.S.G
What is C++?
• Developed by Bjarne Stroustrup (in 1979 at Bell Labs)
• C++ is regarded as a middle-level language, as it comprises a
  combination of both high-level and low-level language features.
• C++ is a statically typed, compiled, general purpose, case-
  sensitive, free-form programming language that supports
  procedural, object-oriented, and generic programming.
• C++ is a superset of C that enhancement to the C language and
  originally named C with Classes but later it was renamed C++.

                         prepared by Taif.A.S.G
identifiers
They are used for naming classes
function, module, variables, object in a program.
They follow the following rules:
1) They can have alphabets , digits, and the underscore(_).
2) They must not begin with a digit.
3) Uppercase and lowercase are distinct.
4) They can be of any length.
5) It should not be a keyword.
6) White space is not allowed.

                      prepared by Taif.A.S.G
Constant
Constant is one whose value cannot be changed after it has
been initialized-any attempt to assign to field will produce a
compile-error .So, we can declare the constant by using
const field and use all uppercase letter.
Syntax of declare the constant is:
  const type name=value

Example:

const int STRENGTH = 100;
const float PI = 3.14;
                         prepared by Taif.A.S.G
Semicolons & Blocks in C++:
• In C++, the semicolon is a statement terminator.
  That is, each individual statement must be ended
  with a semicolon. It indicates the end of one logical
  entity.
• For example: following are two different
  statements:
  x = y;
  y = y+1;


                       prepared by Taif.A.S.G             6
Data type




prepared by Taif.A.S.G
Comments
C++ can use both the single line comments and multi-line
comments .
single line comments begin with // and end at the end of line.
For longer comments we can create multi-line comments by
starting with /* and ending with */




                        prepared by Taif.A.S.G
Operator
* / % + - are the mathematical operators
* / % have a higher precedence than + or –           mathematical
                                                     operators
 ++ Increment operator         –– Decrement operator
 ==    Equal (careful)
 !=            Not equal
 >=    Greater than or equal          Relational
 <=    Less than or equal             operators
 >     Greater than
 <     Less than
 &&    logical (sequential) and
                                       Logical
 ||    logical (sequential) or         operators
 =     assignment
                      prepared by Taif.A.S.G
Declaration of variables

The general form of declaration of variables:

           Type variable1, variable2,...., variableN;
Example:

int count;
float x,y;
double pi;
char c1,c2,c3;
byte b;
                         prepared by Taif.A.S.G
Giving value to variable

The general form of giving value to variables:

                  variableName= value;
Example:

finalValue=100;
x=y=z=0;
Yes = ‘x’;



                         prepared by Taif.A.S.G
Simple programs
 Write C++ Program to find Sum and Average of two
  numbers?

Write C++ Program to find area of a circle?




                    prepared by Taif.A.S.G
C++ statement
                                Control
                              statement
     Selection                     iteration                   jump
     statement                    statement                  statement



If    if-else   switch      for      while   do      break   continue   return


                            prepared by Taif.A.S.G
Decision making
• C++ supports the following statements Known
  as control or decision making statements.
1. if statement.
2. switch statement.
3. Conditional operator ? : statement.




                  prepared by Taif.A.S.G    14
Decision making with if
                statement
The general form of simple if statement is :
                if (<conditional expression>)
                <statement action>

Example:

       if (a > b)
       cout<<"a > b";




                            prepared by Taif.A.S.G   15
Decision making with if
            statement cont..
The general form of simple if else statement is :
                if (<conditional expression>)
                <statement action>
                else
Example:        <statement action>

       if (a > b)
       cout<<" a > b";
       else
       cout<<"a<b";

                            prepared by Taif.A.S.G   16
Decision making with if
            statement cont..
The general form of Multiple if else statement is :
                  if (<conditional expression>)
                  <statement action>
                  else if (<conditional expression>)
                  <statement action>
                  else
Example:          <statement action>
if (a > b)
cout<<" a > b";
 else if (a< b)
 cout<<"b > a";
else
 cout<<" a=b";
                              prepared by Taif.A.S.G   17
Decision making with switch
          statement
• The if statement allows you to select one of
  two sections of code to execute based on a
  boolean value (only two possible values). The
  switch statement allows you to choose from
  many statements.




                    prepared by Taif.A.S.G        18
Decision making with switch
         statement cont..
switch (expr) {
case c1:
statements // do these if expr == c1
 break;
case c2:
statements // do these if expr == c2
 break;
 case c3:
case c4: // Cases can simply fall thru.
statements // do these if expr == any of c's
 break; . . .
default:      // OPTIONAL
statements // do these if expr != any above
 }

                                   prepared by Taif.A.S.G   19
The ? : Operator:
• can be used to replace if...else statements. It has
  the following general form:
  Exp1 ? Exp2 : Exp3;
  Where Exp1, Exp2, and Exp3 are expressions.
• The value of a ? expression is determined like
  this: Exp1 is condition evaluated. If it is true, then
  Exp2 is evaluated and becomes the value of the
  entire ? expression. If Exp1 is false, then Exp3 is
  evaluated and its value becomes the value of the
  expression.
                       prepared by Taif.A.S.G         20
Simple programs
 Write C++ Program to find Number is Positive or
  Negative?

Write C++ Program to find the Grade of student ?

 Write C++ Program to check the day of week by using
  SWITCH-CASE?




                   prepared by Taif.A.S.G
Looping
The C++ language provides three constructs for
  performing loop operations, there are:
   1. The for statement.
   2. The while statement.
   3. The do statement.




                   prepared by Taif.A.S.G        22
Looping cont..
The general form of for statement:

for (initialization; test condition; increment)
 {
    Body of loop
 }


Example:
for( x=0; x<=10; x++)
{
cout<<x;
}                          prepared by Taif.A.S.G   23
Looping cont..
The general form of while statement:
       initialization;
      while(test condition)
     {
    Body of loop
    }

Example:
x=0;
while(x<=10)
{
cout<<x;
x++; }                     prepared by Taif.A.S.G   24
Looping cont..
The general form of do statement:
       initialization;
      do
     {
    Body of loop
    }
   while(test condition);

Example:
x=0;
do
{
cout<<x;
x++; }
while(x<=10) ;            prepared by Taif.A.S.G   25
Int num2        Int num1
                                                             0               0
  Nested Looping                                                             1
for(num2 = 0; num2 <= 3; num2++)                                             2
{                                                                       3 end of loop
   for(num1 = 0; num1 <= 2; num1++)                          1               0
   {                                                                         1
       cout<<num2 << " " <<num1;
                                                                             2
   }
}                                                                       3 end of loop
                                                             2               0
                                                                             1
                                                                             2
                                                                        3 end of loop
                                                             3               0
                                                                             1
                                                                             2
                                                                        3 end of loop
                               prepared by Taif.A.S.G                               26
                                                        4 End of loop
Functions
• A complex problem is often easier to solve by
  dividing it into several smaller
  parts(Modules), each of which can be solved by
  itself. This is called structured programming.
• In C++ Modules Known as Functions & Classes
• main() then uses these functions to solve the
  original problem.


                   prepared by Taif.A.S.G     27
Functions (cont..)
• C++ allows the use of both internal (user-
  defined) and external functions.

• External functions (e.g., abs, ceil, rand,
  sqrt, etc.) are usually grouped into specialized
  libraries (e.g., iostream, stdlib, math,
  etc.)


                     prepared by Taif.A.S.G          28
Function prototype
• The function prototype declares the input and output
  parameters of the function.

• The function prototype has the following syntax:
     <type> <function name>(<type list>);

• Example: A function that returns the absolute value of
  an integer is: int absolute(int);
• If a function definition is placed in front of main(),
  there is no need to include its function prototype.


                       prepared by Taif.A.S.G            29
Function Definition
• A function definition has the following syntax:
  <type> <function name>(<parameter list>){
       <local declarations>
       <sequence of statements>
  }

• For example: Definition of a function that computes the absolute
  value of an integer:

int absolute(int x){
     if (x >= 0) return x;
     else        return -x;
}

• The function definition can be placed anywhere in the program.

                            prepared by Taif.A.S.G                   30
Function call

• A function call has the following syntax:
  <function name>(<argument list>)


  Example: int distance = absolute(-5);




                      prepared by Taif.A.S.G   31

More Related Content

What's hot

Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
C presentation book
C presentation bookC presentation book
C presentation bookkrunal1210
 
History of C Programming Language
History of C Programming LanguageHistory of C Programming Language
History of C Programming LanguageNiloy Biswas
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++Sachin Yadav
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for universitySheikh Monirul Hasan
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 
Function template
Function templateFunction template
Function templateKousalya M
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Languagesatvirsandhu9
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 

What's hot (20)

Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
C presentation book
C presentation bookC presentation book
C presentation book
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
History of C Programming Language
History of C Programming LanguageHistory of C Programming Language
History of C Programming Language
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for university
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Ppt of c vs c#
Ppt of c vs c#Ppt of c vs c#
Ppt of c vs c#
 
Function template
Function templateFunction template
Function template
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 

Viewers also liked

C++ programming intro
C++ programming introC++ programming intro
C++ programming intromarklaloo
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++ Bharat Kalia
 
History of C/C++ Language
History of C/C++ LanguageHistory of C/C++ Language
History of C/C++ LanguageFarid Hilal
 
CReVote: un système de vote électronique résistant à la coercition basé sur l...
CReVote: un système de vote électronique résistant à la coercition basé sur l...CReVote: un système de vote électronique résistant à la coercition basé sur l...
CReVote: un système de vote électronique résistant à la coercition basé sur l...pacomeambassa
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++Pranav Ghildiyal
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++Ilio Catallo
 
LESS, Le CSS avancé
LESS, Le CSS avancéLESS, Le CSS avancé
LESS, Le CSS avancéMahmoud Nbet
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
Overview of c++
Overview of c++Overview of c++
Overview of c++geeeeeet
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Muhammad Tahir Bashir
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#Sireesh K
 
Cours php & Mysql - 4éme partie
Cours php & Mysql - 4éme partieCours php & Mysql - 4éme partie
Cours php & Mysql - 4éme partiekadzaki
 
Cours php & Mysql - 5éme partie
Cours php & Mysql - 5éme partieCours php & Mysql - 5éme partie
Cours php & Mysql - 5éme partiekadzaki
 
Cours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partieCours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partiekadzaki
 

Viewers also liked (20)

C++
C++C++
C++
 
C++ programming intro
C++ programming introC++ programming intro
C++ programming intro
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
History of C/C++ Language
History of C/C++ LanguageHistory of C/C++ Language
History of C/C++ Language
 
CReVote: un système de vote électronique résistant à la coercition basé sur l...
CReVote: un système de vote électronique résistant à la coercition basé sur l...CReVote: un système de vote électronique résistant à la coercition basé sur l...
CReVote: un système de vote électronique résistant à la coercition basé sur l...
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
C vs c++
C vs c++C vs c++
C vs c++
 
Multidimensional arrays in C++
Multidimensional arrays in C++Multidimensional arrays in C++
Multidimensional arrays in C++
 
LESS, Le CSS avancé
LESS, Le CSS avancéLESS, Le CSS avancé
LESS, Le CSS avancé
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
C vs c++
C vs c++C vs c++
C vs c++
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Overview of c++
Overview of c++Overview of c++
Overview of c++
 
Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)Understand Decision structures in c++ (cplusplus)
Understand Decision structures in c++ (cplusplus)
 
difference between c c++ c#
difference between c c++ c#difference between c c++ c#
difference between c c++ c#
 
Cours php & Mysql - 4éme partie
Cours php & Mysql - 4éme partieCours php & Mysql - 4éme partie
Cours php & Mysql - 4éme partie
 
C++ language
C++ languageC++ language
C++ language
 
Cours php & Mysql - 5éme partie
Cours php & Mysql - 5éme partieCours php & Mysql - 5éme partie
Cours php & Mysql - 5éme partie
 
Cours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partieCours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partie
 

Similar to Overview of c++ language

C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8REHAN IJAZ
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++msharshitha03s
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsRai University
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statementsRai University
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsRai University
 
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Igalia
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6Rumman Ansari
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 

Similar to Overview of c++ language (20)

C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Looping statements
Looping statementsLooping statements
Looping statements
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Iteration
IterationIteration
Iteration
 
Session 3
Session 3Session 3
Session 3
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
C++ programming
C++ programmingC++ programming
C++ programming
 
C operators
C operatorsC operators
C operators
 
Btech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statementsBtech i pic u-3 handling input output and control statements
Btech i pic u-3 handling input output and control statements
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
 
Mca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statementsMca i pic u-3 handling input output and control statements
Mca i pic u-3 handling input output and control statements
 
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
 
C fundamental
C fundamentalC fundamental
C fundamental
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 

Recently uploaded

TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 

Recently uploaded (20)

LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 

Overview of c++ language

  • 1. Overview of C++ language
  • 2. Lecture’s outline What is C++? Identifiers. Constant Semicolons & Blocks in C++ Data type Comments Operator Declaration of variables Giving value to variable C++ statements prepared by Taif.A.S.G
  • 3. What is C++? • Developed by Bjarne Stroustrup (in 1979 at Bell Labs) • C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features. • C++ is a statically typed, compiled, general purpose, case- sensitive, free-form programming language that supports procedural, object-oriented, and generic programming. • C++ is a superset of C that enhancement to the C language and originally named C with Classes but later it was renamed C++. prepared by Taif.A.S.G
  • 4. identifiers They are used for naming classes function, module, variables, object in a program. They follow the following rules: 1) They can have alphabets , digits, and the underscore(_). 2) They must not begin with a digit. 3) Uppercase and lowercase are distinct. 4) They can be of any length. 5) It should not be a keyword. 6) White space is not allowed. prepared by Taif.A.S.G
  • 5. Constant Constant is one whose value cannot be changed after it has been initialized-any attempt to assign to field will produce a compile-error .So, we can declare the constant by using const field and use all uppercase letter. Syntax of declare the constant is: const type name=value Example: const int STRENGTH = 100; const float PI = 3.14; prepared by Taif.A.S.G
  • 6. Semicolons & Blocks in C++: • In C++, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. • For example: following are two different statements: x = y; y = y+1; prepared by Taif.A.S.G 6
  • 8. Comments C++ can use both the single line comments and multi-line comments . single line comments begin with // and end at the end of line. For longer comments we can create multi-line comments by starting with /* and ending with */ prepared by Taif.A.S.G
  • 9. Operator * / % + - are the mathematical operators * / % have a higher precedence than + or – mathematical operators ++ Increment operator –– Decrement operator == Equal (careful) != Not equal >= Greater than or equal Relational <= Less than or equal operators > Greater than < Less than && logical (sequential) and Logical || logical (sequential) or operators = assignment prepared by Taif.A.S.G
  • 10. Declaration of variables The general form of declaration of variables: Type variable1, variable2,...., variableN; Example: int count; float x,y; double pi; char c1,c2,c3; byte b; prepared by Taif.A.S.G
  • 11. Giving value to variable The general form of giving value to variables: variableName= value; Example: finalValue=100; x=y=z=0; Yes = ‘x’; prepared by Taif.A.S.G
  • 12. Simple programs  Write C++ Program to find Sum and Average of two numbers? Write C++ Program to find area of a circle? prepared by Taif.A.S.G
  • 13. C++ statement Control statement Selection iteration jump statement statement statement If if-else switch for while do break continue return prepared by Taif.A.S.G
  • 14. Decision making • C++ supports the following statements Known as control or decision making statements. 1. if statement. 2. switch statement. 3. Conditional operator ? : statement. prepared by Taif.A.S.G 14
  • 15. Decision making with if statement The general form of simple if statement is : if (<conditional expression>) <statement action> Example: if (a > b) cout<<"a > b"; prepared by Taif.A.S.G 15
  • 16. Decision making with if statement cont.. The general form of simple if else statement is : if (<conditional expression>) <statement action> else Example: <statement action> if (a > b) cout<<" a > b"; else cout<<"a<b"; prepared by Taif.A.S.G 16
  • 17. Decision making with if statement cont.. The general form of Multiple if else statement is : if (<conditional expression>) <statement action> else if (<conditional expression>) <statement action> else Example: <statement action> if (a > b) cout<<" a > b"; else if (a< b) cout<<"b > a"; else cout<<" a=b"; prepared by Taif.A.S.G 17
  • 18. Decision making with switch statement • The if statement allows you to select one of two sections of code to execute based on a boolean value (only two possible values). The switch statement allows you to choose from many statements. prepared by Taif.A.S.G 18
  • 19. Decision making with switch statement cont.. switch (expr) { case c1: statements // do these if expr == c1 break; case c2: statements // do these if expr == c2 break; case c3: case c4: // Cases can simply fall thru. statements // do these if expr == any of c's break; . . . default: // OPTIONAL statements // do these if expr != any above } prepared by Taif.A.S.G 19
  • 20. The ? : Operator: • can be used to replace if...else statements. It has the following general form: Exp1 ? Exp2 : Exp3; Where Exp1, Exp2, and Exp3 are expressions. • The value of a ? expression is determined like this: Exp1 is condition evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression. If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression. prepared by Taif.A.S.G 20
  • 21. Simple programs  Write C++ Program to find Number is Positive or Negative? Write C++ Program to find the Grade of student ?  Write C++ Program to check the day of week by using SWITCH-CASE? prepared by Taif.A.S.G
  • 22. Looping The C++ language provides three constructs for performing loop operations, there are: 1. The for statement. 2. The while statement. 3. The do statement. prepared by Taif.A.S.G 22
  • 23. Looping cont.. The general form of for statement: for (initialization; test condition; increment) { Body of loop } Example: for( x=0; x<=10; x++) { cout<<x; } prepared by Taif.A.S.G 23
  • 24. Looping cont.. The general form of while statement: initialization; while(test condition) { Body of loop } Example: x=0; while(x<=10) { cout<<x; x++; } prepared by Taif.A.S.G 24
  • 25. Looping cont.. The general form of do statement: initialization; do { Body of loop } while(test condition); Example: x=0; do { cout<<x; x++; } while(x<=10) ; prepared by Taif.A.S.G 25
  • 26. Int num2 Int num1 0 0 Nested Looping 1 for(num2 = 0; num2 <= 3; num2++) 2 { 3 end of loop for(num1 = 0; num1 <= 2; num1++) 1 0 { 1 cout<<num2 << " " <<num1; 2 } } 3 end of loop 2 0 1 2 3 end of loop 3 0 1 2 3 end of loop prepared by Taif.A.S.G 26 4 End of loop
  • 27. Functions • A complex problem is often easier to solve by dividing it into several smaller parts(Modules), each of which can be solved by itself. This is called structured programming. • In C++ Modules Known as Functions & Classes • main() then uses these functions to solve the original problem. prepared by Taif.A.S.G 27
  • 28. Functions (cont..) • C++ allows the use of both internal (user- defined) and external functions. • External functions (e.g., abs, ceil, rand, sqrt, etc.) are usually grouped into specialized libraries (e.g., iostream, stdlib, math, etc.) prepared by Taif.A.S.G 28
  • 29. Function prototype • The function prototype declares the input and output parameters of the function. • The function prototype has the following syntax: <type> <function name>(<type list>); • Example: A function that returns the absolute value of an integer is: int absolute(int); • If a function definition is placed in front of main(), there is no need to include its function prototype. prepared by Taif.A.S.G 29
  • 30. Function Definition • A function definition has the following syntax: <type> <function name>(<parameter list>){ <local declarations> <sequence of statements> } • For example: Definition of a function that computes the absolute value of an integer: int absolute(int x){ if (x >= 0) return x; else return -x; } • The function definition can be placed anywhere in the program. prepared by Taif.A.S.G 30
  • 31. Function call • A function call has the following syntax: <function name>(<argument list>) Example: int distance = absolute(-5); prepared by Taif.A.S.G 31