Programming for Problem Solving- 3110003 Handbook PDF

Title Programming for Problem Solving- 3110003 Handbook
Course Programming For Problem Solving
Institution Gujarat Technological University
Pages 132
File Size 4.6 MB
File Type PDF
Total Downloads 109
Total Views 280

Summary

Download Programming for Problem Solving- 3110003 Handbook PDF


Description

Lecture note Programming for Problem Solving ( 3110003 ) Year: 2020-2021

CHAPTER-1-Introduction to computer and programming TOPIC:1:MAJOR COMPONENTS OF COMPUTER SYSTEM AND ITS FUNCTION

Input Unit Data and instructions must enter the computer system before any computation can be performed on the supplied data. The input unit that links the external environment with the computer system performs this task. Data and instructions enter input units in forms that depend upon the particular device used. For example, data is entered from a keyboard in a manner similar to typing, and this differs from the way in which data is entered through a mouse, which is another type of input device. However,

1

regardless of the form in which they receive their inputs, all input devices must provide a computer with data that are transformed into the binary codes that the primary memory of the computer is designed to accept. This transformation is accomplished by units that are called input interfaces. Input interfaces are designed to match the unique physical or electrical characteristics of input devices to the requirements of the computer system. In short, an input unit performs the following functions. 1. It accepts (or reads) the list of instructions and data from the outside world. 2. It converts these instructions and data in computer acceptable format. 3. It supplies the converted instructions and data to the computer system for further processing. Output Unit The job of an output unit is just the reverse of that of an input unit. It supplied information and results of computation to the outside world. Thus it links the computer with the external environment. As computers work with binary code, the results produced are also in the binary form. Hence, before supplying the results to the outside world, it must be converted to human acceptable (readable) form. This task is accomplished by units called output interfaces. In short, the following functions are performed by an output unit. 1. It accepts the results produced by the computer which are in coded form and hence cannot be easily understood by us. 2. It converts these coded results to human acceptable (readable) form. 3. It supplied the converted results to the outside world. Storage Unit The data and instructions that are entered into the computer system through input units have to be stored inside the computer before the actual

2

processing starts. Similarly, the results produced by the computer after processing must also be kept somewhere inside the computer system before being passed on to the output units. Moreover, the intermediate results produced by the computer must also be preserved for ongoing processing. The Storage Unit or the primary / main storage of a computer system is designed to do all these things. It provides space for storing data and instructions, space for intermediate results and also space for the final results. In short, the specific functions of the storage unit are to store: 1. All the data to be processed and the instruction required for processing (received from input devices). 2. Intermediate results of processing. 3. Final results of processing before these results are released to an output device. Central Processing Unit (CPU) The main unit inside the computer is the CPU. This unit is responsible for all events inside the computer. It controls all internal and external devices, performs “Arithmetic and Logical operations” . The operations a Microprocessor performs are called “instruction set” of this processor. The instruction set is “hard wired” in the CPU and determines the machine language for the CPU. The more complicated the instruction set is, the slower the CPU works. Processors differed from one another by the instruction set. If the same program can run on two different computer brands they are said to be compatible. Programs written for IBM compatible computers will not run on Apple computers because these two architectures are not compatible. The control Unit and the Arithmetic and Logic unit of a computer system are jointly known as the Central Processing Unit (CPU). The CPU is the brain of any computer system. In a human body, all major decisions are taken by the brain and the other parts of the body function as directed by

3

