SlideShare a Scribd company logo
Introduction To C++ Programming
Ali Aminian & Bardia Nezamzadeh
1
Section Outline
• Workspace
• Basics of C++ Environment
• Definition of Types
• Operations in C++
2
Section Outline
• Workspace
• Basics of C++ Environment
• Definition of Types
• Operations in C++
3
Workspace
• One of the most famous workspaces is
“Microsoft Visual Studio”
• Creating a project :
lets follow these pictures :
4
Workspace(cont.)
5
Section Outline
• Workspace
• Basics of C++ Environment
• Definition of Types
• Operations in C++
6
• Comments
-Single-line comment
• Begin with : // this is comment (Fortran : !)
-Multiple-line comment
• Begin with : /* … /* this is a multiple line
• End with : …*/ comment. We still have
this line!*/
• Preprocessor directives
-Processed by preprocessor before compiling
-Begin with # include <math>
Basics of C++ Environment
7
Adding math library to the project.
• Different type of files in C++
– Header files (.h)
– cpp files (.cpp)
– Most important headers:
 iostream.h
 iomanip.h
 math.h
 cstdlib.h
Basics of C++ Environment(cont.)
Standard input/output
Manipulate stream format
Math library function
Conversion function for
text to number , number to
text, memory allocation,
random numbers and various
other utility functions
8
Basics of C++ Environment(cont.)
• Program Framework
int main()
{
………………..
………………..
………………..
return 0;
}
(Frotran Framework:)
PROGRAM name
………………..
………………..
………………..
END
9
• Some important Syntaxes
– include<>
– main()
– cin>> , cout<<
• These are like READ , PRINT
– ; (Semicolon)
• Shows the end of line . (works the same as in Fortran)
Basics of C++ Environment(cont.)
In next slides we introduce the other syntax symbols, these are most
familiar for any program which we could see in any code
10
Basics of C++ Environment(cont.)
Phases of C++ Programs:
1. Edit
2. Preprocess
3. Compile
4. Link
5. Load
6. Execute Loader
Primary
Memory
Program is created in
the editor and stored
on disk.
Preprocessor program
processes the code.
Loader puts program
in memory.
CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
executes.
Compiler
Compiler creates
object code and stores
it on disk.
Linker links the object
code with the libraries,
creates a.out and
stores it on disk
Editor
Preprocessor
Linker
CPU
Primary
Memory
.
.
.
.
.
.
.
.
.
.
.
.
Disk
Disk
Disk
Disk
Disk
11
Basics of C++ Environment(cont.)
1 // Printing multiple lines with a single statement
2 #include <iostream>
3
4 // function main begins program execution
5 int main()
6 {
7 std::cout << "Welcome to C++!n";
8
9 return 0; // indicate that program ended successfully
10
11 } // end function main
Comments
Preprocessor directive to include
input/output stream header file
<iostream>
We include this library to use the
std::cout command for printing.
Function main appears
exactly once in every
C++ program..
Special Characters
We use these characters
to write some characters
that can not be written in
normal way:
n Enter
t Tab
 backslash itself!
Keyword return is
one of several means to
exit function; value 0
indicates program
terminated successfully.
Welcome to C++!
Output:
12
Section Outline
• Workspace
• Basics of C++ Environment
• Definition of Types
• Operations in C++
13
Definition of Types
• Floating point variables
– float : 6 digits after floating point
– double : 12 digits after floating point (more
precision)
All of above types are useful to store real values such as:
0.12E5 Or 2.3212
14
Definition of Types(cont.)
• Integer variables
We can use following words to do some alternative
with int type:
– short – unsigned int
– unsigned short – long
– int – unsigned long
These words change range and starting point of
integer variables :
e.g. short int a; //range -32768 to 32767
15
Type Min. range Max. range
short -32768 32767
unsigned short 0 65535
int -2147483648 2147483647
unsigned int 0 4294967295
long -9223372036854775808 9223372036854775807
unsigned long 0 18446744073709551615
Definition of Types(cont.)
16
Definition of Types(cont.)
• bool
– This type has just two values: (true, false)
– Note : in Fortran we use LOGICAL and .true. And .false.
combination Instead.
• char
– This type is used to store ASCII characters
– e.g. char a =‘Q’;
• enum
– It creates a list, in witch every elements has a number
and we can use the elements instead of numbers
(notice to example in next slide)
17
Definition of Types(cont.)
E.G. :
If we define such an enum :
enum Day{SAT,SUN,MON,TUE,WED,THU,FRI}
Now if we define a variable from Day type then
this variable can accept the values that define
Inside the Day type such as SAT, SUN, MON,…
e.g. Day mybirthday = MON;
18
Definition of Types(cont.)
NOTES:
variable precision:
1.2 / 2 returns integer or double?
Casting:
e.g. : a = (int) c; //a is int and c is double (c was 12.63)
If we didn’t use cast in this example, C++ would
store 12 inside a.
19
Definition of Types(cont.)
• We can have our own types with typedef keyword.
e.g. typedef long double real;
real a; //a is a long double variable now
20
Exactly the same type in C++Type in Fortran
shortINTEGER *2
intINTEGER *4
long intINTEGER *8
floatREAL*4
doubleREAL*8
long doubleREAL*16
charCHARACTER
boolLOGICAL
Basics of C++ Environment(cont.)
• MORE NOTES!
 we use const command to define constant
