Top Banner
Computer Computer can be defined as a high speed electronic data processsing machine that accepts and store input data, process it by doing some kind of manipulation and produces the desired result under the direction of a detail step by step stored set of instructions. Classification of computers based on the SIZE and COMPUTING CAPACITY Micro Computers Mini Computers Mainframe Computers Super Computers
36

Introduction to Programming

Sep 05, 2015

Download

Documents

Definition of Computer, Translators
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Union

Computer

Computer can be defined as a high speed electronic data processsing machine that accepts and store input data, process it by doing some kind of manipulation and produces the desired result under the direction of

a detail step by step stored set of instructions.

Classification of computers

based on the SIZE and COMPUTING CAPACITY

Micro Computers

Mini Computers

Mainframe Computers

Super Computers

Different types of Data

that can be processed by a computer

Numeric data

Character data

Graphics data

Sound data

Programs/Softwares

A group of instructions to be executed by the computer

An instruction commands the computer to perform a task

2 Types of softwares

Application Software

System Software

Application Software

A group of programs designed specially to perform special function

Eg: Media Player

Inventory control

Accounting Packages

System Software

A group of programs required to operate and control the activities of a computer

Provides an environment for developing application programs

Eg :Operating System

Compiler,Interpreter

Hardware

The electronics circuits used in building the computer that executes the software

Stored Program

John von Neumanns idea:

Store programs, together with data, in the memory of the computer

A stored Program can be executed at any time.

This causes the following things to happen

A set of information called the Input Data ,will be entered into the computer

The Input Data will be processed to produce certain desired results(Output Data)

The Output Data and perhaps some of the Input Data will be displayed on a monitor or printed onto a sheet of paper

Calculate the area of a Circle, given radius r

Read the numeric value for the radius r

Calculate the value of the area using the formula r2

This value will be stored ,along with the input data in the computers memory

Display the value of Radius and Area

stop

Programming Language

A programming Language is a set of written symbols that instruct computer hardware to perform specific operations.

All computer languages are controlled by a set of rules called syntax( eg: grammer rules in English)

Types of Programming Languages

Machine Language (Low level Language)

Assembly Language

High Level Language

Machine Language

Instructions are represented as binary code

Difficult to program in Machine Language due to

Machine Language is very difficult to work with

Different type of computers have its own unique instruction set

A program written in one type of computer cant run on another computer without significant alterations.

Assembly Language

Instructions are represented as Symbolic codes or mnemonics

Eg: ADD,SUB,MUL ,etc

High Level Language

Programs are written using English words and Mathematical notations

Translators

System Software which converts the instructions written in one language to a suitable form that can be executed by the computer

Eg: Assembler, Compiler ,Interpreter

Assembler

Assembly Language Program

Assembler

Machine Code/Object Code

Compiler/Interpreter

Compiled Programs generally run faster than Interpreted Programs

Difference between Compiler and Interpreter

Compiler

Translate the whole Source Program into Machine Code then that code is executed by the computer

Interpreter

Translation and Execution are carried out statement by statement

High Level Language Program

Compiler/

Interpreter

Machine Code/Object Code

Logic Representation

The logic developed for getting Output from the Input data can be documented in two ways, They are:

Algorithm Method

Flow Chart Method

Algorithm

Is a finite set of instructions for accomplishing a particular task

The logic of the problem must be clearly expressed in algorithm

A program is an expression of an Algorithm

Thus the success of a program depends upon the algorithm

Algorithm to find the sum of two numbers

Step 1 :Start

Step 2 : Input two numbers a and b

Step 3 : sum=a+b

Step 4 : Display the value of sum

Step 5 : Stop

Algorithm to find the area of a rectangle

Step 1 :Start

Step 2 : Input length l and breadth b

Step 3 : area=l*b

Step 4 : Display the value of area

Step 5 : Stop

Algorithm to find the area of a triangle, given 3 sides

Step 1 :Start

Step 2 : Input 3 sides a, b and c

Step 3 : S=(a+b+c)/2

Step 4 : area=(S*(S-a)*(S-b)*(S-c))

Step 5 : Display the value of area

Step 6 :Stop

A bus covers a distance of 20 km /liter of diesel. The cost of diesel is Rs 50.00 per liter. Write an Algorithm to calculate the cost of diesel to travel 90km

Algorithm

Step 1 :Start

Step 2 : diesel_cost=50,millage=20,distance=90

Step 3 : total_diesel_cost=distance/millage*diesel_cost

Step 5 : Display the value of total_diesel_cost

Step 6 :Stop

Algorithm to find the area of a circle

Algorithm to convert temparature in centigrade to Fahrenheit

Fahrenheit=(9/5)*centigrade+32

Algorithm for Solving the expression a2+b2-2ab

Algorithm to find the sum of a number ,its square and its cube

Algorithm to calculate salesmans salary

