basic c++(1)
TRANSCRIPT
![Page 1: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/1.jpg)
![Page 2: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/2.jpg)
Chapter # 2C++ Programming Basics
Lecture # 1Instructor: Engr. Afshan Asim
![Page 3: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/3.jpg)
Objectives
C++ Program Structure.
Whitespaces
Comments
Escape Sequences
Data Types & Variables
Unsigned Types
![Page 4: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/4.jpg)
![Page 5: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/5.jpg)
Compiler
Compiler is a tool that is used to convert/translate human like language
into machine language
![Page 6: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/6.jpg)
Simple C++ Program
#include<iostream>using namespace std;void main(){cout<<“This is my 1st C++ program”;system(“pause”);}
![Page 7: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/7.jpg)
Whitespace
#include<iostream>using namespace std;
void main() { cout<<“This is my 1st C++ program”;system(“pause”);}
![Page 8: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/8.jpg)
Comments
Single Line Comment//This is single line comment
Or//This is single//Line comment
Multi Line Comment or Block Comment/*This isMulti line Comment*/
![Page 9: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/9.jpg)
Comments Contd…
//demonstrates Comments#include<iostream>using namespace std;//main functionvoid main(){cout<<“This is my 1st C++ program”;system(“pause”);}/* end of program*/
![Page 10: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/10.jpg)
Common Escape Sequences
Escape Sequence
Character
\a Beep
\b Backspace
\f Form feed
\n New line
\r Return
\t Tab
\\ Backslash
\’ Single quotation mark
\” Double quotation marks
\xdd Hexadecimal Notations
![Page 11: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/11.jpg)
Escape Sequences (Contd…)
• cout<<“This is\b my first C++ program”; This i my first C++ program• cout<<“This is\n my first C++ program”; This is my first C++ program• cout<<“This is my first \r C++ program”; C++ programirst• cout<<“This is\t my first C++ program”; This is my first C++ program
![Page 12: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/12.jpg)
Escape Sequences (Contd…)
• cout<<“This is\\ my first C++ program”; This is \ my first C++ program• cout<<“This is\’ my first C++ \’ program”; This is ‘ my first C++ ‘ program• cout<<“\”This is my first C++ program\””; “This is my first C++ program”• cout<<“\x128”; <
![Page 13: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/13.jpg)
Integer Variables
Type Bits Range Syntax
int (32 bit system)
32 bits -2,147,483,648 2,147,483,647
int var1;
int (16 bit system)
16 bits -32,768 32767
int var1;
long 32 bits -2,147,483,648 2,147,483,647
long int var1; orlong var1;
short 16 bits -32,768 32767
short var1;
![Page 14: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/14.jpg)
Integer Variables
//demonstrates integer variables#include<iostream>using namespace std;void main(){int var1; //define var1int var2=20; //20 is integer constantvar1=var2+10;cout<<“value of var1=”<<var1;system(“pause”);}/* end of program*/
![Page 15: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/15.jpg)
Character Variables & Constants
• Character Variable Range: -128 127 Memory: 1 byte (8 bits)• Character Constant Enclosed in single quotation mark e.g. ‘A’ , ‘c’ , ‘2’
![Page 16: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/16.jpg)
Character Variables & Constants Contd…
//Demonstrates Character variables#include<iostream>using namespace std;void main(){char ch1=88;char ch2=‘A’; //’A’ is character constantcout<<ch1<<“\n”<<ch2;ch1++;cout<<ch1;system(“pause”);}
![Page 17: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/17.jpg)
Floating Point Types
Type Bits Range Syntax
float 4 bytes float var;
double 8 bytes double var;
long double 10 bytes long double var;
![Page 18: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/18.jpg)
Floating Point Types (Contd…)
//Floating point types#include<iostream>using namespace std;void main(){float f=312.4F; //type float constant with letter Fdouble d=2.34E5; long double l=2.345E10L; //type float constant with letter Lcout<<“\n Type float:”<<f<<“\n Type double”<<d<<“\n Type long double”<<l;system(“pause”);}
![Page 19: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/19.jpg)
Type bool
• 1 bit of storage…• Only two values.. 0 and 1//Type bool#include<iostream>using namespace std;void main(){bool b,b1;b=5>3; //result is 1b1=3>5; //result is 0cout<<“b=“<<b<<“b1=“<<b1;system(“pause”);}
![Page 20: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/20.jpg)
unsigned Data Types
Type Low High Syntax
unsigned char 0 255 unsigned char var;
unsigned short 0 65,535 unsigned short var;
unsigned int 0 4,294,967,295 unsigned int var;
unsigned long 0 4,294,967,295 unsigned long var;
![Page 21: basic c++(1)](https://reader035.vdocuments.site/reader035/viewer/2022062419/557d46a4d8b42a93078b49f4/html5/thumbnails/21.jpg)