variables ( Fortran : PARAMETER )
e.g. const int a = 12;
 there is no need to write & when we want to
write multiple line commands
 C++ is a case sensitive language ( vs. Fortran )
21
Section Outline
• Workspace
• Basics of C++ Environment
• Definition of Types
• Operations in C++
22
Operations in C++
• Conditional operands
other operands : < , <= , => , >
23
FortranC++
.AND.&&And
.OR.||Or
.NEQV.!=Not equivalent
.EQV.==Equivalent
Operations in C++
• If (condition) {statement }
• If , else
if (a==true)
{
b=b+1;
}
else
{
b=b-1;
}
It is important that how compiler ,
compile these operations
24
Operations in C++
• for(init;condition;command) {statement}
for(i=0; i<10; i++)
{
b--; // b=b-1
}
variable i will advance from 0 itself to 9 itself
during the loop
25
Operations in C++
• while(condition) {statement}
while(a)//if a is true
{
b++; // b=b+1
if(b==100)
{
break;
}
}
 notes :
break: breaks the loop and steps out
Ctrl+C: manually breaking the loop!
26
Operations in C++(cont.)
• Variable++ / ++Variable
x=y++ is different from x=++y
• > , < , => , != , == (Comparisons operand) , =
• ||, && (Logical operand)
• condition ? expression1 : expression2
– if(condition) {expression1 } else {expression2}
• goto : label
you must know what want to do
exactly otherwise this is very dangerous !
27
In future :
i. Pointers and related argues
ii. Functions
iii.Class and related concepts
iv.ERRORS
28
Ad

More Related Content

What's hot (20)

C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
Aami Kakakhel
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
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
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
Nico Ludwig
 
C++
C++C++
C++
Shyam Khant
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
Nilesh Dalvi
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
 
c++
 c++  c++
c++
SindhuVelmukull
 
Lecture01
Lecture01Lecture01
Lecture01
Xafran
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
Himanshu Kaushik
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
Mohamed Loey
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
Sangharsh agarwal
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
Jussi Pohjolainen
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
C++ Language
C++ LanguageC++ Language
C++ Language
Syed Zaid Irshad
 
C++ for beginners
C++ for beginnersC++ for beginners
C++ for beginners
Salahaddin University-Erbil
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
samt7
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
Madhavendra Dutt
 
45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala45 Days C++ Programming Language Training in Ambala
45 Days C++ Programming Language Training in Ambala
jatin batra
 

Viewers also liked (20)

Multi-touch Interface for Controlling Multiple Mobile Robots
Multi-touch Interface for Controlling Multiple Mobile RobotsMulti-touch Interface for Controlling Multiple Mobile Robots
Multi-touch Interface for Controlling Multiple Mobile Robots
Jun Kato
 
Giáo trình lập trình GDI+
Giáo trình lập trình GDI+Giáo trình lập trình GDI+
Giáo trình lập trình GDI+
Sự Phạm Thành
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
Terry Yoast
 
Vc++ 3
Vc++ 3Vc++ 3
Vc++ 3
Raman Rv
 
1. c or c++ programming course out line
1. c or c++ programming course out line1. c or c++ programming course out line
1. c or c++ programming course out line
Chhom Karath
 
Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]
ppd1961
 
Operation engine ii session iv operations scheduling
Operation engine  ii session iv  operations schedulingOperation engine  ii session iv  operations scheduling
Operation engine ii session iv operations scheduling
Fatima Aliza
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programming
mshellman
 
COM
COMCOM
COM
Roy Antony Arnold G
 
2 the visible pc
2 the visible pc2 the visible pc
2 the visible pc
hafizhanif86
 
SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16
SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16
SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16
SDL
 
Data com chapter 1 introduction
Data com chapter 1   introductionData com chapter 1   introduction
Data com chapter 1 introduction
Abdul-Hamid Donde
 
Active x control
Active x controlActive x control
Active x control
Amandeep Kaur
 
Sdi & mdi
Sdi & mdiSdi & mdi
Sdi & mdi
BABAVALI S
 
ICTCoreCh11
ICTCoreCh11ICTCoreCh11
ICTCoreCh11
garcons0
 
Bitmap and Vector Images: Make Sure You Know the Differences
Bitmap and Vector Images: Make Sure You Know the DifferencesBitmap and Vector Images: Make Sure You Know the Differences
Bitmap and Vector Images: Make Sure You Know the Differences
Davina and Caroline
 
11. Computer Systems Hardware 1
11. Computer Systems   Hardware 111. Computer Systems   Hardware 1
11. Computer Systems Hardware 1
New Era University
 
VC++ Fundamentals
VC++ FundamentalsVC++ Fundamentals
VC++ Fundamentals
ranigiyer
 
a+ ptc
a+ ptca+ ptc
a+ ptc
guest026a146
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)
Peter R. Egli
 
Multi-touch Interface for Controlling Multiple Mobile Robots
Multi-touch Interface for Controlling Multiple Mobile RobotsMulti-touch Interface for Controlling Multiple Mobile Robots
Multi-touch Interface for Controlling Multiple Mobile Robots
Jun Kato
 
Giáo trình lập trình GDI+
Giáo trình lập trình GDI+Giáo trình lập trình GDI+
Giáo trình lập trình GDI+
Sự Phạm Thành
 
1. c or c++ programming course out line
1. c or c++ programming course out line1. c or c++ programming course out line
1. c or c++ programming course out line
Chhom Karath
 
Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]Handling Exceptions In C &amp; C++[Part A]
Handling Exceptions In C &amp; C++[Part A]
ppd1961
 
Operation engine ii session iv operations scheduling
Operation engine  ii session iv  operations schedulingOperation engine  ii session iv  operations scheduling
Operation engine ii session iv operations scheduling
Fatima Aliza
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programming
mshellman
 
SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16
SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16
SDL Vision for Digital Experience - Arjen van den Akker at SDL Connect 16
SDL
 
Data com chapter 1 introduction
Data com chapter 1   introductionData com chapter 1   introduction
Data com chapter 1 introduction
Abdul-Hamid Donde
 
ICTCoreCh11
ICTCoreCh11ICTCoreCh11
ICTCoreCh11
garcons0
 
Bitmap and Vector Images: Make Sure You Know the Differences
Bitmap and Vector Images: Make Sure You Know the DifferencesBitmap and Vector Images: Make Sure You Know the Differences
Bitmap and Vector Images: Make Sure You Know the Differences
Davina and Caroline
 
11. Computer Systems Hardware 1
11. Computer Systems   Hardware 111. Computer Systems   Hardware 1
11. Computer Systems Hardware 1
New Era University
 
VC++ Fundamentals
VC++ FundamentalsVC++ Fundamentals
VC++ Fundamentals
ranigiyer
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)
Peter R. Egli
 
Ad

Similar to Learning C++ - Introduction to c++ programming 1 (20)

data structure book in c++ and c in easy wording
data structure book in c++  and c in easy wordingdata structure book in c++  and c in easy wording
data structure book in c++ and c in easy wording
yhrcxd8wpm
 
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.pptchapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
yyu8u
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx
C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptxC++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx
C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx
ApoorvMalviya2
 
(8) cpp abstractions separated_compilation_and_binding_part_i
(8) cpp abstractions separated_compilation_and_binding_part_i(8) cpp abstractions separated_compilation_and_binding_part_i
(8) cpp abstractions separated_compilation_and_binding_part_i
Nico Ludwig
 
Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
Widad Jamaluddin
 
College1
College1College1
College1
Sudharsan S
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
PurvaShyama
 
Fundamental programming Nota Topic 2.pptx
Fundamental programming Nota Topic 2.pptxFundamental programming Nota Topic 2.pptx
Fundamental programming Nota Topic 2.pptx
UmmuNazieha
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
Abhishek Sinha
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
rohassanie
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
GDGKuwaitGoogleDevel
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
Nico Ludwig
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
LakshyaChauhan21
 
C
CC
C
Khan Rahimeen
 
C
CC
C
Anuja Lad
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
Atul Setu
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
Qazi Shahzad Ali
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
Ralph Weber
 
