classtuaa
TRANSCRIPT
-
8/8/2019 classtuaa
1/15
Lecture NoteWEEK 1
Designing Solution to Computer Based
Problem
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
2/15
Algorithm
An algorithm is a well-developed, organized approach to solving aAn algorithm is a well-developed, organized approach to solving a
complex problem.complex problem.
Developing an AlgorithmDeveloping an Algorithm
1.Identify the Inputs1.Identify the Inputs
2.Identify the Processes2.Identify the Processes
3.Identify the Outputs3.Identify the Outputs
1.2 An algorithm must have following properties
There must be no ambiguity in any instruction.
There should not be any doubt about which instruction is to be executed next.
The description of the algorithm must be finite.
The execution of the algorithm should conclude after a finite number of steps.
After performing the instruction that is after the algorithm terminates the desiredresult.
1.3 Three methods used for creating an algorithm
Steeping
Looping
Choosing
Steeping
This is where all the instructions needed to solve our problem are set out one after to
another. Here is an example
Example: Write an Algorithm of Addition of two numbers
STEP 1: START
STEP 2:READ VALUE OF FIRST NUMBER AND SECOND NUMBERSTEP3: CALCULATE ADDITION OF FIRST NUMBER AND SECOND
NUMBER:
SUM=FIRST NUMBER+SECOND NUMBERSTEP 4:DISPLAY SUM
STEP 5: STOP
Example: Write an Algorithm of simple interest (SI=P*R*T/100)
STEP 1: START
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
3/15
STEP 2:READ VALUE OF P, R AND T
STEP3: CALCULATE SIMPLE INTREST BY USING FORMULA:SI=P*R*T/100
STEP 4:DISPLAY SIMPLE INTREST
STEP 5: STOP
Looping
Repeat an instruction or a set of instructions a number of times. In this case use loops
TheRepeat untilloop
The While loop
TheForloop
TheRepeat untilloop
This type of loop keeps carrying out a command a command UNTIL a given
condition is satisfied. The condition is given with the UNTIL command. Here is anexample
Example: Write an Algorithm to print five times Hello.
STEP 1: START
STEP 2: INITILIZE NUM TO 1
STEP3: REPEATSTEP 4: PRINT HELLO
STEP 5: UNTIL THE NUM IS NOT FIVE
STEP 6: STOP
The While loop
In this type of loop the condition is given along with the WHILE command and end
with END WHILE command. Here is an example
Example: Write an Algorithm to print table of 2.
STEP 1: STARTSTEP 2: INITILIZE NUM TO 1
STEP 3: WHILE NUM IS LESS THAN 10STEP 4: MULTIPLAY THE NUM BY 2
STEP 5: DISPLAY TABLE HAS 2STEP 6: END WHILE
STEP 6: STOP
The Forloop
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
4/15
TheForloop number of times it is repeated .the command to be repeated between
FOR and END FOR. Here is an example
Example: Write an Algorithm to print number from 10 to 20.
STEP 1: START
STEP 2: FOR NUMBER=10 TO 20
STEP 3: PRINT NUMBER
STEP 4: END FORSTEP 5: STOP
Choosing
This method is used to take decision. This technique is called choosing, and uses
the commands IF, THEN and ELSE.This type of command a condition is given in the IF command followed by an action to
be taken. If the condition if satisfied follow it by THEN command. Here is an example
Example: Write an Algorithm to decide weather or not go to school
STEP 1: STARTSTEP 2: IF IT IS WEEKDAY AND IT IS NOT A HOLYDAY
STEP 3: THEN GO TO SCHOOL
STEP 4: ELSE STAY AT HOME
STEP 5: STOP
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
5/15
Lecture Note
WEEK 2
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
6/15
1. Flowchart
Flowchart is a pictorial representation of an algorithm in which the steps are drawn in the
form of different shapes of boxes and the logical flow is indicated by interconnectingarrow.The boxes represent operations and the arrows represent the sequence in which the
operations are implemented.The main purpose of the flowchart is to help to understanding the logic of the program.
2.1 Guidelines for Drawing a Flowchart
The following are some guidelines in flowcharting:
a. In drawing a proper flowchart, all necessary requirements should be listed out inlogical order.
b. The flowchart should be clear, neat and easy to follow. There should not be anyroom for ambiguity in understanding the flowchart.
c. The usual direction of the flow of a procedure or system is from left to right or
top to bottom.d. Only one flow line should come out from a process symbol.
e. Only one flow line should enter a decision symbol, but two or three flow lines,
one for each possible answer, should leave the decision symbol.f. Only one flow line is used in conjunction with terminal symbol
g. If the flowchart becomes complex, it is better to use connector symbols to reduce
the number of flow lines. Avoid the intersection of flow lines if you want to makeit more effective and better way of communication.h. Ensure that the flowchart has a logicalstartandfinish.
i. It is useful to test the validity of the flowchart by passing through it with a simple
test data.
2.2 Importance of Flowchart
A flowchart helps to clarify how things are currently working and how they could beimproved.
1. Communication: Flowcharts are better way of communicating the logic of asystem to all concerned.
2. Effective analysis: With the help of flowchart, problem can be analyzed in moreeffective way.
3. Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes.
4. Efficient Coding: The flowcharts act as a guide or blueprint during the systemsanalysis and program development phase.
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
7/15
5. Proper Debugging: The flowchart helps in debugging process.
6. Efficient Program Maintenance: The maintenance of operating program becomeseasy with the help of flowchart. It helps the programmer to put efforts more
efficiently on that part
2.3 Symbols used in flowchart
Flowcharts use special symbol shapes to represent different types of actions or steps ina process. Lines and arrows show the sequence of the steps, and the relationships amongthem.
2.4 Flowchart structure
1. Sequence: A sequence process is a series of processes carried out one afterthe other. Where information can flow in a straight line.
School of Computer Science & IT, DAVV Indore
(Flow Line): Flow lines are used to connect symbols. These lines indicatesequence of steps and the direction of flow.
(Terminal): This symbol is used to represent the beginning (start), the
termination (end) or halt (pause) in the program logic.
(Input/Output): It represents information entering or leaving the system,such as customer order (Input) and serving (Output)
(Processing): Process symbol is used for representing arithmetic and datamovement instruction.
(Decision): Decision symbol denote a decision to be made .the programshould continue along one of the two routes (IF/ELSE).this symbol has one
entry and two exit paths. The path chosen depends on whether the answer toa question is yes or no.
(Connector): Connector symbol is used to join different parts of program.
-
8/8/2019 classtuaa
8/15
2. Selection (branches): Where the decisions are made according to some predefined condition. The If_Else_If processes logically complete the binary
decision block by providing two separate processes. One of the processes will becarried out in the each path of binary decision.
The flow chart of the if statement:
School of Computer Science & IT, DAVV Indore
Example: Find average of fivenumbers
Example: convert Celsius toFahrenheit
F=1.8*C+32
Start
Input T (in C)
End
Display F
Avg=(a+b+c+d+e)/5
Start
Read value a,b,c,d,e
End
Display Avg
-
8/8/2019 classtuaa
9/15
The flow chart of the ifelse statement:
The flow chart of the switch statement:
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
10/15
Example:program to find the greatest number of three numbers.
3. Repetition: Where the logic can repeat in a loop, that is, where a sequence ofsteps is repeated until the desired output is obtained. The while process allow for
the representation of a conditional loop structure within a program.
Flow chart of the while loop:
Flow chart of the for loop:
School of Computer Science & IT, DAVV Indore
NO
-
8/8/2019 classtuaa
11/15
Example: Draw a flowchart to find the sum of first 50 natural numbers
Example: Draw a flowchart to find the sum 20 even numbers natural numbers
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
12/15
2.5 Limitation of flowchart
Complex: The major disadvantage in using flowchart is that when a program isvery large, the flowchart may continue foe many pages, marking them hard to
follow. Flowchart tends to get large very quickly and it is difficult to follow the
represented process.
Costly: Drawing simple flowcharts may be a cost effective process. However, ifthe flowchart is to be drawn for a huge program, the time and cost factor of
program development gets out of proportion, making it a costly affair.
Difficult to modify: Modification to a flowchart usually requires redrawingthe entire logic again, and redrawing a complex flowchart is not a play. It is easyto draw thousands of flow lines and symbols along with proper spacing,
especially for a large complex program.
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
13/15
Lecture Note
WEEK 3
Computer Programming Languages
School of Computer Science & IT, DAVV Indore
-
8/8/2019 classtuaa
14/15
Types of Computer Programming Language
1. Machine language
2. Assembly language
3. High-level languages
Machine language programs were made up of instructions written in binarycode.
This is the native language of the computer.
Each instruction had two parts: Operation code, Operand Operation code (Opcode): The command part of a
computer instruction.
Operand: The address of a specific location in thecomputers memory.
Hardware dependent: Could be performed by only one type of computer with a
particular CPU
Assembly language programs are made up of instructions written in mnemonics. Mnemonics: Uses convenient alphabetic abbreviations to
represent operation codes, and abstract symbols to represent operands. Each instruction had two parts: Operation code, Operand
Hardware dependent.
Because programs are not written in 1s and 0s, thecomputer must first translate the program before it can be executed.
High-level languages: Use statements that resemble English phrases combinedwith mathematical terms needed to express the problem or task being programmed.
Transportable: NOT-Hardware dependent. Because programs are not written in 1s and 0s, the computer must
first translate the program before it can be executed.
School of Computer Science & IT, DAVV Indore
READ num1
READ num2LOAD num1
ADD num2
STORE sum
PRINT sum
STOP
-
8/8/2019 classtuaa
15/15
Assembled, Compiled, or Interpreted Languages
All programs must be translated before their instructions can be executed.
Computer languages can be grouped according to which translation process is used to
convert the instructions into binary code:
Assemblers Interpreters
Compilers
Assembled languages:
Assembler: a program used to translate Assembly language programs.
Produces one line of binary code per original program statement. The entire program is assembled before the program is sent to the
computer for execution.
Interpreted Languages:
Interpreter: A program used to translate high-level programs.
Translates one line of the program into binary code at a time:
An instruction is fetched from the original source code. The Interpreter checks the single instruction for errors. (If an error
is found, translation and execution ceases. Otherwise)
The instruction is translated into binary code. The binary coded instruction is executed.
The fetch and execute process repeats for the entire program.
Compiled languages:
Compiler: a program used to translate high-level programs. Translates the entire program into binary code before anything is sent to
the CPU for execution. The translation process for a compiled program:
First, the Compiler checks the entire program for syntax errors in the
original source code. Next, it translates all of the instructions into binary code.
Two versions of the same program exist: the original source code version,
and the binary code version (object code). Last, the CPU attempts execution only after the programmer requests that
the program be executed.
School of Computer Science & IT, DAVV Indore