SlideShare a Scribd company logo
Introduction to C++
BY HIMANSHU KAUSHIK
What is c++ ?
 C++ is a object-oriented language
 It is the “successor” to C, a procedural language
 (the “++” is called the successor operator in C++)
 C was derived from a language called B which was in turn derived from
BCPL
 C was developed in the 1970’s by Dennis Ritchie of AT&T Bell Labs
 C++ was developed in the early 1980’s by Bjarne Stroustrup of AT&T Bell
Labs.
 Most of C is a subset of C++
People & Programs
 User: an individual who runs, or executes,
a program
 Programmer: an individual who creates, or
writes, a program
C++ Programming
 Consists of…
Declarations
 Define the use of various identifiers, thus creating the elements used by the
program (computer)
Statements
 Or executable statements, representing actions the computer will take on
the user’s behalf
Identifiers
 Names for various entities used in a program;
used for...
 Variables: values that can change frequently
 Constants: values that never changes
 Functions: programming units that represents
complex operations
 Parameters: values that change infrequently
A Simple c++ Program
#include <iostream.h>
int main()
{
// Declarations
// Statements
return 0;
}
The Header File
#include <iostream.h>
int main()
{
// Declarations
// Statements
return 0;
}
 Compiler directive:
Tells the compiler
what to do before
compiling
 This one includes
source code from
another file
The Main Statement
#include <iostream.h>
int main()
{
// Declarations
// Statements
return 0;
}
 Header for main function
States…
 data type for the return
value
 identifier for function
 list of arguments between
parenthesis
(none for this function)
The Braces
#include <iostream.h>
int main()
{
// Declarations
// Statements
return 0;
}
Braces enclose the body of
the function
They represent the start and
end of the function
The Declaration Statement
#include <iostream.h>
int main()
{
// Declarations
// Statements
return 0;
}
 Declarations and
statements
 Main body of function
(or main part)
 “//” represents the start
of a comment
The return Statement
#include <iostream.h>
int main()
{
// Declarations
// Statements
return 0;
}
 Return statement
 specifies the value
the function returns
 All (almost)
declarations and
statements end with
a semi-colon “;”
Sample C++ Program
#include <iostream.h>
void main()
{
int number;
cout << “Enter a number” << endl;
cin >> number;
cout << “You entered: “ << number << endl;
}
What is the Output of this Program?
The DataTypes
#include <iostream.h>
void main()
{
int number;
cout << “Enter a number” << endl;
cin >> number;
cout << “You entered: “ << number << endl;
}
 Variable declaration
 The identifier number is
declared as being of
data type int, or integer
The Count ?
#include <iostream.h>
void main()
{
int number;
cout << “Enter a number” << endl;
cin >> number;
cout << “You entered: “ << number << endl;
}
 cout
the output statement for C++
 Note the direction of “<<“
 endl represents an end-of-line
Cin ?
#include <iostream.h>
void main()
{
int number;
cout << “Enter a number” << endl;
cin >> number;
cout << “You entered: “ << number << endl;
}
cin
the input statement for C++
Note the direction of “>>”
Copy That Down
#include <iostream.h>
void main()
{
int number;
cout << “Enter a number” << endl;
cin >> number;
cout << “You entered: “ << number << endl;
}
Value Assignment In c++
 Assignment is an operation that assigns
the value of an expression to a variable
 Ex. Total = 2 + 3 + 5
 First, the expresssion “2 + 3 + 5” is
evaluated
 Then, this value is assigned to the variable
“Total”
Assignment
 When a variable is declared, space is
allocated in the computer’s memory for
the variable
 Each data type requires a different
number of bytes in memory for storing a
variable
 int - 2
float - 4
double - 8
char, bool - 1
Arithmetic Operations
Addition: 2 + 3
Subtraction: 5 - 2
Multiplication: 10 * 4
Division: 12 / 3
I Have A problem for you
Problem: To determine the average of three
numbers
Task: Request, from the user, three numbers,
compute the average and the three numbers,
and print out the original values and the
computed average
Do it!
You have 20 minutes!
Any Queries ?

More Related Content

What's hot

History of C Programming Language
History of C Programming LanguageHistory of C Programming Language
History of C Programming Language
Niloy Biswas
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
Prof. Dr. K. Adisesha
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
SudhanshuVijay3
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
Thooyavan Venkatachalam
 
History of c++
History of c++ History of c++
History of c++
Ihsan Wassan
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
satvirsandhu9
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
Sangharsh agarwal
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
History of c
History of cHistory of c
History of c
Shipat Bhuiya
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
Neeru Mittal
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
Prof. Dr. K. Adisesha
 
Call by value
Call by valueCall by value
Call by valueDharani G
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
Ankur Pandey
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 

What's hot (20)

Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
History of C Programming Language
History of C Programming LanguageHistory of C Programming Language
History of C Programming Language
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
History of c++
History of c++ History of c++
History of c++
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
History of c
History of cHistory of c
History of c
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
Call by value
Call by valueCall by value
Call by value
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Loops c++
Loops c++Loops c++
Loops c++
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 

Similar to Introduction to c++

Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
Nilesh Dalvi
 
C++
C++C++
C++ functions
C++ functionsC++ functions
C++ functions
Dawood Jutt
 