data structure book in c++ and c in easy wording
data structure book in c++  and c in easy wordingdata structure book in c++  and c in easy wording
data structure book in c++ and c in easy wording
yhrcxd8wpm
 
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.pptchapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
chapter_2_-_basic_c_elements (1)_c++_c++_Wadee3.ppt
yyu8u
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx
C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptxC++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx
C++ LectuNSVAHDVQwyfkyuQWVHGWQUDKFEre-14.pptx
ApoorvMalviya2
 
(8) cpp abstractions separated_compilation_and_binding_part_i
(8) cpp abstractions separated_compilation_and_binding_part_i(8) cpp abstractions separated_compilation_and_binding_part_i
(8) cpp abstractions separated_compilation_and_binding_part_i
Nico Ludwig
 
Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001Lecture 01 Programming C for Beginners 001
Lecture 01 Programming C for Beginners 001
MahmoudElsamanty
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
PurvaShyama
 
Fundamental programming Nota Topic 2.pptx
Fundamental programming Nota Topic 2.pptxFundamental programming Nota Topic 2.pptx
Fundamental programming Nota Topic 2.pptx
UmmuNazieha
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
Abhishek Sinha
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
Nico Ludwig
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
Qazi Shahzad Ali
 
Ad

Recently uploaded (20)

Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Guru
 
Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Journal of Soft Computing in Civil Engineering
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
How to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdfHow to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdf
jamedlimmk
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptxLidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
Lidar for Autonomous Driving, LiDAR Mapping for Driverless Cars.pptx
RishavKumar530754
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Data Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptxData Structures_Linear data structures Linked Lists.pptx
Data Structures_Linear data structures Linked Lists.pptx
RushaliDeshmukh2
 
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Academy - Functional Modeling In Action with PRIZ.pdf
PRIZ Guru
 
Data Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptxData Structures_Linear Data Structure Stack.pptx
Data Structures_Linear Data Structure Stack.pptx
RushaliDeshmukh2
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
SICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introductionSICPA: Fabien Keller - background introduction
SICPA: Fabien Keller - background introduction
fabienklr
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
ZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JITZJIT: Building a Next Generation Ruby JIT
ZJIT: Building a Next Generation Ruby JIT
maximechevalierboisv1
 
How to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdfHow to Buy Snapchat Account A Step-by-Step Guide.pdf
How to Buy Snapchat Account A Step-by-Step Guide.pdf
jamedlimmk
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 

