Sunteți pe pagina 1din 150

Introduction to computer & programming

Ms Sadia Ejaz CS Department

CIIT ATTOCK SADIA EJAZ

Computer ?

CIIT ATTOCK SADIA EJAZ

The Four Equipment Functions of a Computer System

There are four main equipment functions of a computer system: Input, Processing, Storage and Output

CIIT ATTOCK SADIA EJAZ

The Four Equipment Functions of a Computer System


Input the component through which a user instructs a computer about what to do Processor the engine that processes the instructions given by the user Memory where the processor stores information that is required during its computations Storage where information that is required to be used much later is stored Output the component that communicates the results of a computation to the user

CIIT ATTOCK SADIA EJAZ

Hardware/ Software

Hardware - the "machinery" - computer equipment - the CPU, the monitor, the keyboard, the mouse, the external speakers, the scanner, the printer, etc. The physical, touchable parts of a computer system. Software - the program instructions that make the computer do some task, such as word process, manage databases, play games, etc.
CIIT ATTOCK SADIA EJAZ

Hard Copy/Soft Copy

Hard Copy - a paper printout of the program code or data displayed on the screen. Soft Copy - copy of a program stored on a hard drive, diskette, or CD. Network - a hardware and software data communication system. Usually a group of computers that are linked to share memory and programs. Control Unit - the unit inside of the CPU which "directs the traffic" - makes decisions. It performs the functions of fetch, decode, execute, and store.
CIIT ATTOCK SADIA EJAZ

Data Structure

Computer data is in what is called binary format. This means that it is always a 0 or a 1. It only has these two states and must be in one of them. There are several fundamental data units which include: Bit - A data unit which must be in one of the two binary states described above. It is the smallest data unit that exists. Byte - 8 bits of data which has a possible value from 0 to 255. Word - Two bytes or 16 bits of data with a possible unsigned value from 0 to 16535. Long word = 8 bytes = 64 bits Quad word = 16 bytes = 128 bits

CIIT ATTOCK SADIA EJAZ

Bits, Bytes

Unit kilobyte megabyte gigabyte terabyte

Symbol KB MB GB TB

Number of Bytes 210 = 1024 220 (over 1 million) 230 (over 1 billion) 240 (over 1 trillion)

CIIT ATTOCK SADIA EJAZ

All computers have the following essential hardware components:


INPUT PROCESSOR MEMORY

CIIT ATTOCK SADIA EJAZ

INPUT

The devices used to give the computer data or commands are called Input devices. Includes keyboard, mouse, scanner, etc

CIIT ATTOCK SADIA EJAZ

PROCESSOR

Central Processing Unit (CPU) The brain of the computer. This is the component that actually executes instructions Controls all other computer functions In PCs (personal computers) also called the microprocessor or simply processor.. The processor is the logic of a computer
CIIT ATTOCK SADIA EJAZ

Processor

Pentium Celeron Athlon PowerPC StrongARM (PDA) SPARC (Workstations)

CIIT ATTOCK SADIA EJAZ

Arithmetic Logic Unit


It is the place where the actual execution of the instructions take place during the processing operation. The data and instructions, stored in the primary storage before processing, are transferred as and when needed to the ALU, where processing takes place. All ALU are designed to perform Four basic arithmetic operations

Logic operations or comparisons, such as less than, equal to, or greater than.

CIIT ATTOCK SADIA EJAZ

13

Control Unit

It acts as a central nervous system for the other components of the computer system. It manages and coordinates the entire computer system. It obtains instructions from the program stored in main memory, interprets the instructions, and issues signals, which cause other units of the system to execute them.

CIIT ATTOCK SADIA EJAZ

14

Storage Unit

Two types of storage:

Primary Storage Secondary Storage

CIIT ATTOCK SADIA EJAZ

15

Main Memory (Primary Storage)


Main memory holds information such as computer programs, numeric data, or documents created by a word processor. All programs must be brought into main memory before execution. When power is turned off, everything in main memory is lost Main memory is made up of capacitors. If a capacitor is charged, then its state is said to be 1, or ON. We could also say the bit is set. If a capacitor does not have a charge, then its state is said to be 0, or OFF. We could also say that the bit is reset or cleared

