0% found this document useful (0 votes)
15 views34 pages

Module 1

Chapter 1 introduces the basics of computer hardware and software, explaining the integral role of computers in various tasks such as data processing and information retrieval. It differentiates between digital and analog computers, outlines key characteristics of computers like speed, accuracy, and versatility, and describes the components of a computer system including hardware, software, data, and users. The chapter also covers the input-process-output concept and details the components of computer hardware, including the input-output unit, central processing unit, and memory unit.

Uploaded by

sree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
15 views34 pages

Module 1

Chapter 1 introduces the basics of computer hardware and software, explaining the integral role of computers in various tasks such as data processing and information retrieval. It differentiates between digital and analog computers, outlines key characteristics of computers like speed, accuracy, and versatility, and describes the components of a computer system including hardware, software, data, and users. The chapter also covers the input-process-output concept and details the components of computer hardware, including the input-output unit, central processing unit, and memory unit.

Uploaded by

sree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Chapter 1 BASICS OF COMPUTER HARDWARE & SOFTWARE 1.1. Introduction To Computer Computers are an integral part of our lives. They are used for the reservation of tickets for railways and airplanes, payment of telephone and electricity bills, deposit and withdrawal of money from banks, processing of business data, forecasting of weather conditions, diagnosis of diseases, searching for _ information on the internet etc. The term computer was derived from the word compute. The word compute means to calculate. A computer is an electronic machine that accepts data from the user, processes the data by performing calculations and operations on it, and generate the desired output results. Computer performs both simple and complex operations with speed and accuracy. 1.2 Digital And Analog Computers A digital Computer uses distinct values to represent data internally. All information are represented using the digit 0’s and 1’s. Analog computers are another type of computers that represent data as a continuous range of values. Analog computers are used for measuring of parameters that vary continuously in real time such as temperature, pressure and voltage. 1.3. Characteristics Of A Computer 1. Speed: As you know computer can work very fast. It takes only few seconds for calculations that we take hours to complete. You will be surprised to know that computer can perform’ millions (1,000,000) of instructions and even more per second, ‘Therefore, we determine the speed of computer in terms of microsecond (10-6 part of a second) or 1s Programming In C__ + } o part of a second). From this you can -9 pa § Y nanosecond (1010 the Powe nk imagine how fast your compu y uter is very high and every f accuracy of comp! . Accuracy: The degree 0 y Se a ae > calculation is performed with the same ee ater The ie ai is7. It is determined on the basis of design “ cot pI d computer are due to human and inaccurate a 3. Diligence: A computer is free from tiredness, lack of concentration, fatigue, etc. It can work for hours without creating any . millions of calculations are to be performed, a come peseraes every calculation with the same accuracy. Due to this capi ility i overpowers human being in routine type of work. 4, Versatility: It means the capacity to perform completely different type of work. You may use your computer to prepare payroll slips. Next moment you may use it for inventory management or to prepare electric bills. 5. Power of Remembering: Computer has the power of storing any amount of information or data. Any information can be stored and recalled as long as you require it, for any numbers of years. It depends entirely upon you how much data you want to store in a computer and when to lose or retrieve these data. ° 6. No IQ: Computer is a dumb machine and it cannot do any work without instruction from the user. It performs the instructions at tremendous speed and with accuracy. It is you to decide what you want to do and in what sequence. So a computer cannot take its own decision as you can. 7. No Feeling: It does not have feelings or emotion, taste, knowledge and experience. Thus it does not get tired even after long hours of work. It does not distinguish between users, 8. Storage: The Computer has an in-built memory where it can store a large amount of data. You can also store i devices such as floppies, which can be kept. can be carried to other computers. data in secondary storage outside your computer and 16 Programming In C .4 What Is A Computer ? omputer is an electronic device that accepts data as input, processes the input data by performing mathematical and logical operations on it and gives he desired output. The computer system consists of four parts 1) Hardware 2) Software 3) ~ Data and 4) Users. Figure 1.1: Components of a Computer Hardware consists of the mechanical parts that make up the computer as a machine. The hardware consists of physical devices of the computer. The devices are required for input, output, storage and processing of the data. Keyboard, monitor, hard disk drive, floppy disk drive, printer, processor and _ motherboard are some of the hardware devices. Software is a set of instructions that tells the computer about the tasks to be performed and how these tasks are to be performed. Program is a set of instructions written in a language understood by the computer, to perform a specific task. A sot of programs and documents are collectively called software. The hardware of the computer system cannot perform any task on its own. The hardware needs to be instructed about the task to be performed. Software instructs the computer about the task to be performed. Basically, there are six main types of software, which are as follows, 17 Programming In C BS .: Operating System: These specialized programs eolis ae between software and hardware. The operating as sr adees of a other computer programs, and even regulate the s' e computer. Examples: Windows XP, Macintosh etc oftware: These are designed to perform a specific task signed (specific to the user’ Application S« or a bunch of tasks. They can be user-de needs) or ready made application software. Example: PowerPoint, Tally etc. Utility Software: Like operating system, it is a system software. It helps maintain and protect the computer system. For example, Anti-virus software is a utility software. Language Processors: Software that interprets computer language and translates it into machine language. It also checks for errors in language syntax and fixes the problems. System Software: This type of software controls the hardware, the reading of the data and other such internal functions. Connectivity Software: . The special software that facilitates the connection between the computer system and the server. This allows the computer to share information and communicate with each other. Data is essentially the raw facts and figures that we input in the computer. The data gets processed via the computer system and becomes information, which is processed and organized data. Information can then be used for decision-making purposes. The measurement of data is done in terms of “bytes”. One kilobyte (KB) is approximately 1000 bytes, 1 megabyte : MB) i ili bytes and finally, 1 gigabyte (GB) is approximately 1 ae ) e 1 hiligg n bytes. Users are people interacting with the com puter syste of it. We call this clement the Liveware. stem are also an element There are three types of people that interact with the system, ni 1 » namely Programming In C Programmers: Professionals who write the computer programs that allow users to interact with the computer. * System Analyst: They mainly design data processing systems, and solve problems that arise in data processing « End-Users: Also known as operators, they are the people who interact with the computer system. Example of the elements of a computer based system are described jn the three following scenarios: Example 1. Patient monitoring system Hardware __ : Electrode leads, Micro computers, Network platform, and a Server Computer. Software : Monitoring Application, Database, and Operating System. User : Medical staff, Administrators Example 2. Controlling a section of an Assembly Line. Hardware __: A specially embedded system which is developed for this purpose. ‘Software : The machine code loaded on the embedded system Memory. User : Other Machine, Supervisor. Example 3. Playing a game with a Computer Hardware; Game console such as XBox, Playstation. Software: The game itself ‘User The game player .5 The Input-Process-Output Concept processes data, generates computer is an electronic device that accepts data, mation sutput, and stores data. The concept of generating output infor 19 Programming In C i ce itput cor from the input is also referred to as ee ie a es oe The input-process-output concept of the computer is & * Input : The computer accepts input data from the user via an input, devicg like keyboard. The input data can be characters, word, text, sound, images, document, etc. * Process ar dee 4 The computer processes the input data. For this, it performs some actions on the data by using the instructions or program given by i the user of the data. The action could be an arithmetic or logic calculation, editing, modifying a document, etc. During Processing, the data, instructions and the output are stored temporarily in the computer’s main memory. 4 © Output The output is the result generated after the processing of data. The output may be in the form of text, sound, image, document, etc. The computer may display the output on a monitor, send output to the — printer for printing, play the output, etc. © Storage The input data, instructions and output are stored permanently in the © secondary storage devices like disk or tape. The stored data can be - retrieved later, whenever needed. 1.6 Components Of Computer Hardware The computer system hardware comprises of three main components 1. Input-Output unit 2. Central Processing Unit 3, Memory Unit 1. Input unit:The input unit consists of different input devices, The role of an input unit is to give data to the computer. A Computer takes input from input devices in the form of clicks, drags and drops, Pointing, alphanumeric _ characters etc depending upon the device used, Input can be either a data or an instruction. The Keyboard is a type of input device that gives data — 20 Programming In yuter Hardware Figure 1.3: Components of a Comp as input to the computer whereas mouse usually gives instructions through clicks. 2, Processing Unit: Processing unit consists of various parts like CU, ALU, Registers and is often referred to as an electronic brain of a computer m. This unit is responsible for performing overall operations of a computer system. After the input device provides raw data to the computer system, CPU performs specific operations like, addition, subtraction, division ete and produces a result which we call an output, CPU can also access data from secondary storage of computer via primary memory. To carry out any operations the CPU assigns tasks to its component. . 21 Programming In G Components of a Processing Unit i i LU is a logical unit of CPU, This i“ vensing of the data and instructions. Whey unit is responsible for the processing 0 : : : the CU encounters instructions which are related : ee ae or arithmetic operation on data, it passes that instruction ie artis out arithmetic operations like additions, multiplication, divisions etc, The comparison operations that arithmetic logical unit beasiataat comparison — like less than, greater than, less than or equal to, greater than or equal to, 1 not equal to etc. Logical operations includes OR, AND, NOT etc. The data on which ALU performs operations are fetched from memory unit. After the processing completes, the information or result is sent back to the storage or an output device. Gi) : . Registers are not referenced by their address manipulated by the CPU during in: ta, i but are directly accessed ai execution. R Z ons that require processing must b gh in the registers of CPU before they can be processed. For example, if two numbers are to be added, both numbers are brought in the registers, added and the result is also placed in a register. Registers are classified as- Accumulator:This is the most frequently used register used to store data taken from memory, It is in different numbers in different microprocessors. Memory Address Registers (MAR): It holds the address of the location to be accessed from memory. MAR and MDR (Memory Data Register) together facilitate the communication of the CPU and the main memory. Memory Data Registers (MDR): It contains data to be written into — or to be read out from the addressed location, 3 General Purpose Registers: These ave numbered as RO, R1 R2....Rn, © and used to store temporary data during any ongoing oper ation. TE content can be accessed by assembly programming, Z 22 oes Programming In.C Program Counter (PC): Program Counter (PC) is used to keep the track of execution of the program. It contains the memory address of the next instruction to be fetched. PC points to the address of the next instruction to be fetched from the main memory when the previous instruction has been successfully completed. Program Counter (PC) also functions to count the number of instructions. Instruction Register (IR): It is the register which holds the instruction which is currently been executed. Data Register (DR): It stores the operands and any other data. (iii) Control Unit (CU):Control unit is another part of CPU. It supervises the overall operations of other units of the computer. The CU acts as the central nervous system and controls the processing of data according to the instruction given to the computer. e Control unit also determines the sequences of program and instruction’s execution. (iv) Memory Unit:The Memory unit of a computer system is what provides the data that CPU needs for processing. There is a primary and secondary memory in the computer system. Primary memory holds the data so that CPU can process it. The data that CPU process should be pulled to primary ‘memory (RAM) from secondary storage device. (v) Storage Unit:The Storage unit is also a part of a block diagram of computer. Storage unit or secondary storage unit is a non-volatile device that holds programs, files, documents. It provides facilities to store a large volume of data. CPU executes the data stored on storage devices indirectly. The data are transferred to RAM first and after an execution, the data can be again written to storage unit. 3. Output Unit:The output unit of a computer system are the collections of hardware components that show output to the user either in hard-copy or a soft-copy format, After CPU completes the processing on the data, the outcome of processing also known as output or a result is passed to this 23 Programming In C ; It i unit, The output unit is responsible for translating the result in hy understandable format and displaying it- 1.7 Memory > The memory unit consists of cache memory and primary ered Prim; 7 memory or main memory of the computer is used to store the data and” instructions during execution of the instructions. Random Access Memory 9 (RAM) and Read Only Memory(ROM) are the primary memory. There is another kind of storage device known as secondary storage. Secondary memory is non volatile and is used for permanent storage of data and programs, Cache memory e The data and instructions that are required during the processing of — data are brought from the secondary storage devices and stored in the RAM. For processing, it is required that the data and instructions are accessed from the RAM and stored in the registers. © Cache memory is a very high speed memory placed in-between RAM _ and CPU. Cache memory increases the speed of processing. ‘© Cache memory is a storage buffer that stores the data that is used _ more often, temporarily, and makes them available to CPU at a fast rate. During processing, CPU first checks cache for the required data. If data is not found in cache, then it looks in the RAM for data. + To access the cache memory,CPU does not have to use the motherboard’s 4 system bus for data transfer, ¢ Cache memory is built into the processor and may also be located next to it on a separate chip between the CPU and RAM. Cache built into the CPU is faster than separate cache, running at the speed of the — microprocessor itself. However, separate cache ig roughly twice as fast — as RAM. cache and Level? (L2) cache. In some CPU has a separate cache on the motherboard is called’ 4 ‘@ The CPU has a built in Levelt (L1) addition to built in L1 and L2 cache, chip on the motherboard. This cach 24 Programming In C Level (L3) cache, High end processor comes with built in L3 cache like Intel core [Link] L1,1.2,L3 stores the most recently run instructions ,the next ones, possible ones respectively. CPU's have cache size varying from 256K (1.1), 6MB(L2),to 12MB(L3) cache. e Cache memor, very expensive, so it is smaller in size. Generally, Primary Memory - Primary memory is the main memory of computer. It is used to store data and instructions during the processing of data. Primary memory is semiconductor memory. Primary memory is of two kinds-Random Access Memory(RAM) and Read Only Memory(ROM). “* RAMis volatile. It stores data when the computer is ON. The information stored in RAM gets erased when the computer is turned off. RAM provides temporary storage for data and instructions. ROM is non volatile memory, but is a read only memory. The storage in ROM is permanent in nature, and is used for storing programs that permanently reside in the computer. ROM comes programmed by the manufacturer. RAM stores data and instructions during the execution of instructions. The data and instructions that require processing are brought into the RAM from the storage devices like hard disk. CPU accesses the data and instructions from RAM, as it can access it at a fast speed. © The input data that is entered using the input unit is stored in RAM, to be made available during processing of data. Similarly the output data generated after processing is stored in RAM before being sent to the output device. r i gram, Secondary Memory _ The secondary memory stores data and instructions permanently. The information can be stored in secondary memory for long time and is generally permanent in nature unless erased by user. It isa non volatile memory. 25 Programming In C nd instructions. Hard disk drive, © It provides back up storage for data ie cxamples of storage devical Floppy drive and optical drives are 80) ly not being used by cpu, instructi that are currentl: 3 © The data and instructions that tored in secondary memory, but may be required later for processing are $ Secondary memory has a high storage capacity than primary memory, — © Secondary memory is also cheaper than primary memory. © It takes longer time to access the data and instructions stored in secondary memory than in primary memory. 1.8 Input And Output Devices An I/O unit is a component of computer. The I/O unit is composed of two parts input units and output units. The input unit is responsible for providing input to the computer and output unit is for receiving output from the computer. Input Unit ¢ The input unit gets the data and program from various input devices and makes them available for processing to other units of the computer. e The input data is provided through input devices such as-Keyboard, mouse, trackball and joystick. Input data can also be provided by scanning images, voice recording, video recording etc. « Irrespective of the kind of input data provided to a computer, all input devices must translate the input data into a form that is understandable by the computer,i.c, in machine readable form. Output Unit ¢ The output unit gets the processed data from computer and send it to output devices to make them available to the user of computer. ¢ The output data is provided through out put devices like di printer, plotter and speaker, ces like display screen, ova Programming In C Input Devices Input devices allow users and other applications to input data into the computer for processing. The data input to the computer can be in the form of text,audio,video etc. Figure 1.4: Input Devices Input devices can be classified as ¢ Human data entry devices a) Keyboard b) Pointing devices -mouse,trackball,joystick,tablet c) Pick devices-light pen,touch screen Source data entry devices a) Audio input - speech recognition b) Video input - digital camera c) Scanner - hand held scammer, flat bed scanner )Optical Seanner - OCR, OMR, MICR, bar-code reader ‘Output Devices Output devices provide output to the user, which is generated after processing the input data. The processed data presented to the user via the output devices could be text, graphics, audio or video. Output devices are classified as follows 27 Programming In C MonTOR HeAUH HONE Output Devices of Computer 4 Necdbead PROJECTOR OS Figure 1.5: Output Devices ¢ Hard copy devices a) Printer b) Plotter c) Computer output on microfilm ¢ Soft copy devices a) Monitor b) Visual Display Terminal c) Audio Response Printers are output devices used to prepare permanent output on paper Printers can be divided into two main categories as Impact Printers (dot inatrix, daisy wheel, drum), and Non-Impact Printers (ink-jet, laser). 4 1. Impact Printers: In this hammers or pins strike against a ribbon ant paper to print the text. This mechanism is known as electro-mechanical | mechanism. They are of two types. a) Character Printer: It prints only one character at a time. It has relatively slower speed. Ex. Dot: matrix printers. pins on the print head of the printer which form the character. The compute memory sends one character at a time to be printed by the printer, There i a carbon between the pins & the paper. The words get printed on the papel 28 Programming In C when the pin strikes the carbon. ‘There are generally 24 pins. b) Line Printers: Drum Printers are line printers. They are expensive and faster than character printers but produce a low quality output. They can print 200-2500 lines per minute, Drum printers are generally used for voluminous print outputs. 2. Non-Impact Printers: These printers use non-Impact technology such as ink-jet or laser technology. They provide better quality of output at higher speed. They are of two types : a) Ink-Jet Printer : It prints characters by spraying patterns of ink on the paper from a nozzle or jet. It prints from nozzles having very fine holes, from which a specially made ink is pumped out to create various letters and shapes. The ink comes out of the nozzle in a form of vapors. After passing through a reflecting plate, it forms the desired letter/shape at the desired place. b)Laser Printer: Laser Printer is a type of printer that utilizes a laser beam to produce an image on a drum. The light of the laser alters the electrical charge on the drum wherever it hits. The drum is then rolled through a reservoir of toner, which is picked up by the charged portions of the drum. Finally, the toner is transferred to the paper through a combination of heat and pressure. This is also the way copy machines work. Because an entire page is transmitted to adrum before the toner is applied, laser printers are sometimes called page printers. There are two other types of page printers that fall under the category of Jaser printers even though they do not use lasers at all. One uses an arrey of LED's to expose the drum and the other uses LCD's. Once the drum is charged, howover, they both operate like a real laser prin One of the chief characteristics of laser printers is their resolution — how many dots per inch (dpi) they lay down. ‘The available resolutions range from 300 dpi at the low end to 1,200 dpi at the high end. In addition to text, laser printers are very adept at printing graphics, so you need significant 29 Programming In C i i int high- amounts of memory in the printer to prin : print a full-page graphic at 300 dpi, for example, you need at least 1 fi (megabyte) of printer RAM. For a 600 dpi graphic, you need at least, 4 RAM. Because laser printers are non-impact printers, they are much quieter dot -matrix or daisy-wheel printers. They are also relatively fast, alth not as fast as some dot-matrix or daisy-wheel printers. The speed of } printers ranges from about 4 to 20 pages of text per minute (ppm). A ty; tate of 6ppm is equivalent to about 40 characters per second (cps). Chapter 2 APPLICATION SOFTWARE & SYSTEM SOFTWARE 2.1 Types of Software ‘The software is a kind of programs that enable a user to perform some specific task or used to operate a computer. It directs all the peripheral devices on a computer system - what to do and how to perform work. Without Software, we can’t operate hardware and perform any calculations. A computer system can be divided into three components: the hardware, the software and the users. The software can be further divided into mainly two parts: Application software and System Software. Bare use of hardware is not easy, so to make it easy software is created. System Software System Software (a type of computer program) provides a platforin to run computer’s hardware and computer application to utilise system resources and solve their computation problem. It is written in a low-level language, like assembly language so it can easily interact with hardware with basic level. It controls working of peripheral devices. System software act as a scheduler for the execution of the processes and arrange the sequence according to their priority and I/O devices requirement and creation of the process. The best-known example of system software is the operating system(OS). Tt manages all the other programs on a computer. Application Software Applications software is capable of dealing with user inputs and helps the user to complete the task. It is also called end-user programs or only an app. It resides above system software. First user deal with system software after that he/she deals with application software. The end user uses applications software for a specific purpose, It programmed for simple as well as complex tasks. It is either installed or accessed online. It can be a single program or a group of small programs that refers to as an application suite. 31 Programming In C cation software are Word processing software, Spreadsh Some examples of appli g email etc. Software, Presentation, Graphics, CAD/CAM, Sendin Difference between System Software and Application Software System Software Application Software System software is used for operating computer hardware. Application software is used by user perform specific task. System software’s are installed on the computer when operating system is installed. Application softwares are installey according to user’s requirements. In general, the user does not interact with system software because it works In general, the user interacts with application softwares. for running application softwares. in the background. System software can run | Application software can’t rum [Link] provides platform independently. They can’t run without the presence of system software. Some examples of system software's are compiler, assembler, debugger, driver, etc. Some examples of application software’s are word processor, web browser, media player, etc. 2.2 Compilers A compiler is a software program that transforms high-level source code that is written by a developer in a high-level level object code (binary code) in machine by the processor, The process of conver machine language is known as compilati The processor executes object code, which in low signals are required in the arithmetic log’ Programming language into a. low language, which can be understood rting high-level programming into ion, ndlicates when binary high and 1 Unit of the processor, Programming In C 2.3 Interpreter ‘An interpreter is a computer program that is used to directly execute program instructions written using one of the many high-level programming languages. The interpreter transforms the high-level program into an intermediate language that it then executes, or it could parse the high-level source code and then performs the commands directly, which is done line by line or statement, by ‘statement. Difference between Compiler and Interpreter Interpreter Tt considers only one statement in your program at a time as input for converting to machine code. Tt doesn’t create an intermediate object (.obj) code. Slower execution of control statements. Compiler Tt considers the completion of your program as input for converting to machine code. Tt usually generates intermediate code in the form of the object file (.obj). Faster execution of control statements as compared to the interpreter. Detected errors in the program get displayed after the entire program is read by compiler. Example: C++, Java. Detected errors in the program get displayed after each instruction read by the interpreter. Example: BASIC, Python, PHP. 2.4 High Level Language A computer program is a list of instructions that enable a computer to perform a specific task. Computer programs can be written in high and low level languages, depending on the task and the hardware being used. The programming language should be understood, both by the programmer (who is writing the program) and the computer, A computer understands mmer is more comfortable with the language of 0’s and 1’s, while the prograt A A high-level language(HILL) is a programming English-like language. language such as C,FORTRAN, or Pascal that enables @ proe tn Jess independent of a particular type © dered high-level because write programs that are more or computer. Such languages are consi ner to they are closer 33 Programming In C pine languages. to human languages and farther from mac Advantages of High-Level Languages The main advantage of high-level languages over low-level languages they are easier to read, write, and maintain. Ultimately, programs writte a high-level language must be translated into machine language by a comy or interpreter. The first high-level programming languages were designed in the 1950s. No there are dozens of different languages, including Ada, Algol,BASIC, COBOI C, C++, FORTRAN, LISP, Pascal, and Prolog. 2.5 Low Level Language Low-level languages are closer to the hardware than high-level progr. languages, which are closer to human languages. Low level languages ate used to write programs that relate to the specific ar Shard Q of @ particular type of computer, a chitecture and hardn uter, machine ], nbly language is a low level language, Fo ee eueg® or am asseitl level assembly language, but it is stil ured ta hardware, such as device drivers, It is ensy dren language as it: contains few recognisable human 'Y write in machine c i: understand. ode (bi 34 Programming In Difference between High level language and Low level language High level language Low level language Programmer friendly language Mochi friendly language less memory efficient. high memory efficient. easy to understand difficult to understand i simple to debug. complex to debug comparatively. simple to maintain. complex to maintain comparatively. It is portable. It is non-portable. Tt can run on any platform. Tt is machine-dependent. Tt needs compiler or interpreter for translation. Tt needs assembler for translation. 35 Chapter 3 STRUCTURED PROGRAMMING ach In Programming roach’, as: the word suggests, can be in which the program is made as a sin instruction by instruction 3.1 Structured Appro ‘Structured Programming APP defined as a programming approach i 1 ; structure. It means that the code will execute one after the other. It doesn’t support the possibi r instruction to some other with the help of any statement like GOTO, ete, Therefore, the instructions in this approach will be executed in a serial and structured manner. The languages that support Structured programming approach are: Cc CHt+ Java oe ' ete.. On the contrary, in the Assembly languages like Microprocessor 8085, etc, — the statements do not get executed in a str ‘a as ructure : a statements like GOTO. So the program flow mige manner. Tt allows Jam om. The structured program mainly consist; Pee Ss of three t; ‘Yypes of elements: e Selection Statements 36 Programming In C Sequence Statements: Iteration Statements ‘The structured program consists of well structured and separated modules. But the entry and exit in a Structured program is a single-time event. It means that the program uses single-entry and single-exit elements. Therefore a structured program is well maintained, neat and clean program. This is the reason why the Structured programming approach is well accepted in the programming world. Advantages of Structured Programming Approach 1. Easier to read and understand. ; 2. User Friendly. 3. Easier to Maintain. 4. Mainly problem based instead of being machine based. 5. Development is easier as it requires less effort and time. 6. Easier to Debug. 7. Machine-Independent, mostly. Disadvantages of Structured Programming Approach 1, Since it is Machine-Independent, it takes time to convert into machine code. 2, The converted machine code is not the same as for assembly language. 3, The program depends upon changeable factors like data-typ it needs to be updated with the need on the go. time as it is language, the achine. 4, Usually the development: in this approach takes longer language-dependent. Whereas in the case of assembly development takes lesser time as it is fixed for the m 37 es. Therefore Programming In i ach 3.2 Procedural Programming Appro may be the first ee Paradigm, the procedural co that. a new developer will learn. Fundamentally finish a task in ee the one that directly instructs @ device on n approach and treats dat steps. This paradigm uses a Tinear topmdow! the concept of a’ proce and procedures as two different entities. Based on t' to procedures, which call, Procedural Programming divides the program 1”! a ‘a geries ‘of stegel also known as routines or functions, simply containing CPs to be carried out. Procedural Programming approach Simply put, Procedural programming involves writing down a list of instru to tell the computer what it should do step-by-step to finish the task at ha Key Features of Procedural Programming Predefined functions: A predefined function is typically an instructi identified by a name. Usually, the predefined functions are built into higher-level programming languages, but they are derived from the — library or the registry, rather than the program. One example of a pre-defined function is ‘charAt ()’, which searches for a character position in a string. . Global Variable: A global varialy outside every other function define variables can be used in all functioi le is a variable which is declared din the code. Due to this, global ns, unlike a local variable. © Modularity: different tasks at hand but are grou task first. Every group of finished one after the other until all tasks are compl e Parameter Passing: Par ‘ameter Passing: j, ao ; parameters to functions, subroutines or as eduren asm used to pal Procedures. Parameter Passing. 38 Programming In C can be done through ‘pass by value’, ‘pass by reference’, ‘pass by result’, ‘pass by value-result” and ‘pass by the name’. Advantages and Disadvantages of Procedural Programming Procedural programming comes with its own set of pros and cons, some of which are mentioned below. Advantages © Procedural Programming is excellent for general-purpose programming. © The coded simplicity along with ease of implementation of compilers and interpreters © A large variety of books and online course material available on tested algorithms, making it casicr to learn along the way. © The source code is portable, therefore, it can be used to target a different CPU as well. © The code can be reused in different parts of the program, without the need to copy it. Through Procedural Programming technique, the memory requirement also slashes. ¢ The program flow can be tracked easily. Disadvantages © The program code is harder to write when Procedural Programming is employed. ‘© The Procedural code is often not reusable, which may pose the need to recreate the code if is needed to use in another application © Difficult to relate with real-world objects. The importance is given to the operation rather than the data, which might pose issues in some data-sensitive cases. © The data is exposed to the whole program, making it not so much security friendly. 39 Programming | gramming (OOP) Approa 3.3 Object-Oriented Pro: ig which recognizes life as we kno OOP is an approach to programming H : Wj as a coltectivd of objects, which work in tandem with each othe; , solve a particular problem at hand. The Oa eae ab OOP is encapsulation, which is the idea that eat ; obj a ea program is self-sustainable, which means that all the oe j Ss t at n up the object are within the object itself. Now since each module within thy paradigm is self-sustainable, objects can be taken from one program and tse, to resolve another problem at: hand with little or no altcrations. Advantages © Due to modularity and encapsulation, OOP offers case of management | e OOP mimics the real world, making it easier to understand. ¢ Since objects are whole within themselves, they are reusable in other | programs Disadvantages * Object-Oriented programs tend to be slower and use up a high amount of memory. © Over-generalization 3.4 Algorithm And Flow Chart Algorithm An algorithm is a step by step methog of s f solving a rob! mmo a 8 @ problem. It is co ly 40 Programming In C used for data processing, calculation and other related computer and mathematical operations. It must have the following characteristics: © Clear and Unambiguous: Algorithm should be clear and unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning. © Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs. © Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it should be well-defined as well. « Finiteness: The algorithm must be finite, i.e. it should not end up in an infinite loops or similar. Feasible: The algorithm must be simple, generic and practical, such that it can be executed upon will the available resources. It must not contain some future technology, or anything. « Language Independent: The Algorithm designed must be language-independent, i.e. it must be just plain instructions that can be implemented in any language, and yet the output will be same, as expected. Flowchart Flowchart is a diagrammatic representation of an algorithm. Flowclart is very helpful in writing program and explaining program to others. Symbols Used In Flowchart Different symbols are used for different states in flowchart, For example: Input/Output and decision making has different symbols. The following figure describes all the symbols that are used in making flowchart. 41 [Sembor | Purpose, ca to indicate the flow of logic by connecting eset .d end of flowchart animal a Gsed to represent staft eeminastop’St"0 sed fer input and ouput OPe*=N OT: Used for airthmetic operations and data- | =| ing esiipurations. jon in which there are ed to represent the operation if SP used to scrives rue and false. jin different flowline bo prnomm fewe lUused to connect flowchart portion on different benwcmew [Used to represent a group of statements performing one processing task. i i g ll Figure 3.1: Symbols used in Flowchart Example 1: Algorithm to find the sum of 5 numbers Algorithm (in simple English) 1. Initialize the variables sum = 0 and count = 0 //(PROCESS) 2. Enter the number n //(I/O) 3. Pind sum + n and assign it to variable sum and then i t by 1 //(PROCESS) en increment count 4, Is count < 5 //(DECISION) 5. if YES go to step 2 else e Print sum //(I/O) Example 2: Algorithm to print Hi Algorithm (in simple English) ello World 10 times 1, Initialize count. = 0 //(PROCESS) 2. Print Hello World //(1/0) 42 Programming In C Figure 3.2: Flowchart to find the sum of 5 numbers 3. Increment count by 1 (PROCESS) 4, Is count < 10 (DECISION) 5. if YES go to step 2 else STOP Figure 3.3: Flowchart to print ‘Hello World’ 10 times 43 Daciare variables ured pum? woe sue Figure 3.4: Flowchart to add two numbers entered by user Example 4: Flowchart to find the largest among three different numbers entered by user Figure 3.5: Flowchart to find the largest among three numbers le 5: Flowchart to fi ‘ol err . i rw © find all the roots of a quadratic equation 44 Programming In C Figure 3.6: Flowchart to find the roots of a quadratic equation 3.5. Bubble Sort Bubble sort is an algorithm that compares the adjacent elements and swaps their positions if they are not in the intended order. The order can be ascending or descending. How Bubble Sort Works? 1. Starting from the first index, compare the first and the second elements. If the first element is greater than the second element, they are swapped. Now, compare the second and the third elements. Swap them if they are not in order. The above process goes on until the last element. 2. The same process goes on for the remaining iterations. After each iteration, the largest clement among the unsorted clements is placed at the end. In each iteration, the comparison takes place up to the last unsorted element. The array is sorted when all the unsorted elements are placed at their correct positions. 45 iven. Consider an unsorted array as BiVe Bubble sort starts with very first two elements, comparing them to che which one is greater. In this case, value 33 is greater than 14, so it is already in sorted k Next, we compare 33 with 27. The new array should look like this- Next we compare 33 and 35, positions. * We find that both are in already 46 Programming In C Then we move to the next two values, 35 and 10. ‘We swap these values. We find that we have reached the end of the array. After the first iteration, the array should look like this j a To be precise, we are now showing how an array should look like after cach iteration. After the second iteration, it, should look like this Notice that after cach iteration, at least one valuc moves at the end. (AE) And when there’s no swap required, bubble sorts learns that an array is completely sorted. 47 for Bubble Sort st of sortable items ) 3.6 Pseudo code procedure pubbleSort( A: z n= length(A) repeat fal swapped = false for 2 1 to n-1 inclusive do if Afi-t] >Ali] then swap(A[i-1], Ali) swapped = true end if end for n=n-l ‘until not swapped end procedure 3.7 Linear Search Linear search is a very simple search algorithm. In this type of se: sequential search is made over all items one by one. Every item is che and if a match is found then that particular item is returned, otherwise th search continues till the end of the data collection. Linear Search ( Array A, Value x) Step 1: Set itol Step 2: ifi > n then go to step 7 Step 3: if Ali] = x then go to step 6 Step 4: Setitoi+1 Step 5: Go to Step 2 Step 6: Print Element x Found at i : zp vs Prin element not found" 184 go to step 8 a

You might also like