lecture 5+6 introduction to computer & programming

66
MS Sadia Ejaz CIIT ATTOCK Lecture 5+6 Introduction to computer & programming MS SADIA EJAZ CS DEPARTMENT

Upload: kreeli

Post on 14-Feb-2016

41 views

Category:

Documents


2 download

DESCRIPTION

Lecture 5+6 Introduction to computer & programming. MS SADIA EJAZ CS DEPARTMENT. The Internet. It is a huge network of computers, which links many different types of computers all over the world. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Lecture 5+6Introduction to

computer & programming

MS SADIA EJAZCS DEPARTMENT

Page 2: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

The Internet It is a huge network of computers,

which links many different types of computers all over the world.

It is a network of networks, which share a common mechanism for addressing (identifying) computers, and a common set of communication protocols for communication between two computers on the network.

2

Page 3: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

The Internet’s Major Services The World Wide Web Electronic mail News File Transfer Protocol Chat Instant Messaging Online- Services Peer-to-Peer Services

3

Page 4: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

The World Wide Web The World Wide Web (commonly shortened

to the Web) is a system of interlinked hypertext documents accessed via the Internet.

With a Web browser, a user views Web pages that may contain text, images, videos, and other multimedia and navigates between them using hyperlinks.

4

Page 5: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Web Search Engine A Web search engine is a search engine

designed to search for information on the World Wide Web.

A search engine lets you search for information by typing one or more words. The engine then displays a list of Web pages that contain information related to your words.

Example: Google search engine

5

Page 6: Lecture 5+6 Introduction to  computer &                   programming

E - Mail Electronic mail, often abbreviated to e-

mail, is a store-and-forward method of writing, sending, receiving and saving messages over electronic communication systems.

6

Page 7: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Programming Language Generations Machine languages: first generation Assembly languages: second generation Higher-level languages: third generation

(3GLs)

Page 8: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Fading Third-Generation Languages FORTRAN (FORmula TRANslator) COBOL (COmmon Business Oriented

Language) BASIC (Beginner’s All-Purpose Symbolic

Instruction Code) Pascal

Page 9: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Thriving Third-Generation Languages C C++ Java ActiveX

Page 10: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Fourth-Generation Languages (4GLs) Builds programs with a front end, which is an

interface that hides much of the program from the user

Provides prototypes, which are samples of the finished programs

Page 11: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Examples of Fourth-Generation Languages Visual Basic (VB) VisualAge Authoring environments

Page 12: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Fifth-Generation Languages (5GLs) Advanced authoring environments

considered by some to be 5GLs

Page 13: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

World Wide Web Development Languages HyperText Markup Language (HTML) Extensible Markup Language (XML) Wireless Markup Language (WML) Dreamweaver Flash Director

Page 14: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Systems Development Life Cycle for Programming Phase 1: Needs analysis Phase 2: Program design Phase 3: Development (also called coding) Phase 4: Implementation Phase 5: Maintenance

Page 15: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Why We Do Programming ? For solving problems

Computers are used as a tool to solve complex problems by developing computer programs that provide the solution of the problems.

Example: Program : For adding 2 numbers, i.e 3 and 5 Solution: A computer program will be developed

for their addition.

Page 16: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Problem-Solving Techniques Program Algorithm Pseudo Code Flowchart , etc.

Page 17: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Program

A set of instructions that tells a computer what to do is called program.

Computer programs are written in programming languages.

A person who develops a program is called programmer.

Page 18: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Algorithms

It is a step-by-step procedure to solve a problem.

Properties of Algorithm The given problem should be broken down

into simple and meaningful steps. The steps should be numbered sequentially. The steps should be descriptive and written

in simple English.

Page 19: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Pseudo Code / Pseudo Language Algorithms are written in a language,

which is similar to simple English , which is known as pseudo language.

The purpose of using pseudo code is that it may be easier for humans to read than conventional programming languages.

No standard for pseudo code syntax exists, as a program in pseudo code is not an executable program.

Page 20: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Parts of Program Development Two main parts

