SlideShare ist ein Scribd-Unternehmen logo
1 von 28
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

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
C++
C++C++
C++
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
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
 
c++
 c++  c++
c++
 
Lecture01
Lecture01Lecture01
Lecture01
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Intro to C++ - language
Intro to C++ - languageIntro to C++ - language
Intro to C++ - language
 
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
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
C++ for beginners
C++ for beginnersC++ for beginners
C++ for beginners
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 

Andere mochten auch

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 RobotsJun 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 lineChhom 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 schedulingFatima Aliza
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programmingmshellman
 
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 16SDL
 
Data com chapter 1 introduction
Data com chapter 1   introductionData com chapter 1   introduction
Data com chapter 1 introductionAbdul-Hamid Donde
 
ICTCoreCh11
ICTCoreCh11ICTCoreCh11
ICTCoreCh11garcons0
 
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 DifferencesDavina and Caroline
 
11. Computer Systems Hardware 1
11. Computer Systems   Hardware 111. Computer Systems   Hardware 1
11. Computer Systems Hardware 1New Era University
 
VC++ Fundamentals
VC++ FundamentalsVC++ Fundamentals
VC++ Fundamentalsranigiyer
 
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
 

Andere mochten auch (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
 
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+
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Vc++ 3
Vc++ 3Vc++ 3
Vc++ 3
 
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
 
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]
 
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
 
Chapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to ProgrammingChapter 1 - An Introduction to Programming
Chapter 1 - An Introduction to Programming
 
COM
COMCOM
COM
 
2 the visible pc
2 the visible pc2 the visible pc
2 the visible pc
 
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
 
Data com chapter 1 introduction
Data com chapter 1   introductionData com chapter 1   introduction
Data com chapter 1 introduction
 
Active x control
Active x controlActive x control
Active x control
 
Sdi & mdi
Sdi & mdiSdi & mdi
Sdi & mdi
 
ICTCoreCh11
ICTCoreCh11ICTCoreCh11
ICTCoreCh11
 
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
 
11. Computer Systems Hardware 1
11. Computer Systems   Hardware 111. Computer Systems   Hardware 1
11. Computer Systems Hardware 1
 
VC++ Fundamentals
VC++ FundamentalsVC++ Fundamentals
VC++ Fundamentals
 
a+ ptc
a+ ptca+ ptc
a+ ptc
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)
 

Ähnlich wie Learning C++ - Introduction to c++ programming 1

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
(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_iNico Ludwig
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444PurvaShyama
 
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 programmingNico Ludwig
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5thConnex
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptxMark82418
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...Cyber Security Alliance
 

Ähnlich wie Learning C++ - Introduction to c++ programming 1 (20)

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
(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
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
College1
College1College1
College1
 
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
C_plus_plus
C_plus_plusC_plus_plus
C_plus_plus
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5th
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
 

Kürzlich hochgeladen

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 

Kürzlich hochgeladen (20)

Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

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

Hinweis der Redaktion

  1. Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  2. Comments : (//)make a line comment wherever it appear until end line Preprocessor examples : 1.includes 2.defines
  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