Você está na página 1de 5

Chapter one

Problem solving using computers


Computer Fundamentals
Programming Languages
Identifying and Analyzing problems
Software Crisis
Software development method (Problem Definition, Requirement analysis, Design (algorithm, Flow charts,
Pseudo codes), Coding, Testing & Maintenance, Documentation.

Computer Fundamentals
At their simplest, all computers are made up of four basic building blocks: Input, Processor, Storage, and Output.
The following diagram shows the relationships of these blocks, with arrows indicating the direction in which
data can flow. If you like, you can make an analogy to humans: our senses accept Input from the outside world,
our brain is the Processor, our memory is the Storage, and our muscles Output our intentions and actions to the
world.

Computer programs can also be thought of as made up of simple operations that interact with the computer's
basic building blocks. Depending on how you count, there are eight of these:

Accept Input: allows the user to enter text via a keyboard, clicks and movements via a mouse, digitized
images via a scanner, etc.

Calculate: performs arithmetic calculations.

Sequentially Execute: processes each instruction in a program from the first to the last and then stops.

Decide: decides which instructions to process based on some criteria.

Repeat: repeatedly processes sets of instructions over and over until some condition is met, or maybe
forever.
1

Store: temporarily stores values for use in subsequent instructions.

Retrieve: retrieves previously-stored values for use in the current instruction.

Emit Output: reveal the results of the program to the user via the monitor, a printer, etc.

Programming Languages
Types of programming languages
Machine language: lowest level of programming languages usually referred to as first generation language.
It is understood completely by computer; Instruction in machine language is in the form of strings of 0s and 1s.
Assembly language: referred to as second generation language. These languages use symbols or mnemonic
codes to describe machine instructions. It is machine dependent languages.
High level language: language that look like natural language. High level languages are further subdivided
into three generations:
o Third generation languages: need to spell out in detail each step and the exact order of steps the computer
system must take to accomplish a task.
Procedure- oriented language: organize instructions into group of functions and give little attention to the
data that are used by various function. FORTRAN, PASCAL
Object- oriented language: treat data as critical element in the program development. Decompose a problem
into a number of entities called objects and build data and functions around these objects. E.g. Java, C++, visual
basic and so on.
o Fourth generation languages: allow computer user to retrieve, manipulate and analyze data from computer
storage without requiring step by step procedure. Designed to solve specific problems. Example: Query
languages and report generator.
o Fifth generation languages: close to natural languages. Program written in 5GLs tell the computer what to do
not how to do.
A program written in assembly language or high level language is called the source code and the
translated machine code program is called the object code.
Software Crisis
It was in late 1960s
Many software projects failed.
Many software projects were late, over budgeted, unreliable and expensive to maintain.
Many software projects produced software which did not satisfy the requirements of the customer.
Complexities of software projects increased as hardware capability increased.
Larger software system is more difficult and expensive to maintain.
Demand of new software increased faster than ability to generate new software.
This situation is called Software Crisis.
So, software engineers understood that a systematic software development method should be followed to avoid
this software crisis.
Software development method
In order to design a program, a programmer must determine three basic rudiments:
The instructions to be performed.
The order in which those instructions are to be performed.
The data required to perform those instructions.

There are five steps for program/software development such as task analysis program (Algorithm) design, coding
testing, implementation, and maintenance.
1. Analysis: It deals with defining and understanding the problem. In this phase, we decide what must be done
rather than how to do it. It includes identifying
Which part of the problem is going to be solved
What input data are needed to the problem
What output data arc expected
What procedure arc needed to achieve the goal
2. Program (Algorithm) design: It deals with providing a solution to solve the problem. An algorithm is a finite
set of steps to solve a problem.
There are two approaches of problem solving:
Top down design: This approach will try to disintegrate a larger problem into more smaller and manageable
problems to narrow the problem domain.

Bottom up design: is the reverse process where the lowest level component are built first and the system
builds up from the bottom until the whole process is finally completed.
The algorithm that we select must be:
Simple and powerful,
There must be no ambiguity in any instruction
There should not be any uncertainty about which instruction is to be executed next
The execution of algorithm should end after a finite number of steps
The algorithm must be general enough to deal with any contingency.
The algorithm must be easy to maintain and correct
Does the algorithm terminate?
Do the appropriate input data produce expected output data?
Does it properly handle valid and extreme cases?
The algorithm must be efficient. That means, it should not take too much space and time
There are different ways of describing an algorithm. These are narrative (or verbal form), flowchart, pseudo code
and so on.
Narrative
Example : Algorithm that determine the largest number out of three numbers A,B, and C
1. Start
2. Read three number let say A, B, and C
3. Find the largest number between A and B and store it in Max_AB
4. Find the largest number between MaxAB and C and store it in Max
5. Display Max
6. Stop
A flowchart is a diagram consisting of labeled symbols, together with arrows connecting one symbol to another.
It is means of showing the sequence of steps of an algorithm. The primary purpose of flowchart is to help the
programmer in understanding the logic of the program. The basic symbol of flowchart and their meaning arc
given as follow:

Guide line to draw flow chart


Every program flowchart should begin with the oval symbol containing START or BEGIN and end with STOP
or END
In every program flowchart, crossing flow of lines should be avoided
Only one flow of line should come from a process symbol
Only one flow line should enter a decision symbol However, two or three flow lines (one for each possible
answer) may leave the decision symbol.
Only one flow line is used with a terminal symbol.
The direction of the flow of procedure should always be from left to right or top to bottom.
Flow chart structure
There are three key constructs which are used in drawing flowcharts
1. Sequence where information flows in straight line. In a flow chart the symbol representing each instruction has
only a single entering path and a single exiting path. Typical sequence operations consist of process and
input/output steps.

2. Selection: where the decision is made according to some predefined condition

3. Repetition: where the logic can be repeated in a loop, that is, where a sequence of steps is repeated until the
desired output is obtained.

3. Coding: At this step the language independent algorithm is implemented /translated to an equivalent program
of certain programming language.
4. Implementation: - It consist of three steps such as debugging, testing and documenting the problem.
Debugging: The process of removing errors in a program is called debugging. Errors in a program arc called
bugs.
Testing: It is a process of checking whether a program is correct or not. That is, to test whether it does what it is
supposed to do. Testing data should be organized and prepared which include valid data that check the validity of
main flow of the logic and invalid data that checks the capability of the program for handling exceptional cases.
Documentation: Comments should be added to the program wherever necessary.
Exercises

For each of the problems below, develop a flow chart


1)
Receive a number and determine whether it is odd or even.
2)
Obtain two numbers from the keyboard, and determine and display which (if either) is the larger
of the two numbers.
3)
Receive 3 numbers and display them in ascending order from smallest to largest
4) Add the numbers from 1 to 100 and display the sum
5) Add the even numbers between 0 and any positive integer number given by the user.
6)
Find the average of two numbers given by the user.
7)
Find the average, maximum, minimum, and sum of three numbers given by the user.
8)
Find the area of a circle where the radius is provided by the user.
9)
Swap the contents of two variables using a third variable.
10) Swap the content of two variables without using a third variable.
11) Read 10 integers from the keyboard in the range 0 -100, and count how many of them are larger
than 50, and display this result.
12) Take an integer from the user and display the factorial of that number
***
5

Você também pode gostar