Logic Design Coding

Page 21: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Logic Design

Logic of the program is designed by specifying different steps required and the sequence of these steps to solve the problem.

Page 22: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Coding

The algorithm is converted into a program.

Page 23: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Example

Algorithm for calculating and displaying the sum of two numbers,

1. Input A, B2. Total / Sum A + B3. Display Total4. Exit

Page 24: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Advantages of Algorithms

Reduced Complexity Increased Flexibility Ease of Understanding

Page 25: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Flowchart It is combination of two words i.e. flow and

chart. Flowchart is a graphical representation of an

algorithm. Chart consists of different symbols to display

information about any program. Flow indicates the direction of processing that takes

place in the program. It is used to show all the steps of an algorithm

in a sequence.

Page 26: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Flowchart (contd.)

Page 27: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Uses of Logic Flowchart It is used to represent an algorithm in simple

graphical manner. It is used to show the steps of an algorithm in

an easy way. It is used to understand the flow of the

program. It is used to improve the logic for solving a

problem. Programs can be reviewed and debugged

easily.

Page 28: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols

Input/Output Parallelogram symbol is used to

represent an input or output step. Input statement is used to get input from the user. The output statement is used to display a message to the use or to display a value.

Input Output

Page 29: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.) Process Rectangle symbol is used to represent a

process step.

Page 30: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.) Selection Diamond symbol is used to represent a

selection step.

Page 31: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.) Start/End Oval symbol is used to represent the

start or end of the flowchart.

Start End

Page 32: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.) Connector

Indicates that the flow continues where a matching symbol (containing the same letter) has been placed.

Page 33: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.) Flow Line

Lines indicate the sequence of steps and the direction of flow.

Page 34: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

ExampleStart

End

Sum = A+B

Input A, B

Display Sum

Page 35: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Difference Between Pseudo Code and Flowchart

Flowchart Pseudo Code

It contains standard symbols to represent different computer operations.

There is no standard for writing pseudo code.

It is less frequently used as it takes more time to design.

It is more frequently used as it takes less time.

It is difficult to modify. It is easier to modify.

It is a graphical representation of solution.

It is not a graphical representation of solution.

Page 36: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Program Development Process A programmer has to go through the

following stages to develop a computer program: Defining and Analyzing the Problem. Designing the Algorithm Coding or Writing the Program Test Execution Debugging Final Documentation

Page 37: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Integrated Development Environment (IDE)

Editor Compilers Debugger Linkers Loaders

Page 38: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Preprocessor programprocesses the code.

Loader puts program in memory.

CPU takes eachinstruction and executes it, possibly storing new data values as the program executes.

Compiler creates object code and storesit on disk.Linker links the objectcode with the libraries

LoaderPrimary Memory

Compiler

Editor

Preprocessor

Linker

 

Primary Memory

.

.

.

.

.

.

.

.

.

.

.

.

Disk

Disk

Disk

CPU

Disk

DiskProgram is created in the editor and stored on disk.

Page 39: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Tools of the trade Editor

First of all we need a tool for writing the code of a program. For this purpose we used Editors in which we write our code.

Page 40: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Debugger It is used to debug the program.

Page 41: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Linker Most of the time our program is using

different routines and functions that are located in different files, hence it needs the executable code of those routines/functions.

Linker is a tool which performs this job, it checks our program and includes all those routines or functions which we are using in our program to make a standalone executable code and this process is called Linking.

Page 42: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Loader Another process which is needed to load the

program into memory and then instruct the processor to start the execution of the program from the first instruction (the starting point of every C program is from the main function).

This processor is known as loader. Linker and loaders are the part of

development environment. These are part of system software.

Page 43: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Debugging in Turbo C++ An error in a computer program is

known as bug. The process of finding and removing

bugs is known as debugging.

Page 44: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Types of Errors Syntax Errors Logical Errors Run-Time Errors

Page 45: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Syntax Errors It is a type of error that occurs when an

invalid statement is written in program.

Page 46: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Logical Errors It is a type of error that occurs due to