the brain. Similarly, in a computer system, all major calculations and comparisons are made inside the CPU and the CPU is also responsible for activating and controlling the operations of other units of a computer system. Arithmetic and Logic Unit (ALU) The arithmetic and logic unit (ALU) of a computer system is the place where the actual execution of the instructions take place during the processing operations. All calculations are performed and all comparisons (decisions) are made in the ALU. The data and instructions, stored in the primary storage prior to processing are transferred as and when needed to the ALU where processing takes place. No processing is done in the primary storage unit. Intermediate results generated in the ALU are temporarily transferred back to the primary storage until needed at a later time. Data may thus move from primary storage to ALU and back again as storage many times before the processing is over. After the completion of processing, the final results which are stored in the storage unit are released to an output device. The arithmetic and logic unit (ALU) is the part where actual computations take place. It consists of circuits that perform arithmetic operations (e.g. addition, subtraction, multiplication, division over data received from memory and capable to compare numbers (less than, equal to, or greater than). While performing these operations the ALU takes data from the temporary storage are inside the CPU named registers. Registers are a group of cells used for memory addressing, data manipulation and processing. Some of the registers are general purpose and some are reserved for certain functions. It is a high-speed memory which holds only data from immediate processing and results of this processing. If these results are not needed for the next instruction, they are sent back to the main memory and registers are occupied by the new data used in the next instruction.

4

All activities in the computer system are composed of thousands of individual steps. These steps should follow in some order in fixed intervals of time. These intervals are generated by the Clock Unit. Every operation within the CPU takes place at the clock pulse. No operation, regardless of how simple, can be performed in less time than transpires between ticks of this clock. But some operations required more than one clock pulse. The faster the clock runs, the faster the computer performs. The clock rate is measured in megahertz (Mhz) or Gigahertz (Ghz). Larger systems are even faster. In older systems the clock unit is external to the microprocessor and resides on a separate chip. In most modern microprocessors the clock is usually incorporated within the CPU. Control Unit How the input device knows that it is time for it to feed data into the storage unit? How does the ALU know what should be done with the data once it is received? And how is it that only the final results are sent to the output devices and not the intermediate results? All this is possible because of the control unit of the computer system. By selecting, interpreting, and seeing to the execution of the program instructions, the control unit is able to maintain order and directs the operation of the entire system. Although, it does not perform any actual processing on the data, the control unit acts as a central nervous system for the other components of the computer. It manages and coordinates the entire computer system. It obtains instructions from the program stored in main memory, interprets the instructions, and issues signals that cause other units of the system to execute them. The control unit directs and controls the activities of the internal and external devices. It interprets the instructions fetched into the computer, determines what data, if any, are needed, where it is stored, where to store the results of the operation, and sends the control signals to the devices involved in the execution of the instructions. Memory Unit: 5

The main memory is also called primary memory, is used to store data temporarily. Although the CPU is the brain behind all the operations in the computer, it needs to be supplied with the data to be processed and the instructions to tell it what to do. Once the CPU has carried out an instruction, it needs the result to be stored. This storage space is provided by the computer’s memory. Data provided by the input device and the result of that processed data is also stored in the memory unit. This main memory is like a scratchpad. The storage capacity of the memory is generally measured in megabytes. 8 Bits = 1 Byte 1024 Bytes = 1 Kilobyte (KB) 1024 Kilobytes = 1 Megabyte (MB) 1024 Megabytes = 1 Gigabyte (GB) 1024 Gigabytes = 1 Terabyte (TB) 1024 Terabytes = 1 Petabyte (PB) 1024 Petabytes = 1 Exabyte (EB) 1024 Exabytes = 1 Zettabyte (ZB) 1024 Zettabytes = 1 Yottabyte (YB) Different kinds of primary memory are Random Access Memory (RAM) and Read-Only Memory (ROM). You can read and write data in RAM but the data is volatile or temporary that is whenever the power is switched off the data of RAM is lost so, it is required to store the data in the secondary memory if the data is required for the future use. But you can only read the data from ROM and you cannot write anything into it and the data is permanent. The manufacturer himself has written the data in it initially, for example, BIOS chip. Secondary Memory

6

This is the permanent memory. The data stored in it is permanent. But you can delete the data whenever you want. There are different kinds of secondary storage devices. A few of them are Floppy disks, hard disks, and optical disks, etc. Topic 2: SOME IMPORTANT DIFFERENCES FOR EXAM Difference between primary and secondary memory

Difference between volatile and non volatile memory

7

Difference between RAM(Random access memory) and ROM(Read only memory)

8

TOPIC 3:CONCEPT OF HARDWARE AND SOFTWARE Every computer is composed of two basic components: hardware and software. ● hardware includes the Physical features, which are every part that you can either see or touch, for example: monitor, case, keyboard, mouse, and printer. ● The part which activates the physical components called software. It includes the features that responsible for directing the work to the hardware.

9

Topic 4: TYPES OF SOFTWARE:

10

System Software: System software is computer software designed to operate the computer hardware to provide basic functionality and to provide a platform for running application software. Refers to the operating system and all utility programs that manage computer resources at a low level. Example: Basic Input/Output System (BIOS) Program,Disk Partition Tool,etc Application Software • A program or group of programs designed for end users • Allows end users to accomplish one or more specific tasks. Examples of Computer Application Software • Word processor • Database Management System • Web Browser Difference between system software and application software

11

Topic 5:compiler and interpreter ● Compiler is a program which translates the source code written in a high level language into computer readable machine language. ● Interpreter translates a high level language statement in a source program to a machine code and executes it immediately.

12

Topic 6:concept of machine level ,assembly level and high level programming

Assembly Language Assembly Language is a low-level programming language. It helps in understanding the programming language to machine code. In computer, 13

there is assembler that helps in converting the assembly code into machine code executable. Assembly language is designed to understand the instruction and provide to machine language for further processing. It mainly depends on the architecture of the system whether it is the operating system or computer architecture. Assembly Language mainly consists of mnemonic processor instructions or data, and other statements or instructions. It is produced with the help of compiling the high-level language source code like C, C++. Assembly Language helps in fine-tuning the program. Advantages: 1. 2. 3. 4. 5. 6. 7. 8.

It allows complex jobs to run in a simpler way. It is memory efficient, as it requires less memory. It is faster in speed, as its execution time is less. It is mainly hardware oriented. It requires less instruction to get the result. It is used for critical jobs. It is not required to keep track of memory locations. It is a low-level embedded system.

Disadvantages: 1. 2. 3. 4.

It takes a lot of time and effort to write the code for the same. It is very complex and difficult to understand. The syntax is difficult to remember. It has a lack of portability of program between different computer architectures . 5. It needs more size or memory of the computer to run the long programs written in Assembly Language.

14

Machine Language : Machine Language is the only language that is directly understood by the computer. It does not needs any translator program. We also call it machine code and it is written as strings of 1's (one) and 0’s (zero). When this sequence of codes is fed to the computer, it recognizes the codes and converts it in to electrical signals needed to run it. For example, a program instruction may look like this:

1011000111101

It is not an easy language for you to learn because of its difficult to understand. It is efficient for the computer but very inefficient for programmers. It is considered to the first generation language. It is also difficult to debug the program written in this language.

Advantage Machine Language: The only advantage is that program of machine language run very fast because no translation program is required for the CPU.

Disadvantages Machine Language: 1. It is very difficult to program in machine language. The programmer has to know details of hardware to write program. 2. The programmer has to remember a lot of codes to write a program which results in program errors. 3. It is difficult to debug the program.

15

High level language High level language is abbreviated as HLL .High level languages are similar to the human language. Unlike low level languages, high level languages are programmers friendly, easy to code, debug and maintain. High level language provides higher level of abstraction from machine language. They do not interact directly with the hardware. Rather, they focus more on the complex arithmetic operations, optimal program efficiency and easiness in coding. Advantages of High level language 1. High level languages are programmer friendly. They are easy to write, debug and maintain. 2. It provide higher level of abstraction from machine languages. 3. It is machine independent language. 4. Easy to learn. 5. Less error prone, easy to find and debug errors. 6. High level programming results in better programming productivity. Disadvantages of High level language 1. It takes additional translation times to translate the source to machine code. 2. High level programs are comparatively slower than low level programs. 3. Compared to low level programs, they are generally less memory efficient. 4. Cannot communicate directly with the hardware.

16

Topic 7:flowcharts and algorithms An algorithm is a step-by-step analysis of the process, while a flowchart explains the steps of a program in a graphical way.In other words, an algorithm is a procedure for solving problems. In order to solve a mathematical or computer problem, this is the first step of the procedure.An algorithm includes calculations, reasoning and data processing.Algorithms can be presented by natural languages, pseudocode and flowcharts, etc. A flowchart is the graphical or pictorial representation of an algorithm with the help of different symbols, shapes and arrows in order to demonstrate a process or a program. With algorithms, we can easily understand a program. The main purpose of a flowchart is to analyze different processes. Several standard graphics are applied in a flowchart.

Difference between algorithm and flowchart

17

EXAMPLES: 1) Write an algorithm and draw the flowchart to find out largest among 3

numbers taken from the users as input.

18

19

Figure 1: flowchart to find largest among 3 numbers

20

2) Write an algorithm and draw the flowchart to find area of a triangle.

3) write an algorithm to check whether the number entered by the user is odd or

even.

21

22

Figure 2: flowchart for checking odd or even number( entered by the user)

23

Chapter 2: Fundamentals of C

Features of C Language • • • • • • • • • • • •

Simple Machine Independent or Portable Mid-level programming language structured programming language Rich Library Memory Management Fast Speed Pointers Recursion Extensible Case sensitive Compiler Based

1) Simple C is a simple language in the sense that it provides a structured approach (to break the problem into parts), the rich set of library functions, data types, etc. 2) Machine Independent or Portable Unlike assembly language, c programs can be executed on different machines with some machine specific changes. Therefore, C is a machine independent language. 3) Mid-level programming language Although, C is intended to do low-level programming. It is used to develop system applications such as kernel, driver, etc. It also supports the features of a high-level language. That is why it is known as mid-level language.

4) Structured programming language C is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify. Functions also provide code reusability. 5) Rich Library C provides a lot 6) Memory Management

of

inbuilt

functions

that

make

the

development

fast.

It supports the feature of dynamic memory allocation. In C language, we can free the allocated memory at any time by calling the free() function.

7) Speed The compilation and execution time of C language is fast since there are lesser inbuilt functions and hence the lesser overhead. 8) Pointer C provides the feature of pointers. We can directly interact with the memory by using the pointers. We can use pointers for memory, structures, functions, array, etc. 9) Recursion In C, we can call the function within the function. It provides code reusability for every function. Recursion enables us to use the approach of backtracking. 10) Extensible C language is extensible because it can easily adapt new features. 11) Case sensitive C is a case sensitive language, where int and INT makes a difference in upper-case and lower-case. 12) Compiler Based Every program written in c programming language needs to get compiled first before execution.

History • In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C Programming Language by Kernighan & Ritchie caused a revolution in the computing world • In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or "ANSI C", was completed late 1988.

C is Middle Level Language • C stands in between these two categories. • Since it was designed to have both: • A relatively good programming efficiency as...


Similar Free PDFs