Introduction to Imperative Programming Unit01 FYBSCIT J M
Introduction to Imperative Programming Unit-01 FYBSCIT J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Introduction Imperative Programming is used by the most professional programmers in their day-to-day jobs or business. It is also called as Procedural Programming language which includes the programming languages like C, C++, Java, COBOL, etc. we can tell the computer what exactly he has to do. For example “Computer, add x & y, ” or “Computer, present a dialog box onto the screen. ” Imperative programming focuses on describing how a program operates. Uses a sequence of statements State of program changes J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
An imperative Programming language uses a sequence of statements to make us understand how to reach to a certain goal and these statements are said to change the state of the program as each statement is executed in turn. For example C is an Imperative Programming language in which a program can be created to add a sequence of numbers: int total = 0; int num 1 = 5; int num 2 = 10; int num 3 = 15; total = num 1 + num 2 + num 3; Here each statement changes the state of program from assigning values to each variable(identifier) to the final addition of these values. By using this sequence of five statements the program is explicitly told how to add the numbers 5, 10 and 15 together. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Thus, Imperative Programming involves writing a program as a sequence of instructions or statements that can actively modify memory (variables, arrays). It focuses in the sense that you express the logic of a program based on how the computer is going to execute it. Since Imperative Programming is a list of steps that has to be executed, there should be some way of keeping track of everything computed to that point. Where obviously the variables come in. They are changing the “state” of where the program is at which state then can control where the program should go to next state which continues to modify the state J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
What is programming The programs characterize what a computer actually does. A program is constituted by two fundamental parts: 1. A representation of the information (data) relative to the domain of interest: objects 2. A description of how to manipulate the representation (object): operations J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
LANGUAGE/SOFTWARE J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Understanding Computer Systems computer system is a combination of all the components required to process and store data using a computer. Every computer system is composed of multiple pieces of hardware and software. Hardware is the equipment, or the physical devices, associated with a computer. For example, keyboards, mouse, speakers, and printers are all hardware. When you think of a computer, you often think of its physical components first, but for a computer to be useful, it needs more than devices; a computer needs to be given instructions. Just as your stereo equipment does not do much until you provide music, computer hardware needs instructions that control how and when data items are input, how they are processed, and the form in which they are output or stored J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Software is computer instructions that tell the hardware what to do. Software is programs, which are instruction sets written by programmers. For example, businesses use word-processing and accounting programs, and casual computer users enjoy programs that play music and games. Alternatively, you can write your own programs. When you write software instructions, you are programming. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Classified into two broad types: Application software comprises all the programs you apply to a task, such as word processing programs, spreadsheets, payroll and inventory programs, and games. When you hear people say they have “downloaded an app onto a mobile device, ” they are simply using an abbreviation of application. System software comprises the programs that you use to manage your computer, including operating systems such as Windows, Linux, or UNIX for larger computers and Google Android and Apple i. OS for smartphones. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Programming languages programming languages specially developed so that you could pass your data and instructions to the computer to do specific job There are two major types of programming languages, Low Level Languages and High Level Languages Low Level languages are further divided in to Machine language and Assembly language High Level Languages are, for scientific application FORTRAN and C languages are used. On the other hand COBOL is used for business applications. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Machine Language is the only language that is directly understood by the computer. It does not needs any translator program The only advantage is that program of machine language run very fast J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Assembly Language It is the first step to improve the programming structure. You should know that computer can handle numbers and letter. The set of symbols and letters forms the Assembly Language and a translator program is required to translate the Assembly Language to machine language This translator program is called `Assembler J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
q. Advantages: Assembly Language is easier to understand saves a lot of time and effort. It is easier to correct errors and modify program instructions. Assembly Language has the same efficiency of execution as the machine level language q. Disadvantages: • Assembly language is machine dependent. A program written for one computer might not run in other computers with different hardware configuration. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
3 HIGH LEVEL LANGUAGES assembly and machine level languages require deep knowledge of computer hardware where as in higher language you have to know only the instructions in English words and logic of the problem. Higher level languages are simple languages that use English and mathematical symbols like +, -, %, / etc. for its program construction J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Any higher level language has to be converted to machine language for the computer to understand For example COBOL (Common Business Oriented Language), FORTRAN (Formula Translation) and BASIC (Beginners All-purpose Symbolic Instruction Code) are high level languages q. Advantages of High Level Languages Higher level languages have a major advantage over machine and assembly languages that higher level languages are easy to learn and use (similar to the languages used by us in our day to day life. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Compiler : It is a program translator that translates the instruction of a higher level language to machine language. It is called compiler because it compiles machine language instructions for every program instructions of higher level language. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Thus compiler is a program translator like assembler but more sophisticated. It scans the entire program first and then translates it into machine code. The programs written by the programmer in higher level language is called source program. After this program is converted to machine languages by the compiler it is called object program A compiler can translate only those source programs, which have been written, in that language J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
Interpreter An interpreter is another type of program translator used for translating higher level language into machine language. It takes one statement of higher level languages, translate it into machine language and immediately execute it. Translation and execution are carried out for each statement. It differs from compiler, which translate the entire source program into machine code and J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
The advantage of interpreter compared to compiler is its fast response to changes in source program do not require large memory in computer. The disadvantage of interpreter is that it is time consuming method because each time a statement in a program is executed then it is first translated. Thus compiled machine language program runs much faster than an interpreted program. J. M. Patel Collge of Commerce Complied by Ms. Crimita Almeida
- Slides: 19