CIIT ATTOCK SADIA EJAZ

Main Memory (cont.)

Memory is divided into cells, where each cell contains 8 bits (a 1 or a 0). Eight bits is called a byte. Each of these cells is uniquely numbered. The number associated with a cell is known as its address. Main memory is volatile storage. That is, if power is lost, the information in main memory is lost.
CIIT ATTOCK SADIA EJAZ

Secondary Storage Media (Secondary Storage)


Provides permanent storage for information Retains information even when power is off Examples of secondary storage: Hard Disks (sequential access) Floppy Disks (sequential access) Tapes (sequential access) CD-ROMs (random access) DVDs (random access) Secondary storage media store files that contain computer programs data other types of information This type of storage is called persistent (permanent) storage because it is non-volatile.
CIIT ATTOCK SADIA EJAZ

Speed

Primary storage is much faster to access than secondary storage because of the proximity of the storage to the processor or because of the nature of the storage devices. On the other hand, secondary storage can hold much more data than primary storage.

CIIT ATTOCK SADIA EJAZ

Hard disk

Hard disk is a computer storage device which saves and retrieves the data when required. Its capacity is much greater than the computer memory (RAM, ROM). Data on hard disk is stored. Today we can save huge amount of data on a single hard disk. Now hard disks can contain several billion bytes.

CIIT ATTOCK SADIA EJAZ

CD

A compact disc [sometimes spelled disk] (CD) is a small, portable, round medium for electronically recording, storing, and playing back audio, video, text, and other information in digital form.

CIIT ATTOCK SADIA EJAZ

Floppy disk

A diskette is a random access, removable data storage medium that can be used with personal computers. The term usually refers to the magnetic medium housed in a rigid plastic cartridge measuring 3.5 inches square and about 2 millimeters thick. Also called a "3.5-inch diskette," it can store up to 1.44 megabytes (MB) of data.

CIIT ATTOCK SADIA EJAZ

DVD

DVD (digital versatile disc) is an optical disc technology that is expected to rapidly replace the CDROM disc (as well as the audio compact disc) over the next few years. The digital versatile disc (DVD) holds 4.7 gigabyte of information on one of its two sides, or enough for a 133-minute movie.

CIIT ATTOCK SADIA EJAZ

Storage Devices - Other

USB drive

Very popular 64-512 MB Similar to cassette tape Used for backup

Tape drive

Zip drive

100 MB to 2 GB capacity Everyday use and backup


CIIT ATTOCK SADIA EJAZ

OUTPUT

The devices to which the computer writes data are called Output devices. Often converts the data into a human readable form. Monitor and printer are output devices.

CIIT ATTOCK SADIA EJAZ

ROM

ROM is "built-in" computer memory containing data that normally can only be read, not written to. ROM contains the programming that allows your computer to be "booted up" or regenerated each time you turn it on. Unlike a computer's random access memory (RAM), the data in ROM is not lost when the computer power is turned off.

CIIT ATTOCK SADIA EJAZ

Types of ROM

PROM

PROM stands for Programmable read only memory In PROM chip , the user can write his own instructions but at once If there is any error in writing the instruction the error can not removed from the PROM The chip become unusable

CIIT ATTOCK SADIA EJAZ

Types of ROM

EPROM

Stands for erasable programmable read only memory User can erase a instruction if any any error occurred Stands for Electronically Erasable Programmable Read Only memory

EEPROM

CIIT ATTOCK SADIA EJAZ

EXAMPLE

CIIT ATTOCK SADIA EJAZ

Introduction to computer & programming Lecture 5+6

MS SADIA EJAZ CS DEPARTMENT


CIIT ATTOCK

Software Categories

Software is categorized into two main categories


System Software Application Software

MS Sadia Ejaz CIIT ATTOCK

System Software

The system software controls the computer. It communicates with computers hardware (key board, mouse, modem, sound card etc) and controls different aspects of operations. Sub categories of system software are:

Operating system Device drivers Utilities

MS Sadia Ejaz CIIT ATTOCK