poor logic of the programmer.

Page 47: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Run-Time Errors It is a type of error that occurs during

the execution of program.

Page 48: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

C++ Statement

The statement of the program are writen under the main() function between the curely bracket{}.

These statement are the body of program Each statement of the c++ ends with a semicolon(;) C++ is a case sensitive language The c++ statement are normally written in lowercase

letters but in some exceptional but in some exceptional cases, these can also be written in upper case

Page 49: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

keyword The words that are used by the language for

special purpose are called keywords e.g. in c++ program, the word main is used to

indicate the starting of program, include is used to header files, int to declare an integer data type

All these words are keyword of c++ The keyword cannot be used as variable

names in program

Page 50: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Identifiers The identifiers are the names used to

represent variable, constants, types, functions and labels in the program.

An identifier in C++ may consist of 31 characters.

Page 51: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Types of Identifiers Standard Identifiers

A type of identifier that has special meaning in C++ is known standard identifier.

For example. cout, cin, etc. User-defined Identifiers

The type of identifier that is defined by the programmer to access memory location is known as user-defined identifier.

For example, marks, age, etc.

Page 52: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Keywords Keyword is a word in C++ language

that has a predefined meaning and purpose.

They are also known as reserved words. The total number of keywords is 63. For example, int, class, etc.

Page 53: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Data Types The data type defines a set of values

and a set of operations on these values. A C++ program may need to process

different types of data.

Page 54: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Data Types Data Type Purpose

int to store numeric values

float to store real values double to store large real

values char to store character

values

Page 55: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Integer Data Type Integer data is numeric value with no

decimal point or fraction.Types of Integers Size in Bytes int 2 short int 2 long int 4

unsigned int 2 unsigned long int 4

Page 56: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Real Data Types Real data is numeric value with decimal

point or fraction. It is also called floating point number. Types of Real Size in Bytes float 4 double 8

long double 10

Page 57: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Character Data Type char data type is used to store

character value. It takes 1 byte in memory. The characters are stored in ASCII code

form. ASCII American Standard Code for

Information Interchange.

Page 58: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Integer Overflow and Underflow Integer Overflow

It occurs when the value assigned to an integer variable is more than maximum possible value.

Integer Underflow It occurs when the value assigned to an

integer variable is less than possible minimum value.

Page 59: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Variables A variable is a named memory location

or memory cell. The value stored in a variable is

referred by variable name.

Page 60: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Variables Declaration The process of specifying the variable

name and its type is called variable declaration.

Syntax Data type variable_name ; e.g. int marks ;

Page 61: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Rules for Declaring Variables Variable may include letter, numbers

and underscore (_). The first character of variable must be a

letter or underscore _. The use of underscore is not recommended. The variables 9minute, #home and 2kg are invalid.

Blank spaces are not allowed in variable names. The variables my var and your car are invalid.

Page 62: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Rules for Declaring Variables (contd.) Both upper and lower cases are

allowed. A user-defined variable is conventionally written in lower case. The constants are conventionally written in upper case.

Special symbols cannot be used as variable name.

Reserved word cannot be used as variable name. The names int, void and while are invalid variables.

Page 63: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Rules for Declaring Variables (contd.) A variable can be up to 31 characters

long for many compiler. If a variable consists of more than 31 characters, only first 31 characters will be used. The remaining characters will be ignored.

A variable can be declared only for one data type.

Page 64: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Variable Initialization The process of assigning a value to a

variable at the time of declaration is known as variable initialization.

Syntax Data type variable _name = value; e.g. int n = 100 ; int n= 100 ;

Page 65: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Tokens A program statement consist of variable

names, keywords, constant, operator etc, these elements of statement are called tokens

e.g. int main(){

int x,y;

x = 5;

}

Page 66: Lecture 5+6 Introduction to  computer &                   programming

MS Sadia Ejaz CIIT ATTOCK

Example simple program #include< stdio.h >

#include< iostream.h >

int main(){

int x;

x = 5; cout << x; return 0;}