muhammad abrar [email protected] +. m uhammad a brar ???? ms (computer science) gold medal...

43
Muhammad Abrar [email protected] + +

Upload: barbara-baker

Post on 18-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

Muhammad [email protected]

+ +

Page 2: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

MUHAMMAD ABRAR????MUHAMMAD ABRAR???? MS (Computer Science) Gold MedalMS (Computer Science) Gold Medal

◦ Specialization in Database SystemsSpecialization in Database Systems Research PublicationResearch Publication

M. Abrar, Z. Jan, Dr A.M. Mirza S. Bashir “Seasonal to M. Abrar, Z. Jan, Dr A.M. Mirza S. Bashir “Seasonal to Interannual Climate Prediction Using Data Mining Interannual Climate Prediction Using Data Mining technique KNN” Springer Verlag Communications in technique KNN” Springer Verlag Communications in Computer and Information Science Series Book. 2008 Computer and Information Science Series Book. 2008

Research Areas: Data Mining , Data Ware Research Areas: Data Mining , Data Ware Housing, Distributed DatabaseHousing, Distributed Database

Areas of expertise : Programming (.NET (Visual Areas of expertise : Programming (.NET (Visual Basic, Visual C++ etc), C++, JAVA)Basic, Visual C++ etc), C++, JAVA)OOP Analysis, Structure Analysis and DesigningOOP Analysis, Structure Analysis and Designing

2

Page 3: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

MUHAMMAD ABRAR???? MUHAMMAD ABRAR???? (CONT’D)(CONT’D)

ExperienceExperience◦ January 2009 – ---- January 2009 – ---- (kardan Institute of Higher Education, Kabul)(kardan Institute of Higher Education, Kabul)

◦ Assistant Professor In Computer ScienceAssistant Professor In Computer Science◦ September 2006 – Dec 2008 September 2006 – Dec 2008 (IBMS/CS , Agricultural University (IBMS/CS , Agricultural University

Peshawar)Peshawar) Lecturer In Computer Science,Lecturer In Computer Science, Assistant In-charge Computer ScienceAssistant In-charge Computer Science

◦ September 2002- August 2006 September 2002- August 2006 (Govt. College of Commerce (Govt. College of Commerce Mardan)Mardan) Computer InstructorComputer Instructor In-charge Computer Literacy Program.In-charge Computer Literacy Program.

◦ February 2004 – August 2006 February 2004 – August 2006 (Ansi Institute of Management (Ansi Institute of Management Sciences) MardanSciences) Mardan Visiting Lecturer In Computer Science.Visiting Lecturer In Computer Science.

3

Page 4: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

DEFINITIONS

•one that computes: a programmable electronic device that can store, retrieve, and process data (Merriam-Webster’s Collegiate Dictionary)

•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.

com*put*er

Programming

Computer Programming

ComputerProgram

Page 5: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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.

Page 6: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

DEFINITIONS• Machine Language : The language, made up of binary-coded 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.•

Page 7: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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.

Page 8: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

http://sites.google.com/site/bcskardan/

Page 9: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

WHAT WE WILL STUDY?

History of Computer Languages Variables & Constants Operators Conditional Statements Loops Arrays

One dimensional array Two Dimensional array

Functions Pointers

Page 10: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

BOOKS

Object Oriented Programming in C++ (text Book) BY Robert Lafore 3rd Edition

C++ How to program (recommended Book) By Deitel and Deitel

Page 11: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 12: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

LETS START

C++ Program Structure

#include <iostream.h>#include<conio.h>Void main(){

cout<<“Welcome to the world of excitement”;getch();

}

Page 13: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 14: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 15: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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.

Page 16: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 17: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

Lets start playing with computer

Run the first program of this semester

Page 18: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

PROGRAMMING CONCEPTSLECTURE NO 2Muhammad Abrar

[email protected]

Page 19: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

COMMENTS

Comments are used to describe the statements

They are ignored by compiler

They are only used for the programmer to understand the code

Page 20: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 21: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

COMMENTS SYNTAX

Single Line Comments // this is single line comments

Multiple Line Comments

/* this is Multiline comments */

Page 22: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

COMMENTS EXAMPLE

C++ Program Structure

#include <iostream.h>#include<conio.h>//main function start hereVoid main(){ /* this program display the text

phrase on the screen*/cout<<“Welcome to the world of excitement”;getch();//end of program

}

Page 23: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 24: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 25: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 26: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 27: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

PROGRAMMING CONCEPTSLECTURE NO 3Muhammad Abrar

[email protected]

Page 28: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 29: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

DATA TYPE IS C++

In C++ we have the following built in data type For integer

int reserve 2 bytesvalue range (-32768 to 32767)

long reserve 4 bytes value range (-2147483648 to 2147483647)

Real Numbersfloat reserve 4 bytesvalue 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

Page 30: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

DATA TYPES IN C++ (CONT’D)

Unsigned Data type

unsigned int (0 to 65,535)Same as ‘int’ but store only positive numbers

unsigned long (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

Page 31: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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();

}

Page 32: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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();

}

Page 33: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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;

Page 34: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 35: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

#include<iostream.h>#include<conio.h>void main(){

int var1, var2, var3;var1 = 521;var2 = 2;var3 = var1 / var2;cout<<var3;getch();

}

Page 36: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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; // declaration var1 = 25; //initialization

C++ allows us to declare and initialize a variable in a single line e.g. int var1 = 25;

Page 37: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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();

}

Page 38: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 39: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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)

Page 40: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

RAM (CONT’D)

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)

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

. .

. .

. .

. .

N-2

N-1

Page 41: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 42: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

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

Page 43: Muhammad Abrar muhammadabrar78@yahoo.com +. M UHAMMAD A BRAR ????  MS (Computer Science) Gold Medal ◦ Specialization in Database Systems  Research Publication

VISUALIZE THE VARIABLE

int var1;

var1 = ;

cout<<var1;

25

0

1

2

3

4

5

6

7

8

.

.

.

.N-1

var1

25

25