Operating System

Operating system is the software responsible for controlling the allocation and usage of hardware resources such as memory, central processing unit (CPU) time, disk space, and peripheral devices. The operating system is the foundation on which applications, such as word processing and spreadsheet programs, are built. (Microsoft)
MS Sadia Ejaz CIIT ATTOCK

Device drivers/ Utility Software

The device driver software is used to communicate between the devices and the computer.

Utility software is a program that performs a very specific task, usually related to managing system resources.

MS Sadia Ejaz CIIT ATTOCK

Application software

A program or group of programs designed for end users. For example a program for Accounting, Payroll, Inventory Control System, and guided system for planes.

MS Sadia Ejaz CIIT ATTOCK

Database Management System

A DBMS is a complex set of software programs that controls the organization, storage, management, and retrieval of data in a database. It is a set of prewritten programs that are used to store, update and retrieve a Database.

MS Sadia Ejaz CIIT ATTOCK

36

Computer Viruses

A computer virus is a program which reproduces itself. It may attach to other programs, it may create copies of itself (as in companion viruses). It may damage or corrupt data, change data, or degrade the performance of your system by utilizing resources such as memory or disk space.

MS Sadia Ejaz CIIT ATTOCK

37

Computer Network

A computer network is a group of interconnected computers.

MS Sadia Ejaz CIIT ATTOCK

38

What is programming

Definition: "A program is a precise sequence of steps to solve a particular problem. It means that when we say that we have a program, it actually mean that we know about a complete set activities to be performed in a particular order. The purpose of these activities is to solve a given problem.

MS Sadia Ejaz CIIT ATTOCK

Language?

Way of communication When we communicate one another then we need a specific language to express our words Example

English Urdu Arabic etc

MS Sadia Ejaz CIIT ATTOCK

Computer Programming

Computer programming is defined as telling a computer what to do through a special set of instructions which are then interpreted by the computer to perform some task(s). These instructions can be specified in one or more programming languages including (but not limited to) Java, PHP, C, and C++.

MS Sadia Ejaz CIIT ATTOCK

Programming Language

A set of words, symbols and codes used to write a programs is called program language. Different programming languages are available for writing different types of programs.

MS Sadia Ejaz CIIT ATTOCK

Types of Computer Programming Language

There are two types of computer programming languages.


Low-Level languages High- Level Languages

MS Sadia Ejaz CIIT ATTOCK

Low-Level Languages

These are near to computer hardware and far from human language. Two low-level languages.

Machine Language Assembly Language

MS Sadia Ejaz CIIT ATTOCK

Machine Language

In this language, instructions are written in binary from. It is directly understood by the computer. Programs written in this language are machinedependent. It is also known as first generation language.

MS Sadia Ejaz CIIT ATTOCK

Assembly Language

In this language, symbols are used.

Symbols are called mnemonics.

Symbolic Language It is mostly used for writing system software. Second generation language.

MS Sadia Ejaz CIIT ATTOCK

High-Level Language

Language that is close to human languages. It is easier to write and modify.

MS Sadia Ejaz CIIT ATTOCK

Categories of High Level Languages

Procedural Languages Object-Oriented Languages Non-procedural Languages

MS Sadia Ejaz CIIT ATTOCK

Procedural Languages

Third generation languages In these languages, program is a predefined set of instructions. Popular procedural languages .

FORTRAN FORmula TRANslation BASIC Beginner All Purpose Symbolic Instruction Code COBOL Common Business Oriented Language PASCAL C Middle-level language Application Software as well as System Software

MS Sadia Ejaz CIIT ATTOCK

Object- Oriented Languages

Programs are written on the basis of objects. Object Collection of data and functions Easier to learn and modify. C++ and Java

MS Sadia Ejaz CIIT ATTOCK

Features of Object-Oriented Programming

Objects Classes Real-world Modeling Reusability Information Hiding Encapsulation Polymorphism Multiple ways

MS Sadia Ejaz CIIT ATTOCK

C++

Object-Oriented Language Developed in 1980 at Bell Lab. Improved version of C language. Powerful language.