Learning C++ - Introduction to c++ programming 1

  • 1. Introduction To C++ Programming Ali Aminian & Bardia Nezamzadeh 1
  • 2. Section Outline • Workspace • Basics of C++ Environment • Definition of Types • Operations in C++ 2
  • 3. Section Outline • Workspace • Basics of C++ Environment • Definition of Types • Operations in C++ 3
  • 4. Workspace • One of the most famous workspaces is “Microsoft Visual Studio” • Creating a project : lets follow these pictures : 4
  • 6. Section Outline • Workspace • Basics of C++ Environment • Definition of Types • Operations in C++ 6
  • 7. • Comments -Single-line comment • Begin with : // this is comment (Fortran : !) -Multiple-line comment • Begin with : /* … /* this is a multiple line • End with : …*/ comment. We still have this line!*/ • Preprocessor directives -Processed by preprocessor before compiling -Begin with # include <math> Basics of C++ Environment 7 Adding math library to the project.
  • 8. • Different type of files in C++ – Header files (.h) – cpp files (.cpp) – Most important headers:  iostream.h  iomanip.h  math.h  cstdlib.h Basics of C++ Environment(cont.) Standard input/output Manipulate stream format Math library function Conversion function for text to number , number to text, memory allocation, random numbers and various other utility functions 8
  • 9. Basics of C++ Environment(cont.) • Program Framework int main() { ……………….. ……………….. ……………….. return 0; } (Frotran Framework:) PROGRAM name ……………….. ……………….. ……………….. END 9
  • 10. • Some important Syntaxes – include<> – main() – cin>> , cout<< • These are like READ , PRINT – ; (Semicolon) • Shows the end of line . (works the same as in Fortran) Basics of C++ Environment(cont.) In next slides we introduce the other syntax symbols, these are most familiar for any program which we could see in any code 10
  • 11. Basics of C++ Environment(cont.) Phases of C++ Programs: 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load 6. Execute Loader Primary Memory Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU Primary Memory . . . . . . . . . . . . Disk Disk Disk Disk Disk 11
  • 12. Basics of C++ Environment(cont.) 1 // Printing multiple lines with a single statement 2 #include <iostream> 3 4 // function main begins program execution 5 int main() 6 { 7 std::cout << "Welcome to C++!n"; 8 9 return 0; // indicate that program ended successfully 10 11 } // end function main Comments Preprocessor directive to include input/output stream header file <iostream> We include this library to use the std::cout command for printing. Function main appears exactly once in every C++ program.. Special Characters We use these characters to write some characters that can not be written in normal way: n Enter t Tab backslash itself! Keyword return is one of several means to exit function; value 0 indicates program terminated successfully. Welcome to C++! Output: 12
  • 13. Section Outline • Workspace • Basics of C++ Environment • Definition of Types • Operations in C++ 13
  • 14. Definition of Types • Floating point variables – float : 6 digits after floating point – double : 12 digits after floating point (more precision) All of above types are useful to store real values such as: 0.12E5 Or 2.3212 14
  • 15. Definition of Types(cont.) • Integer variables We can use following words to do some alternative with int type: – short – unsigned int – unsigned short – long – int – unsigned long These words change range and starting point of integer variables : e.g. short int a; //range -32768 to 32767 15
  • 16. Type Min. range Max. range short -32768 32767 unsigned short 0 65535 int -2147483648 2147483647 unsigned int 0 4294967295 long -9223372036854775808 9223372036854775807 unsigned long 0 18446744073709551615 Definition of Types(cont.) 16
  • 17. Definition of Types(cont.) • bool – This type has just two values: (true, false) – Note : in Fortran we use LOGICAL and .true. And .false. combination Instead. • char – This type is used to store ASCII characters – e.g. char a =‘Q’; • enum – It creates a list, in witch every elements has a number and we can use the elements instead of numbers (notice to example in next slide) 17
  • 18. Definition of Types(cont.) E.G. : If we define such an enum : enum Day{SAT,SUN,MON,TUE,WED,THU,FRI} Now if we define a variable from Day type then this variable can accept the values that define Inside the Day type such as SAT, SUN, MON,… e.g. Day mybirthday = MON; 18
  • 19. Definition of Types(cont.) NOTES: variable precision: 1.2 / 2 returns integer or double? Casting: e.g. : a = (int) c; //a is int and c is double (c was 12.63) If we didn’t use cast in this example, C++ would store 12 inside a. 19
  • 20. Definition of Types(cont.) • We can have our own types with typedef keyword. e.g. typedef long double real; real a; //a is a long double variable now 20 Exactly the same type in C++Type in Fortran shortINTEGER *2 intINTEGER *4 long intINTEGER *8 floatREAL*4 doubleREAL*8 long doubleREAL*16 charCHARACTER boolLOGICAL
  • 21. Basics of C++ Environment(cont.) • MORE NOTES!  we use const command to define constant variables ( Fortran : PARAMETER ) e.g. const int a = 12;  there is no need to write & when we want to write multiple line commands  C++ is a case sensitive language ( vs. Fortran ) 21
  • 22. Section Outline • Workspace • Basics of C++ Environment • Definition of Types • Operations in C++ 22
  • 23. Operations in C++ • Conditional operands other operands : < , <= , => , > 23 FortranC++ .AND.&&And .OR.||Or .NEQV.!=Not equivalent .EQV.==Equivalent
  • 24. Operations in C++ • If (condition) {statement } • If , else if (a==true) { b=b+1; } else { b=b-1; } It is important that how compiler , compile these operations 24
  • 25. Operations in C++ • for(init;condition;command) {statement} for(i=0; i<10; i++) { b--; // b=b-1 } variable i will advance from 0 itself to 9 itself during the loop 25
  • 26. Operations in C++ • while(condition) {statement} while(a)//if a is true { b++; // b=b+1 if(b==100) { break; } }  notes : break: breaks the loop and steps out Ctrl+C: manually breaking the loop! 26
  • 27. Operations in C++(cont.) • Variable++ / ++Variable x=y++ is different from x=++y • > , < , => , != , == (Comparisons operand) , = • ||, && (Logical operand) • condition ? expression1 : expression2 – if(condition) {expression1 } else {expression2} • goto : label you must know what want to do exactly otherwise this is very dangerous ! 27
  • 28. In future : i. Pointers and related argues ii. Functions iii.Class and related concepts iv.ERRORS 28

Editor's Notes

  • #3: Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  • #4: Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  • #5: Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  • #6: Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  • #7: Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  • #8: Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  • #14: Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines