Module 1 - C

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Module 1 1. What are the different steps to be followed while solving a problem?

(Problem Solving) In order to solve a problem using computer, the following steps should be carried out: a) The given problem is analyzed. b) The method to solve the problem is broken down into a sequence of elementary tasks. c) Based on this analysis, an algorithm to solve the problem is formulated. d) The algorithm can then be expressed in a pictorial form known as flowchart. e) The next step is to express the flowchart in a more precise and concise notation called programming language (computer program). f) The computer program is fed to the computer. g) The computers processing unit interprets the instruction in the program, executes them and sends results to output unit. 2. Define algorithm: what are the basic characteristics an algorithm should have? An algorithm may be defined as a finite sequence of instructions to be carried out to solve a problem. Each instruction tells what task is to be performed. An algorithm has 5 characteristics: a) An algorithm begins with instruction(s) to accept inputs. b) The processing rules specified in the algorithm must be precise and unambiguous. It must also be able to carry out. c) Each instruction must be basic so that it can be carried out by a person using pen and paper. d) The total time to carry out all the instructions in an algorithm must be finite. e) An algorithm must produce one or more outputs (results). 3. Define flowchart: A flowchart may be defined as a pictorial representation of algorithm. It shows the sequence in which instructions are carried out in an algorithm. The flowcharts are primarily used as an aid in formulating and understanding algorithms. They are also used to document algorithms. The sequencing of instructions and repetition of groups of instructions can be easily monitored using a flowchart. For easiness, a standard convention is followed in drawing flowcharts. a) Rectangles with rounded ends are used to indicate START and STOP.

b) Parallelograms are used for input and output operations. c) Diamond shaped boxes are used to indicate questions asked or to test conditions and based on its answers appropriate exits are taken. These exits are labeled with answers to the questions. d) Rectangles are used to indicate processing operation such as storage and arithmetic. e) A circle is used to connect different parts of a flowchart. This is called a connector. f) Arrows indicate the direction to be followed in a flowchart. 4. How do you debug a program? Or what are the different debugging techniques available? Methods that are available for finding the location of execution errors and logical errors within a program are generally referred to as debugging techniques. The various debugging techniques that are commonly used are error isolation, tracing, watch values, breakpoints and stepping. a) Error isolation: Error isolation is useful for locating an error resulting in a diagnostic message. If the general location of the error is not known, it can frequently be found by temporarily deleting a portion of the program and then rerunning the program to see if the error disappears. The temporary deletion is accomplished by surrounding the instructions with comment markers (/ * and * /), causing the enclosed instructions to become comments. If the error message then disappears, the deleted portion of the program contains the source of the error. b) Tracing: Tracing involves the use of printf statements to display the values assigned to certain key variables, or to display the values that are calculated internally at various locations within the program. This information is vital, because it verifies that the values actually assigned to certain variables really are (or are not) the values that should be assigned to those values. It is very common to find that the actual assigned values are different from those expected. In addition, this information allows you to monitor the progress of the computation as the program executes. In many situations, it will help to identify a particular place where things begin to go wrong because the values generated will be obviously incorrect. c) Watch Value: A watch value is the value of a variable or an expression which is displayed continuously as the program executes. Thus, one can see the changes in a watch value as they occur, in response to the program logic. By monitoring a few

carefully selected watch values, you can often determine where the program begins to generate incorrect or unexpected values. d) Breakpoint: A breakpoint is a temporary stopping point within a program. Each breakpoint is associated with a particular instruction within the program. When the program is executed, the program execution will temporarily stop at the breakpoint, before the instruction is executed. The execution may then be resumed, until the next breakpoint is encountered. Breakpoints are often used in conjunction with watch values, by observing the current watch value at each breakpoint as the program executes. a) Stepping: Stepping refers to the execution of one instruction at a time, typically by pressing a function key to execute each instruction. In Turbo C++, for example, stepping can be carried out by pressing either function key F7 or F8. F8 steps over subordinate functions, whereas F7 steps through the functions. 5. Explain Von Newman concept: The major contribution of John Von Newman is the idea of storing program and data to be processed in contiguous memory locations and the instructions are carried out one after the other till the program halts or a STOP is encountered. Storing a program in memory is essential if a series of instructions are to be carried out repeatedly. Storing a program in memory also makes the operation of computers automatic. The instruction execution goes through the following phases. Each instruction is brought from the memory to an instruction register (IR) in CPU. This is called fetch phase. Then it is decoded by an instruction decoder to generate various control signals. This is called Instruction Decode phase. These instructions are routed to different blocks of computer to perform required operations. This is called execution phase. The Von Newman machine has 5 basic parts, the memory, the arithmetic and logic unit, the program control unit, and the input and output units.

6. What is a hypothetical decimal computer? 7. What are the functional units of a computer? All computer systems perform the following 5 basic functions: a) The process of entering data and instructions into the computer system. b) Storing: saving data and instructions so that they are available for initial or further processing as and when required. c) Processing: performing arithmetic or logical operations on data in order to convert them into useful information. d) Outputting: the process of producing results for the user, such as a printed report or visual display. e) Controlling: Directing the manner and sequence in which all of the above operations are performed.

