Introduction To Computer
Introduction To Computer
Objectives
Identify the different components of a computer Know about programming languages and their categories Understand the program development life cycle and apply it in problem solving To create a flowchart using problem sets.
A computer is a machine that performs a variety of tasks according to specific instructions. It is a data processing machine which accepts data via an input device and its processor manipulates the data according to a program. The computer has two major components. The first one is the Hardware which is the tangible part of the computer. It is composed of electronic and mechanical parts. The second major component is the software which is the intangible part of a computer. It consists of data and the computer programs.
The Program Development Life Cycle Programmers do not sit down and start writing code right away when trying to make a computer program. Instead, they follow an organized plan or methodology, that breaks the process into a series of tasks. Basic steps in trying to solve a machine problem: 1. Problem Definition 2. Problem Analysis 3. Algorithm design and representation (Pseudocode or flowchart) 4. Coding and debugging
1. Problem Definition A programmer is usually given a task in the form of a problem. Before a program can be designed to solve a particular problem, the problem must be well and clearly defined first in terms of its input and output requirements.
A clearly defined problem is already half the solution. Computer programming requires us to define the problem first before we even try to create a solution.
Let us now define our example problem: Create a program that will determine the number of times a particular name occurs in a list.
2. Problem Analysis After the problem has been adequately defined, the simplest and yet the most efficient and effective approach to solve the problem must be formulated. Usually, this step involves breaking up the problem into smaller and simpler subproblems. Example Problem: Determine the number of times a name occurs in a list Input to the program: list of names, name to look for Output of the program: the number of times the name occurs in a list
3. Algorithm design and representation Once our problem is clearly defined, we can now set to finding a solution. In computer programming, it is normally required to express our solution in a step-by-step manner. An Algorithm is a clear and detailed specification of the steps needed to solve a problem. It may be expressed in either Human language (English, Tagalog), through a graphical representation like a flowchart or through a pseudocode, which is a cross between human language and a programming language.
Expressing our solution through Human language: 1. Get the list of names. 2. Get the name to look for, let's call this the keyname. 3. Compare the keyname to each of the names in the list. 4. If the keyname is the same with a name in the list, add 1 to the count. 5. If all the names have been compared, output the result.
Expressing our solution through pseudocode: Let nameList = List of Names Let keyName = the name to be sought Let Count = 0 For each name in NameList do the following if name == keyName Count = Count + 1 Display Count
Coding and Debugging After constructing the algorithm, it is now possible to create the source code. Using the algorithm as basis, the source code can now be written using the chosen programming language. Most of the time, after the programmer has written the program, the program isn't 100% working right away. The programmer has to add some fixes to the program in case of errors (also called bugs) that occurs in the program. This process of is called debugging. There are two types of errors that a programmer will encounter along the way. The first one is compile-time error, and the other is runtime error.
Compile-Time Errors occur if there is a syntax error in the code. The compiler will detect the error and the program won't even compile. At this point, the programmer is unable to form an executable that a user can run until the error is fixed.
Forgetting a semi-colon at the end of a statement or misspelling a certain command, for example, is a compile-time error. It's something the compiler can detect as an error.
Compilers aren't perfect and so can't catch all errors at compile time. This is especially true for logic errors such as infinite loops. This type of error is called runtime error.