Programs and Programming Languages
Programming A computer needs a set of instructions called a program to perform the I-P-O cycle. A program needs to be written in a specific language called programming language, so that computer can understand the instructions. Let us discuss program and programming language in more detail. Details Programs How does a computer know 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 preceding 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 specify: 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 processing that needs to be done. For example, accepting the values, checking for availability of seats, and displaying results. The kind of output expected. For example, the seat availability status. 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 or false, 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 and associated reports might have the following 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 in 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 computer system uses a number system that consists of only two digits, 0 and 1, which is called the machine language. For example, the following table displays the machine code of the commands, ADD and SUBTRACT. CommandADDSUBTRACT Machine Code0000000100000010 Machine Code of ADD and SUBTRACT Command However, it is difficult for anybody to remember instructions in the form of machine language. 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. 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. The vocabulary of the programming languages is referred to as the set of keywords of that language, and the grammar is referred to as the syntax. 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.
Sent from Windows Mail