8. How do you choose a suitable data structure to solve a particular problem? 9. Explain the need of documenting a program PART B 10. What are the functional units of a computer? Qn. No 8 + Input Unit: Information is entered into a computer using input devices. An input device reads the data and program into computer. It also converts the input information into binary form acceptable for the computer. Some popular input devices are Keyboard, Mouse, Joystick, Floppy, Punched Reader, Optical Mark Reader etc. Output Unit: The output devices receive results and other information from computer and provide them to the users. The computer sends results to an output device in binary form. The output device converts this to a suitable form convenient to the users such as printed form, display on a screen, voice output etc. some popular output devices are VDU(Visual Display Unit), Printer, Plotter etc. Storage Unit: the function of a storage unit is to store information. The data and instructions entered into the computer must be stored before the actual processing starts. Similarly, the results produced after processing must be stored somewhere before they

are displayed to the user. There are two types of storage units: the main(1) memory and the auxiliary (2) memory. The main memory is a fast memory and is directly accessed by CPU. The auxiliary memory is used to store data and instructions of a program permanently. Central Processing Unit: the CPU is the brain of computers. Its primary function is to execute programs. Besides executing programs, it also controls the operation of all other components such as input and output devices, storage devices etc. CPU consists of 2 parts: Arithmetic and logic unit (ALU) and Control unit (CU). Arithmetic and logic unit performs all arithmetic and logic operations such as addition, subtraction, AND, OR etc. It also performs increment and decrement, shift and clear operations. Control unit is the central part of CPU as it controls and co-ordinates all the activities of other units such as input/output, ALU and storage units. 11. Explain the different storage units of a computer? A memory or a store is an important component of a digital computer. It stores programs and data. A memory is made up of a large number of cells, with each cell capable of storing one bit. The cells are organized as a set of addressable words, each word storing a sequence of bits. Memory can be broadly divided into two categories, depending upon technology as: (i) Primary storage and (ii) Secondary storage Primary store: It is also called main memory or semi conductor memory. It stores data and instructions currently needed by CPU. It is much faster than secondary memory and has lower capacity than secondary memory. Hence it is more costly than secondary memory. There are mainly two types of main memory: (i) RAM (i) (ii) ROM

RAM: RAM stands for Random Access Memory. In RAM, it is possible to select any memory location randomly to store information or to retrieve information. The access time is same for any memory location. Since information can be written into or read from RAMs, they are used as read/write memory of the computer system. The memory is volatile because it retains information only when the power supply is on. Thus, the programmer has to reload a program each time when the power supply is interrupted. There are two types of RAMs: Static RAM (SRAM) and Dynamic RAM (DRAM). SRAM retains the stored information as long as power supply is on, but a DRAM

retains its contents only for a few milliseconds. I.e. it stores information in the form of a charge on a capacitor. Therefore, the contents must be refreshed regularly. It is because of this reason that DRAMs are provided with refreshing and control circuitry. DRAMs are cheaper, have high packing density, have moderate speed and consume less power. SRAMs are costlier and consume more power. Along with a refreshing circuitry, they need read/write facility also. But they are faster than DRAMs. (ii) ROM: ROM stands for Read Only Memory. In ROM, information is permanently stored i.e. it is non-volatile memory. The information from the memory can be only read and is not possible to write new information into it. The contents of ROM are not lost or erased even when power supply is terminated. Such memories are also known as field stores, permanent stores or dead stores. It is generally used to store initialing programs of a computer, microcodes of a CISC processor, fixed programs in microcontrollers etc. it is simple, cheap and dense. ROM chips are provided by computer manufactures and its not possible for the user to change the contents of a ROM chip. PROM: a PROM is a Programmable ROM. In PROM, the contents are decided by the user. The user can store permanent programs or any kind of information in a PROM. However, once the chip has been programmed, the recorded information cannot be changed. EPROM: EPROM stands for Erasable PROM. As the name suggests it is possible to erase the contents of an EPROM chip. The stored data in EPROM is erased by exposing it to high density short wave ultraviolet light for 20 minutes. EPROMs are used to store programs which are permanent but need updating. EEPROM: EEPROM is Electrically Erasable PROM. The chip can be erased and reprogrammed on byte by byte basis. Hence selective erasing is possible. Its disadvantage is that it requires different voltages for erasing (21 V), writing (21 V) and reading (5 V) the stored information. It also has high cost and low reliability. Secondary store: A computer is able to store bulk of data and retrieve or access the stored information as and when required. The bulk of data cant be stored in main memory as this memory is costly and naturally some other cheaper memory devices are required. These cheaper memory devices are called secondary storage devices and can store bulk of data at very low cost. The commonly used secondary storage devices are

(i)