MS Sadia Ejaz CIIT ATTOCK

History of C++

The C language was developed in late 60s and early 70s, in Bell Laboratories. In those days BCPL and B languages were developed there. The BCPL language was developed in 1967 by Martin Richards as a language for writing operating systems software and compilers. In 1970 Ken Thompson used B language to create early versions of the UNIX operating system at Bell Laboratories. Dennis Ritchie developed a general purpose language, called C language, by using different features of BCPL and B languages. In the early 1980's, also at Bell Laboratories, another programming language was created which was based upon the C language. This new language was developed by Bjarne Stroustrup and was called C++

MS Sadia Ejaz CIIT ATTOCK

Difference b/w c and c++

When he designed C++, he added OOP (Object Oriented Programming) features to C without significantly changing the C component. Thus C++ is a "relative" (called a superset) of C, meaning that any valid C program is also a valid C++ program.

MS Sadia Ejaz CIIT ATTOCK

Non-Procedural Languages

Fourth-generation language Need to tell computer what to do not how to do. It is used in database application and report generation. Important Non-procedural languages.

SQL Structured Query Language RPG Report Program Generator

MS Sadia Ejaz CIIT ATTOCK

Difference Between Low-Level & High-Level Languages


High-Level Language High-level language are easy to learn. Low-Level Language Low-level languages are difficult to learn.

Translator is required.

No translator is required.

Programs in high-level languages Programs in low-level languages are slow in execution. are fast in execution.

Programs in high-level languages Programs in low-level languages are easy to modify. are difficult to modify.

MS Sadia Ejaz CIIT ATTOCK

Difference Between Low-Level & High-Level Languages


High-Level Language Low-Level Language

High-level languages are near to human languages.


High-level languages do not provide much facility at hardware level. Deep knowledge of hardware is not required to write programs. These languages are normally used to write application programs.

Low-level languages are far from human languages.


Low-level languages provide facility to write programs at hardware level. Deep knowledge of hardware is required to write programs. These languages are normally used to write hardware programs.

MS Sadia Ejaz CIIT ATTOCK

Natural Programming Language

Fifth generation language Very complex Most of these languages are in experimental phase.

MS Sadia Ejaz CIIT ATTOCK

Types of Codes

Source Code

Written in high-level language


Translated by language processor. Machine code

Object Code

Computer can not understand source code but directly understands object code.

MS Sadia Ejaz CIIT ATTOCK

Difference Between Source Code & Object Code


Source Code
Source code is written in highlevel or assembly language. Source code is easy to understand. Source code is easy to modify. Source code contains fewer statements than object code.

Object Code
Object code is written in machine language through compilers. Object code is difficult to understand. Object code is difficult to modify. Object code contains more statements than source code.

MS Sadia Ejaz CIIT ATTOCK

Language Processor

It is a software that converts high-level language into machine language.

MS Sadia Ejaz CIIT ATTOCK

Types of Language Processor

Complier Interpreter Assembler

MS Sadia Ejaz CIIT ATTOCK

Compiler

It converts source program as a whole into machine code / object program.

Source Program

Compiler

Object Program

MS Sadia Ejaz CIIT ATTOCK

Interpreter

It converts one statement of a program at one time.

MS Sadia Ejaz CIIT ATTOCK

Assembler

It translated the instruction of a assembly language into machine language.

Assembly Language Program

Assembler

Object Program

MS Sadia Ejaz CIIT ATTOCK

Difference Between Compiler & Interpreter


Compiler

Interpreter

Compiler will stop translating if Interpreter will execute all the it finds an error and there will be lines before error and will stop at no executable code generated. the line which contains the error. Compiler compile the program as It converts one statement of a whole. program at one time.
Compiler generate object file. Interpreter generates no object file.

Compiler translation is fast.

Interpreter translation is slow.

MS Sadia Ejaz CIIT ATTOCK

Programming Techniques

Structured Programming Object-Oriented Programming Event-Driven Programming Visual Programming

MS Sadia Ejaz CIIT ATTOCK

Structured Programming

A program is divided in small units called modules or sub-programs. Sequential Structure Control flows in logical sequence. Conditional/ Selective structure Selection on basis of condition