C++ functions
C++ functionsC++ functions
C++ functions
Dawood Jutt
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
somu rajesh
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
Abdullah Jan
 
Presentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakurPresentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakur
Thakurkirtika
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
bhargavi804095
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
cpjcollege
 
C++basics
C++basicsC++basics
C++basics
amna izzat
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
JVenkateshGoud
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
LidetAdmassu
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
atulchaudhary821
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
WaheedAnwar20
 
BASIC C++ PROGRAMMING
BASIC C++ PROGRAMMINGBASIC C++ PROGRAMMING
BASIC C++ PROGRAMMING
gufranresearcher
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
floraaluoch3
 

Similar to Introduction to c++ (20)

Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
C++
C++C++
C++
 
C++ functions
C++ functionsC++ functions
C++ functions
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
Presentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakurPresentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakur
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C++basics
C++basicsC++basics
C++basics
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 
Chapter2
Chapter2Chapter2
Chapter2
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 
BASIC C++ PROGRAMMING
BASIC C++ PROGRAMMINGBASIC C++ PROGRAMMING
BASIC C++ PROGRAMMING
 
Functions.pptx, programming language in c
Functions.pptx, programming language in cFunctions.pptx, programming language in c
Functions.pptx, programming language in c
 

Recently uploaded

GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 

Recently uploaded (20)

GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 

Introduction to c++

  • 1. Introduction to C++ BY HIMANSHU KAUSHIK
  • 2. What is c++ ?  C++ is a object-oriented language  It is the “successor” to C, a procedural language  (the “++” is called the successor operator in C++)  C was derived from a language called B which was in turn derived from BCPL  C was developed in the 1970’s by Dennis Ritchie of AT&T Bell Labs  C++ was developed in the early 1980’s by Bjarne Stroustrup of AT&T Bell Labs.  Most of C is a subset of C++
  • 3. People & Programs  User: an individual who runs, or executes, a program  Programmer: an individual who creates, or writes, a program
  • 4. C++ Programming  Consists of… Declarations  Define the use of various identifiers, thus creating the elements used by the program (computer) Statements  Or executable statements, representing actions the computer will take on the user’s behalf
  • 5. Identifiers  Names for various entities used in a program; used for...  Variables: values that can change frequently  Constants: values that never changes  Functions: programming units that represents complex operations  Parameters: values that change infrequently
  • 6. A Simple c++ Program #include <iostream.h> int main() { // Declarations // Statements return 0; }
  • 7. The Header File #include <iostream.h> int main() { // Declarations // Statements return 0; }  Compiler directive: Tells the compiler what to do before compiling  This one includes source code from another file
  • 8. The Main Statement #include <iostream.h> int main() { // Declarations // Statements return 0; }  Header for main function States…  data type for the return value  identifier for function  list of arguments between parenthesis (none for this function)
  • 9. The Braces #include <iostream.h> int main() { // Declarations // Statements return 0; } Braces enclose the body of the function They represent the start and end of the function
  • 10. The Declaration Statement #include <iostream.h> int main() { // Declarations // Statements return 0; }  Declarations and statements  Main body of function (or main part)  “//” represents the start of a comment
  • 11. The return Statement #include <iostream.h> int main() { // Declarations // Statements return 0; }  Return statement  specifies the value the function returns  All (almost) declarations and statements end with a semi-colon “;”
  • 12. Sample C++ Program #include <iostream.h> void main() { int number; cout << “Enter a number” << endl; cin >> number; cout << “You entered: “ << number << endl; } What is the Output of this Program?
  • 13. The DataTypes #include <iostream.h> void main() { int number; cout << “Enter a number” << endl; cin >> number; cout << “You entered: “ << number << endl; }  Variable declaration  The identifier number is declared as being of data type int, or integer
  • 14.
  • 15. The Count ? #include <iostream.h> void main() { int number; cout << “Enter a number” << endl; cin >> number; cout << “You entered: “ << number << endl; }  cout the output statement for C++  Note the direction of “<<“  endl represents an end-of-line
  • 16. Cin ? #include <iostream.h> void main() { int number; cout << “Enter a number” << endl; cin >> number; cout << “You entered: “ << number << endl; } cin the input statement for C++ Note the direction of “>>”
  • 17. Copy That Down #include <iostream.h> void main() { int number; cout << “Enter a number” << endl; cin >> number; cout << “You entered: “ << number << endl; }
  • 18. Value Assignment In c++  Assignment is an operation that assigns the value of an expression to a variable  Ex. Total = 2 + 3 + 5  First, the expresssion “2 + 3 + 5” is evaluated  Then, this value is assigned to the variable “Total”
  • 19. Assignment  When a variable is declared, space is allocated in the computer’s memory for the variable  Each data type requires a different number of bytes in memory for storing a variable  int - 2 float - 4 double - 8 char, bool - 1
  • 20. Arithmetic Operations Addition: 2 + 3 Subtraction: 5 - 2 Multiplication: 10 * 4 Division: 12 / 3
  • 21. I Have A problem for you Problem: To determine the average of three numbers Task: Request, from the user, three numbers, compute the average and the three numbers, and print out the original values and the computed average Do it! You have 20 minutes!