Muhammad Abrar

Download Report

Transcript Muhammad Abrar

++
Muhammad Abrar
[email protected]

MS (Computer Science) Gold Medal
◦

Research Publication



Specialization in Database Systems
M. Abrar, Z. Jan, Dr A.M. Mirza S. Bashir “Seasonal to
Interannual Climate Prediction Using Data Mining
technique KNN” Springer Verlag Communications in
Computer and Information Science Series Book. 2008
Research Areas: Data Mining , Data Ware Housing,
Distributed Database
Areas of expertise : Programming (.NET (Visual
Basic, Visual C++ etc), C++, JAVA)
OOP Analysis, Structure Analysis and Designing
2
MUHAMMAD ABRAR????

Experience
◦
January 2009 – ---- (kardan Institute of Higher Education, Kabul)
Assistant Professor In Computer Science
◦
◦
September 2006 – Dec 2008 (IBMS/CS , Agricultural University
Peshawar)


◦
September 2002- August 2006 (Govt. College of Commerce Mardan)


◦
Lecturer In Computer Science,
Assistant In-charge Computer Science
Computer Instructor
In-charge Computer Literacy Program.
February 2004 – August 2006 (Ansi Institute of Management
Sciences) Mardan

Visiting Lecturer In Computer Science.
3
MUHAMMAD ABRAR???? (CONT’D)
DEFINITIONS
com*put*er
•one that computes: a programmable electronic
device that can store, retrieve, and process data
(Merriam-Webster’s Collegiate Dictionary)
Programming
Computer
Programming
Computer
Program
•Planning or scheduling the performance of a
task or an event.
•The process of planning a sequence of steps
for a computer to follow.
•A logically arranged set of instructions to be
performed by a computer.
DEFINITIONS
• Algorithm :A step-by-step procedure for
solving a problem in a finite amount of time.
• Programming Language : A set of rules,
symbols, and special words used to construct
a computer program.
DEFINITIONS
• Machine Language : The language, made up of binarycoded instructions, that is used directly by the computer.
• Assembly Language : A low-level programming language
in which a mnemonic is used to represent each of the
machine language instructions for a particular computer.
• Assembler :A program that translates an assembly language
program into machine code.
• Compiler : A program that translates a high-level language
into machine code.
•
DEFINITIONS
Source Program : A program written in a high-level
programming language.
 Object Program : The machine language version of a
source program.
 Syntax : The formal rules governing how valid instructions are
written in a programming language.
 Key Word : A word that has special meaning in C++; it cannot be
used as a programmer-defined identifier.

 http://sites.google.com/site/bcskardan/
WHAT WE WILL STUDY?
History of Computer Languages
 Variables & Constants
 Operators
 Conditional Statements
 Loops
 Arrays

One dimensional array
 Two Dimensional array

Functions
 Pointers

BOOKS

Object Oriented Programming in C++ (text Book)


BY Robert Lafore 3rd Edition
C++ How to program (recommended Book)

By Deitel and Deitel
HISTORY OF C++

C was developed in 1970 By Danis Ritche

C++ was developed in 1979 by bijarne Stroustroup

Super class of C


Every Program written in C can be a legal program in C++
but the reverse may not be true
Object Oriented Language
LETS START
C++ Program Structure
#include <iostream.h>
#include<conio.h>
Void main()
{
cout<<“Welcome to the world of excitement”;
getch();
}
FUNCTIONS




Functions are basic building block of C++ program
Function is a set related code that perform a specific
task
Function name must be followed by parentheses
Each C++ program that you want to run must have
‘main()’ function
PROGRAM DESCRIPTION

There are two statement in the previous program

cout<<“Welcome to the world of Excitement”;

cout is a special word that is used as output
statement
What ever you want to display on the screen can be
done using cout.
 This statement will display the phrase “Welcome to
the world of excitement” on the screen


cout<<“Welcome to the world of Excitement”;

Notice the semicolon ‘;’ at the end of cout statement.

Semicolon inddicate the end of statement

In C++ each statement must be terminated with a
semicolon.

getch();

Is it a function????

Whatever is followed by parentheses is a function
When the result is displayed on the screen, then this
function will retain the result on the screen until you
press a key from the keyboard
 We will study its other usage in coming lectures


Lets start playing with computer

Run the first program of this semester
PROGRAMMING CONCEPTS
LECTURE NO 2
Muhammad Abrar
[email protected]
COMMENTS

Comments are used to describe the statements

They are ignored by compiler

They are only used for the programmer to understand the
code
WHEN TO USE COMMENTS?

Always good thing to use comments

Other programmer may not understand your code




They may need some short description about the code that you
written
You may also need comments if revisit your own code after a
long time
Do not put large details in comments
Comments should be simple, clear and short
COMMENTS SYNTAX

Single Line Comments


// this is single line comments
Multiple Line Comments
/* this is
 Multiline comments */

COMMENTS EXAMPLE
C++ Program Structure
#include <iostream.h>
#include<conio.h>
//main function start here
Void main()
{ /* this program display the text
phrase on the screen*/
cout<<“Welcome to the world of excitement”;
getch();
//end of program
}
WHAT IF WE WANT TO STORE DATA IN A
PROGRAM?

Write a program that add two numbers

How to put these two values in a program?

Variables are used for this purpose
VARIABLES
Variables are named memory locations that store
data.
 The value of variable may change during the