MS Sadia Ejaz CIIT ATTOCK

Structured Programming (contd.)

Iterative / Repetitive Structure Loops Function Call Control moves to block of code

MS Sadia Ejaz CIIT ATTOCK

Advantages & Disadvantages of Structured Programming

Advantages

Reusability Easier to code Easier to modify Easier to maintain


Difficult to separate data from functions.

Disadvantage

MS Sadia Ejaz CIIT ATTOCK

Object-Oriented Programming

Programs are written on the basis of objects. Object

Collection of data and function

Easier to learn and modify Examples:


C ++ Java

MS Sadia Ejaz CIIT ATTOCK

Event-Driven Programming

Statements are executed in response to an event. For Example: Clicking the mouse button.

MS Sadia Ejaz CIIT ATTOCK

Visual Programming

Graphical user interface

User friendly interface

MS Sadia Ejaz CIIT ATTOCK

Features of C++

It is very convenient language. It is a well-structured language. It is case sensitive language. It provides machine independent. It is an object oriented language. In C++. A program can be divided into small modules.

MS Sadia Ejaz CIIT ATTOCK

Basic Structure of C++ Program

The format of writing program in C++is known as its structure. It consists of following parts.

Pre-processor directive Main( ) function Program body C++ statements

MS Sadia Ejaz CIIT ATTOCK

Pre-processor Directive

It is an instruction given to the compiler before the execution of actual program. Include preprocessor directive is used in C++ to include header files in the program. # include <iostream.h>

Preprocessor Directive

Header files

MS Sadia Ejaz CIIT ATTOCK

Header Files

It is a collection of standard library functions to perform different tasks. There are many header files for different purposes. It must be included in the program before calling any of its function.

MS Sadia Ejaz CIIT ATTOCK

Main ( ) Function

It is the starting point of a C++ program. C++ statements are written in the body of the main () function. void main( ) { Body of the main function }

MS Sadia Ejaz CIIT ATTOCK

C++ Statements

These are the instructions for the computer to perform a task.

MS Sadia Ejaz CIIT ATTOCK

Basic Structure of C++ Program


# include <iostream.h> void main( ) { cout<<Hello World; }
Preprocessor Directive Main function

C++ Statement

MS Sadia Ejaz CIIT ATTOCK

Using cout

The cout object is used to print a message on the screen.

MS Sadia Ejaz CIIT ATTOCK

Purpose of C++

Stroustrup states that the purpose of C++ is to make writing good programs easier and more pleasant for the individual

MS Sadia Ejaz CIIT ATTOCK

versions of the C++

There are several versions of the C++ language, of which Visual C++ is only one. Other dialects include Borland C++, Turbo C++, and Code Warrior (Mac).

MS Sadia Ejaz CIIT ATTOCK

LAB WORK

MS Sadia Ejaz CIIT ATTOCK

Lecture 5+6 Introduction to computer & programming

MS SADIA EJAZ CS DEPARTMENT


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.

MS Sadia Ejaz CIIT ATTOCK

86

The Internets Major Services

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

MS Sadia Ejaz CIIT ATTOCK

87

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.

MS Sadia Ejaz CIIT ATTOCK

88

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

MS Sadia Ejaz CIIT ATTOCK

89

E - Mail

Electronic mail, often abbreviated to e-mail, is a storeand-forward method of writing, sending, receiving and saving messages over electronic communication systems.

90

Programming Language Generations


Machine languages: first generation Assembly languages: second generation Higher-level languages: third generation (3GLs)

MS Sadia Ejaz CIIT ATTOCK

Fading Third-Generation Languages

FORTRAN (FORmula TRANslator) COBOL (COmmon Business Oriented Language) BASIC (Beginners All-Purpose Symbolic Instruction Code) Pascal

MS Sadia Ejaz CIIT ATTOCK

Thriving Third-Generation Languages

C C++ Java ActiveX

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

MS Sadia Ejaz CIIT ATTOCK

Examples of Fourth-Generation Languages

Visual Basic (VB) VisualAge Authoring environments

