Chapter 1 | Introduction to Programming Concepts - Part 1 |
Input, Process, and Output
You might have noticed computers being used at airline reservation counters, shops, restaurants, and various other locations. At each of these places, a user enters some values in the computer and the computer generates an output, which is either displayed on the computer screen or printed on paper. Let us consider the example of an airline reservation counter. When you want a seat reserved on a particular flight, you provide information about your requirements such as destination, date and time of your departure, and the class in which booking is required. The clerk at the reservation counter enters this information into a computer. Details regarding the availability of tickets are then displayed on the screen.
Let us see what are the phases involved and the process followed for each of the task.Phases
To understand what happens when you enter some values in the computer, let us break the entire set of activities into separate phases. In the first phase, flight requirements are keyed into the computer. This phase is called the input phase. The flight requirement information is then processed to determine whether or not seats are available on the particular flight. This phase is known as the process phase. Once the processing is complete, the result is displayed on the computer screen, indicating the status of seat availability. This phase is called the output phase.
I-P-O Cycle
The cycle of activities performed by a computer also follows the Input-Process-Output cycle or the I-P-O cycle. A computer consists of several components such as a keyboard, mouse, monitor, printer and a central processing unit. Each component participates in either one of the input, process, or output phases. For example, the keyboard and mouse are used for input. The central processing unit and the memory inside the system unit of the computer are used for processing. The monitor and printer are used for output.
Programs and Programming Language
Computer follows an I-P-O cycle. It needs set of instructions called program to specify the input required, process to be followed, and the output required. Program is written in a specific language called Programming Language, so that computer can understand the instructions. Let us understand Program and Programming Language more in detail.
Programs
How does a computer know what are the steps to be followed to process reservation requests? How does it manage to calculate your shopping bills at the local store? How does it generate your report card at school? Is it an all-knowing machine? Do you have to buy a different computer for each of these above-mentioned activities? The answer to the last two questions is âNoâ. It is not an all-knowing machine and you do not require a separate computer for each of these activities.
Then, how does a computer function? A computer is designed to accept input, process it, and generate output. However, it has to be provided with a set of instructions that state the following:
- The kind of input that will be provided. For example, in the case of reservation requests, flight date, flight time, class, and destination will be some of the inputs.
- The kind of output expected. For example, the seat availability status.
- The processing that needs to be done. For example, accepting the values, checking for availability of seats, and displaying results.
A set of instructions to perform a particular job is called a program . Therefore, for each job that you want the computer to perform, you require a separate program. Instructions in a program can be:
- Sequential : Instructions that are executed one after the other.
- Decision Making : Instructions that evaluate an expression (relation or condition) first and then, depending upon whether the value of the expression is 'true' (non-zero) or 'false' (zero), it transfers the control to a particular statement.
- Iterative : Instructions that are executed repeatedly, depending on the value of an expression (relation or condition).
Any real-life problem will consist of a number of small jobs. Therefore, to solve a real-life problem, you have a number of programs that together form an application. For example, a payroll application for processing employee compensation details and generating paychecks and associated reports might have two programs:
- Program to generate paychecks
- Program to print reports.
Programming Languages
A computer is made up of a number of electronic components. An electronic component can be either in an on state or an off state. Therefore, the components of a computer are represented as a combination of on and off states. The on state is represented by â1â and the off state by â0â. This implies that a computer can understand only 0s and 1s.
Therefore, any instruction given to a computer must be a sequence of 0s and 1s.
A sequence of 0s and 1s can be used to describe any physical operation that the computer performs. Therefore, a computer system uses a number system that consists of only two digits, 0 and 1. This number system is known as the binary number system.
The language that the computer understands is called the machine language . For example, the machine language for a particular computer could have the following instruction set:
It is doubtful if you would be comfortable writing a program in machine language. It is certainly difficult for anybody to remember instructions in the form of 0s and 1s. Therefore, we use high-level programming languages to write programs. A high-level programming language consists of a set of instructions, which are represented using simple English words. So, when you want the computer to display the output on the screen, you type the instruction âWRITE ON SCREENâ and not â00100000â.
There are many high-level programming languages available, such as C, C++, and Java. Each language has its own advantages. You need to evaluate the problem at hand before deciding on the programming language to use.
All languages have a vocabulary, which is a list of words that have a specific meaning in that language. Languages also have their own grammar rules, which state the rules for combining words to form sentences. This is what ensures that whatever is spoken in a particular language is interpreted similarly by all people who understand the language. Simi larly, programming languages also have a vocabulary, whi ch is referred to as the set of keywords of that language, and a grammar, which is referred to as the syntax.
As stated earlier, a program written in any programming language is a set of logically related instructions. These instructions have two parts, as shown in the following figure:
Format of a Programming Language Instruction |
The two parts of a programming language instruction are:
- Operation code (opcode) : This part instructs a computer about the operation to be performed.
- Operand : This part instructs the computer about the location of the data on which the operation specified by the opcode is to be performed.
For example, in the instruction Add A and B, Add is the opcode and A and B are operands.
Compilers
Can computers directly interpret the instructions written in any programming language? No, they cannot. Then, how do you ensure that a computer executes the instructions from a program, as intended? What would you do if you got hold of a recipe for a delicious dish written in a foreign language that you do not understand? You would get it translated into English or any other language you understand to be able to prepare the dish. Similarly, you need a translator to convert the instructions written in a programming language into machine language.
A compiler is a special program that processes the statements written in a particular programming language and converts them into machine language at one go. Like everything else in the computer, the compiler also follows the I-P -O cycle. It takes the programming language instructions as input. It then processes these instructions to convert them to machine language. These instructions can then be executed by the computer. This process of conversion is called compilation. For each programming language, there is a different compiler available. For example, for compiling a program written in the C language, you require a C compiler, and likewise, for a Java program, you require a Java compiler.
No comments:
Post a Comment