Gross salary=basic+(quantity*bonusrate)+

(quantity*price)*commision

Basic=10,000

Commision=2%

Bonusrate=200

Write an algorithm to find the largest of two numbers

Write an algorithm to find the largest of three numbers

Algorithm to find the largest of two numbers

Step 1 :Start

Step 2 : Input two numbers a and b

Step 3 : if a>b then step 4 otherwise step 5

Step 4 : Display largest as a ,go to step 6

Step 5 : Display largest as b

Step 6: stop

Algorithm to find the largest of three numbers

Step 1 :Start

Step 2 : Input three numbers a , b and c

Step 3 : if a>b then step 4 otherwise step 6

Step 4 : if a>c then step 5 otherwise step 6

Step 5 :Display largest as a, goto step 8

Step 6: if b>c then step 7 otherwise step 8

Step 7 :Display largest as b, goto step 8

Step 8: Display largest as c

Step 8: stop

Flowchart

A flowchart is a pictorial representation of step by step solution of a problem

SymbolPurpose

Start/stop

Input/Output

Processing

Decision Box

Flowchart

SymbolPurpose

Connector

Flow of control

Flowchart

Flow Chart to find the sum of two numbers

Start

Input a, and b

sum=a+b

Display sum

Stop

Flowchart

Flow Chart to find the area of a rectangle

Start

Input l, and b

area=l*b

Display area

Stop

Flowchart

Flow Chart to find the area of a triangle ,given 3 side

Start

Input sides a,b and c

s=(a+b+c)/2

Display area

Stop

area=(s(s-a)(s-b)(s-c))

Flowchart

Flow Chart to find the area of a triangle ,given 3 sides

Using connector

Start

Input sides a,b and c

s=(a+b+c)/2

Display area

Stop

area=(s(s-a)(s-b)(s-c))

Flowchart

Flow Chart to find the largest of two numbers

Yes No

Start

Input a, and b

Display b

Stop

If a>b

Display a

Steps in Computer Programming

Understand the problem thoroughly

Analyze the problem and find out what are the Input Data & Output Data

Develop logic to work out the result

Draw flowchart and write algorithm steps to formulate the logic

Translate the logic into program steps(Coding)

Store the program

Test and Debug(Locate and Remove Errors)

Run the Program and get the Result

If expected result is not getting , modify the logic , And Repeat Steps from Step 4 to Step 8

Features of a good program

Integrity refers to the accuracy of the calculations

Clarity- refers to overall readability of the program

If the program is clearly written ,it should be possible for another programmer to follow the program logic Without any effort

Simplicity- the program should be simple as possible to

enhance clarity and accuracy

Efficiency concerned with execution speed and memory

utilization

Modularity- it is good programming practice to implement

each of the subtask as separate program module

Generality a program should be as general as possible

Number System & Description

Decimal Number System

Base 10. Digits used: 0 to 9

Eg:12,10,99,900,

Binary Number SystemBase 2. Digits used: 0, 1

Eg:11,10,1000,1111,

Octal Number System

Base 8. Digits used: 0 to 7

Eg:12,10,777,600,

Hexa Decimal Number SystemBase 16. Digits used: 0 to 9, Letters used: A- F

Eg:FF,A,99F,12CF,

Number System & Description

Decimal Number System

Base 10. Digits used: 0 to 9

Eg:12,10,99,900,

1234 can be written as

(1x1000)+ (2x100)+ (3x10)+ (4xl)

(1x103)+ (2x102)+ (3x101)+ (4xl00)

1000 + 200 + 30 + 1

1234

Number System & Description

Binary Number SystemBase 2. Digits used: 0, 1

Eg:11,10,1000,1111,

Each position in a binary number represents a 0 power of the base (2). Example 20

Binary Number: 101012

Calculating Decimal Equivalent:

((1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20))

=21 10

Number System & Description

Octal Number System

Base 8. Digits used: 0 to 7

Eg:12,10,777,600,

Uses eight digits, 0,1,2,3,4,5,6,7.

Also called base 8 number system

Each position in a octal number represents a 0 power of the base (8). Example 80

Octal Number: 125708

Calculating Decimal Equivalent:

((1 x 84) + (2 x 83) + (5 x 82) + (7 x 81) + (0 x 80))=549610

Number System & Description

Hexa Decimal Number SystemBase 16. Digits used: 0 to 9, Letters used: A- F

Uses 10 digits and 6 letters, 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.

Letters represents numbers starting from 10.

A = 10. B = 11, C = 12, D = 13, E = 14, F = 15.

Also called base 16 number system

Each position in a hexadecimal number represents a 0 power of the base (16). Example 160

Number System & Description

Hexadecimal Number: 19FDE16

Calculating Decimal Equivalent:

((1 x 164) + (9 x 163) + (F x 162) + (D x 161) + (E x 160))=

10646210