execution of program


Each variable has ….
Name
 Data Type

VARIABLE NAME





Variable name are called user defined Identifiers
Variable Name may have alphabets, Numbers and ‘_’
and nothing else.
Variable Name must start from Alphabet
C++ keywords cannot be used as variable name (we
will discuss keywords in detail later)
C++ is case sensitive language so it distinguish
between lower and upper case alphabets
DECLARING VARIABLES



When we need use a variable, we must declare it first.
Declaration introduce a variable’s name into a
program and specify its type
Syntax

Datatype variableName;

int var1;
int var2;
etc


PROGRAMMING CONCEPTS
LECTURE NO 3
Muhammad Abrar
[email protected]
DATA TYPES



In C++ each variable has their associated data type
that tell the compiler that what type of value will be
store in the variable
When the variable is declared, a space in computer is
reserved.
That memory location then store the data
DATA TYPE IS C++

In C++ we have the following built in data type

For integer
int
reserve 2 bytes
value range (-32768 to 32767)
 long
reserve 4 bytes
value range (-2147483648 to 2147483647)


Real Numbers
float
reserve 4 bytes
value range 3.4 x 10-38 to 3.4 x 1038
 Double
reserve 8 bytes
value range 1.7 x 10-308 to 1.7 x 10308

DATA TYPES IN C++ (CONT’D)

Unsigned Data type

unsigned int



Same as ‘int’ but store only positive numbers
unsigned long

(0 to 65,535)
(0 to 4,289,497,295)
Same as ‘long’ but store only positive numbers
If we need to store only positive numbers then best option
is to use unsigned data types
USING INTEGER DATA TYPE

Write a C++ program that add two numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int var1;
int var2;
var1 = 28;
var2 = 2;
int var3;
var3 = var1 + var2;
cout<<var3;
getch();
}
PROBLEM WITH “INT’

Write a program to divide 521/2
#include<iostream.h>
#include<conio.h>
void main()
{
int var1;
int var2;
var1 = 521;
var2 = 2;
int var3;
var3 = var1 / var2;
cout<<var3;
getch();
}
Integer when divide by integer always result in
integer
 At least one variable should be float when the result
is expected in real number
 i.e.








int var1;
float var2;
float var3;
var1= 521;
var2 = 2;
var3 = var1/var2
cout<<var3;
MULTIPLE DECLARATION ON SINGLE LINE
It is difficult to declare many variable of same type on
separate lines
 C++ allows us to declare same type of variable on
single line

i.e.
 int var1, var2, var3 ………..;
 float var1, var2, var3, ……….;


When declaring multiple variable on single line keep
following points in mind
Variable list should be separated by comma
 You can only declare same type of variable on single line

#include<iostream.h>
#include<conio.h>
void main()
{
int var1, var2, var3;
var1 = 521;
var2 = 2;
var3 = var1 / var2;
cout<<var3;
getch();
}
VARIABLE INITIALIZATION
Initialization mean to put a value in a variable for the
first time
 Initialization can be done at any stage in a program


Normally we initialize variable immediately after
declaration e.g.
int var1;
 var1 = 25;


// declaration
//initialization
C++ allows us to declare and initialize a variable in a
single line e.g.

int var1 = 25;
DECLARATION AND INITIALIZATION ON SAME
LINE
#include<iostream.h>
#include<conio.h>
void main()
{
int var1 = 521, var2 = 2, var3;
var3 = var1 / var2;
cout<<var3;
getch();
}
MEMORY CONCEPT OF VARIABLE
Now we now that when we declare a variable it
reserve some memory that is used to hold user data
 Lets explain this in detail


What is memory??



Hard Disk, Optical Disk, RAM, ROM
What is meant by memory when we talk in
programming language?
RAM
RAM (RANDOM ACCESS MEMORY)
RAM is main memory that can be access directly by
the processor
 Every thing that we run on the computer must be in
RAM
 If it is not in RAM then we can not process it
 Then what about those program that are stored on
Hard Disk and we are still able to run it?????


When we click on the icon of a program, the program
is first loaded into main memory and then its
execution starts (It start working)
0
1
RAM (CONT’D)
2
So when we use a variable, the memory that it
reserve must be in main memory(RAM).
 Main Memory consist of large number of Cells called
bytes
 Each Cell has it own numerical value by which we
identify each cell
 These numeric value is called memory Address
 1GB Ram has 1,073,741,824 cells (1 Billion)
4

3
5
6
7
8
9
10
11
12
13
14
.
.
.
.
.
.
.
.
N-2
N-1
If we now the address of some empty cell then we can
directly put our data in that specific cell i.e.
 [13] = 24
 It means that put value (24) at location number 13
 What is problem with this method?

1) if we use this technique then the previous data written
at that location will be overwritten and we will loss the
previous data
 2) We don’t know which memory location is in use and
which one is free
 3) after all this technique is difficult to memorize that
which location store the specific data



So we need a human understandable name for these
location
Variable are the human understandable name for
these memory location
The compiler and operating System then keep track
of the numeric values that are associated with these
names
 We only use variable to access and store values at
that locations

VISUALIZE THE VARIABLE

int var1;
var1
0
1
2

var1 = 25 ;
3
4

cout<<var1;
5
6
7
8
.
.
.
.
N-1
25