0% found this document useful (0 votes)
5 views

Lecture#02 03

Uploaded by

abdullahsnap1919
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture#02 03

Uploaded by

abdullahsnap1919
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Programming Fundamentals

CS-111
(4 CrH = 3 Theory 1 Lab)
Lecture No. 2&3

Department of Computational Sciences


The University of Faisalabad (TUF)
Course Modules
• Functional C++ (Procedural)
– Basic Concepts
– Incremental (Sequential, Selective, Iterative)
– Functions
– Arrays
– Pointers
– Structures
• Object Oriented C++
– Class and Object Concepts
– File Handling
Necessary Code for C++ in Every Program

#include<iostream>
using namespace std;
int main( )
{
// write here your statement1;
// write here your statement2;
// write here your statement3;
// and so on …
return 0;
Today’s Lecture Agenda….
• Variables
• Operators
Programming in C++

Some important things you must


memorized before starting
programming in C++
• Syntax:
Rules and regulations for writing the
code of any programming language is called
Syntax of that language.
• Case sensitive:
C++ is case sensitive means you can’t
use capital “M” when you write main() like:
main() ≠ Main()
What is Syntax and constructs
of a programming language?
• Rules and regulation of writing any
code statement of a programming
language is called syntax.
• There are different constructs in a
programming language and every
construct has its own syntax.
• For example: the fowling are the
constructs in C++:
• variable; if; for; while; condition;
functions etc;
Variables (Named Memory)
• A variable is a location in
computer memory where a value
can be stored
• Variable Declaration
1. Variable type
2. Variable name (identifier)
• Storing Values in Variables
– = (Assignment Operator)
– Input Run Time ( cin>>)
• Capacity of Variable
• Scope of a Variable
Syntax for Variable declaration
1. datatype space identifier semicolon
e.g. int a;

2. datatype space identifier comma identifier


semicolon
e.g. int a, b;

3. datatype space identifier comma identifier


comma identifier semicolon
e.g. int a, b, c;
Syntax for Variable declaration
and initialization (assigning value)
1. datatype space identifier space = space value semicolon
e.g. int a = 5;
Plz reserve RAM location and keep its name “a”
and also store 5 in this location
2. datatype space identifier space = space value
comma identifier semicolon
e.g. int a = 5, b;

3. datatype space identifier space = space value


comma identifier space = space value
semicolon
e.g. int a = 3, b = 2;
Variables
• Every variable has two parts:
1. Variable type
2. Variable name (identifier)

• int a;
• float x;
• char abc;
• Storing character value in abc
variable
abc = ‘z’ ;
• This process is known as Variable
Declaration
Giving Names to Variables
• Following rules should follow for naming
the variables:
1. Upper case, lower case letters and
digits(0 to 9)
2. Underscore(_) can also be used
3. Name must start with a letter or
underscore
4. Keywords cannot be used as variable
name i.e. return,int, void etc.
Keywords
Variables
• Variables must be declared before
they are used in a program
Assigning Values
RAM
100

int abc; 101


102
abc=10; 100
10
abc103
abc=100; 104
105
int abc=10;
106
Assigning Values
RAM
100

int abc; 101


102
cin>>abc;
abc103
104
105

106
Displaying Values
RAM
100

101
int abc=10;
102
cout<<abc; 103

cout<<“abc=”<<abc; 104

abc105 10
106
Assigning Wrong type Values
RAM
100

int abc=10.545; 101


102
103
104

abc 105 10
106
• Swapping of variables
• #include<iostream>
• #include<conio>
• int main(){
• int x,y,temp;
• cin>>x>>y;
• temp=x;
• x=y;
• y=temp;
• cout<<x<<endl<<y;
• return 0;
• }
Variables Types
Keyword Range Bytes of
Low High Memory
char -128 127 1
short -32,768 32768 2
int -2,147,483,648 2,147,483,647 4
long -2,147,483,648 2,147,483,647 4
float 3.4*10-38 3.4*1038 4
double 1.7*10-308 1.7*10308 8
long 3.4*10-4932 3.4*104932 10
double
Using Character
• #include<iostream>
• #include<conio>
• int main(){
• char x;
• x=‘A’;
• cout<<x;
• getch();
• return 0;
• }

You might also like