Floppy Disk: a floppy disk is a very popular 2 storage device for micro and mini computers. A floppy is a round, flat piece of plastic coated with iron oxide and encased in a plastic cover. Floppies come in 2 physical sizes 5 inch and 3 inch. The head actually contacts the surface during reading/writing, in other times its lifted up from the surface. The hole at the center is to allow a spindle to lock the floppy so that it can rotate. The index hole is used to recognize the starting sector of any track. The purpose of write permit notch is to protect valuable information on the floppy from accidental damage. If this notch is covered, writing is not allowed on the floppy.

(ii)

Hard Disk: hard disk is the most popular 2 storage medium. It is also called magnetic disk and is made of aluminium or other metal alloys. The disk is coated on both sides with magnetic material (iron oxide). Unlike a floppy disk, a hard disk cannot be inserted or removed from hard disk drive. A disk drive is a device that writes information on recording platters that resemble gramophone records. Disk drive reads information written on the disk. They have read/write heads to read from or write into the disks. In order to increase the storage capacity, a large no of disks or platters are grouped together and mounted on a common drive to form a disk pack (cylinder). A cylinder usually consists of 6 platters, with 2 surfaces, one above the other. Each surface has concentric circles dividing the disks into tracks. Each track is divided into a no of fixed length physical blocks called sectors. Sectors are the smallest unit of data for transfer. Sectors are separated by inter record gaps. Disks are available in different sizes with different speeds. No of tracks is generally 800 and no of sectors per track is 64.

(iii)

CD-ROM: CD-ROM stands for Compact Disk ROM. The disk is made of a resin, such as polycarbonate and is coated with a material that is highly reflective, such as aluminium. The disk is 5.25 inch in diameter. Its an optical storage media that make use of pinpoint precision which is possible with laser beams. Data is recorded by focusing a laser beam on the surface of the disk. The laser beam is turned on and off at a varying rate. Hence tiny holes are produced on the metal coating. In order to read the stored data, a less powerful beam is focused on the disk surface. This beam is strongly reflected by the coated surface and weakly reflected at the pits, there by

producing on-off reflection patterns. This is converted into electronic signals. The capacity of CD-ROM is 600 MB and track density is 16000 tracks per inch. 12. What is a programming language? What are the different types of programming languages? A computer needs definite instructions to do a specific job. These instructions have to be in a language which is understood by a computer. A programming language can be defined as a language used for expressing a set of computer instructions. The programming languages can be divided into two major categories: Low level and High level languages. The low level languages can be further dived into Machine language and Assembly language. Thus, all computer languages can be classified into 3 broad categories: (i) Machine Language: machine language is the language directly understood by a computer. Its in binary format consisting of only 0s and 1s. The symbol 1 stands for presence of an electric pulse while 0 stands for absence of pulse. Since writing machine language programs is a very complicated task, only experts can write machine language programs. Advantages: (1) Programs written in machine language can be executed very fast. (2) Highly suited for small computers having only limited memory. Disadvantages: (1) Machine dependent. It is different from computer to computer and depends on ALU, control unit and the size as well as word limit of the memory unit. (2) Its very difficult to write programs in machine language as instructions are in binary format. (3) Its easy to make errors while writing programs in machine language because instructions and data are in binary format. Also, it is very difficult to locate the errors. (4) Any modification in a machine language program requires addresses of all subsequent instructions to be changed. (ii) Assembly Language: assembly language programming makes use of instructions that corresponds to machine language. It also adds new features such as Mnemonic Operation Codes and Symbolic Addresses to simplify the programming. A mnemonic is an abbreviated word that serves as a memory aid with its sound suggesting its

meaning. For eg: LDA is the mnemonic code for Load Accumulator. A program written in assembly language is converted into binary form by a translator called Assembler. Advantages: (1) Easier to understand and use because mnemonics are used for op codes and symbolic addresses or variables are used for memory addresses. (2) Fewer errors are committed while programming in assembly language as compared to machine language programming. Its also easier to locate errors. (3) Its easier to modify programs in assembly language as compared to machine language because modification doesnt require changes in the subsequent section. (4) Besides being easier to read, write and understand, the efficiency of assembly language is almost the same as machine language. Disadvantages: (1) Its machine dependent. It is different from computer to computer and depends on ALU, control unit and the size as well as word limit of the memory unit. (2) An intermediate translating program is required to convert the assembly language instructions into their binary form and this increases the overhead. (3) An assembly language program cannot be executed on small sized computers. (4) There is no standardization of assembly languages. (iii) High Level Language: high level languages are symbolic languages that use English words and Mathematical symbols than mnemonic codes. This makes it easier to read, write and understand. It has been developed to facilitate the programmers to use computers without the need to know the internal structure of the computer. Every instruction written in high level language is translated into machine language instructions. Few examples of high level languages are Basic, COBOL, FORTRAN, C and C++. Advantages: (1) The high level languages are easy to understand and learn. (2) High level languages are machine independent. (3) Fewer errors are committed while writing programs in high level language. (4) Its easier to modify and maintain programs written in high level language.

Disadvantages: (1) Programs written in a high level language take more time to run and require more memory. Hence less efficient compared to machine or assembly language programs.
(2) They are less flexible as compared to machine or assembly language programs.

Therefore, some tasks are impossible in high level languages.

13.

You might also like