Lecture# 3
This presentation is the property of its rightful owner.
Sponsored Links
1 / 28

Lecture# 3 Programming Concepts PowerPoint PPT Presentation


  • 44 Views
  • Uploaded on
  • Presentation posted in: General

Lecture# 3 Programming Concepts. In Last Lecture. First Program Programs consists of Blocks(Functions) Statements end with semi-colon(;) Preprocessor Directive Escape characters Sequential Flow cout, getch(),return 0. Preprocessor directive. main function. Simple Program.

Download Presentation

Lecture# 3 Programming Concepts

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Lecture 3 programming concepts

Lecture# 3

Programming Concepts


In last lecture

In Last Lecture

  • First Program

  • Programs consists of Blocks(Functions)

  • Statements end with semi-colon(;)

  • Preprocessor Directive

  • Escape characters

  • Sequential Flow

  • cout, getch(),return 0


Lecture 3 programming concepts

Preprocessor directive

main function

Simple Program

  • #include<iostream>

  • #include<conio>

  • int main(){

  • cout<<"Every age

  • has a language of its own\n";

  • getch();

  • return 0;

  • }


Lecture 3 programming concepts

Simple Program

  • #include<iostream>

  • #include<conio>

  • void main(void){

  • cout<<"Every age

  • has a language of its own\n";

  • getch();

  • }


Comments

Comments

  • We can comment something if we do not want it to be compiled

  • It is mostly used to define or explain something in the code

  • Single line comments //

  • Multi line comment  /*……….*/


Lecture 3 programming concepts

Comments

  • //This is our First Program

  • #include<iostream>

  • #include<conio>//Preprocessor Directive

  • int main(){ //start of the function

  • cout<<"Every age has a language of its own\n";

  • /*getch();

  • return 0;*/

  • }


Escape characters

Escape Characters

  • #include<iostream>

  • #include<conio>

  • int main(){

  • cout<<“*\n**\n***\n*****\n";

  • getch();

  • return 0;

  • }


Escape characters1

Escape Characters


Variables

Variables

  • A variable is a location in computer memory where a value can be stored

  • Every variable has two parts:

  • Variable type

  • Variable name (identifier)

  • i.e. int a;

  • Variables must be declared before they are used in program


Lecture 3 programming concepts

100

101

102

103

104

105

106

RAM

int abc;

abc=10;

10

abc


Variables1

Variables

  • #include<iostream>

  • #include<conio>

  • int main(){

  • int var1;

  • int var2;

  • var1=20;

  • var2=var1+10;

  • cout<<“var1+10 is :”;

  • cout<<var2<<endl;

  • getch();

  • return 0;

  • }


Lecture 3 programming concepts

  • Initialize five variables a,b,c,d,e.Display them on screen

  • #include<iostream>

  • #include<conio>

  • int main(){

  • int a,b,c,d,e;

  • a=3;

  • b=4;

  • c=6;

  • d=e=9;

  • cout<<a<<endl<<b<<endl<<c<<“ ”<<d;

  • return 0;

  • }


Lecture 3 programming concepts

100

101

102

103

104

105

106

Swapping of variables

10

a

int a=10;

30

b

int b=30;

a=b;


Lecture 3 programming concepts

  • Swapping of variables

  • #include<iostream>

  • #include<conio>

  • int main(){

  • int x,y,temp;

  • x=3;

  • y=4;

  • temp=x;

  • x=y;

  • y=temp;

  • cout<<x<<endl<<y;

  • return 0;

  • }


Variables names

Variables Names

  • Following rules should follow for naming the variables:

  • Upper case, lower case letters and digits(0 to 9)

  • Underscore(_) can also be used

  • Name must start with a letter or underscore

  • Keywords cannot be used as variable name i.e. return,int, void etc.


Variables names1

Variables Names

  • C++ is a case sensitive language uppercase and lower case are different: a1 is different from A1

  • Valid identifiers: int abc, int aBc, int first_var, int _first

  • Invalid identifiers: int 3bc, int a*b, int #a


Adding two integers

Adding Two Integers

  • #include<iostream>

  • #include<conio>

  • int main(){

  • int integer1, integer2, sum;

  • cout<<“Enter first integer\n”;

  • cin>>integer1;

  • cout<<“Enter second interger\n”;

  • cin>>integer2;

  • sum = integer1+integer2;

  • cout<<“Sum is :”<<sum<<endl;

  • getch();

  • return 0;

  • }


Arithmetic operators

Arithmetic Operators


Problem

Problem

  • Ask user to enter a three digit number.Then display the number in reverse order


Lecture 3 programming concepts

  • #include<iostream>

  • #include<conio>

  • void main(){

  • cout<<"Enter a three digit number\n";

  • int a;

  • cin>>a;

  • cout<<a%10;

  • a=a/10;

  • cout<<a%10;

  • a=a/10;

  • cout<<a;

  • getch();

  • }


Variables types

Variables Types


Using character

Using Character

  • #include<iostream>

  • #include<conio>

  • int main(){

  • char x;

  • x=‘a’;

  • cout<<x;

  • getch();

  • return 0;

  • }


  • Login