Sie sind auf Seite 1von 5

TAKORADI POLYTECHNIC

SCHOOL OF ENGINEERING

DEPARTMENT OF ELECTRICAL/ELECTRONIC ENGINEERING

COMPUTER PROGRAMMING

NAME:

INDEX NUMBER:

ix)Computer programming is a process of writing or creating a sequence of


instructions(program) that a computer must follow in order to perform a desired
task. The process of computer programming consists of six major steps which
are; defining the problem or program specification, preparing an algorithm,
preparing a program flowchart, coding the program, debugging and testing, and
documentation.

x)Three errors one can encounter when writing a program are:

a)Syntax error: This is violation of the rules of the programming language. That
is, it is the error in the grammar of a programming language. For instance “write
in” is wrong or is a syntax error in programming language called Pascal. It is
rather written as “writein”.

b) Logic error: This error occurs when the programmer uses an incorrect
calculation or leaves out a programming procedure. For example, a pay roll
program that did not compute extra hours worked would have a logic error.

c) A run time error: this type of error occurs during the time the computer is
running, when a programmer attempts to perform an illegal operation such as
dividing a value by zero.

xiv)a. The outputs of the code fragments are:

FOR j=1 to 5

When j=1

1+2=3

8*1=8

When j=2

2+2=4
8*2=16

When j=3

3+2=5

8*3=24

When j=4

4+2=6

8*4=32

When j=5

5+2=7

8*5=40

b) It gives error as output.

viii) The DMA technique is much more efficient than interrupt driven IO’s
because the DMA is a method by which a hardware device can transfer data to
and from the system memory directly, rather than using the CPU.

Whiles the interrupt driven IO’s are more complicated than for straight machine
instruction. This is due to the considerable speed difference between IO devices
and the CPU, the need for synchronization, the need for not losing any external
event and the concern for optimizing processing time. The need often arises
during program loading and execution to transfer block data between the main
memory and disk or other storage IO’s.

For these reasons the DMA works very faster and hence much more efficient
than the interrupt driven IO’s.

iv) A program to determine the roots of a quadratic equation.

a) The algorithm

Step 1: Read coefficients A, B and C if A =0, display “Expression not quadratic”


and go to step13.

Step 2: Calculate (B^2) -4AC and store in say D

Step 3: If D <0, go to step 6

Step4: If D=0, go to step7


Step5: If D>0, go to step 10

Step6: Display “there is no roots” and go to step13

Step7: Calculate Root1=-B/2A

Step8: Calculate Root2=Root1

Step9: Go to step12

Step 10: Calculate Root1= (-B+D^ (1/2))/(2A)

Step11: Calculate Root2= (-B-D^ (1/2))/(2A)

Step12: Display the values for Root1 and Root2

Step13: Stop

b) Program flowchart

Start

Read A,B
and C

Y
Is A=
0?

Calculate D=(B^2)- Display


4AC “Expression not
quadratic”
Is D<0?
D<0 D=0
Is D=0?

Is D>0?

D>0

Calculate Root1=Root2=(-B)/ (2A)


Root1= (-B+D^ (1/2))/
(2A)
Root2= (-B-D^ (1/2))/ (2A)

Display “there
is no real Display values of
Roots” Root1 and Root2

Stop
iii) If the CPU wants to delegate any responsibility to the DMA module,the CPU first steps up the
DMA registers, which contain a memory address and number of bytes to be transferred.

Das könnte Ihnen auch gefallen