MS Sadia Ejaz CIIT ATTOCK

Fifth-Generation Languages (5GLs)

Advanced authoring environments considered by some to be 5GLs

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

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

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.

MS Sadia Ejaz CIIT ATTOCK

Problem-Solving Techniques

Program Algorithm Pseudo Code Flowchart , etc.

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.

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.

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.
MS Sadia Ejaz CIIT ATTOCK

Parts of Program Development

Two main parts

Logic Design Coding

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.

MS Sadia Ejaz CIIT ATTOCK

Coding

The algorithm is converted into a program.

MS Sadia Ejaz CIIT ATTOCK

Example

Algorithm for calculating and displaying the sum of two numbers,


1. 2.

3.
4.

Input A, B Total / Sum A + B Display Total Exit

MS Sadia Ejaz CIIT ATTOCK

Advantages of Algorithms

Reduced Complexity Increased Flexibility Ease of Understanding

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.

MS Sadia Ejaz CIIT ATTOCK

Flowchart (contd.)

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.

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

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.)

Process Rectangle symbol is used to represent a process step.

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.)

Selection Diamond symbol is used to represent a selection step.

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

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.

MS Sadia Ejaz CIIT ATTOCK

Basic Flowchart Symbols (contd.)

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

MS Sadia Ejaz CIIT ATTOCK

Example
Start

Input A, B

Sum = A+B

Display Sum

End

MS Sadia Ejaz CIIT ATTOCK

Difference Between Pseudo Code and Flowchart


Flowchart It contains standard symbols to represent different computer operations. Pseudo Code There is no standard for writing pseudo code.

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


It is difficult to modify.

It is more frequently used as it takes less time.


It is easier to modify.

It is a graphical representation of It is not a graphical solution. representation of solution.


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

MS Sadia Ejaz CIIT ATTOCK

Integrated Development Environment (IDE)

Editor Compilers Debugger Linkers Loaders

MS Sadia Ejaz CIIT ATTOCK

Editor
Preprocessor Compiler

Disk Disk Disk Disk

Program is created in the editor and stored on disk. Preprocessor program processes the code. Compiler creates object code and stores it on disk. Linker links the object code with the libraries

Linker

Primary Memory

Loader

Disk

Loader puts program in memory.


. . . . . .

Primary Memory

CPU

. . . . . .

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

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.

MS Sadia Ejaz CIIT ATTOCK

Debugger

It is used to debug the program.

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.

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.

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.

MS Sadia Ejaz CIIT ATTOCK

Types of Errors

Syntax Errors Logical Errors Run-Time Errors

MS Sadia Ejaz CIIT ATTOCK

Syntax Errors

It is a type of error that occurs when an invalid statement is written in program.

MS Sadia Ejaz CIIT ATTOCK

Logical Errors

It is a type of error that occurs due to poor logic of the programmer.

MS Sadia Ejaz CIIT ATTOCK

Run-Time Errors

It is a type of error that occurs during the execution of program.

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

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

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.
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.
MS Sadia Ejaz CIIT ATTOCK

User-defined Identifiers

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.

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.

MS Sadia Ejaz CIIT ATTOCK

Data Types
Data Type
int float double char

Purpose
to store numeric values to store real values to store large real values to store character values

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

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

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.

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. It occurs when the value assigned to an integer variable is less than possible minimum value.

Integer Underflow

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.

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 ;

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.

MS Sadia Ejaz CIIT ATTOCK

Rules for Declaring Variables (contd.)

Both upper and lower cases are allowed. A userdefined 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.
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.

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 e.g. int int n= 100 ;

variable _name n =

= 100

value ; ;

MS Sadia Ejaz CIIT ATTOCK

Tokens
A program statement consist of variable names, keywords, constant, operator etc, these elements of statement are called tokens int main(){ e.g.

int x,y; x = 5;

MS Sadia Ejaz CIIT ATTOCK

Example

simple program #include< stdio.h > #include< iostream.h > int main(){ int x; x = 5; cout << x; return 0; }

MS Sadia Ejaz CIIT ATTOCK

S-ar putea să vă placă și