I ns t i t ut eo fMa na g e me nt & Te c hni c a lSt udi e s
COMPUTERFUNDAMENTAL & CPROGRAMMI NG 500
Ma s t e ri nCo mp u t e rAp p l i c a t i o n www. i mt s i ns t i t ut e . c om
IMTS (ISO 9001-2008 Internationally Certified) COMPUTER FUNDAMENTAL & C PROGRAMMING
COMPUTER FUNDAMENTAL & C PROGRAMMING
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
CONTENTS: UNIT – I
01-23
Introduction to computers: Introduction–Types of Computers-Characteristics of Computers-Word Length-speed-Storage-Accuracy-Versatility-AutomationDiligence.
Five generations of modern Computers: First Generation
Computers-Second Generation Computers-Third Generation ComputersFourth Generation Computers- Fifth Generation Computers. Classifications of digital computer system: Introduction- Microcomputers-Personal ComputersWorkstations-PortableComputers-Minicomputers-MainframesSupercomputers -Network Computers.
Number system:
Introduction-
Decimal Number System -Binary number System-Binary to decimal Conversion-Decimal to Binary Conversion-Binary Addition-Binary SubtractionComplements -9’s Complement -10’s Complement-1’s Complement-2’s Complement-Signed
and
unsigned
Number
Representation-Fixed-point
Representation of numbers-Floating-point Representation of Numbers-Binary Coded Decimal-Gray Code-Excess-3 Code –ASCII-8 Code-EBCDIC CodeBits, Bytes and Words-Octal Number System-Hexadecimal Number System. UNIT – II Boolean Algebra and Gate Networks:
24-54 Fundamental concepts of Boolean
Algebra-Logical Multiplication –AND Gates and OR Gates-Complementation and Inverters – Evaluation of Logical Expressions – Evaluation of an Expression containing parentheses – Basic Laws of Boolean Algebra – Simplification of expressions – De Morgan’s theorems – Basic Duality of Boolean Algebra – Derivation of a Boolean Expression – Interconnecting Gates-Sum of products and products of sums – Derivation of products of sums expressions – Derivation of three Input variable expression – NAND gates and NOR gates – The Map method for simplifying expressions – Sub cubes and covering – Product of sums. Expressions – Don’t care.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
UNIT – III Anatomy of a Digital:
55-80 Functions and Components of a Computer
Central Processing Unit-Control Unit – Arithmetic Logic Unit-Memory – Registers Addresses – How the CPU and Memory Work. Memory units : Introduction – RAM – ROM – EPROM – EEPROM – Flash memory. Input Devices: Introduction-Keyboard-Mouse-Types of Mice-Connections-Mouse Pad-Trackball – Joystick – Digitizing Tablet – Scanners – Digital Camera – MICR-OCR-OMR- Barcode Reader – speech input Devices-continuous speech- Discrete Word-Touch Screen – Touch Pad-Light Pen.
Output
Devices: Introduction-Monitor – Classification of Monitors – Based on Color – Classification of Monitors Based on signals – characteristics of a Monitor – Video Standards-Printer-Plotter-Sound Cards and Speakers – Auxiliary storage Devices : Introduction – Magnetic Tape – Hard disk – Floppy Disk – CD-ROM-CD-R Drive-CD-RW Disks. UNIT-IV
81-127
Dos – Wordstar – Database Management System – Dbase III plus – Electronic Spreadsheets – LOTUS 1-2-3 – Internet – Electronic Mail. UNIT-V
128-182
MS-WINDOWS – MS-WORD – MS-EXCEL – Introduction to Desktop publishing – Overview of Power point
UNIT-V
183-236
Overview Of C: History Of C – Importance Of C – Basic Structure Of C Programs. Constants, Variables and Data Types. Operators and Expression. Managing Input And Output Operations: Reading And Writing A Character –Formatted Input And Output. Decision Making And Branching: Simple If, If-Else, Nesting Of If-Else, Else-If Ladder, Switch Statements – Goto Statements. Decision Making And Looping: While Statement - Do Statement- For Statement.
UNIT-VI
237-269
Structure And Unions. Arrays: Definition – One Dimensional Arrays – Declaration Of One-Dimensional Arrays – Initialization Of One-Dimensional
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
Arrays – Two-Dimensional Arrays- Initializing Two Dimensional Arrays – Multidimensional Arrays – Dynamic Arrays.
UNIT-VII
270-298
Character Arrays And Strings: Introduction – Declaring And Initializing String Variables – Reading Strings From Terminal – Writing Strings To Screen – String Handling Functions – Pointers – Files – Opening/Closing Files – Files – Input/Output – Error Handling During I/O Operations – Random Access To Files – Command Line Arguments.
UNIT QUESTIONS
299-317
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
UNIT-I INTRODUCTION TO COMPUTERS 1.0 Introduction 1.1 Types of Computers 1.2 Characteristics of Computers 1.3 Five Generations of Modern Computers 1.4 Classification of Digital Computer Systems 1.4.1 Introduction 1.4.2 Microcomputers 1.4.3 Minicomputers 1.4.4 Mainframes 1.4.5 Supercomputers 1.4.6 Network computers 1.5 Number System 1.5.1 Introduction 1.5.2 Decimal Number System 1.5.3 Binary Number System 1.5.4 Complements 1.5.5 Signed and Unsigned Number Representations 1.5.6 Fixed – Point Representation of Numbers 1.5.7 Floating – Point Representation of Numbers 1.5.8 Binary Coded Decimal (BCD) 1.5.9 Gray Code 1.5.10 Excess-3 Code 1.5.11 ASCII CODE 1.5.12 EBCDIC CODE 1.5.13 Bits, Bytes and Words 1.5.14 Octal Number System 1.5.15 Hexadecimal Number System
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
1
COMPUTER FUNDAMENTAL & C PROGRAMMING
1.0 INTRODUCTION
A computer is a programmable machine. The two principal characteristics of a computer are :
It responds to a specific set of instructions in a well-defined manner.
It can execute a prerecorded list of instructions (a program)
Modern computers are electronic and digital. The actual machinery – wires, transistors, and circuits – is called hardware; the instructions and data are called software. All general – purpose computers require the following hardware components:
Central processing unit (CPU) The “heart” of the computer, the component that actually executes instructions.
Memory Enables a computer to store, atleast temporarily, data and programs.
Input device Usually a keyboard or mouse, the input device is the conduit through which data and instructions enter a computer.
Output device A display screen, printer, or other such devices that lets you see what the computer has accomplished.
Mass storage device Allows a computer to permanently retain large amounts of data. Common mass storage devices include disk drives and tape drives. In addition to these components, many others make it possible for the basic
components of a computer to work together efficiently. For example, every computer requires a bus that transmits data from one part of the computer to another.
1.1 TYPES OF COMPUTERS Computers can be classified by their size and power as follows:
Personal computer A small, single – user computer based on a microprocessor. In addition to the microprocessor, a personal computer has a keyboard for entering data, a monitor for displaying information, and a storage device for saving data.
Workstation A powerful, single-user computer. A workstation is like a personal computer, but it has a more powerful microprocessor and a higher-quality monitor.
Minicomputer A multi-user computer capable of supporting 10 to hundreds of users simultaneously.
Mainframe A powerful multi-user computer capable of supporting many hundreds of users simultaneously.
Supercomputer An extremely fast computer that can perform hundreds of millions of instructions per second.
1.2 CHARACTERISTICS OF COMPUTERS All computers have certain common characteristics irrespective of their type and size.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
2
COMPUTER FUNDAMENTAL & C PROGRAMMING
Word Length A digital computer operates on binary digits – 0 and 1. It can understand information only in terms of 0s and 1s. A binary digit is called a bit. A group of 8 bits is called a byte. The number of bits that a computer can process at a time in parallel is called its word length. Commonly used word lengths are 8, 16, 32 or 64 bits. Word length is the measure of the computing power of a computer.
Speed Computers can calculate at very high speeds. A microcomputer, for example, can execute millions of instructions per second over and over again without any mistake. As the power of the computer increases, the speed also increases. For example, supercomputers can operate at speeds measured in nanoseconds and even in picoseconds – one thousand to one million times faster than microcomputers.
Storage Computers have their main memory and auxiliary memory systems. A computer can store a large amount of data. With more and more auxiliary storage devices, which are capable of storing huge amounts of data, the storage capacity of a computer is virtually unlimited. The factor that makes computer storage unique is not that it can store vast amount of data, but the fact that it can retrieve the information that the user wants in a few seconds.
Accuracy The accuracy of a computer system is very high. Errors in hardware can occur, but error detecting and correcting techniques will prevent false results. In most cases, the errors are due to the human factor rather than the technological flaws. For example, if a program is wrongly coded, if the data is corrupted, or if the program logic is flawed, then irrespective on which computer you run it, you will always get wrong results. Another area where mistakes can creep in is during data entry. People often make mistakes when data is keyed-in and the computer accepts whatever that is keyed-in. So if a wrong input is given, the output also will be wrong – GIGO (Garbage In Garbage Out).
Versatility Computers are very versatile machines. They can perform activities ranging from simple calculations to performing complex CAD modeling and simulation to navigating missiles and satellites. In other words, they are capable of performing almost any task, provided the task can be reduced to a series of logical steps. Computers can communicate with other computers and can receive and send data in various forms like text, sound, video, graphics, etc. This ability of computer to communicate to one another has led to the development of computer networks, Internet, WWW and so on.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
3
COMPUTER FUNDAMENTAL & C PROGRAMMING
Automation The level of automation achieved in a computer is phenomenal. It is not a simple calculator where you have to punch in the numbers and press the ‘equal to’ sign to get the result. Once a task is initiated, computers can proceed on its own till its completion. Computers can be programmed to perform a series of complex tasks involving multiple programs. Computers will perform these things flawlessly. They will execute the programs in the correct sequence, they will switch on/off the machines at the appropriate time, they will monitor the operational parameters, they will send warning signals or take corrective actions if the parameters exceed the control level, and so on. Computers are capable of theses levels of automation, provided they are programmed correctly.
Diligence Diligence means being constant and earnest in effort and application. Human beings suffer fro weakness like tiredness, lack of concentration, etc. Humans have feelings, they become sad, depressed, bored, and negligent and it will reflect on the work they do. Moreover, human beings cannot perform the same or similar tasks over and over again with the same precision, accuracy and enthusiasm as the first time. After some time, people will become bored and tedium will set in. This will affect the performance. Being a machine, a computer does not have any of these human weaknesses. They won’t get tired or bored. They will not go into depression or loose concentration. They will perform the tasks that are given to them, irrespective of whether it is interesting, creative, monotonous or boring, irrespective of whether it is the first time or the millionth time, with exactly the same accuracy and speed.
1.3 FIVE GENERATIONS OF MODERN COMPUTERS The computers are classified into different generations – from first generation to fifth generation computers. The classification and the time period is given bellow: 1. First Generation (1945-1956) 2. Second Generation (1956-1963) 3. Third Generation (1964-1971) 4. Fourth Generation (1971 – Present) 5. Fifth Generation (Present and Beyond)
FIRST GENERATION (1945-1956) John Presper Eckert (1919-1995) and John W.Mauchly(1907-1980), built the first digital computer using parts called vacuum tubes. They named their new invention ENIAC. Consisting of 18,000 vacuum tubes, 70,000 resistors and 5 million soldered joints.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
4
COMPUTER FUNDAMENTAL & C PROGRAMMING Von Neumann designed the Electronic Discrete Variable Automatic Computer (EDVAC) in 1947 with a memory to hold both a stored program as well as data. This “stored memory” technique as well as the “conditional control transfer”, that allowed the computer to be stopped at any point and then resumed, allowed for greater versatility in computer programming. The key element to the Von Neumann architecture was the central processing unit, which allowed all computer functions to be coordinated through a single source. In 1951, UNIVSC I (Universal Automatic Computer), built by Remington Rand, became one of the first commercially available computer.
SECOND GENERATION COMPUTERS (1956-1963) Second – generation computers replaced machine language with assembly language, allowing abbreviated programming codes to replace long, difficult binary codes. There were a number of commercially successful second-generation computers used in businesses, universities, and government. These second-generation computers were also of solid state design, and contained transistors in place of vacuum tubes. It was the stored program and programming language that gave computers the flexibility to finally be cost effective and productive for business use. The stored program concept meant that instructions to run a computer for a specific function (known as a program) were held inside the computer’s memory, and could quickly be replaced by a different set of instructions for a different function. A computer could print customer invoices and minutes later design products or calculate pay cheques. More sophisticated high-level languages such as COBOL (Common Business-Oriented Language) and FORTRAN (Formula Translator) came into common use during this time, and have expanded to the current day. These languages replaced cryptic binary machine code with words, sentences, and mathematical formulae, making it much easier to program a computer. New types of careers (programmer, analyst, and computer system expert) and the entire software industry began with second generation computers. Paralleling the development of second-generation system was the creation of a new industry, built around the idea of integrating transistors and other components into circuits that could be placed on small chips of silicon.
THIRD GENERATION COMPUTERS (1964-1971) Though transistors were clearly an improvement over the vacuum tube, they still generated a great deal of heat, which damaged the computer’s sensitive internal parts. The quartz rock eliminated this problem. The IC combined three electronic components onto a small silicon disc, which was made from quartz. Scientists later managed to fit even more components on a single chip, called a semiconductor. Third generation development included the use of an operating system that allowed machines to run many different programs at once with a central program that monitored and coordinated the computer’s memory.
FOURTH GENERATION COMPUTERS ( 1971-PRESENT)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
5
COMPUTER FUNDAMENTAL & C PROGRAMMING After the integrated circuits, the only place to go was down – in size, that is. Large – scale integration (LSI) could fit hundreds of components onto one chip. Very large scale integration (VLSI) squeezed hundreds of thousands of components onto a chip. Ultra – large scale integration (ULSI) increased that number into the millions. The ability to fit so much onto an area about half the size of one-rupee coin helped diminish the size and price of computers. It also increased their power, efficiency and reliability. One microprocessor could be manufactured and then programmed to meet any number of demands. Soon everyday household items such as microwave ovens, television sets and automobiles incorporated microprocessors. There minicomputers came complete with user-friendly software packages that offered even non-technical users an array of applications, most popularly word processing and spreadsheet programs. FIFTH GENRATION (PRESENT AND BEYOND) Many advances in the science of computer design and technology are coming together to enable the creation of fifth-generation computers. Another advance is superconductor technology, which allows the flow of electricity with little or no resistance, greatly improving the speed of information flow. Computers today have some attributes of fifth generation computers. For example, expert systems assist doctors in making diagnoses by applying the problem-solving steps a doctor might use in assessing a patient’s needs.
th
Schematic diagram of a 5 generation computer
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
6
COMPUTER FUNDAMENTAL & C PROGRAMMING Fifth generation computers aim to be able to solve highly complex problems, ones, which require reasoning, intelligence and expertise when solved by people. They are intended to be able to cope with large subsets of natural languages, and draw on very large knowledge basis. Fifth generation computers are being designed to be used by people who are not necessarily computer experts. In order to achieve these very ambitious aims, fifth generation computers will not have a single processor, or a small number of tightly coupled processors as computers do today. As said before they are being designed to contain a large number of processors, grouped into three major subsystems: a knowledge base system, an inference mechanism and an intelligent user interface. The knowledge base system has a very large store of knowledge with a set of processors, which access and update it. It is likely that knowledge bases will evolve from current work in relational databases. Operations on knowledge bases require the manipulation of large numbers of individual elements: this manipulation will be done in parallel by the arrays of knowledge processing elements. The inference mechanism draws reasoned conclusions from the knowledge base. Much of its processing will be drawing logical inferences of the :
If <condition> then <action>
variety. Accordingly, the processing power of fifth generation computers is expressed in logical inferences per second (lips). The target is in the range 50 to 1000 million lips (compared with a current performance of 10 to 100 thousand lips). Most of this improved performance is planned to be achieved via highly parallel architectures, such as the data-flow and graph reduction architectures. The intelligent user interface is the point of contact between a fifth generation computer and its user. Many of these will be based on communication in a large subset of a natural language. Others will make extensive use of advanced graphics, including image processing. The intention is to build a user interface, which is close to the natural way of thinking of the user, rather than close to the way of working of the computer. 1.4 CLASSIFICATION OF DIGITAL COMPUTER SYSTEMS 1.4.1 INTRODUCTION Computer systems are classified as Microcomputers, Minicomputers, Mainframes and Supercomputers.
1.4.2 MICROCOMPUTERS The most familiar kind of computer is the microcomputer. In the past, microcomputers have been considered to be of two types â&#x20AC;&#x201C; Personal Computers and Workstations. Personal Computers (PCs)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
7
COMPUTER FUNDAMENTAL & C PROGRAMMING PCs were desktop or portable machines.These machines ran comparatively easy – to – use applications software such as the word processors, spreadsheets, etc. They were usually easier to use and more affordable than workstations. However, they had less sophisticated video display screens, operating systems and networking capabilities. They did not have the processing power that workstations did. Examples of personal computers are Acer’s Aspire, Compaq Presario, etc. Workstations Workstations expensive, powerful machines used by engineers, scientists, and other professionals who processed a lot of data. Workstations use high-resolution colour graphics and operating systems such as UNIX that permitted multitasking. Workstations also use powerful networking links to other computers. The most significant distinguishing factor, however, is the powerful processor, which could churn out results much faster than the PCs. The more powerful workstations are called supermicros. Examples of well-known workstations are those made by Sun, Apollo, Hewlett-Packard, NeXT and IBM. PCs are now as powerful as many of those used in workstations. More powerful microprocessors and increased graphics and communications capabilities now let end users run software that previously ran only on more powerful machines.
Portable Computers Personal computing market is seeing the miniaturization phenomena. Computers are becoming smaller yet more powerful. There are three categories of portable computers: Laptops or Notebook PCs, Subnotebooks and Personal Digital Assistants. Laptops / Notebooks Laptops may be either AC-powered, battery-powered, or both. These computers are ideal for users who have to work away from their offices. The user of these computers might be an executive on the move, a student, a journalist, a salesperson, etc. Subnotebooks Subnotebooks are for frequent flyers and life–on-the-road professionals. Subnotebook users give up a full display screen and keyboard in exchange for less weight. These computers fit easily into any briefcase. They typically have an external floppy disk drive and monochrome monitor, although of late colour models are available. An example of a colour sub notebooks is Toshiba Protégé. Personal Digital Assistants (PDAs) PDAs are much smaller than the sub notebooks. They combine pen input, writing recognition, personal organization tools, and communication capabilities in a very small package. Typical users are executives, businessmen, etc. who use these machines for their day-to-day activities – scheduling, organization, etc. An example PDA is Apple’s Newton. 1.4.3 MINICOMPUTERS Minicomputers, also known as mid range computers. They were used to control machines in a manufacturing unit. They are widely used as general – purpose computers. The more powerful minicomputer models are called superminis. The increasing power of
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
8
COMPUTER FUNDAMENTAL & C PROGRAMMING
9
microcomputer gives minutes. One of the popular minicomputer systems is the VAX made by Digital Equipment Corporation. Minicomputers work well in what are known as Distributed Data Processing (DDP). That is, a company’s processing
power is decentralized, or distributed across different
computers. An example of such a computer architecture is the Client/Server model, in which end users can process at their own microcomputers. End users can also access and share the resources of the server, which usually is a minicomputer. For example, an executive could use the server to search the company’s centralized database and retrieve selected data. He / she could then use a spreadsheet on his/her microcomputer to analyze the data. 1.4.4 MAINFRAMES Mainframe computers can process several million – program instructions per second. Large organizations rely on these room-size systems to handle large programs with lots of data. Mainframes are mainly used by insurance companies, banks, airline and railway reservation systems, etc. An advanced mainframe made by IBM is S/390. 1.4.5 SUPERCOMPUTERS Supercomputers are the fastest calculating devices. A desktop microcomputer processes data and instructions in millionths of a second, or microseconds. A supercomputer, by contrast, can operate at speeds measured in nanoseconds and even in picoseconds. One thousand to one million times as fast as microcomputers. Most supercomputers are used by government agencies. These machines are for applications requiring very large programs and huge amounts of data that must be processed quickly. Examples of such task are weather forecasting, oil exploration, weapons research, and large-scale simulation. The chief difference between a supercomputer and a mainframe is that a supercomputer channels all its power into executing a few programs as fast as possible, whereas a mainframe uses its power to execute many programs concurrently. Supercomputers
use
a
technology
called
massively
parallel
processing.
These
supercomputers consist of thousands of integrated microprocessors. One massively parallel computer built by Intel Corporation is capable of performing 8.6 billion mathematical calculations per second. 1.4.6 NETWORK COMPUTERS Network computers are computers with minimal memory, disk storage and processor power designed to connect to a network, especially the Internet.Network computers is that many users who are connected to a network. Network computers designed to connect to the internet are sometimes called internet boxes, Net PCs and Internet appliances. 1.5 NUMBER SYSTEM 1.5.1 INTRODUCTION We use the decimal numbers or the decimal number system for our day-to-day activities. In the decimal number system there are ten digits – 0 through 9. But computers
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
10
understand only 0s and 1s – the machine language. We can use the decimal numbers, the alphabets and special characters like +,-,*,?,/, etc. for programming the computer. Inside the computer, these decimal numbers, alphabets and the special characters are converted into 0s and 1s. So that the computer can understand what we are instructing it to do. 1.5.2 DECIMAL NUMBER SYSTEM The base or radix of a number system is defined as the number of digits it uses to represent the numbers in the system. Since decimal number system uses 10 digits – 0 through 9 – its base or radix is 10. The decimal number system is also called base -10 number system. The weight of each digit of a decimal number system depends on its relative position within the number. For example, consider the number 3256. 3256 = 3000 + 200 + 50 + 6 or, in other words, 3
2
1
3256 = 3 x 10 + 2 x 10 + 5 x 10 + 6 x 10
0 th
From the above example, we can see that the weight of the n digit of the number th
from the right hand side is equal to n digit x 10
n-1
th
n-1
which is again equal to n digit x (base) .
1.5.3 BINARY NUMBER SYSTEM The base or radix of the binary number system is 2. It uses only two digits – 0 and 1. Data is represented in a computer system by either the presence or absence of electronic or magnetic signals in its circuitry or the media it uses. This is called a binary, or two-state representation of data since the computer is indicating only two possible states or conditions.
For example, consider the binary number 10100. 4
3
2
1
0
10100 = 1 x 2 + 0 x 2 + 1 x 2 + 0 x 2 + 0 x 2 = 16 + 0 + 4 + 0 + 0 = 20
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
11
Binary â&#x20AC;&#x201C;decimal Conversion To convert a binary number to its decimal equivalent we use the following expression: th
th
The weight of the n bit of a number from right hand side = n bit x 2
n-1
After calculating the weight of each bit, they are added to get the decimal value as shown in the following examples: 2
1
0
101 = 1 x 2 + 0 x 2 + 1 x 2 = 4 + 0 + 1 = 5 3
2
1
0
3
2
1
0
1010 = 1 x 2 + 0 x 2 + 1 x 2 + 0 x 2 = 8 + 0 + 2 + 0 = 10 1111 = 1 x 2 + 1 x 2 + 1 x 2 + 1 x 2 = 8 + 4 + 2 + 1 = 15 1.001
0
-1
-2
-3
= 1 x 2 + 0 x 2 + 0 x 2 + 1 x 2 = 1 + 0 + 0 + .125 = 1. 125
Decimal â&#x20AC;&#x201C; binary Conversion Decimal numbers are converted into binary by a method called Double Dabble Method. In this method, the mantissa part of the number is repeatedly divided by two and noting the reminders, which will be either 0 or 1. This division is continued till the mantissa becomes zero. The reminders, which are noted down during the division is read in the reverse order to get the binary equivalent. This can be better illustrated using the following example.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
The number is written from below, that is 1110. So the binary equivalent of 14 is 1110. If the decimal number has a fractional part, then the fractional part is converted into binary by multiplying it with 2. Only the integer of the result is noted and the fraction is repeatedly multiplied by 2 until the fractional part becomes 0. This can be explained using the following example.
Here the number is written from top - .001. So the binary equivalent of 0.125 is .001 Therefore, from the above two examples, we can conclude that the binary equivalent of the decimal number 14.125 is 1110.001. Binary Addition The addition of numbers in the binary system is shown in the table 5.2 and is illustrated by the examples.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
12
COMPUTER FUNDAMENTAL & C PROGRAMMING The addition of 101101 and 1111 (which are 45 and 15 in the decimal system ) is done as follows:
Similarly, the addition of 1111011 and 11011 ( which are 123 and 27 in the decimal system ) is:
The subtraction of Binary Numbers is given the table.
Binary Subtraction The subtraction of 1111 from 101101 (which are 15 and 45 in the decimal system) is done as follows:
Similarly the subtraction of 11011 from 1111011(which are 27 and 123 in the decimal system) is:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
13
COMPUTER FUNDAMENTAL & C PROGRAMMING When you are subtraction a larger number from a smaller number, the result obtained will be the 2’s complement. If we subtract 45 (101101) from 15 (1111), we should get – 30. But when we do the binary subtraction, instead of getting
- 11110 (-30) we will get the 2’s
complement of 11110 which is 10.
1.5.4 COMPLEMENTS Computers use complemented numbers or complements to perform subtraction. In the binary number system there are two types of complements – 1’s complement and 2’s complement.Similaraly,in the decimal number system also there two types of complements9’s complement and the 10’s complement. 9’s Complement The 9’s complement of a decimal number is obtained by subtracting each digit of the number from 9. Example 9’s complement of 2 is
9-2=7
9’s complement of 123 is 999-123=876 10’s Complement The 10’s complement of decimal number is obtained by adding 1 to 9’s complement of that number. Example 10’s complement of 2 is 9-2=7+1=8 10’s complement of 123 is 999-123=876+1=877 1’s Complement To get the 1’s complement at a number replace 0 by 1 & 1 by 0. For example, the 1’s complement of 1010 is 0101, that of 1111 is 0000 and so on. 2’s Complement To get the 2’s complement of a number, add 1 to the 1’s complement of the number. For example, the 2’s complement of 1010 is 0110, that of 1111 is 0001, etc. Just as adding a number to the 10’s complement of another number is equivalent to subtraction the second number from the first in the decimal system, adding a number to the 2’s complement of another number is equivalent to subtracting the second number from the first in the binary system. For example, if you want to subtract 101 from 1111, you add the 2’s complement of 101 to 1111 as shown below:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
14
COMPUTER FUNDAMENTAL & C PROGRAMMING
1.5.5 SIGNED AND UNSIGNED NUMBER EPRESENTATIONS We put a plus (+) or minus (-) sign before the number to represent its sign. In computers such notations cannot be employed and therefore, a different method is used. To represent a positive number a 0 is placed before the binary number. Similarly, to represent a negative number, a 1 is placed before the binary number. For example +15 and -15 are represented by 01111 and 11111 respectively. There is only one way to represent a positive number, but there are different ways to represent a negative number. These are:
Signed – magnitude representation
Signed – 1’s complement representation
Signed – 2’s complement representation
The number 15 can be represented in the above three ways as 11111, 10000 and 10001 respectively. Since 15 is represented by 4 bits and a separate bit is used to represent sign, in a computer, the most significant bit (MSB) can be used to represent the sign of the number. For example, an 8-bit computer will represent- 15 as 10001111, 10000000 and 10000001 for signed- magnitude, signed -1’s complement and signed-2’s complement respectively. 7 bits are used to represent the number and the MSB is used to represent the sign of the number. When all the bits of the computer word (in an 8-bit computer, the length of a word is 8 bits) are used to represent the number and no bit is used for sign representation, it is called unsigned representation of numbers. 1.5.6 FIXED – POINT REPRESENTATION OF NUMBERS In the fixed – point number representation system, all numbers are represented as integers or fractions. Signed integer or BCD numbers are referred to as fixed-point numbers because they contain no information regarding the location of the decimal point or the binary point. The binary or decimal point is assumed to be at the extreme right or left of the number.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
15
COMPUTER FUNDAMENTAL & C PROGRAMMING If the binary or decimal point is at the extreme right of the computer word, then all numbers are positive or negative integers. If the radix point is assumed to be at the extreme left, then all numbers are positive or negative fractions. Consider that you have to multiply 23.15 and 33.45. This will be represented as 2315 x 3345. The result will be 7743675. The decimal point has to be placed by the user to get the correct result, which is 774.3675. So in the fixed-point representation system, the user has to keep track of the radix point, which can be a tedious job. 1.5.7 FLOATING – POINT REPRESENTATION OF NUMBERS In most computing applications, fractions are used very used frequently. So a system of number representation which automatically keeps track of the position of the binary or decimal point is better than the fixed-point representation. Such a system is the floating-point representation of numbers.
A number, which has both an integer part and a fractional part, is called a real number or a floating-point number.
These numbers can be dither positive or negative.
Examples of real numbers (decimal) are 123.23, -56.899, 0.008, etc. The real number 123.23 can be written as 1.2323 x 10
2
can be represented as 0.8 x 10
3
or 0.12323 x 10 . Similarly the numbers 0.008 and 1345.66 -2
and 1.34566 x 10
3
respectively. This of representation is
called the scientific representation. Using this scientific form, any number can be expressed as a combination of a mantissa and an exponent, or in other words, the number ‘n’ can be e
expressed as ‘n=mr ’ where ‘m’ is the mantissa, ‘r’ is the radix of the number system and ‘e’ is the exponent. In a computer also the real or floating – point number is represented by two parts – mantissa and exponent. Mantissa is a signed fixed point number and the exponent indicates the position of the binary or decimal point. For example, the number 123.23 is represented in the floating-point system as:
The zero in the left most position of the mantissa and exponent indicates the plus sign. The mantissa can be either a fraction or an integer, which is dependent on the computer manufacturer. Most computers use the fractional system of representation for mantissa. The decimal point shown above is an assumed decimal point and is not stored in the register.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
16
COMPUTER FUNDAMENTAL & C PROGRAMMING The exponent of the above example, +3, indicates that the actual decimal point is three digits to the right of the assumed one. In the above example, the mantissa is shown as a fraction. As mentioned , we can use an integer as the mantissa. The following example shows how it is done.
In the above representation, the sign of the exponent is negative and it indicates that the actual decimal point lies two decimal positions to the left of the assumed point (in this case, the assumed decimal point is placed at the extreme right of the integer or 12323).
A negative number say-123.23 can be expressed as follows
A negative fraction, say-0.0012323 can be represented as follows
1.5.8 BINARY CODED DECIMAL (BCD) The BCD is the simplest binary code that is used to represent a decimal number. In the BCD code, 4 bits represent a decimal number. For example, 2 is represented as 0010. If a decimal number consists of more than 1 digit, each decimal digit is represented individually by its 4-bit binary equivalent for example, 123 is represented as 0001 0010 0011. There is a difference between the equivalent of a decimal number and its BCD code. For example, the binary equivalent of 45 is 101101 and its BCD code is 0100 0101. Computers perform subtraction using complements and there is difficulty in forming complements when numbers
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
17
COMPUTER FUNDAMENTAL & C PROGRAMMING are representing in BCD. For example 1â&#x20AC;&#x2122;s complement of 2 (0010) is 1101 which is 13 in the decimal system and is not an acceptable BCD code. To overcome this difficulty, other BCD codes such as Excess -3 are used.
1.5.9 GRAY CODE The Gray code is binary code. It is used in shift encoder, which indicates the angular position of a shift in digital form. The bits of arranged in such a way that only one bit changes at a time when we make a change from one number to the next. Its use reduces the error in reading shift position. The largest possible errors will be one least significant digit. The gray code is often used in computer controlled machines such as lathes, etc,. Photoelectric coders or shift position encoders are used as sensors.
The table 5.3 shows the Gray codes for the decimal numbers 0 through 15.
1.5.10 EXCESS-3 CODE
As mentioned above, to overcome the disadvantages of BCD in forming complements, other systems like Excess-3 are used. This code is formed by adding 3 to the decimal number and forming the binary coded number. For instance, to form the Excess-3 representation of 5, first 3 is added to 5 yielding 8, and normal BCD is used which is 1000.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
18
COMPUTER FUNDAMENTAL & C PROGRAMMING
19
Similarly, the decimal number 123 coded in Excess-3 will be 0011 0100 0101. The table 5.4 shows the BCD and Excess-3 codes for decimal number 0 through 9.
1.5.11 ASCII CODE
ASCII stands for American Standard Code for Information Interchange. ASCII code is used extensively in small computers, peripherals, instruments and communications devices. It is a seven-bit code. Microcomputers using 8-bit word length use 7 bits to represent the basic th
code. The 8 bit is used for parity or it may be permanently 1 or 0. With 7 bits, up to 128 characters can be coded. A letter, digit or special symbol is called a character. It includes upper and lower case alphabets, numbers, punctuation mark and special and control characters.
ASCII-8 Code A newer version of ASCII is the ASCII-8 code, which is an 8-bit code. With 8 bits, the code capacity is extended to 256 characters.
1.5.12 EBCDIC CODE EBCDIC stands for Extended BCD Interchange Code. It is the standard character th
code for large computers. It is an 8-bit code without parity. A 9 bit can be used for parity. With 8 bits up to 256 characters can be coded.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING In ASCII-8 and EBCDIC, the first 4 bits are known as zone bits and the remaining 4 bits represent digit values. In ASCII, the first 3 bits are zone bits and the remaining 4 bits represent digit values.
1.5.13 BITS, BYTES AND WORDS
A byte is a basic grouping of bits (binary digits) that the computer operates on as a single unit. It consists of 8 bits and is used to represent a character by the ASCII and EBCDIC coding systems. For example, each storage location of computers using EBCDIC or ASCII-8 codes consist of electronic circuit elements or magnetic or optical media positions that can represent at least 8 bits. Thus each storage location can hold one character. The capacity of a computerâ&#x20AC;&#x2122;s primary storage and its secondary storage devices is usually expressed in terms of bytes. A word is a grouping of bits (usually larger than a byte) that is transferred as a unit between primary storage and the registers of the ALU and control unit. Thus, a computer with a 32-bit word length might have registers with a capacity of 32 bits, and transfer data and instructions within the CPU in groupings of 32 bits. It should process data faster than computers with a 16-bit or 8-bit word length.
1.5.14 OCTAL NUMBER SYSTEM Refers to the base-8 number system, which uses just eight unique symbols (0,1,2,3,4,5,6, and 7).
In octal format, each digit represents three binary digits, as shown in the table 5.6.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
20
COMPUTER FUNDAMENTAL & C PROGRAMMING
21
With this table, it is easy to translate between octal and binary. For example, the octal number 3456 is 011 100 101 110 in binary. To convert an octal number to decimal, the same method used for binary- decimal conversion is used, the only difference is that, instead of 2 the base is 8. For example, the octal number 24.25 is 20.328125 in decimal as shown below. 1
0
-1
-2
24.25 = 2 x 8 + 4 x 8 + 2 x 8 + 5 x 8 = 16 + 4 + 0.25 + 0.078125 = 20.328125 To convert a decimal number to octal system, it is repeatedly divided by 8 as illustrated in the following example, where the number 888 is converted to octal system (1570).
Here the number is written from top â&#x20AC;&#x201C; .04. So the binary equivalent of 0.0625 is .04. Therefore, from the above two examples, we can conclude that the binary equivalent of the decimal number 888.0625 is 1570.04.
1.5.15 HEXADECIMAL NUMBER SYSTEM Hexadecimal number system uses 16 as the base or radix. This base -16 number system consists of 16 unique symbols: the numbers 0 to 9 and the letters A to F.
For
example, the decimal number 15 is represented as F in the hexadecimal numbering system as shown in the table 5.7.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
The hexadecimal system is useful because it can represent every byte (8bits) as two consecutive hexadecimal digits. Compared to binary numbers, hexadecimal numbers are easier for humans to read. To convert a value from hexadecimal to binary, you merely translate each hexadecimal digit into 4-bit binary equivalent. For example, the hexadecimal number 3F7A translates to the following binary number: 0011 1111 0111 1010. To convert a hexadecimal number to decimal the same method used for binarydecimal conversion is used, the only difference is that instead of 2 the base is 16. For example, the hexadecimal number 24.25is 36.14453125 in decimal as shown below: 1
0
-1
-2
24.25 = 2x16 +4x16 +2x16 +5x16
= 32+4+0.125+0.01953125
= 36.14453125
To convert a decimal number to hexadecimal system, it is repeatedly divided by 16 as illustrated in the following example. To convert 888 to hexadecimal system.
The number is written from below, that is 378. So the hexadecimal equivalent of 888 is 378.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
22
COMPUTER FUNDAMENTAL & C PROGRAMMING If the decimal number has a fractional part, then the fractional part is converted into hexadecimal by multiplying it with 16. Only the integer of the result is noted and the fraction is repeatedly multiplied by 16 until the fractional part has become 0. This can be explained using the following example.
Therefore, from the above two examples, we can conclude that the hexadecimal equivalent of the decimal number 888.62 is 378.9EB approximately.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
23
COMPUTER FUNDAMENTAL & C PROGRAMMING
UNIT –II 2.0 Boolean Algebra and Gate Networks 2.1 Fundamental Concepts of Boolean Algaebra 2.2 logical Multiplication 2.3 And Gates and OR Gates 2.4 Complementation and Inverters 2.5 Evaluation of Logical Expressions 2.6 Evaluation of an Expression Containing Parentheses 2.7 Simplifications of Expressions 2.8 De Morgan’s Theorems 2.9 Basic Duality of Boolean Algebra 2.10 Derivation of a Boolean Expression 2.11 Interconnecting Gates 2.12 Sum of Products and Product Of Sums 2.13 Derivation of Product-of-Sums Expression 2.14 Derivation of a Three-Input-Variable Expression 2.15 NAND Gates and NOR Gates 2.16 Map Method for Simplyfying Expressions 2.17 Subcubes and Covering 2.18 Product-Of-Sums Expressions- Don’t-Care Self Assessment Questions Self Assessment Answers
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
24
COMPUTER FUNDAMENTAL & C PROGRAMMING 2.0 BOOLEAN ALGEBRA AND GATE NETWORKS Modern digital computers are designed and maintained, and their operation is analyzed, by using techniques and symbology from a field of mathematics called modern algebra. Algebraists have studied for over a hundred years mathematical systems called boolean algebras.
2.1 FUNDAMENTAL CONCEPTS OF BOOLEAN ALGAEBRA When a variable is used in an algebraic formula, it is generally assumed that the variable may take any numerical value. For instance, in the formula 2X - 5Y = Z, we assume that X, Y, and Z may range through the entire field of real numbers. The variable used in boolean equations have a unique characteristic, however; they may assume only one of two possible values. These two values may be represented by the symbols 0 and 1. If an equation describing logical circuitry has several variables, it is still understood that each of the variables can assume only the value 0 or 1. For instance, in the equation X + Y = Z, each of the variables X, Y, and Z may have only the values 0 or 1. This concept will become clearer if a symbol is defined, the + symbol. When the + symbol is placed between two variables, say X and Y , since both X and Y can take only the role 0 or 1, we can define the + symbol by listing all possible combinations for X and Y and the resulting values of X + Y. The possible input and output combinations may be arranged as follows:
This is a logical addition table and could represent a standard binary addition table except the last entry. When both X and Y represent 1s, the value of X + Y is 1. The + symbol therefore, does not have “normal” meaning, but is a logical addition or logical OR symbol. The equation X + Y = Z can be read “X or Y equals Z” or “X plus Y equals Z”. This concept may be extended to any number of variables. For instance, in the equation A + B + C + D = E, even if A, B, C, and D all had the value of 1, E would represent only a 1. To avoid ambiguity, a number of other symbols have been recommended as 3
replacement for the + sign. Some of these are U, v and V. computer people still use the + sign, however, which was the symbol originally proposed by Boole.
2.2 LOGICAL MULTIPLICATION A second important operation in Boolean algebra we call logical multiplication or the logical 4
AND operation . The rules of this operation can be given by simply listing all values that might occur:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
25
COMPUTER FUNDAMENTAL & C PROGRAMMING
Thus, for instance, if we write Z = X . Y and find X = 0 and Y = 1, then Z = 0. Only when X and Y are both 1s would Z be a 1. Both + and. Obey a mathematical rule called the associative law. This law says, for +, that (X + Y)+Z = X + (Y + Z) and for . , that X.(Y.Z) = (X.Y).Z. This means that we can write X + Y + Z without ambiguity, for no matter in what order the operation is performed, the result is the same.
2.3 AND GATES and OR GATES The + and . operations are physically realized by two types of electronic circuits, called OR gates and AND gates. A gate is simply an electronic circuit which operates on one or more input signals to produce an output signal. One of the simplest and most frequently used gates is called the OR gate, and the block diagram symbol for the OR gate is shown figure 1, as is the table of combinations for the inputs and outputs for the OR gate. Similarly, the AND gate in figure 2 ANDs or logically multiplies input values, yielding an output Z with value X . Y, so that Z is a 1 only when both X and Y are 1s.
Figure 1.
Figure 2.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
26
COMPUTER FUNDAMENTAL & C PROGRAMMING AND gate
2.4 COMPLEMENTATION AND INVERTERS The two operations defined so far have been what algebraists would call binary operations in that they define an operation on two variables. There are also singular or unary, operations, which define an operation on a single variable. A familiar example of unary operation is -, for we can write -5 or -10 or â&#x20AC;&#x201C;X, meaning that we are to take the negative of these values.
The complementation operation is physically realized by a gate or circuit called an inverter. Figure 3 shows an inverter and the table of combinations for its input and output.
Figure 3.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
27
COMPUTER FUNDAMENTAL & C PROGRAMMING
28
2.5 EVALUATION OF LOGICAL EXPRESSION The tables of values for the three operations just explained are sometimes called truth tables, or tables of combinations. To study a logical expression, it is very useful to construct a table of values for the variables and then to evaluate the expression for each of the possible combinations of variables in turn. Consider the expression
. There are three
variables in this expression : X, Y and Z, each of which can assume the value 0 or 1. The 5
possible combinations of values may be arranged in ascending order, , as in Table 1. One of the variables, Z, is complemented in the expression now added to the table listing values of
. So a column is
(see Table 2).
A column is now added listing the values that
assumes for each value of the X, Y,
and Z. This column will contain the value 1 only when both Y is a 1and
is a 1 (see Table 3)
Now the ORing, or logical addition, of the values of X to the values which have been calculated for
is performed in a final column (see Table 4).
The final column contains the value of
for each set of inputs values which X,
Y, and Z may take. For instance, when X = 1, Y = 0, and Z = 1, the expression has the value of 1.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
Table 4
2.6 EVALUATION OF AN EXPRESSION CONTAINING PARENTHESES The following example illustrations the procedure for constructing a truth table for the expression
. There are only two variables in the expression, X and Y. First a
table of the values which X and Y may assume is constructed.(see table 5) Now, since the expression contains both
and
two columns are added listing
complements of the original values of the variables (see table 6). The various values of The values for
are now calculated (see table 7). are now multiplied (ANDed) by the values of Y in the table,
forming another column representing
(see table 8).
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
29
COMPUTER FUNDAMENTAL & C PROGRAMMING
Finally the values for
are added (ORed) to the values for X which are listed,
forming the final column and completing the table(see table 9). Inspection of the final column of the table indicates that the values taken by the function are identical with the values found in the table for ORing X and Y. This indicates that the function
is equivalent to the function X + Y. This
equivalence has been established by trying each possible combination of values in the variables and noting that both expressions then have the same value. This is called a proof by perfect induction. If a logic circuit were constructed for each of the two expressions, both circuits would perform the same function, yielding identical outputs for each combination of inputs.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
30
COMPUTER FUNDAMENTAL & C PROGRAMMING
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
31
COMPUTER FUNDAMENTAL & C PROGRAMMING BASIC LAWS OF BOOLEAN ALGEBRA Some fundamental relations of Boolean algebra have been presented. A complete set of the basic operations is listed below.
Table 10
A list of useful relations is presented in table 10. Most of the basic rules by which Boolean algebra expressions may be manipulated are contained in this table. Each rule may be proved by using the proof by perfect induction. An example of this proof for rule 3 in table 10 is as follows: the variable X can have only the value 0 or 1. If X has the value 0, then 0 + 0 = 0; if X has the value 1, then 1 + 1 = 1. Therefore X + X = X.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
32
COMPUTER FUNDAMENTAL & C PROGRAMMING
33
The same basic technique may be used to prove the remainder of the rules. Rule 9 states that double complementation of a variable results in the original variable. If X equals 0, then
the
first
complement
is
1
and
the
second
will
be
0, the original value.If the original value for X is 1, then the first complement will be 0 and the second 1, the original value. Therefore X =
.
Rules 10 and 11, which are known as the commutative laws, express the fact that the order in which a combination of terms is performed does not affect the result of the combination. Rule 10 is the commutative law of addition, which states that the order of addition or ORing does not affect the sum (X + Y = Y + X). Rule 11 is the commutative law of multiplication (XY = YX), which states that the order of multiplication or ANDing does not affect the product. Rules 12 and 13 are the associative laws. Rule 12 states that in the logical addition of several terms, the sum which will be obtained if the firs term is added to the second and then the third term is added will be the same as the sum obtained if the second term is added to the third and then the first term is added [X. + (Y + Z) = (X+Y)+Z]. Rule 13 is the associative law of logical multiplication, stating that in a product with three factors, any two may be multiplied, followed by the third [X(YZ) = (XY)Z]. Rule 14, the distributive law, states that the product of a variable (X) times a sum (Y + Z) is equal to the sum of the products of the variable multiplied by each term of the sum [X(Y + Z) = XY + XZ]
2.7 SIMPLIFICATIONS OF EXPRESSIONS The rules given may be used to simplify boolean expressions, just as the rules of normal algebra may be used to simplify expressions. Consider the expression
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
2.8 DE MORGAN’S THEOREMS The following two rules are known as De Morgan’s theorems:
The complement of any boolean expression, or a part of any expression, may be found by means of these theorems. In these rules, two steps are used to form a complement: 1
The + symbols are replaced with · symbol and · symbols with + symbols.
2
Each of the terms in the expression is complemented.
The use of De Morgan’s theorem may be demonstrated by finding the complement of the expression X + YZ. First, note that a multiplication sign has been omitted and the expression could be written X + (Y.Z). To complement this, the addition symbol is replaced with a multiplication symbol and the two
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
34
COMPUTER FUNDAMENTAL & C PROGRAMMING
2.9 BASIC DUALITY OF BOOLEAN ALGEBRA De Morganâ&#x20AC;&#x2122;s theorem expresses a basic duality which underlies all boolean algebra. The postulates and theorems which have been presented can all be divided into pairs. For example, (X + Y) + Z = X + (Y + Z) is the dual of (XY)Z = X(YZ), and X + 0 = X is the dual of X . 1 = X.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
35
COMPUTER FUNDAMENTAL & C PROGRAMMING Often the rules or theorems are listed in an order which illustrates the duality of the algebra. In proving the theorems or rules of the algebra, it is then necessary to prove only one theorem, and the dual of the theorem follows necessarily. For instance, if you prove that X +XY = X, you can immediately add the theorem X(X + Y) = X to the list of theorems as the 8
dual of the first expression. In effect all boolean algebra is predicated on this two-for-one basis. 2.10 DERIVATION OF A BOOLEAN EXPRESSION When designing a logical circuit, the logical designer works from two sets of known values: (1) the various which the inputs to the logical network can take and (2) the desired outputs for each input condition. The logical expression is derived from these sets of values. Consider a specific problem. A logical network has two inputs X and Y and an output Z. The relationship between inputs and outputs is to be as follows:
1. When both X and Y are 0s, the output Z is to be 1.
2. when X is 0 and Y is 1, the output Z is to be 0.
3. when X is 1 and Y is 0, the output Z is to be 1.
4. when X is 1 and Y is 1, the output Z is to be 1.
These relations may be expressed in tabular form, as shown in table 11
Table 11 It is now necessary to add another column to the table. This column will consist of a list of product terms obtained from the values of the input variables . The new column will contain each of the input variables listed in each row of the table, with the letter representing the respective input complemented when the input value for this variable is 0 and not complemented when the input value is 1. The terms obtained in this
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
36
COMPUTER FUNDAMENTAL & C PROGRAMMING manner are designated as product terms. With two input variables X and Y, each row of the table will contain a product term consisting of X and Y, with X or Y complemented or not, depending on the input values for that row(see table 12) Whenever Z is equal to 1, the X and Y product term from the same row is removed and formed into a sum-of-products expression. Therefore, the product terms from the first, third, and fourth rows are selected. These
, and XY.
Table 12
There are now three items, each the product of two variables. The logical sum of these products is equal to the expression desired. This type of expression is often referred to as a canonical expansion for the function. The complete expression in normal form is
The truth table may be constructed to check the function that has been derived (see table 13). The last column of this table agrees with the last column of the truth table of the desired function, showing that the expressions are equivalent.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
37
COMPUTER FUNDAMENTAL & C PROGRAMMING
38
2.11 INTERCONNECTING GATES The OR gates, AND gates, and inverters described can be interconnected to form gating, or logic, networks. The Boolean algebra expression corresponding to a given gating network can be derived by systematically progressing from input to output on the gates. The below figure 4(a)
shows
a
gating
network
with
Figure 4 Three gating networks. .
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
39
2.12 SUM OF PRODUCTS AND PRODUCT OF SUMS An important consideration in dealing with gating circuits and their algebraic counterparts is the form of the boolean algebra expression and the resulting form of the gating network. Certain types of Boolean algebra expressions lead to gating networks which are more desirable from most implementation viewpoints. We now define the two most used and usable forms for boolean expressions. First let us define terms 1. Product term A product term is a single variable or the logical product of several variables. The variables may or may not be complemented. 2. Sum term A sum term is a single variable or the sum of several variables. The variables may or may not be complemented. For example, the term X.Y.Z is a product term ; X + Y is a sum term; X is both a product term and a sum term; X + Y. Z is neither a product term nor a sum term; term
is a product term;
is a sum
is a both a sum term and a product term.
We now define two most important types of expressions.
1. Sum of product expressions A sum-of-products expression is a product term or several product terms logically added. 2. Product-of-sums expressions A product-of-sums expression is a sum term or several sum terms logically multiplied. For example, the expression
is a sum-of-products expression;
is a product-of-sums expression. The following are all sum-ofproduct expressions:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING One prime reason for liking sum-of-products or product-of-sums expressions is their straightforward conversion to very nice gating networks. Figure 3.7 shows several gating networks. Figure 3.7(a) shows sum-of-product networks, and figure 3.7(b) shows product-of-sums networks. Figure3.7
2.13 DERIVATION OF RPODUCT-OF-SUMS EXPRESSION The method for arriving at the desired expression is as follows: 1
Construct a table of the input and output values.
2
Construct an additional column of sum terms containing complemented and uncomplemented variables (depending on the values in the input columns) for each row of the table. In each row of the table, a sum term is formed. However, in
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
40
COMPUTER FUNDAMENTAL & C PROGRAMMING
41
this case, if the input value for a given variable is 1, the variable will be complemented; and if 0, not complemented. 3
The desired expression is the product of the sum terms from the rows in which the output is 0.
The use of these rules is illustrated by working examples in this and the following sections. Table 16 contains the input and output values which describe a function to be realized by a logical network.
A column containing the input variables in sum-term form is now added in each row. A given variable is complemented if the input value for the variable is 1 in the same row and is not complemented if the value is 0(see table 17). Each sum term is, therefore, simply the complement of the product term which occurs in the same row in the previous table for sumof-products expressions. Notice that the sum term complement of the product term
in the third row of Table 17 is the
used in the sum-of-products derivation.
A product-of-sum expression is now formed by selecting those sum terms for which the output is 0 and multiplying them. In this case, 0s appear in the second and third rows, showing that the desired expression is
. A sum-of-products expression
may be found by multiplying the two terms of this expression, yielding
. I this
case the same number of gates would be required to construct circuits corresponding to both the sum-of-products and the product-of-sum expressions.
2.14 DERIVATION OF A THREE-INPUT-VARIABLE EXPRESSION Consider Table 18, expressing an input-to-output relationship for which expression is to be derived. Two columns will be added this time, one containing the sum-of-products terms and the other the product-of-sums terms(see table 19). The two expressions may be written in the following way:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
42
The two expressions may be simplified as shown:
The
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING two final expressions clearly can be seen to be equivalent, Notice, however, that the shortest sum-of-products expression, which is requires two AND gates and an OR gate(fig 3.8), while the shortest product-of-sums expression,
, requires only a single AND gate and a single OR gate.
Figure 3.8
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
43
COMPUTER FUNDAMENTAL & C PROGRAMMING
44
2.15 NAND GATES AND NOR GATES Two other types of gates, NAND gates and NOR gates, are often used in computers. A NAND gate is shown in figure3.9. The inputs are A, B and C, and the output from the gate is written
. the output will be a 1 if A is a 0 or B is a 0 or C is a 0,
and the output will be a 0 only is A and B and C are all 1s. The operation of the gate can be analyzed using the equivalent block diagram circuit shown fig 3.9, which has an AND gate followed by an inverter. If the inputs are A, B and C, the
output
of
the
AND
gate
will
be
A.B.C,
and
the
complement of
this
, as shown in the figure. Figure 3.9
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
is
COMPUTER FUNDAMENTAL & C PROGRAMMING
45
NAND gate
Figure 3.10. NOR gate
The NOR gate can be analyzed in a similar manner. Figure3.10 shows the NOR gate . This shows the NOR gateâ&#x20AC;&#x2122;s
block diagram symbol with inputs, A, B, C and output
output will be 1 only when all three inputs are 0s. If any input represents a 1, the output of a NOR gate will be a 0. Below the NOR gate block diagram symbol in fig 3.10 is an equivalent circuit showing 9
an OR gate and an inverter. The inputs A, B and C are ORed by the OR gate, giving A + B + C, which is complemented by he inverter, yielding
=
.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
46
Gates in two level networks.
2.16 MAP METHOD FOR SIMPLYFYING EXPRESSIONS There are several other ways to represent or list function values, and the use of certain kinds of maps, also permits minimization of the expression The particular type of map we use is called karnaugh map figure 3.15 shows the layouts for Karnaugh maps of two to four variables. The diagram in each case lists the 2
n
different product terms which can be formed in exactly n variables, each in a different square. For a function of n variables, a product term in exactly these n variables is called a 3
minterm.Thus for are three variables X, Y and Z there are 2 , or 8, different minterms, which are
. For four variables 4,
there are 2 or 16, terms; for five variables there are 32 terms; etc. As a result, a map of n n
variables will have 2 squares, each representing a single minterm. The minterm in each box, or cell, of the map is the product of the variables listed at the abscissa and ordinate of the cell. Thus
is at the intersection of
and Z.
Given a Karnaugh map form, the map is filled in by placing 1s in the squares, or cells, for each term which leads to a 1 output. As an example, consider a function of three variables for which the following input values are to be 1:
This function is shown in fig 3.16(a) in both table-of-combinations and Karnaugh map form.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Figure 3.15.
Figure 3.16. MAP METHOD FOR SIMPLIFYING EXPRESSIONS
2.17 SUBCUBES AND COVRING m
A subcube is a set of exactly 2 adjacent cells containing 1s. for m = 0 the subcube consists of a single cell. For m = 1 a
subcube consists of two adjacent cells;for
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
47
COMPUTER FUNDAMENTAL & C PROGRAMMING instance,the cells containing 3.17(a), as do
and
and
form a subcube, as shown kin fig
(since the map is rolled).
For m = 2 a subcube has four adjacent cells, and several such subcubes are shown in fig 3.17 (c). Notice that here we have omitted 0s for clarity and filled in only the 1s for the function. This policy will be continued. Finally, subcubes containing eight cells (for m=3) are shown in figure3.17(d). To demonstrate the use of map and subcubes in minimizing boolean algebra expressions, we need to examine a rule of Boolean algebra:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
48
COMPUTER FUNDAMENTAL & C PROGRAMMING
There are four terms here, each with two variables WX constant while the other two variables Y and Z take all possible values. The term WX is equal to the sum of the other terms, for
Thus WX could be substituted for the other four terms in an expression
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
49
COMPUTER FUNDAMENTAL & C PROGRAMMING
50
The set of minters in an expression does not necessarily form a single subscale, however, and there are two cases to be dealt with. Call a maximal subcube the largest subcube that can be found around a given minterm. Then the two cases are as follows:
1
All maximal subcubes are nonintersecting: that is no cell in a maximal
subcube is a part of another maximal subcube. Several examples are shown in Fig.3.18
2.The maximal sub cubes intersect; that is ,cells in one maximal subcube are also in other maximal subcubes. Figure 3.19 shows examples of this. Case 1 is the more easily dealt with. In this case, the product terms corresponding to the maximal subcubes are selected, and the sum of these forms a minimal sum-of-products expression. (In switching theory, the product term corresponding to a maximal subcube is called a prime implicant.) Figure 3.18(a) shows an example of this in four variables. There is a subcube of two cells containing WXYZ and
which can be covered by the product term WXZ. There
is also a sub cube of four cells containing which can be covered by
. The minimal expression is, therefore,
, + WXZ.
Two other examples are shown in figure 3.18(b) and (c).In each case the subcubes do not intersect or share cells and so the product term(prime implicant)which corresponds to a given maximal subcube can be readily derived and the sum of these for a given map forms the minimal expression.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
51
When the subcubes intersect, the situation can be more complicated.
The first
principle to note is this: Each cell containing a 1 (that is, each 1 cell) must be contained in some subcube which is selected. Figure 3.19(a) shows a map with an intersecting pair of subcubes plus another subcube. The minimal expression is, in this case, formed by simply adding the three product terms associated with the three maximal subcubes. Notice that a Figure 3.19
Single term,
, is shared between two subcubes and, because of this, is
effectively in the minimal expression twice. This is permissible because of
the idempotent
rule of Boolean algebra, A + A = A, which states that repetition of terms does not change functional equivalence. As long as the maximal subcubes can be readily found and there are no options in subcube selection, the minimization problem is straight forward.In some case the problem is more complicated. Figure 3.20 shows an expression with a subcube of four cells in the center of the map, which is maximal. The selection of this maximal subcube does not lead to a minimal expression, however, because the four cells with 1s around this subcube must be covered also .In each case these 1 cells can be found to have a single adjacent cell and so to be part of maximal subcubes consisting of 2 cells. In fig.3.20 (a), adjacent to only form
subcues
is in a cell
and so forms part of a 2 cell. Figure 3.20(b shows another way to for
the
map,
and
this
leads
to
the
minimal
expression
The finding of minimal expressions for such maps is not direct, but follow these rules: 1
Begin with cells that are adjacent to no other cell. The minters in these
cells can not be shortened and must be used as they are.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING 2
52
Find all cells that are adjacent to only one other cell. These form subcubes of two cells each.
3
Find those cells that lead to maximal subcubes of four cells. Then find
subcubes of eight cells, etc. 4
the minimal expression is formed from a collection of as few cubes as
possible, each of which is as possible, that is, each of which is a maximal subcube. 2.18 PRODUCT-OF-SUMS EXPRESSIONS-DONâ&#x20AC;&#x2122;T-CARES The technique for product-of-sums expressions is almost identical with the design procedure using sum-of-products. The basic rule can be stated quite simply:Solve for 0s, and then complement the resulting expression. Let us take example.figure 3.22(a) shows a table of combinations and a karnaugh map for a four-variable problem. In fig. 3.22(a) the sum-of-products expression is derived and in minimal form is found to be In fig .3.22(b) the same problem is solved for the 0s,which gives
. .Since
we have solved for 0s,we have solved for the complement of the desired problem. If the output is called F, then we have solved for
.we then write
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Now, what is wanted is F: so both sides of this expression are complemented, And we have
This expression is in product-of-sums form and is somewhat simpler then the sum-ofproducts expression.
If sum-of-products and product-of-sums expression are equally easy to Implement, then a given problem must be solved in both forms and the simpler solution chosen. There is no way to determine which will be simpler other than by a complete working of the problem. There is another frequently encountered situation in which certain outputs are not specified in a problem .such outputs are called don’t -care outputs, for the designer does not care what the outputs are for these particular inputs. Figure 3.23(a) shows such a problem with 6 of the possible 16 output values Listed as d’s (don’t cares).this is a part of a BCD translator, and so these particular six input combinations are never used. Since don’t care output values are of no importance, they may be filled in with 1s and 0s in any way that is advantageous .figure 3.23(a) shows a karnaugh map of the table of combinations in the figure, with d’s in the appropriate places. In solving this table, a d may be used as either a 1 or a 0; so the d‘s are used to enlarge or complete a subcube whenever possible, but otherwise are
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
53
COMPUTER FUNDAMENTAL & C PROGRAMMING ignored (that is, made 0). The d’s need not be covered by subcubes selected, but are used only to enlarge subcubes containing 1s, which must be covered. In fig.3.23(a) ,the vertical string of four d’s in the WX column is of use twice, once in filling out, or completing, the row of 1s and once in competing the third row. These subcubes give the terms
and YZ; so the minimal
sum-of-products expression is
+ YZ. Notice that if all the d’s were made os, the
solution would require more terms. Another problem is worked in fig.3.23 (b). For this problem the solution is .Notice that two of the d’s are made 0s.In effect, the d’s are chosen so that they lead to the best solution.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
54
COMPUTER FUNDAMENTAL & C PROGRAMMING
UNIT-III Anatomy of a Digital Computer 3.0 Functions and Components of a Computer 3.0.1 Central Processing Unit 3.0.2 Memory 3.0.3 How the CPU and Memory Work 3.1 Memory Units 3.1.1 Introduction 3.1.2 RAM 3.1.3 ROM 3.1.4 PROM 3.1.5 EPROM 3.1.6 EEPROM 3.1.7 Flash Memory 3.2 Input Devices 3.2.1 Introduction 3.2.2 Keyboard 3.2.3 Mouse 3.2.3.1 Types of Mice 3.2.3.2 Connections 3.2.3.3 Mouse Pad 3.2.4 Trackball 3.2.5 Joystick 3.2.6 Digitizing Tablet 3.2.7 Scanners 3.2.8 Digital Camera 3.2.9 Magnetic Ink Charater Recognition 3.2.10 Optical Character Recognition 3.2.11 Optical Mark Recognition 3.2.12 Bar Code Reader 3.2.13 Speech Input Devices 3.2.14 Touch Screen 3.2.15 Touch Pad 3.2.16 Light Pen 3.3 Output Devices 3.3.1 Introduction 3.3.2 Monitor
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
55
COMPUTER FUNDAMENTAL & C PROGRAMMING 3.3.2.1 Classification of Monitors-Based on Color 3.3.2.2 Classification Monitors-Based on Signals 3.3.2.3 Characteristics of a Monitor 3.3.3 Video Standards 3.3.4 Printer 3.3.5 Plotter 3.3.6 Sound Cards & Speakers 3.4 Auxiliary Storage Devices 3.4.1 Introduction 3.4.2 Magnetic Tape 3.4.3 Winchester Disk 3.4.4 Hard Disk 3.4.5 Floppy Disk 3.4.6 Zip Disk 3.4.7 Jaz Disk 3.4.8 Super Disk 3.4.9 Optical Disk 3.4.10 CD – ROM 3.4.11 CD – R Drive 3.4.12 CD – RW Disks
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
56
COMPUTER FUNDAMENTAL & C PROGRAMMING 3.0 FUNCTIONS AND COMPONENTS OF A COMPUTER To function properly, the computer needs both hardware and software. Hardware consists of the mechanical and electronic devices. The software consists of programs, the operating systems and the data that reside in the memory and storage devices. A computer does mainly the following four functions:
Receive input – Accept information from outside through various input devices like the keyboard, mouse, etc.
Process information – perform arithmetic or logical operations on the information.
Produce output – Communicate information to the outside world through output devices like monitor, printer, etc.
Store information – Store the information in storage devices like hard disk, floppy disks, etc.
Computer hardware falls into two categories: processing hardware, which consists of the central processing unit (CPU), and the peripheral devices. 3.0.1 CENTRAL PROCESSING UNIT (CPU) The part of the computer that executes program instructions is known as the processor or central processing unit (CPU). The CPU has two parts – the control unit and the arithmetic – logic unit (ALU). Control unit The control unit tells the rest of the computer system how to carry out a program’s instructions. It directs the movement of electronic signals between memory – which temporarily holds data, instructions and processed information – and the ALU. It also directs these control signals between the CPU and input/ output devices.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
57
COMPUTER FUNDAMENTAL & C PROGRAMMING
58
Arithmetic – Logic Unit (ALU) Arithmetic Logic Unit, usually called the ALU, performs two types of operations – arithmetic and logical. Arithmetic operations are the fundamental mathematical operations consisting of addition, subtraction, multiplication and division. Logical operations consist of comparisons. That is, two pieces of data are compared to see whether one is equal to., less than, or greater than the other. 3.0.2 MEMORY Memory – also known as the primary storage or main memory – is a part of the microcomputer that holds data for processing, instructions for processing the data (the program) and information. Part of the contents of the memory is held only temporarily, that is, it is stored only as long as the microcomputer is turned on. When you turn the machine off, the contents are lost. The capacity of the memory to hold data and program instructions varies in different computers hold approximately 6,40,000 characters of data or instructions only.
But modern microcomputers can hold millions, even billions of characters in their
memory. Registers Computers also have several additional storage locations called registers. These appear in the control unit and ALU and make processing more efficient. Registers areas hold data and instructions temporarily during processing. They are parts of the control unit and ALU rather than the memory. Addresses To locate the characters of data or instructions in the main memory, the computer stores them in locations known as addresses. A unique number designates each address. Addresses can be compared to post office mailboxes. Their numbers stay the same, but contents continuously change.
3.0.3 HOW THE CPU AND MEMORY WORK The various steps involved for multiplying two numbers is explained below: 1. The control unit recognizes that the programs has been loaded into memory.
It
begins to execute the first step in the program. st
2. The program tells the user, “Enter 1 Number.” 3. The user types the number 10 on the keyboard. An electronic signal is sent to the CPU. 4. The control unit recognizes this signal and routes the signal to an address in memory – address 7. 5. After completing the above instruction, the next instruction tells user, “Enter 2
nd
Number.” 6. The user types the number 4 on the keyboard. An electronic signal is sent to the CPU. 7. The control unit recognizes this signal and routes it to memory address 8.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING st
8. The next program instruction is executed – “Multiply 1 and 2
59 nd
Numbers.”
9. To execute this instruction, the control unit informs the ALU that two numbers are coming and the ALU is to multiply them. The control unit next sends to the ALU a copy of the contents of address 7(10) and address 8 (4). 10. ALU performs the multiplication: 10 X 4 = 40. 11. The control unit sends a copy of the multiplied result (40) back to memory, to address
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
60
12. The next program instruction is executed: “Print the Result.’ 13. To execute this instruction, the control unit sends the contents of the address 9(40) to the monitor. 14. Monitor displays the value 40. 15. Final instruction is executed: “End.” The program is complete.
3.1 MEMORY UNITS 3.1.1 INTRODUCTION Memory units are the internal storage areas in a computer.
The term “memory”:
identifies data storage that comes in the form of chips, and the word “storage” is used for memory that exists on tapes or disks.
Every computer comes with a certain amount of
physical memory, usually referred to as the main memory or the RAM. The main memory can hold a single byte of information in each location.
A computer that has 1 megabyte of
memory, therefore, can hold about 1 million bytes (or characters)of information. There are several different types of memory. 3.1.2 RAM Pronounced ramm, acronym for random access memory, a type of computer memory that can be accessed randomly; that is, any byte memory can be accessed without touching the preceding bytes. RAM is the most type of memory found in computers and other devices, such as printers. RAM refers to read and write memory. Most Ram is volatile when the power is turned off, whatever data was in Ram is lost. There are two types of RAM:
Dynamic RAM->It needs to be refreshed thousands of times per second.
Static RAM->It needs to be refreshed less often, which makes it faster; but it is also more expensive than dynamic RAM.
3.1.3 ROM Pronounced ROM, acronym for read-only memory, a computer memory on which data has been prerecorded. Once data has been written onto a ROM chip, it cannot be removed and can only be read. Unlike the main memory (RAM), ROM retains its contents even when the computer is turned off. ROM is referred to as being nonvolatile, whereas RAM is volatile. Most personal computers contain a small amount of ROM that stores critical programs such as the program that boots the computer.
In addition, ROMs are used
extensively in calculators and peripheral devices such as laser printers, whose fonts are often stored in ROMs. A variation of a ROM is the PROM (programmable read-only memory). PROMs are manufactured as blank chips on which data can be written. 3.1.4 PROM Pronounced prom, an acronym for programmable read-only memory. A PROM is a memory chip on which data can be written only once. Once a program has been written onto
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
61
a PROM, it remains there forever. Unlike the main memory, PROMs retain their contents when the computer is turned off. The difference between a PROM and a ROM (read-only memory) is that a PROM is manufactured as blank memory, whereas a ROM is programmed during the manufacturing process.
To write data onto a PROM chip, you need a special device called a PROM
programmer or a PROM burner. The process of programming a PROM is sometimes called burning the PROM. 3.1.5 EPROM Acronym for Erasable Programmable Read â&#x20AC;&#x201C;Only Memory, and pronounced eeprom, EPROM is a special type of memory that retains its contents until it is exposed to ultraviolet light. The ultraviolet light clears its contents, making it possible to reprogram the memory. An EPROM differs from a PROM in that a PROM can be written to only once and cannot be erased. EPROMs are used widely in personal computers because they enable the manufacture to change the contents of the PROM before the computer is actually shipped. This means that bugs can be removed and new versions installed shortly before delivery. 3.1.6 EEPROM Acronym for electrically erasable programmable read-only memory. Pronounced double-ee-prom, an EEPROM is a special type of PROM that can be erased by exposing it to an electrical charge. Like other types of PROM, EEPROM retains its contents even when the power is turned off. Also like all other types of ROM, EEPROM is not as fast as RAM. EEPROM is similar to flash memory (sometimes called flash EEPROM).
The
principle difference is that EEPROM requires data to be written or erased one byte at a time whereas flash memory allows data to be written or erased in blocks.
This makes flash
memory faster. 3.1.7 FLASH MEMORY Flash memory is a special type of EEPROM that can be erased and reprogrammed in blocks instead of one byte at a time. Many modern PCs have their BIOS (Basic Input Output System) stored on a flash memory ship so that it can easily be updated if necessary. Such a BIOS is sometimes called a flash BIOS. Flash memory is also popular in moderns because it enables the modern manufacturer to support new protocols as they become standardized.
3.2 INPUT DEVICES
3.2.1 INTRODUCTION An input device is any machine that feeds data into a computer. For example, a keyboard is an input device, whereas a display monitor is an output device. Input devices other than the keyboard are sometimes called alternate input devices. Mice, trackballs, and light pens are all alternate input devices.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
3.2.2 KEYBOARD Keyboard is an input device consisting of a set typewriter-like keys that enable you to enter data into a computer. Computer keyboards are similar to electric-typewriter keyboards but contain additional keys. The keys on computer keyboards are often classified as follows:
Alphanumeric keys – letters and numbers
Punctuation keys – comma, period, semicolon, and so on.
Special keys – function keys, control keys, arrow keys, caps Lock key, and so on.
There are actually three different PC keyboards: the original PC keyboard, with 84 keys; the AT keyboard, also with 84 keys; and the enhanced keyboard, with 101 keys. In addition to these keys, IBM keyboards contain the following keys: Page UP, Page Down, Home, End, Insert, Pause, Num Lock, Scroll Lock, Break, Caps Lock, Print Screen.
3.2.3 MOUSE Mouse is a device that controls the movement of the cursor or pointer on a display screen. A mouse is a small object you can roll along a hard, flat surface. As you move the mouse, the pointer on the display screen moves in the same direction. Mice contain at least one button and sometimes as many as three, which have different functions depending on what program is running. In particular, the mouse is important for graphical user interfaces because you can simply point to options and objects and click a mouse button. Such applications are often called point- and – click programs. The mouse is also useful for graphics programs that allow you to draw pictures by using the mouse like a pen, pencil, or paintbrush.
3.2.3.1 Types of Mice There are three basic of Mice. Mechanical
Has a rubber
or metal ball on its underside that can roll in all directions.
Mechanical sensors within the mouse detect the direction the ball is rolling and move the screen pointer accordingly. Optomechanical
Same as a mechanical mouse, but uses optical sensors to detect motion
of the ball. Optical Uses a laser to detect the mouse’s movement. You must move the mouse along a special mat with a grid so that the optical mechanism has a frame of reference. Optical mice have no mechanical moving parts. They respond more quickly and precisely than mechanical and optomechanical mice, but they are also more expensive. 3.2.3.2 Connections Mice connect to PCs in one of three ways:
Serial mice connect directly to an RS-232C serial port or a PS/2 port. This is the simplest type of connection.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
62
COMPUTER FUNDAMENTAL & C PROGRAMMING
Bus mice connect to the bus through an interface card. This is somewhat more complicated because you need to configure and install an expansion board.
Cordless mice aren’t physically connected at all. Instead they rely on infrared or radio waves to communicate with the computer.
3.2.3.3 Mouse pad Mouse pad is a pad over which you can move a mouse. 3.2.4 TRACKBALL Trackball is another pointing device. Essentially, a trackball is a mouse lying on its back. To move the pointer, you rotate the ball with your thumb, your fingers, or the palm of your hand. There are usually one to three buttons next to the ball, which you use just like mouse buttons. The advantage of trackballs over mice is that the trackball is stationary so it does not require much space to use it. In addition, you can place a trackball on any type of surface, including your lap.
For both these reasons, trackballs are popular pointing devices for
portable computers. 3.2.5 JOYSTICK A lever that moves in all directions and controls the movement of a pointer or some other display symbols. A joystick is similar to a mouse, except that with a mouse cursor stops moving as soon as you stop moving the mouse. With a joystick, the pointer continues moving in the direction the joystick is pointing. To stop the pointer, you must return the joystick to its upright position. Joystick are used mostly for computer games, but they are also used occasionally for CAD/CAM systems and other applications. 3.2.6 DIGITIZING TABLET This is an input device that enables you to enter drawings and sketches into a computer. A digitizing tablet consist of an electronic tablet and a cursor or pen. A cursor (also called a puck) is similar to a mouse, except that it has window with crosshairs for pinpoint placement and it can have as any as 16 buttons A pen (also called a stylus) which looks like a simple ballpoint pen but uses an electronic head instead of ink.
The tablet contains electronic that enable it to detect
movement of the cursor or pen and translate the movements into digital signals that it sends to the computer. Digitizing tablet are also called digitizers, graphics tablets, touch tablets, or simply tablets. 3.2.7 SCANNERS Scanner is an input device that can read text or illustrations printed on paper and translate the information into a form that the computer can use. A scanner works by digitizing an image – dividing it into a grid of boxes and representing each box with either a zero or a one, depending on whether the box is filled in. The resulting matrix of bits, called a bit map, can then be stored in a file, displayed on a screen, and manipulated by programs.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
63
COMPUTER FUNDAMENTAL & C PROGRAMMING Optical scanners do not distinguish text from illustrations; they represent all images as bit maps. Therefore, you cannot directly edit text that has been scanned. To edit text read by an optical scanner, you need an optical character recognition (OCR) system to translate the image into ASCII characters.
Most optical scanners sold today come with OCR
packages. Scanners differ from one another in the following respects: Scanning technology Most scanners use charge – coupled device (CCD) arrays, which consists of tightly packed rows of light receptors that can detect variations in light intensity and frequency. The quality of the CCD array is probably the single most important factor affecting the quality of the scanner.
Industry – strength drum scanners use a different
technology that relies on a photomultiplier tube (PMT) but this type of scanner is much more expensive than the more common CCD – based scanners. Resolution The denser the bit map, the higher the resolution. Typically, scanners support resolutions from 72 to 600 dots per inch (dpi). Bit depth
The number of bits used to represent each pixel. The greater the bit depth, the
more colors or grayscales can be represented. For example, a 24-bit color scanner can th
represent 2 to the 24 power (16.7 million) colors. Note, however, that a large color range is useless if the CCD arrays are capable of detecting only a small number of distinct colors. Size and shape Some scanners are small hand-held devices that you move across the paper. These hand- held scanners are often called half-page scanners,which are adequate for small pictures and photos, but they are difficult to use if you need to scan an entire page of text or graphics. Larger scanners include machines into which you can feed sheets of paper. These are called sheet-fed scanners. Sheet-fed scanners are excellent for loose sheets of paper, but they are unable to handle bound documents. A second type of large scanner, called a flatbed scanner, is like a photocopy machine. It consist of a board on which you lay books, magazines, and other documents that you want to scan.
3.2.8 DIGITAL CAMERA Images can be input into a computer using a digital camera. These images can then be manipulated in many ways using the various imaging tools available. The digital camera takes a still photograph, stores it, and then sends it as digital input into the computer. The images are then stored as digital files.
3.2.9 MAGNETIC INK CHARATER RECOGNITION (MICR)
Magnetic Ink Character Recognition (MICR) allows the computer to recognize characters printed using magnetic ink. MICR is a direct-entry method used in banks. This technology is used to automatically read those frustrating – looking numbers on the bottom of the cheque. A special –purpose machine known as a reader/sorter reads characters made of ink containing magnetized particles. A related technology is the magnetic strip, used on the
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
64
COMPUTER FUNDAMENTAL & C PROGRAMMING
65
back of credit cards and bank debit cards, that allows readers such as Automated Teller Machines (ATMs) to read account information and facilitate monetary transactions. Another example of magnetic strip technology is in ID cards, which can be used for a variety of functions from attendance monitoring to restricting access to specific locations. 3.2.10 OPTICAL CHARACTER RECOGNITION (OCR) Often abbreviated OCR, optical character recognition refers to the branch of computer science that involves reading text from paper and translating the images into a form that the computer can manipulate (for example, into ASCII codes). An OCR system enables you to take a book or a magazine article and feed it directly into an electronic computer file. All OCR systems include an optical scanner for reading text, and sophisticated software for analyzing images.
Most OCR systems use a combination of hardware
(specialized circuit boards) and software to recognize characters, although some inexpensive systems do it entirely through software. Advanced OCR systems can read text in a large variety of fonts, but they still have difficulty with handwritten text.
3.2.11 OPTICAL MARK RECOGNITIO0N (OMR) Optical Mark Recognition (OMR) also called mark sensing is a technology where an OMR device senses the presence or absence of a mark, such as a pencil mark. OMR is used in tests such as aptitude tests.
3.2.12 BAR CODE READER You are probably familiar with the bar code readers in supermarkets, bookshops, etc. Bar code readers are photoelectric scanners that read the bar codes, or vertical zebra striped marks, printed on product containers.
Supermarkets use a bar code system called the
Universal Product Code (UPC). The bar code identifies the product to the supermarket’s computer, which has a description and the latest price of the product. The computer automatically tells the POS (Point Of Sales) terminal what the price is.
3.2.13 SPEECH INPUT DEVICES Speech or voice input devices convert a person’s speech into digital form. These input devices, when combined with appropriate software, form voice recognition systems. These systems enable users to operate microcomputers using voice commands. Some of these systems must be ‘trained ’ to the particular user’s voice. This is done by his/her spoken words to patterns previously stored in the computer.
More advanced
systems that can recognize the same word spoken by many different people have been developed. However, until recently the list of words has been limited. A newly developed voice recognition system like IBM Voice Type identifies more than 30,000 words and adapts to individual voices. There are even systems that will translate from one language to another, such as from English Japanese.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING There are two types of voice recognition systems:
Continuous Speech
Discrete – Word
Continuous Speech Continuous speech recognition systems are used to control a microcomputer’s operations and to issue commands to special application programs. For example, rather than using the keyword to save a spreadsheet file, the user could simply say “Save the file”. Two popular systems are Apple Computer’s Plain Talk and IBM’s continuous speech series. Discrete – word A common activity in business is preparing memos and other written documents. Discrete – word recognition systems allow users to dictate directly into a microcomputer using a microphone. The microcomputer stores the memo in a word processing file where it can be revised later or directly printed out. IBM Voice Type Simply Speaking is an example.
3.2.14 TOUCH SCREEN Touch screen is a type of display screen that has a touch-sensitive transparent panel covering the screen. Instead of using a pointing device such as a mouse or light pen, you can use your finger to point directly to objects on the screen. Although touch screens provide a natural interface for computer novices, they are unsatisfactory for most applications because the finger is such a relatively large object. It is impossible to point accurately to small areas of the screen. In addition, most users find touchscreens tiring to the arms after long use.
3.2.15 TOUCH PAD A small, touch – sensitive pad used as a pointing device on some portable computers. By moving a finger or other object along the pad, you can move the pointer on the display screen.
3.2.16 LIGHT PEN Light pen is a device that utilizes a light – sensitive detector select objects on a display screen. A light pen is similar to a mouse, expect that with a light pen you can move the pointer and select objects on the display screen by directly pointing to the objects with the pen.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
66
COMPUTER FUNDAMENTAL & C PROGRAMMING
3.3 OUTPUT DEVICES
3.3.1 INTRODUCTION Output is anything that comes out of a computer. An output device is any machine capable of representing information from a computer.
Output devices include display
screens, loudspeakers, printers, plotters, etc.
3.3.2 MONITOR Monitor is another term for the display screen. The term monitor, however, usually refers to the entire box, whereas display screen can mean just the screen. 3.3.2.1 CLASSIFICATION OF MONITORS – BASED ON COLOUR There are many ways to classify monitors. The most basic is in terms of colour capabilities, which separates monitors into three classes.
Monochrome Monochrome monitors actually display two colours, one for the background and one for the foreground. The colours can be black and white, green and black, or amber and black. and white, green and black, or amber and black. Gray – scale A gray – scale monitor is a special type of monochrome monitor capable of displaying different shades of gray.
Colour Colour monitors can display anywhere from 256 to over 1 million different colours. Colour monitors are sometimes called RGB monitors because they accept three separate signals – red, green, and blue. All colour computer monitors are RGB monitors. An RGB monitor consists of a vacuum tube with three electron guns – one each for red , green, and blue at one end and the screen at the other end. The three electron guns fire electrons at the screen, which contains a phosphorous coating.
When the electron beams excite the
phosphors, they glow. Depending on which beam excites them, they glow red, green, or blue. Ideally, the three beams should converge for each point on the screen so that each pixel is a combination of the three colours. Colour and gray – scaling monitors are often classified by the number of bits they use to represent each pixel. For example, an 8- bit monitor each pixel with 8 bits. The more bits per pixel, the more colours and shades of gray the monitor can display.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
67
COMPUTER FUNDAMENTAL & C PROGRAMMING
68
3.3.2.2 CLASSIFICATION MONITORS â&#x20AC;&#x201C; BASED ON SIGNALS Another common way of classifying is in terms of the type of signal they accept; analog or digital. Digital Monitor A digital monitor accepts digital signals rather than analog signals.
All monitors
(except flat- panel displays) use CRT technology, which is essentially analog. The term digital, therefore, refers only to the type of input received from the video adapter. A digital monitor then translates the digital signals into analog signals that control the actual display. Although digital monitors are fast and produce clear images, they cannot display variable colours continuously. Consequently, only low-quality video standards such as MDA (Monochrome Display Adepter), CGA (Colour/Graphics Adapter), and EGA (Enhanced Graphics Adapter), specify digital signals. VGA (Video Graphics Array) and SVGA (Super VGA), on the other hand, require an analog monitor. Some monitors are capable of accepting either analog or digital signals. Analog Monitor This is the traditional type of colour display screen that has been used for years in televisions. In reality, all monitors based on CRT technology (that is, all monitors except flatpanel displays) are analog. Some monitors, however, are called digital monitors because they accept digital signals from the video adapter. EGA monitors, for example, must be digital because the EGA standard specifies digital signals.
Digital monitors must nevertheless
translate the signals into an analog form before displaying images.
Some monitors can
accept both digital and analog signals. Some monitors have fixed frequency, which means that they accept input at only one frequency. Another type of monitor, called a multiscanning monitor, automatically adjusts to the frequency of the signals being sent to it. This means that it can accept input from different types of video adapters. Like fixed â&#x20AC;&#x201C; frequency monitors, multiscanning monitors accept TTL, analog, or both types of input.
3.3.2.3 CHARACTERISTICS OF A MONITOR Size The most important aspect of a monitor is its screen size. Like televisions, screen sizes are measured in diagonal inches, the distance from one corner to the opposite corner diagonally. A typical size for small VGA monitors is 14 inches. Monitors that are 16 or more inches diagonally are often called full- page monitors. In addition to their size, monitors can be either portrait (height greater than width) or landscape (width greater than height). Larger landscape monitors can display two full pages, side by side. Resolution The resolution of a monitor indicates how densely the short for Picture Element.
pixels are packed. Pixel is
A pixel is a single point in a graphic image. Graphics monitors
display pictures by dividing the display screen into thousands (or millions) of pixels, arranged
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
69
in rows and columns. The number of bits used to represent each pixel determines how many colours or shades of gray can be displayed. For example an 8- bit colour monitor uses 8 bits for each pixel, making it possible to display 2 to the 8
th
power (256) different colours or
shades of gray. On colour monitors, each pixel is actually composed of three dots – a red, a blue, and a green one. The quality of a display monitor largely depends on its resolution, how many pixels it can display, and how many bits are used to represent each pixel.
VGA
monitors display 640 by 480, or about 300,000 pixels. In contrast, SVGA monitors display 1,024 by 768, or nearly 800,000 pixels. Most modern monitors can display 1024 by 768 pixels, the SVGA standard. Some high – end models can display 1280 by 1024, or even 1600 by 1200.
Bandwidth The amount of data that can be transmitted in a fixed amount of time. For digital devices, the bandwidth is usually expressed in bits or bytes per second (bps). For analog devices, the bandwidth is expressed in cycles per second, or Hertz (Hz).
Refresh Rate Display monitors must be refreshed many times per second.
The refresh rate
determines hoe many times per second the screen is to be refreshed (redrawn). The refresh rate for a monitor is measured in hertz (Hz) and is also called the vertical frequency or vertical refresh rate.
The old standard for monitor refresh rates was 60 Hz, but a new
standard developed by VESA sets the refresh rate at 75Hz for VGA and SVGA monitors. The faster the refresh rate, the less the monitor flickers. Interlaced or Non – interlaced Interlacing is a display technique that enables a monitor to provide more resolution in expensively. With interlacing monitors, the electron guns draw only half the horizontal lines with each pass (for example, all odd lines on one pass and all even lines on the next pass). Because an interlacing monitor refreshes only half the lines at one time, it can display twice as many lines per refresh cycle, giving it greater resolution. Another way of looking at it is that interlacing provides the same resolution as non-interlacing, but less expensively.
A
shortcoming of interlacing is that the reaction time is slower, so programs that depend on quick refresh rates (animation and video, for example), may experience flickering or streaking. Given two monitors that offer the same resolution, the non – interlacing one will generally be better. Dot – pitch A measurement that indicates the vertical distance between each pixel on a display screen. Measured in millimeters, the dot pitch is one of the principal characteristics that
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING determine the quality of display monitors.
The dot pitch of colour monitors for personal
computers ranges from about 0.15 mm 0.30mm. Another term for dot pitch is phosphor pitch.
Convergence Convergence refers to how sharply an individual colour pixel on a monitor appears. Each pixel is composed of three dots â&#x20AC;&#x201C; a red, blue, and green one. If the dots are badly misconverged, the pixel will appear blurry. All monitors have some convergence errors, but they differ in degree.
3.3.3 VIDEO STANDARDS There are a variety of video standards that define resolution and colours for displays. Support for a graphics standard is determined by both the monitor and the video adapter. The monitor must be able to show the resolution and colours defined by the standard, and the video adapter must be capable of transmitting the appropriate signals to the monitor. Listed here, in approximate order of increasing power and sophistication, are the more popular video standards for PCs. Note that many of these numbers represent only the minimums specified in the standards. resolution and more colours.
Many suppliers of video adapters provide greater
For more information, refer to the entries for the specific
graphics systems given in table 9.1.
VGA Abbreviation of video graphics array, a graphics display system for PCs developed by IBM. VGA has become one of the de facto standards for PCs. In text mode, VGA systems
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
70
COMPUTER FUNDAMENTAL & C PROGRAMMING
71
provide a resolution of 720 by 400 pixels. In graphics mode, the resolution is either 640 by 480 (with 16 colours) or 320 by 200 (with 256 colours).
The total palette of colours is
262,144.
SVGA Short for Super VGA, a set of graphics standards designed to offered greater resolution than VGA.
There are several varieties of SVGA, each providing a different
resolution:
800 by 600 pixels
1024 by 768 pixels
1280 by 1024 pixels
1600 by 1200 pixels
All SVGA standards support a palette of 16 million colours, but the number of colours that can be displayed simultaneously is limited by the amount of video memory installed in a system.
8514/A A high – resolution video standard for PCs developed by IBM in 1987.
It was
designed to extend the capabilities of VGA. The 8514/A standard provides a resolution of 1,024 by 768 pixels, which gives it about 2.5 times the pixels of VGA (640 by 480). Like VGA, 8514/A provides a palette of 262,000 colours, of which 256 can be displayed at one time. On monochrome displays, 8514/A provides 64 shades of gray. XGA Short for extended graphics array, a high – resolution graphics standard introduced by IBM in 1990. XGA was designed to replace the order 8514/A video standard. It provides the same resolutions (640 by 480 or 1024 by 768 pixels), but supports more simultaneous colours (65 thousand compared to 8514/A’s 256 colours). In addition, XGA allows monitors to be non – interlaced. TI 34010 TI 34010 is a video standard from Texas Instruments that supports a resolution of 1,024 by 768. TI 34010 conforms to TI’s Graphics Architecture (TIGA ). Unlike IBM’s 8514/A, which supports the same resolution. TI 34010 is non – interlaced.
3.3.4 PRINTER Printer is a device that prints text or illustrations on paper and in many cases on transparencies and other media. There are many different types of printers. In terms of the technology utilized, printers fall into the following categories. Daisy – wheel Printer Daisy – wheel printers are a type of printer that produces letter- quality type. A daisy – wheel printer works on the same principles as a ball – head typewriter. The daisy wheel
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING is a disk made of plastic or metal on which characters stand out in relief along the outer edge. To print a character, the printer rotates the disk until the desired letter is facing the paper. Then a hammer strikes the disk, forcing the character to hit an ink ribbon, leaving an impression of the character on the paper. You can change the daisy wheel to print different fonts. Daisy – wheel printers cannot print graphics, and in general they are noisy and slow, printing from 10 t about 75 characters per second. Dot – matrix Printer Dot – matrix printers create characters by striking pins against an ink ribbon. Each pin makes a dot, and combinations of dots form characters and illustrations. Dot- matrix printers are inexpensive and relatively fast, but they do not produce high – quality output. Dot – matrix printers vary in two important characteristics:
Speed – Given in characters per second (cps), the speed can vary from about 50 to over 500 cps.
Print quality – Determined by the number of pins (the mechanisms that , print the dots), it can vary from 9 to 24. The best dot– matrix printers (24 pins) can produce near letter- quality type, although you can still see a difference if you look closely.
Ink – jet Printer Ink – jet printers work by sparing ionized ink at a sheet of paper. Magnetized plates in the ink’s path direct the ink onto the paper in the paper in the desired shapes. Ink – jet printers are capable of producing high quality print approaching that produced by laser printers. A typical ink- jet printer provides a resolution of 300 dots per inch. The price of ink – jet printers is lower than that of laser printers. However, they are also considerably slower. Another drawback of ink – jet printers is that they require a special type of ink that is apt to smudge on inexpensive copier paper. Laser Printer Laser printer utilizes a laser b4eam 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. Because an entire page is transmitted to a drum 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 laser printers even though they do not use lasers at all. One uses an array of LEDs to expose the drum, and the other uses LCDs. Once the drum is charged, however, they both operate like a real laser printer. 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. By comparison, offset printing usually prints at 1,200 or 2,400 dpi.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
72
COMPUTER FUNDAMENTAL & C PROGRAMMING Some laser printers achieve higher resolutions with special techniques known generally as resolution enhancement. In addition to the standard monochrome laser printer, which uses a single toner, there also exist colour laser printers that use four toners to print in full colour. Colour laser printers tend to be about five to ten times as expensive as their monochrome siblings. Laser printers produce very high – quality print and are capable of printing an almost unlimited variety of fonts. Most laser printers come with a basic set of fonts, called internal or resident fonts, but you can add additional fonts in one of two ways:
Font cartridges – Laser printers have slots in which you can insert font cartridges, ROM boards on which fonts have been recorded. The advantage of font cartridges is that they use none of the printer’s memory.
Soft fonts – All laser printers come with a certain amount of RAM memory, and you can usually increase the amount of memory by adding memory boards in the printer’s expansion slots. You can then copy fonts from a disk to the printer’s RAM. This is called downloading fonts. A font that has been downloaded is often referred to as a soft font, to distinguish it from the hard fonts available on font cartridges. The more RAM a printer has, more fonts that can be downloaded at one time.
LCD & LED Printers Similar to a laser printer but uses liquid crystals or light – emitting diodes rather than a laser to produce an image on the drum. Line Printer Line printers are high speed printers capable of printing an entire line at one time. A fast line printer can print as many as 3,000 lines per minute. The disadvantages of line printers are that they can print only one font, they cannot print graphics, the print quality is low, and they are very noisy. Thermal printer Thermal printers are printers that produce images by pushing electrically heated pins against special heat- sensitive paper. Thermal printers are inexpensive and are used in most calculators and many fax machines. They produce low- quality print, and the paper tends to curl and fades after a few weeks or months. Printers are also classified according to the following characteristics:
Quality of type – Type output produced by printers is said to be either letter quality (as good as a typewriter), near letter quality, or draft quality. Only daisy - wheel, ink – jet, and laser printers produce letter- quality type. Some dot –matrix printers claim letter – quality print, but if you look closely, you can see the difference.
Speed – Measured in characters per second (cps) or pages per minute (ppm), the speed of printers varies widely.
Daisy – wheel printers tend to be the slowest,
printing about 30 cps. Line printers are fastest (up to 3,000 lines per minute). Dot –
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
73
COMPUTER FUNDAMENTAL & C PROGRAMMING matrix printers can print up to 500 cps, and laser printers range from about 4 to 20 text pages per minute.
Impact or non – impact – Impact printers include all printers that work by striking an ink ribbon. Daisy – wheel, dot – matrix, and line printers are impact printers. Non – impact printers include laser printers and ink – jet printers. The important difference between impact and non – impact printers is that impact printers are much noisier but are useful for making multiple copies like carbon copies.
Graphics – Some printers (daisy – wheel and line printers) can print only text. Other printers can print both text and graphics.
Fonts – Some printers, notably dot –matrix printers, are limited to one or a few fonts. In contrast, laser and ink – jet printers are capable of printing an almost unlimited variety of fonts. Daisy – wheel printers can also print different fonts, but you need to change the daisy wheel, making it difficult to mix fonts in the same document.
3.3.5 PLOTTER Plotter is a device that draws pictures on paper based on commands from a computer. Plotters differ from printers in that they draw lines using a pen. As a result, they can produce continuous lines, whereas printers can only simulate lines by printing a closely spaced series of dots. Multicolour plotters use different – coloured pens to draw different colours. In general, poltters are considerably more expensive than printers. They are used in engineering applications where precision is mandatory.
3.3.6 SOUND CARDS & SPEAKERS An expansion board that enables a computer to manipulate and output sounds. Sound cards are necessary for nearly all CD-ROMs and have become commonplace on modern personal computers. Sound cards enable the computer to output sound through speakers connected to the board, to record sound input from a microphone connected to the computer, and ,manipulate sound stored on a disk. Nearly all sound cards support MIDI, a standard for representing music electronically. In addition, most sound cards are Sound Blaster – compatible, which means that they can process commands written for a Sound Blaster care, the de facto standard for PC sound. Sound cards use two basic methods to translate digital data into analog sounds:
FM (Frequency Modulation) Synthesis mimics different musical instruments according to built – in formulas.
Wavetable Synthesis relies on recordings of actual instruments to produce sound. Wavetable synthesis produce more accurate sound, but is also more expensive.
3D Audio 3D audio is a technique for giving more depth to traditional stereo sound. Typically, 3D sound, or 3D audio, is produced by placing a device in a room with stereo speakers. The
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
74
COMPUTER FUNDAMENTAL & C PROGRAMMING device dynamically analyzes the sound coming from the speakers and sends feedback to the sound system so that it can readjust the sound to give the impression that the speakers are further apart. 3D audio devices are particularly popular for improving computer audio where speakers tend to be small and close together. There are a number of 3D audio devices that attach to a computer’s sound card.
3.4 AUXILIARY STORAGE DEVICES
3.4.1 INTRODUCTION Auxiliary storage also known as auxiliary memory or secondary storage, is the memory that supplements the main storage. This is a long – term, non – volatile memory. The term non –volatile means it stores and retains the programs and data even after the computer is switched off. Unlike RAM which looses the contents when the computer is turned off, and ROM, to which it is not possible to add anything new, auxiliary storage devices allows the computer to record information semi – permanently, so it can be read later by the same computer or by another computer. Auxiliary storage devices are also useful in transferring data or programs from one computer to another. They also function as back – up devices which allows to back – up the valuable information that you are working on. So even if by some accident your computer crashes and the data in it is unrecoverable, you can restore it from your back – ups. The most common types of auxiliary storage devices are magnetic disks, floppy disks, hard disks, etc. There are two types of auxiliary storage devices. This classification is based on the type of data access: sequential and random. Based on the type of access they are called sequential – access media and random – media. In the case of sequential – access media, the data stored in the media can only be read in sequence and to get to a particular point on the media you have to go through all the preceding points. Magnetic tapes are examples of sequential access media. In contrast, disks are random access also called direct access media because a disk drive can access any point at random without passing through intervening points. Other examples of direct access media are magnetic disks, optical disks, zip disks etc.
3.4.2 MAGNETIC TAPE Magnetic tape is a magnetically coated strip of plastic on which data can be encoded. Tapes for computers are similar to the tapes used to store music. Some personal computers, in fact, enable you to use normal cassette tapes. Storing data on tapes is considerably cheaper than storing data on disks. Tapes also have large storage capacities, ranging from a few hundred kilobytes to several gigabytes. Accessing data on tapes, however, is much slower than accessing data on disks. Tapes are sequential access media, which means that to get to a particular point on the tape,
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
75
COMPUTER FUNDAMENTAL & C PROGRAMMING
76
the tape must go through all the preceding points. In contrast, disks are random access media because a disk drive can access any point at random without passing through intervening points. Because tapes are so slow, they are generally used only for long – term storage and backup. Data to be used regularly is almost always kept on a disk. Tapes are also used for transporting large amounts of data. Tapes come in a variety of sizes and formats (see table 10.1). Tapes are sometimes called streamers or streaming tapes. Type Half – inch
Capacity 60 MB – 400 MB
Description Half – inch tapes come both as 9 track reels and as cartridges. These tapes are relatively cheap, but require expensive tape drives.
Quarter – inch
40 MB – 5 GB
Quarter – inch cartridges (QIC tapes) are relatively inexpensive and support fast data transfer rates. QIC mini cartridges are even less expensive, but their data capacities are smaller and their transfer rates are slower.
8-mm Helical – scan
1GB – 5GB
8-mm helical – scan cartridges use the same technology as VCR tapes and have the greatest capacity. But they require expensive tape drivers and have relatively slow data transfer rates.
4-mm DAT
2GB-24G B
DAT (Digital Audio Tape) cartridges have the greatest capacity but they require expensive tape drivers and have relatively slow data transfer rates.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
77
Helical – scan Cartridge A type of magnetic tape that uses the same technology as VCR tapes. The term helical scan usually refers to 8-mm tapes, although 4-mm tapes (called DAt tapes ) uses the same technology. The 8-mm helical – scan tapes have data capacities from 2.5GB to 5GB.
DAT
Cartridge DAT (Digital Audio Tape) is a type of magnetic tape that uses an ingenious scheme
called helical scan to record data. A DAT cartridge is slightly larger than a credit card and contains a magnetic tape, that can hold from 2 to 24 gigabytes of data. It can support data transfer rates of about 2 MBps (Million bytes per second). Like other types of tapes, DATs are sequential – access media. The most common format for DAT cartridge is DDS (digital data storage) which is the industry standard for digital audio tape (DAT) formats. The latest format, DDS-3, specifies tapes that can hold 24 GB (the equivalent of over 40 CD-ROMs) and support data transfer rates of 2 MBps.
3.4.3 WINCHESTER DISK The term Winchester comes from an early type of disk drive developed by IBM that stored 30 MB and had a 30– millisecond access time; so its inventors named it a Winchester in honor of the 30-caliber rifle of the same name. Although modern disk drives are faster and hold more data, the basic technology is the same, so Winchester has become synonymous with hard disk.
3.4.4 HARD DISK Hard disk is a magnetic disk on which you can store computer data. The hard is used to distinguish it from a soft, or floppy, disk. Hard disks hold more data and are faster than floppy disks. A hard disk, for example, can store anywhere from 10 megabytes to several gigabytes, whereas most floppies have a maximum storage capacity of 1.4 megabytes. A single hard disk usually consists of several platters. Each platter requires two read/write heads, one for each side. All the read/write heads are attached to a single access arm so that they cannot move independently. Each platter has the same number of tracks, and a track location that cuts across all platters is called a cylinder. For example, a typical 84 megabyte hard disk for a PC might have two platters (four sides) and 1,053 cylinders In general, hard disks are less portable than floppies, although it is possible to buy removable hard disks.
There are two types of removable hard disks :
disk packs and
removable cartridges..
3.4.5 FLOPPY DISK Floppy disk is a soft magnetic disk. It is called floppy because it flops if you wave it (at least, the 5
1/4
– inch variety does). Unlike most hard disks, floppy disks (often
called floppies or diskettes) are portable, because you can remove them from a disk drive.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Disk drives for floppy disks are called floppy drives. Floppy disks are slower to access than hard disks and have less storage capacity, but they are less expensive and are portable. Floppies come in two basic sizes:
5
1/4
– inch – The common size for PCs made before 1987. This type of
floppy is generally capable of storing between 100K and 1.2 MB (megabytes) of data. The most common sizes are 360 K and 1.2MB.
3
1/2_
inch – Floppy is something of a misnomer for these disks, as they are
encased in a rigid envelope. Despite their small size, microfloppies have a larger storage capacity than their cousins – from 40K to 1.4MB of data. The most common sizes for PCs are 720K (double - density) and 1.44MB (highdensity). Macintoshes support disks of 400K, 800K, and 1.2MB.
3.4.6 ZIP DISK These are high – capacity floppy disk drives developed by the Iomega Corporation. Zip disks are slightly larger than the conventional floppy disks, and are about twice as thick. They can hold 100MB of data. Because they’re relatively inexpensive and durable, they have become a popular media for backing up hard disks and for transporting large files.
3.4.7 JAZ DISK These are removable disk drivers developed by the Iomega Corporation. The Jaz drive has a 12-ms average seek time and a transfer rate 5.5 Mbps. The removable cartridges hold 1GB of data.
The fast rates and large storage
capacity make it a viable alternative for backup storage as well as everyday use.
3.4.8 SUPER DISK This is a new disk storage technology developed by the Imation Corporation that supports very high-density diskettes. SuperDisk diskettes are etched with a servo pattern at the factory. This pattern is then read by the SuperDisk drive to precisely slign the read/write head. The result is that a SuperDisk diskette can have 2,490 tacks, as opposed to the 135 tacks that conventional 3.5 – inch 1.44 MB diskettes use. This density translates into 120MB capacity per diskette.
3.4.9 OPTICAL DISK Optical Disks are a storage medium from which data is read and to which it is written by lasers. Optical disks can store much more data – up to 6 gigabytes (6 billion bytes)- than magnetic media, such as floppies and hard disks. There are three basic of optical disks:
CD-ROM - Like audio CDs, CD-ROMs come with data already encoded onto them. The data is permanent and can be read any number of times, but CD-ROMs cannot be modified.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
78
COMPUTER FUNDAMENTAL & C PROGRAMMING
WORM – This term stands for write – once, read many. With a WORM disk drive, you can write data onto a WORM disk, but only once. After that, the WORM disk behaves just like a CD-ROM.
Erasable - Optical disks that can be erased and loaded with new data, just like magnetic disks. These are often referred to as EO (erasable optical) disks.
3.4.10 CD – ROM CD – ROM, which is pronounced as ‘see – dee - rom’, is the abbreviation of Compact Disc – Read – Only Memory. CD – ROM is a type of optical disk capable of storing large amounts of data - up to 1GB, although the most common size is 630 MB (megabytes). A single CD – Rom has the storage capacity of 700 floppy disks, enough memory to store about 300,000 text pages. CD – ROMs are recorded by the vendor, and once recorded, they cannot be erased and filled with new data. To read a CD, you need a CD – ROM player. Also called a CD – ROM drive, a CD – ROM player is a device that can read information from a CD – ROM. There are a number of features that distinguish CD – ROM players, the most important of which is probably their speed. CD– Rom players are generally classified as single – speed or some multiple of single – speed. For example, a 4X player access data at four times the speed of a single – speed player. Within these groups, however, there is some variation. Also, you need to be aware of whether the CD – ROM uses the CLV (Constant Linear Velocity) or CAV (Constant Angular Velocity) technology. Two more precise measurements are the drives seek time and data transfer rate. The seek time, also called the access time, measures how long, on average; it takes the drive to access a particular piece of information. The data transfer rate measures how much data can be read and sent to the computer in a second. Most CD –ROMs connect via a SCSI bus. Other CD – ROMs connect to an IDE or enhanced IDE interface, which is the one used by the hard disk drive. CD – ROMs are particularly well suited to information that requires large storage capacity. This includes color graphics, sound, and especially video. 3.4.11 CD – R Drive CD – R drive which is short for Compact Disk – Recordable drive, is a type of disk drive that can create CD- ROMs and audio CDs. This allows the users to “master” a CD – Rom or audio CD for publishing. Until recently, CD – R drives were quite expensive, but prices have dropped dramatically. A feature of many CD – R drives, called multisession recording, enables you to keep adding data to a CD – ROM over time. This is extremely important if you want to use the CD – R drive to create backup CD – ROMs. To create CD – ROMs and audio CDs, you’ll need not only a CD – R drive, but also a CD – R software package.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
79
COMPUTER FUNDAMENTAL & C PROGRAMMING
80
Often, it is the software package, not the drive itself that determines how easy or difficult it is to create CD – ROMs. CD – R drives can also read CD – ROMs and play audio CDs. 3.4.12 CD – RW Disks CD – RW disk is short for CD Rewritable disk and this is a new type of CD disk that enables you to write onto it in multiple sessions. One of the problems with CD – R disks is that you can only write to them once. With CD – RW drives and disks, you can treat the optical disk just like a floppy or hard disk, writing data onto it multiple times. The first CD – RW drives became available in mid – 1997. They can read CD– ROMs and can write onto today’s CD – R disks, but they cannot write on CD – ROMs. Many experts
believe
that
they’ll
be
a
popular
storage
medium.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
UNIT -IV DOS 4.0 Introduction 4.0.1 Different Versions of DOS 4.0.2 DOS Files 4.0.3 DOS Filenames 4.0.4 DOS Directory 4.0.5 DOS Prompt 4.0.6 Command Line 4.0.7 Cursor\>_ â&#x2020;? Cursor 4.0.8 DOS Commands WORD STAR 4.1 Introduction to Word Star DATABASE MANAGEMENT SYSTEM 4.2 Introduction to Database Management Systems 4.2.1 What is a Database 4.2.2 Why a Database 4.2.3 Characteristics of data in a Database 4.2.4 What is a Database Management System 4.2.5 Why DBMS 4.2.6 Types of Database Management Systems 4.2.6.1 Hierarchical Model 4.2.6.2 Network Model 4.2.6.3 Relational Model 4.2.6.4 Object-Oriented Model 4.2.6.5 Deductive/Inference Model
DBASE III PLUS 4.3 Introduction to Dbase III Plus 4.3.1 Starting and Quiting Dbase 4.3.2 Assist Command 4.3.3 Dos Prompt and Commands 4.3.4 Database Operations 4.3.4.1 Modifying the Database Structure 4.3.4.2 Editing Records 4.3.4.3 Retrieving Records 4.3.4.4 Deleting Records 4.3.4.5 Creating Reports
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
81
COMPUTER FUNDAMENTAL & C PROGRAMMING
ELECTRONIC SPREADSHEETS |4.4 Introduction to Electronic Spreadsheets 4.4.1 Characteristics of a Spreadsheet LOTUS 1-2-3 4.5 Lotus 1-2-3 4.5.1 @ Functions 4.5.2 Macros 4.5.3 Graphs & Charts INTERNET 4.6 Introduction to Internet 4.6.1 Whatâ&#x20AC;&#x2122;s Special about Internet 4.6.2 Internet Access 4.6.3 Internet Basics 4.6.4 Internet Protocols 4.6.4.1 Transmission Control Protocol/Internet Protocol (TCP/IP) 4.6.4.2 File Transfer Protocol (FTP) 4.6.4.3 Hypertext Transferred Protocol (HTTP) 4.6.4.4 Telnet 4.6.4.5 Gopher 4.6.4.6 Wais 4.6.5 Internet Addressing 4.6.5.1 IP Address 4.6.5.2 Domain Name 4.6.5.3 Electronic Mail Addresses 4.6.5.4 Uniform Resource Locator (URL) 4.6.6 The World Wide Web (WWW) 4.6.7 Web Pages & HTML 4.6.8 HTML 4.6.9 HTML Tags 4.6.10 Web Browsers 4.6.11 Searching the Web 4.6.11.1 Web Index 4.6.11.2 Searching Engines 4.6.11.3 Meta-Search Engines 4.6.12 Internet Chart 4.6.12.1 Internet Relay Chat (IRC) E-MAIL 4.7 Electronic Mail 4.7.1 Introduction
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
82
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.7.2 How E-Mail Works 4.7.3 E-Mail – Names & Addresses 4.7.4 Mailing Baiscs 4.7.5 E-Mail – Advantages & Disadvantages 4.7.6 Mailing Lists 4.7.7 Newsgroups
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
83
COMPUTER FUNDAMENTAL & C PROGRAMMING
84
DOS
4.0 INTRODUCTION DOS is the acronym for disk operating system. The term DOS can refer to any operating system, but it is most often used as a short form for MS-DOS (Microsoft disk operating system). Originally developed by Microsoft for IBM, MS-DOS is the standard operating system for IBM-compatible personal computers.
4.0.1 DIFFERENT VERSIONS OF DOS There have been several upgrades since MS-DOS was introduced.
The 1981
original labeled version 1.0. Since then there have been DOS 2.0, 2.1, 3.0, 3.1, 3.2, 3.3, 4.0, 4.1, 5.0, 6.0 and 6.2.
4.0.2 DOS FILES DOS is actually a collection of programs, each of which performs specific tasks. In DOS, programs and data are stored in files. A file is a group of related records and is the primary storage unit of data storage in DOS-based systems. A DOS file can contain either program instructions or data. Each DOS file has a unique file name. A filename is a unique name used to identify a file. It can be up to 8 characters in length followed by an optional period or dot and a threecharacter filename extension. DOS requires an ‘.EXE’ or ‘.COM’ extension for a program file.
4.0.3 DOS FILENAMES The different types of files used in DOS are distinguished from one another by their filename extensions. Some of the most common extensions are ‘.EXE’ or ‘.COM’ ‘.SYS’ etc.
4.0.4 DOS DIRECTORY DOS stores files on a disk in a directory. A directory is a list of files stored on a portion of the disk. The primary directory is called the root directory. DOS allows you to create subdirectories under the root directory.
4.0.5 DOS PROMPT Prompt is a character or message that tells the user that the computer is ready to accept a command or input. In DOS, the prompt is a right-pointing arrow or caret that looks like ‘:>’. You can enter your DOS commands at the DOS prompt. For example, when you want to see the root directory, you go to that directory and type the command ‘dir’. For example if you want to see the files in the C drive, you will type the ‘dir’ command at the prompt ‘C:>dir’.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.0.6 COMMAND LINE The portion of the screen where you enter instructions is called the command line. 4.0.7 CURSOR The cursor is usually a blinking rectangle or a blinking underline that appears just to the right of the prompt. The figure 20.2 shows the command line, the prompt and the cursor.
Command line
C:\>_ ← Cursor
→ccdd
↑ Prompt
C:\>_ ← Cursor ↑ Prompt
20.2 Command line with prompt and cursor
4.0.8 DOS COMMANDS If you want to accomplish certain tasks in DOS you do so by typing the appropriate DOS command and pressing enter. There are many Dos commands, but only a handful of them are used frequently. Some of most common DOS commands are given below:
COPY - Copies one or more files to a new destination directory or disk.
DATE - Displays the current date.
DEL
- Delete one or more files. Same as ERASE.
DIR
- Displays the listing of files in the current directory.
FORMAT - Prepares a new disk for use by DOS.
HELP - Starts DOS help.
MKDIR - Creates a new directory on a disk.
PATH - Specifies that DOS should execute commands or programs found in specific directories.
PRINT - Prints a DOS file.
REN or RENAME - Changes the name of a file.
TYPE - Displays the contents of a file on the screen.
WORD STAR
4.1 INTRODUCTION WordStar is the first and still one of the most popular word processing package. During the period from the mid 1970’s to the mid 1980’s MicroPro WordStar ruled the word processing world. WordStar was the first word processing program that was produced for microcomputers. AN INTERFACE DESIGNED FOR TOUCH TYPISTS WordStar was first released in 1979, before there was any standardization in computer keyboards. At that time, many keyboards lacked arrow keys for cursor movement
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
85
COMPUTER FUNDAMENTAL & C PROGRAMMING and special function keys for issuing commands. Some even lacked such keys as Tab. Insert, Delete, Backspace, and Enter. About all you could count on was having a standard QWERTY typewriter layout of alphanumeric keys and a Control key. The Control key is a specialized shift key. When depressed simultaneously with an alphabetic key, it causes the keyboard to generate a specific command instruction, rather than the letter. The control codes are named Ctrl-A through Ctrl-Z (there are a few punctuation keys that can generate control codes, too). Control codes are frequently indicated in text by preceding the letter with a caret, like: ^A. WordStar’s original designers, Seymour Rubenstein and Rob Barnaby, selected five control codes to be prefixes for bringing up additional menus of functions: ^O for On-screen functions; ^Q for Quick cursor functions; ^P for Print functions; ^K for block and file functions; and ^J for help.
Now, the first three of these are alphabetically mnemonic. The last two, ^K and ^J, might at first glance seem to be arbitrary choices. They aren’t. Look at a typewriter keyboard. You’ll see that for a touch typist, the two strongest fingers of the right hand rest over ^J and ^K on the home typing row. WordStar recognizes that the most-often-used functions should be the easiest to physically execute. To serve as arrow keys for moving the cursor up, left, right, or down, WordStar adopted ^E, ^S, ^D, and ^X. Again, looking at a typewriter keyboard makes the logic of this plain. These four keys are arranged in a diamond under the left hand:
E S
D X
Such positional, as opposed to alphabetic, mnemonics form a large part of the WordStar interface.
Additional cursor movement commands are clustered around the
E/S/D/X diamond:
W A
E
S Z
R D
X
F
C
^A and ^F, on the home typing row, move the cursor left and right by words. ^W and ^Z, to the left of the cursor-up and cursor-down commands, scroll the screen up and down by single lines. ^R and ^C, to the right of the cursor-up and cursor- down commands, scroll the screen up and down a page at a time (a “page” in the computer sense of a full screen of text).
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
86
COMPUTER FUNDAMENTAL & C PROGRAMMING ^Q the aforementioned quick-cursor-movement menu prefix extends the power of this diamond.
Just as ^E, ^S, ^D, ^X move the cursor up, left, right, and down by single
characters, ^QE, ^QS, ^QD, and ^QX move it all the way to the top, left, right, or bottom of the screen. ^W scrolls up one line; ^QW scrolls up continuously. ^Z scrolls down one line; ^QZ scrolls down continuously. And since ^R and ^C take you to the top and bottom of the screen, ^QR and ^QC take you to the top and bottom of the document. There are many more ^Q commands, but I think you can see from this sampling that there is an underlying logic to the WordStar
interface, something sorely lacking in many other programs particularly
WordPerfect.
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS
4.2 INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS A database management system (DBMS) is software that provides services for accessing a database, while maintaining all the required features of the data 4.2.1 WHAT IS A DATABASE A collection of data designed to be used different people is called a database. It is a collection of interrelated data stored together, with controlled redundancy to serve one or more applications in an optimal fashion. The data are stored in such a fashion that they are independent of the programs of people using the data. A common and controlled approach is used in adding new data and modifying and retrieving the existing data within the database. 4.2.2 WHY A DATABASE Why should an organization choose to use an integrated database to store its operational data? A general answer to this question is that a database system provides the organization with centralized control of its data. This is in sharp contrast to the situation that prevails in many enterprises, where typically each application has its own private files in its own tapes and disks, so that the data is widely dispersed and therefore difficult to control. Deficiencies of pre-database information processing include (but not limited to ) the following:
Encoded data (data hard-coded in the application)
Interdependence between programs and data files
Data repetition or redundancy
Data inconsistency
Lack of data integrity
Ad hoc representation of relationships
Ad hoc data management techniques
Lack of coordination across applications using common data
Lack of foolproof data security mechanisms
Inability to manage concurrent access to data
Non-uniform back-up and recovery methods
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
87
COMPUTER FUNDAMENTAL & C PROGRAMMING The advantage of having data in a database is summarized below: Redundancy can be reduced In non-database system, each application or department has its own private files resulting in a considerable amount of redundancy of the stored data. Thus, storage, space is wasted. By having a centralized database, most of this can be avoided. We do not say or suggest that all redundancy should be eliminated. Sometimes there are sound business and technical reasons for maintaining multiple copies of the same data. In a database system, however, this redundancy can be controlled. Inconsistency can be avoided This is really a corollary to the above point. When the same data is duplicated and changes are made at one site, which is not propagated, to the other site, its gives rise to inconsistency. Then the two entries regarding the same data will not agree. At such times, the data is said to be inconsistent. So, if redundancy is removed, the change of having inconsistent data is also removed. Data can be shared The existing applications can share the data in a database. Standards can be enforced With the central control of the database, he database administrator can enforce standards. Security restrictions can be applied With complete authority over the operational data, the database administrator can ensure that the only means of access to the database is through proper channels. He can define authorization checks to be carried out whenever access to sensitive data is attempted. Different checks can be established for each type of access (retrieve, modify, delete, etc.) to each piece of information in the database. Integrity can be maintained Integrity means that the data in the database is accurate. Centralized control of the data helps in permitting the administrator to define integrity constraints to the data in the database. Conflicting requirements can be balanced Knowing the overall requirements as opposed to the individual requirements, the database can be structured to provide an overall service that is best for the organization.
4.2.3 CHARACTERISTICS OF DATA IN A DATABASE The data in a database should have the following features:
Shared – Data in a database are shared among different users and applications.
Persistence – Data in a database exist permanently in the sense, the data can live beyond the scope of the process that created it.
Validity/integrity/Correctness – Data should be correct with respect to the real world entity that they represent.
Security – Data should be protected from unauthorized access.
Consistency – Whenever more than one data element in a database represents related real-world values, the values should be consistent with respect to the relationship.
Non-redundancy – No two data items in a database should represent the same realworld entity.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
88
COMPUTER FUNDAMENTAL & C PROGRAMMING
89
Independence – The three levels in the schema (internal, conceptual and external) should be independence of each other so that the changes in the schema at one level should not affect the other levels.
4.2.4 WHAT IS A DATABASE MANAGEMENT SYSTEM A database management system (DBMS) is software that provides services for accessing a database, while maintaining all the required features of the data. The major components of a DBMS are shown in the figure 24.4.
Catalog management
Applications Programming interface
Database
Security management Recovery management Transaction management Concurrency control Data Access
Storage manager
Some of the services provided by a DBMS are given below: Transaction processing A transaction in a sequence of database operations that represents a logical unit of work. It accesses a database and transforms it from one state to another. A transaction can update a record, delete one, modify a set of records, etc. When the DBMS does a ‘commit’, the changes made by the transaction are made permanent. If you don’t want of make the changes permanent you can rollback the transaction and the database will remain in its original state. Concurrency management Concurrency management is the database management activity of cording the actions of database manipulation process that operate concurrently, access shared data and can concurrency while maintaining the consistency of the shared data. Recovery The objective of recovery in a database is to ensure that the aborted or failed transactions do not create any adverse effects on the database or other transactions. Recovery mechanisms in a DBMS make sure that the database is returned to a consistent state after a transaction fails or aborts. Recovery is very much related to concurrency in the sense that, the more concurrency, the more is the chance of an aborted transaction can affect many other transactions. Security Security refers to the protection of data against unauthorized access.
Security
mechanisms of a DBMS make sure that only authorized users are given access to the data in the database. The level of access for each user and the operations that each user can perform on the data will be monitored and controlled by the DBMS depending on the access privileges of the users.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
90
Language interface The DBMS provides support languages used for the definition and manipulation of the data in the database. The data structures are created using the data definition language commands. The data manipulation is done using the data manipulation commands. By the users can do their jobs without worrying about the physical implementation. Data catalog Data catalog or Data Directory is a system database that contains the description of data in the database (metadata). It contains information about data, relationships, constraints and the entire schema that organize these features into a unified database. The data catalog can be queried to get information about the structure of the database. Storage management The DBMS provides a mechanism for the management of permanent storage of the data. The internal schema defines how the data should be stored by be storage management mechanism and the storage manager interfaces with the operating with the operating system to access the physical storage. 4.2.5 WHY DBMS A DBMS provides a secure and survivable medium for the storage and retrieval of data. If the users and applications do not share data among themselves and if the longevity of the data is only till the end of the process or application that created it, then there is not much need for a DBMS. But in real world, the data is shared and is persistent (that is, the data has a life beyond the boundaries of the programs and applications that created it). Also, the real world data have a structure. It is related to one another and has constraints. These features are well represented and can be efficiently managed using a DBMS. Also, the different users of the data need to create, access and manipulate the data. The DBMS provides mechanisms to archive these objectives without compromising the security and integrity of the data. Therefore, if the data is shared, if it is persistent, if the users want it be secure and easy to access and manipulate, then use of a database management system is the best available alternative.
4.2.6 TYPES OF DATABASE MANAGEMENT SYSTEMS While storage of data determines much about how best it is used, there are other measures of the usefulness of data. One of these measures is how the data is structured. The structure of the data refers to the view the programmer or user has of the data, as data is inserted, retrieved or deleted form the system. Of course, the structure of the data is ultimately embodied at the basic physical level. This means that, at a lower level, data structures, however they are presented, consists of records, blocks, addresses etc.
To illustrate the usefulness of a data structure, consider the simple relationship of data as shown in the figure 24.5.
BOOK
Distributor
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING In the above figure a book and a distributor are shown to be related. There are several ways to depict this relationship. One way for the relationship to exist from the book to the distributor (a 1:n relationship). In this case, given a book, the distributors of that particular book can be determined. Another form of relationship is from the distributorâ&#x20AC;&#x2122;s point of view (another 1:n relationship). What books does the distributor supply? Still a third view combines both the book and the distributor view, so that the relationship may be viewed from either perspective (an m:n relationship). Thus the book/distributor relationship can be described in many different ways. As we have seen above, the relationships between the data elements can be expressed in different ways. A DBMS can take any one of the several approaches to manage the data. Each approach constitutes a database model. A database model is an organizing principle that specifies particular mechanisms for data storage and retrieval. The model explains, in terms of services available to an interfacing application, how to access a data element when other related data elements are known. Regardless of the underlying database model, a specific DBMS manages information from some real-world application. From the application viewpoint, the different database models share a common goal-to facilitate the storage and retrieval of information. The primary difference between the different database models lie in the methods of expressing the relationships and constraints among the data elements. In this chapter five database models are introduced: Hierarchical, Network, Relational, Object- oriented and Deductive. The systematic development of databases started with the hierarchical and network models, which were popular in the 1960s and 1970s. The Relational model is the current favorite while the object-oriented and deductive models are slowly emerging and point the way to the future. The reason shy the relational model is the most popular is because of its immense user base, its power to organize data, its performance as a data management tool and its many popular-commercial implementations (DB2. Oracle, Sybase, MS-SQL Server, MS-Access, etc. To name a few). When relational model came into the scene its superiority over the existing models (hierarchical and network) was very striking. After the infancy and a series of refinements and enhancements, the relational model matured to become so successful that it rendered its predecessors obsolete. The newer models (object-oriented and deductive) do offer some advantages over the relational model, but their evolution has not been dramatic as that of the relational model. Also, from the industrial trends, it seems unlikely that these newer models will quickly replace the relational model, especially because extended relational products (for example objectrelational models) continue to appear. 4.2.6.1HIERARCHICAL MODEL Hierarchical Database model is one of the oldest database models, dating from the late 1950s. The hierarchical model assumes that a tree structure is the most frequently occurring relationship. This assumption is recognized today as misleading. In fact, many of
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
91
COMPUTER FUNDAMENTAL & C PROGRAMMING
92
the limitations and shortcomings of the hierarchical model result from this overly restrictive view of relationships. Hierarchical model organizes data elements as tabular rows, one for each instance of an entity. Consider a company’s organizational structure. At the top we have a general manager (GM). Under him, we have several Deputy General Managers (DGMs). Each DGM looks after a couple of departments and each department will have a manager and many employees. When represented in a hierarchical model, there will be separate rows for representing the GM, each DGM, each Department, each Manager and each Employee. The row position implies a relationship to the other rows. A given employee belongs to the department that is closest above it in the list and the department belongs to the manager who is immediately above it in the list and so on.
4.2.6.2 Network Model: The Network model replaces the hierarchical tree with a graph thus allowing more general connections among the nodes. Suppose an employee works for two departments. The strict hierarchical arrangement is not possible here and the tree becomes a more general graph – a network. Logical proximity fails because you can’t place a data item simultaneously in two locations in the list. Although it is possible to handle such situations in a hierarchical model, it becomes more complicated and difficult to comprehend. The network model was evolved to specifically handle non-hierarchical relationships. Now we will consider a book-distributor example. A book can have many attributes like ISBN, Title, Author, Publisher, Year of Publication, Distributor, price, etc. Similarly, a distributor can have attributes like Name, Contact, Discount, Lead-time, etc. We will use this example to illustrate some of the models.
4.2.6.3 Relational Model The relational model uses tables to organize the data elements. Each table corresponds to an application entity, and row represents an instance of that entity. For example, the book entity in an application corresponds to a book table in the database. Each row in the table represents a different book. Relationships link rows from two tables by embedding row identifiers (keys) from one table as attribute values in the other table. For example, the Distributor Name, which is the row identifier in the Distributor table, is embedded as an attribute in the book table and for each book there will be a distributor name thus associating the book with a distributor. Structured Query Language (SQL)
serves as a
uniform interface for users providing a collection of standard expressions for storing and retrieving data. Although the relational model is currently the most popular database model, two other models- the object-oriented and deductive database models – which claim to be more flexible in data representation, at least for specialized applications are emerging into the commercial arena. Each offers an alternative to the table for maintaining relation ships between elements.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
4.2.6.4 Object-oriented Model Object-oriented model represents an entity as a class. A class represents both object attributes as well as the behavior of the entity. For example a book class will have not only the book attributes such as ISBN, Title, Author, Publisher, Year of Publishing, Distributor, Price, etc. but also procedures that imitate actions expected of a book such as UpdatePrice ( ), etc. Instances of the class-object- corresponds to individual books. Within an object, the class attributes takes specific values, which distinguish one book (object) from another. However the behavior patterns of the class is shared by all the objects belonging to the class. The object-oriented model does not restrict attribute values to the small set of native data types usually associated with databases and programming languages, such as integer, numeric, character, etc. Instead the values can be other objects. For example, one of the attributes of a book can be distributor and the value of that attribute can be a distributor object corresponding to the distributor who is distributing the book. The object-oriented model maintains relationships through ‘logical containment’. Consider the book distributor example. You find the distributor of a particular book in the book as one of its attributes. Since distributors is an object in its own right, you can recursively examine its attributes. The distributor object can have a title attribute, which can be a book object (assuming for the moment, that the distributor has only one book). But the book is the same book in which you originally found the distributor. So book ‘B’ contains distributor ‘BD’ which contains book ‘B’. This is logical containment and this is how the object-oriented model maintains relationships.
4.2.6.5 Deductive/Inference Model Deductive model also known as the inferential model, stores as little data as possible, but compensates by maintaining rules that allow new data combinations to be created when needed. Suppose the database stores the facts of the form DistBook (D,B) which means that distributor ‘D’ is distributing the book ‘B’. For example, DistBook (Mind Mart, ISO 9000 Handbook) can appear in the database meaning that the book ‘ISO 9000 Handbook’ is being distributed by the distributor with a name ‘Mind Mart’. A distributor can distribute more than one book and likewise one book can be distributed by many distributors. So you can form another relationship where two books distributed by the same distributor and which can be represented as SameDist (X,Y), meaning books X and Y are distributed by the same distributor. Although, the database explicitly stores the DistBook (D,B) facts, it does not store the SameDist (X,Y) facts.
Instead, it stores a rule stating that SameDist (X,Y) fact, say
SameDist(ISO9000 Handbook, Kaizen), can be deduced from the existing facts say DistBook (Mind Mart, ISO 9000 Handbook) and DistBook (Kaizen, Mind Mart). Such inference rules indirectly capture relationship groupings. The database thus stores certain elementary facts – axioms – from which other facts can be derived as
and when needed using the rules.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
93
COMPUTER FUNDAMENTAL & C PROGRAMMING
DBASE III PLUS 4.3 INTRODUCTION The introduction of dBase III raised this standard to a newer and less programmer dependent level. With dBase III plus, the user can retrieve information from stored data without the detailed knowledge of the database management system. The user can select the required operations from an easy to understand menu, ask questions about the data on the spur of the moment, and find answers that will help n get the job done better, faster, and more accurately.
4.3.1 STARTING AND QUITING dBASE You can a start the program by typing the command ‘DBASE’ after getting into the dBase subdirectory. Once you are in dBase you can get out of dBase either by selecting ‘Quit dBASE III PLUS’ menu item from the ‘File’ menu and pressing ENTER key or use the command ‘QUIT’ at the dot prompt.
4.3.2 ASSIST COMMAND ASSIST is a menu system that allows the user to interact with dBase III plus without programming.
dBase III plus automatically starts in ASSIST mode. After displaying the opening message, a horizontal menu bar appears at the top of the screen and a status line appears at the bottom. The submenus can be pulled down from the menu bar. The user can then move to a menu item by using the cursor-control keys and select it by it by pressing the ENTER key. Set Up Create Update Position Retrieve Organize Modify Tools 10:08:21pm
Database file Format for Screen Query Catalog View Quit dBASE III PLUS 4.3.3 DOS PROMPT AND COMMANDS From the assist screen, if you press the ‘Esc’ key, you will go to the dBase dot prompt. You can enter the dBase commands at the dot prompt. Once you are familiar with the
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
94
COMPUTER FUNDAMENTAL & C PROGRAMMING dBase commands, then you can use the dot prompt instead of going through the menu. For example, if you want to create database file, you can do it in two ways. First, you can select the ‘Database file’ menu item from item from the ‘Create’ menu. Another way of doing this is typing the command ‘CREATE’ at dot prompt. You can also enter abbreviated versions of the dBase commands at the dot prompt. The abbreviated form of any command is the first characters of each command. So instead of ‘CREATE’ you can enter ‘CREA’ and the result will be the same.
4.3.4 DATABASE OPERATIONS You can create a database in dBase. You can go through the ‘Create’ menu. choose the ‘Database file’ menu item and press the ‘ENTER’ key. You can also type the command ‘CREATE’ at the dot prompt. dBase will ask for the name of the database and once you have entered the name, will present you with a screen where you can enter the database structure. We will create a database with name CATALOG. Type the name and dBase will create a database with the extension ‘.dbf’. So the full name of the database will be CATALOG.DBF. You can enter the structure for the CATALOG database. The database contains information about books in a library. We will limit the number of books to 10 for convenience. So the CATALOG database will store information about books like title, author name, publisher name, price, stock position, publication data, etc. You can type in the field names, data type and length. The various data or field types are character, numeric, logical (since character fields for situations like Yes/No, True/False, etc), date and memo.
4.3.4.1 MODIFYING THE DATABASE STRUCTURE You can alter the database structure that you have created and saved. You can add fields or changes the field widths, etc. For example, if you want to increase the width of the field TITLE from 30 to 40 characters. First you type the command ‘MODIFY STRUCTURE’ at the dot prompt. You will be presented with the structure of the database where you can make the modifications. This is shown in the figure 25.4
4.3.4.2 EDITING RECORDS You can also give search criteria to find a particular record for editing. For example the command ‘EDIT FOR AUTHOR = “Joseph Heller”’ will display the record where the value of the field AUTHOR is ‘Joseph Heller’ for editing.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
95
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.3.4.3 Retrieving Records If you want to see only the TITLE and AUTHOR of the books, you can give the command ‘LIST TITLE, AUTHOR’. .LIST TITLE, AUTHOR
Record # TITLE
AUTHOR
1
Internet for everyone
Alexis Leon
2
Internet in a Nutshell
Mathews Leon
3
Count down 2000
4
Catch 22
Alexis Leon Joseph Heller
4.3.4.4 Deleting Records You can delete unwanted records from the database using the ‘DELETE’ command. For example, the command ‘DELETE FOR AUTHOR = “Alexis Leon”’ will delete all the records whose AUTHOR field has the value “Aexis Leon”. 4.3.4.5 Creating Reports You can create reports using dBase. The command for creating a report is ‘CREATE REPORT<report_name>’. Reports usually contain report headings or title, date, page numbers, column headings, data, etc. In the ‘Create Report’ screen you can enter all the details like, report title, page width, column headings, column widths, whether you want total or sub-totals for numeric fields. Once you have created the report, you can modify it any time you want by typing the command ‘MODIFY REPORT <report_name>’ at the dot prompt.
INTRODUCTION TO ELECTRONIC SPREADSHEETS
4.4 INTRODUCTION An electronic spreadsheet, or spreadsheet for short, is a table with rows and columns into which data is entered. Spreadsheet software makes it possible to enter data into a table format, manipulate them, store them, print them and create reports and graphs using them.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
96
COMPUTER FUNDAMENTAL & C PROGRAMMING
4.4.1 CHARACTERISTCS OF A SPREADSHEET Although spreadsheet software organizes data into rows and columns, it has many other characteristics, which makes it one of the most popular applications packages. A user must understand these characteristics so that he can develop applications using it and use it as a problem-solving and decision-making tool. These characteristics include:
Table format
Data forms
Recalculations
Storage and retrieval
Presentation
Standard format
Table format We have seen that the spreadsheet resembles a table with rows and columns and is made of cells. We have also seen that the location or address of a cell can be identified by the column and row that intersect to form the cell. Data forms Three different kinds of data can be entered into spreadsheet. They are:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
97
COMPUTER FUNDAMENTAL & C PROGRAMMING
Labels or titles
Numbers
Calculated entries
Labels or titles A label is a description. In the salary, Name, Basic, HRA, TA, Net Pay, etc. are labels as are the names of the employees.
B5*0.01
B5+B6+B7+B8+B9
Numbers
B5+C5+D5-E
F5-((F5*G5)/100)
H5+H6+H7+H8+H9
Numbers which the user enters directly into a cell are the second kind of data
in a spreadsheet. For example, the entry in the cells B5 to B9 (Basic Pay) or those in the cells E5 to E9 (Deductions) are data, which come under this category. Calculated entries
Calculated entries are figures that are derived or calculated from or
using the existing entries (numbers or other calculated entries). Calculated entries are computed using a formula, an instruction that specifies the steps to obtain the desired
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
98
COMPUTER FUNDAMENTAL & C PROGRAMMING mathematical result. The user enters the formula in the cell and the software calculates the value using the formula and puts it in the cell. For example, as mentioned before, the HRA is 10% of the basic pay. So the entry in cell C5 (HRA for employee Ravi) is a calculated entry. The user enters the formula ‘B5*0.1’ (which says to multiply the contents of the cell B5 with 0.1) in the cell C5. The spreadsheet software calculates the value and puts it in the cell. Another example of a calculated entry is the computation of gross pay. So the formula in the cell F5 will be ‘B5+C5+D5-E5’. This will instruct the computer to add the basic pay, HRA and TA (contents of the cell B5, C5 and D5) and subtract the deductions (which is the cell E5) and put it in F5. It is important to realize that although the formula is entered in the cell, when the spreadsheet is designed, only the result of the formula is displayed when the cell is used. Shows the formulas used in the salary example. Note that even though the formula ‘B5+B6+B7+B8+B9’ is entered in the cell B11, the cell only shows the computed value of the calculated entry, which is 15,500. Recalculations Once the tables, numbers, and formulas have been entered, the spreadsheet software can automatically complete the calculate results. And results can be recalculated when revised numbers are entered. F
For instance, in our salary example, if the basic pay of one employee say Joseph, is
increased from 1500 to 2500, all you have to do is to change the value in the cell B8. The values in other cells (the computed entries) like C8, D8, F8, H8, C11, D11, F11 and H11 will be automatically recalculated by the software and displayed and displayed. This is shown in the figure 26.4.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
99
COMPUTER FUNDAMENTAL & C PROGRAMMING
Storage and Retrieval The ability to store and retrieve data is central to any business information system. Consequently, an important feature of spreadsheet software is its ability to store and retrieve the data with which it works.
In the salary application, for example, the spreadsheet may be stored on a hard or floppy disk and retrieved several times.
Each time, one or more of the values may be
changed. Presentation Most spreadsheet users need to present the results of their analysis in a way that communicates the information as effectively as possible. Sometimes a simple printout of all or a section of the spreadsheet will suffice. In these cases, the spreadsheetâ&#x20AC;&#x2122;s row-and-column format is considered satisfactory.
But more and more spreadsheet users are utilizing the graphic capabilities of the spreadsheets for information dissemination. Most of the commercial spreadsheet packages have capabilities that make it easy to create graphs and charts. For example, figure 26.5 shows a pie graph of the net pay.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
100
COMPUTER FUNDAMENTAL & C PROGRAMMING
Standard Formats Another important feature of the spreadsheet software is that it can be used as a standard format into which data can be downloaded from other computers and data sources. In this process, data stored in a database can be downloaded into the spreadsheet and can then be manipulate, analyzed and used for decision-making, problem-solving and presentation purposes.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
101
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.5 LOTUS 1-2-3 Spreadsheet software makes it possible to enter data into a table format, manipulate them, store them, print them and create reports and graphs using them. Lotus 1-2-3 was the first commercially available and one of the most popular spreadsheets.
You can use Lotus 1-2-3 for a variety of applications like accounting, budgeting, sales reports, etc. You can manipulate numbers with ease, create graphs and charts for presentation, do a ‘what-if’ analysis for decision making, etc.
4.5.1 @ Functions Lotus 1-2-3’s @functions are built-in formulas that perform specialized calculations automatically.
You can use a @function by itself as a formula, combine it with other
@functions and formulas, or use it in a script or a macro. Some @functions perform simple calculations; for example, @SUM (D2..D7) adds, the values in the range D2..D7 and is easier to enter than the formula +D2+D3+D4+D5+D6+D7. Many @functions, however, simplify your work by performing complex calculations; for example, @NPV calculates the net present value of a series of future cash-flow values. The 1-2-3 @function menu lists a few of the most commonly used @functions. Click the @function selector to display the @function menu as shown in the figure 27.3
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
102
COMPUTER FUNDAMENTAL & C PROGRAMMING
You can quickly use an @function by selecting it from the menu. In addition to the @functions on the menu, 1-2-3 provides nearly 300 other @functions. To choose from the complete list of @functions, choose â&#x20AC;&#x2DC;List Allâ&#x20AC;&#x2122; from the @function menu. To make @functions faster, you can change which @functions appear on the @function menu. 4.5.2 Macros A macro is a series of commands that automates a 1-2-3 task. You can use macros to automate repetitive tasks, streamline complex procedures, and create applications based on 1-2-3. You create a macro by entering macro commands in a sheet. You can create macros to use just once or to use over and over again. You run macros either by explicitly starting them or by having them start automatically when you open a workbook. 4.5.3 Graphs & Charts You can create a wide variety of charts and graphs using Lotus 1-2-3. The chart assistant will help you in creating the charts and graphs very easily.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
103
COMPUTER FUNDAMENTAL & C PROGRAMMING
Once you have selected the type of chart you want and have given the necessary details, Lotus 1-2-3 will create the chart for you. For example, we will create a 3D bar chart of the salary details.
Once you have created a particular chart type, say 3D bar graph, you can change the type and other properties very easily. I
NINTERNET 4.64INTRODUCTION Internet is the world’s largest computer network, the network of networks, scattered all over the world. It was created nearly 25 years ago as a project for the U.S. Department of Defense. Its goal was to create a method for widely separated computers to transfer data efficiently even of a nuclear attack. From a handful of computer and users in the 1960s, today the Internet has grown to thousands of regional networks that can connect millions of users. Any single individual, company, or country does not own this global network. A network of networks, or “Internet”, is a group of two or more networks that are:
Interconnected physically.
Capable of communicating sharing data with each other.
Able to act together as a single network.
Machines on one network can communicate with machines on other networks, and send data, files, and other information back and forth. The Internet offers access to data, graphics, sound, software, text, and people through a variety of services and tools for communication and data exchange:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
104
COMPUTER FUNDAMENTAL & C PROGRAMMING
Remote login (telnet)
File transfer (ftp)
Electronic mail (e-mail)
News (USENET or network news)
Hypertext (WWW)
105
4.6.1 WHAT’S SPECIAL ABOUT INTERNET There are three obvious reasons. Internet is the cheapest and fastest means to
Get information
Provide information
Compile information
Getting Information on the Internet The amount of information available through the Internet is staggering. To make all of it more easily available to users, programs such as the gopher were developed to help present material in some logical fashion. The most recent and very successful attempt at presenting information over the Internet is the World Wide Web (WWW). You could get information an information about people, products, organizations, research data, electronic versions of the printed media, etc. from the Internet Providing information on the Internet Most of what you want to provide could be considered advertising. While that may should somewhat commercial, It is the best and most inexpensive way to let people know who you are, what you are doing/have done, and how. For an organization or institution, setting up a home page is a good way to let the world know what its products and services are. In addition to advertising, the other critical functions that relate to provision of information are
Publishing, include full text articles, reports, illustrated articles, abstracts, computer programs, and demonstrations.
Extension, in which some of the delays associated with the printed media, may be reduced.
Teaching, The possibilities here include both distance learning and assistance for students.
Compiling Information from the Internet This is obviously a special case of “getting” information. The distinction is that it is possible to get specialized information from the web. For instance, if you wanted to poll the readership for a magazine or conduct a survey to detect the pulse of a selected community, the web provides you with the ideal platform and opportunity. Using forms, e-mail, etc., you can conduct surveys; get opinion of people across the world.
There are hundreds of
discussion groups and List servers, where one can post a question and get it answered by hundreds of people who participate in these discussions.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
106
4.6.2 INTERNET ACCESS You can connect to the Internet in one of two basic ways, dialing into an Internet Service Provider’s (ISP) computer, or with a direct connection to an Internet Service Provider. The difference is mainly in the speed and cost. In most cases you connect to your ISP using a telephone line and modem. This type of connection is called the Dial-up connection. Some times you go in for a direct connection. Dial-up Connection With a dial-up account, you use your modem to convert computer bits and bytes into modulated (tonal) signals that the phone lines can transmit. These signals are received by a modem at your ISP and demodulated into bits and bytes for their computer. “modem” is short for “modulator - demodulator”. To establish a conventional dial-up connection to the Internet, you will need the following. 1. An account with an internet Access Provider (In India, at present, Videsh Sanchar Nigam Ltd.(VSNL) is the only Internet Access Provider). The account can be either TCP/IP or shell. 2. A telephone connection. 3. A computer with serial port (for External modems) or an expansion slot (for Internet modems). 4. A modem (External/Internal). 5. A communication (or terminal emulation) software.
SLIP/PPP (TCP/IP) account
holders will require browser software (Internet Explorer, Netscape Navigator, etc.) and e-mail software (Microsoft Internet Mail, Netscape Messenger, Eudora, etc.). For Shell account holders the browser software (Lynx) and the E-mail software (Pine) are available on the VSNL server and can be accessed using the Shell account menu. The figure 28.1 shows the components of a conventional dial-up connection:
Direct Connection You can also get a direct connection to your ISP, where you have a fixed cable or a dedicated phone line to the ISP. Often the dedicated line is an ISDN (Integrated Services
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Digital Network) line which is a higher-speed version of the standard phone line, but actually requires two phone lines. ISDN can handle more than 56,600 bps. ISDN lies scale upward, meaning you can transparently add more lines to get faster speeds with a single ISDN connection, up to about 1.28 million bps. You can also get a dedicated line called a T-1 or T-3. A T-1 (‘Tee-one’) line can handle 1,280 Kilobytes per second. A T-3 line can handle ten times that speed. If you have a dedicated line, you do not use a modem to connect your computer to the Internet, but instead a router.
If you have a network in the office and several people need to
access the Internet simultaneously, consider ISDN or T-1 connection. Then, when a user does something on the Internet, the route automatically handles the connection, even multiple tasks at the same time and you need not have a modem or telephone line for each computer and user.
4.6.3 INTERNET BASICS For most people who are new to the Internet, the first experience is quite overwhelming. Faced with the wide range of features and options and the scope, magnitude and amount of information and other resources, newbie’s spend a lot of time simply finding their bearings. However as one gets the feel of the Internet, if becomes clear that Internet is similar to any other medium of information and/or communication. Once you know the information that you want to find, how to find it, where to find it and how to access it, the Internet becomes an extremely powerful resource – irrespective of whether you are using it for work, education, entertainment or just for the fun of exploring. Once you know how to send and receive electronic mail, subscribe it mailing lists, join and participate in discussion groups and Internet chats, your power to communicate with people anywhere in the world increases dramatically. The beauty of Internet is that all these power and resources are available at a very minimal cost. So Internet literacy is a must for every individual who wants to succeed in this information age. What Should I Do Before you can decide how you want to use the Internet, you should get an idea about what all you can do and what is out there in the cyberspace. For beginners, the best way to get inducted into the cyber world is to start browsing the Internet using one of the powerful web browsers like Internet Explorer (Microsoft Corporation) or Netscape Navigator (Netscape Communications). Web browsers are mainly used to access pages of the World Wide Web. By clicking on the hypertext links on a page it is possible to jump from one Internet site to another, regardless of its location. Hypertext links are usually highlighted or different colored text, images or icons. You can check for hypertext links by moving the mouse over the area; if the mouse pointer changes its shape to that of a hand [] then it is a hypertext link. This
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
107
COMPUTER FUNDAMENTAL & C PROGRAMMING jumping from one site to another using the hypertext links is called ‘net surfing’ or ‘web browsing’. But, the today’s web browsers can do much more than browsing. You can download files, play games, send and receive mails and even chat with others. In other words, the modern day web browsers are very versatile and they allow you to do almost all the activities that are possible on the internet. Given below is a list of activities that you could do with a web browser:
Visit web sites
Send and receive electronic mail
Read and post articles in newsgroups
Download files to your Pc
Chat with other users on-line
Play games with others on-line
Access on-line multimedia including radio and video broadcasts
Search the Internet for information
Subscribe to electronic newsletters, e-zines, etc.
Join contests
Contribute articles, and other materials
Do on-line shopping
Post your resumes on the Internet
Create your own web sites.
Create an e-mail ID and account for you
Use the e-mail remainder service
Find a person’s details
Send flowers or gifts to others
The above list is by no means a complete and comprehensive one. There are a lot of other things that you can do on the Internet.
4.6.4 INTERNET PROTOCOLS We will examine the various Internet protocols used. The most commonly used protocols are:
Transmission Control Protocol/internet Protocol (TCP/IP)
File Transfer Protocol (FTP)
Hyper Text Transfer Protocol (HTTP)
Telnet
Gopher
Wide Area Information Service (WAIS)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
108
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.6.4.1 Transmission Control Protocol/Internet Protocol (TCP/IP) TCP/IP stands for Transmission Control Protocol/Internet Protocol. TCP/IP is actually a collection of protocols, or rules, that govern the way data travels from one machine to another across networks. The Internet is based on TCP/IP. TCP/IP has two major components: TCP and IP. IP The IP component does the following:
Envelopes and addresses the data
Enables the network to read the envelope and forward the data to its destination
Defines how much data can fit in a single “envelope” (a packet).
TCP The TCP component does the following:
Breaks data up into packets that the network can handle efficiently
Verifies whether all the packets have arrived at their destination
“Reassembles’ the data.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
109
COMPUTER FUNDAMENTAL & C PROGRAMMING
4.6.4.2 File Transfer Protocol (FTP) FTP stands for File Transfer Protocol, and is part of the TCP/IP protocol suite. It is the protocol, or set of rules, which enables files to be transferred between computers. FTP is a powerful tool which allows files to be transferred from “computer A’ to “computer B”, or vice versa.
FTP works on the client/server principle. A client program enables the user to interact with a server in order to access information and services on the server computer. Files that can be transferred are stored on computers called FTP servers. To access these files, an FTP client program is used. This is an interface that allows the user to locate the file(s) to be transferred and initiate the transfer process.
The basic steps to use FTP are: 1. connect to the FTP server 2. navigate the file structure to fid the file you want 3. Transfer the file The specifics of each step will vary, depending on the client program being used and the type of Internet connection. Anonymous FTP allows a user to access a wealth of publicly available information. No special account or password is needed .
However, an anonymous FTP site will sometimes ask that users login with the name “anonymous” and use their electronic mail address as the password.
There are a wide variety of files that are publicly available through anonymous FTP:
Shareware – software that you can use free for a trial period but then pay a fee for.
Freeware – completely free software, for example fonts, clipart and games.
Upgrades & patches – upgrades to current software and “fixes” for software problems.
Documents – examples include research papers, articles and Internet documentation.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
110
COMPUTER FUNDAMENTAL & C PROGRAMMING
Files on FTP servers are often compressed. Compression decreases file size. This enables more files to be stored on the server and makes file transfer time shorter. In order to use a compressed file it needs to be decompressed using appropriate software. It is a good idea to have current virus checking software on the computer before files are transferred to it. 4.6.4.3 Hypertext Transferred Protocol (HTTP) HTTP is short for Hypertext Transfer Protocol. It is the set of rules, or protocol, that governs the transfer of hypertext between two or more computers. The World Wide Web encompasses the universe of information that is available via HTTP.
Hypertext is text that is specially coded using a standard system called Hypertext Markup Language (HTML. The HTML codes are used to create links. These links can be textual or graphic, and when clicked on, can “link” the user to another resource such as other HTML documents, text files, graphics, animation and sound. HTTP is based on the client/server principle. HTTP allows “computer A” (the client) to establish a connection with “computer B” (the server) and make a request. The server accepts the connection initiated in and tells the server what “action” to take on the resource.
when a user selects a hypertext link, the client program on their computer uses HTTP to contact the server, identify a resource, and ask the server to respond with an action. The server accepts the request, and ten uses HTTP to respond to or perform the action. Usually hypertext links will be blue in color and will be underlined (this is the normal convention, which is not always followed). When you move the mouse pointer over a hypertext links will be highlighted and you can navigate between them using the keyboard. In the previous figure, indexes of sample web pages are given as hypertext links. When you click on one link, say, ‘Pages with graphics’, you will be taken to that page. Thus, when you
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
111
COMPUTER FUNDAMENTAL & C PROGRAMMING select any of the hypertext links, you are identified a particular resource, and asking the server to send it back to your computer in a format that your computer can display or store. HTTP also provides access to other Internet protocols like file Transfer Protocol (FTP), Simple Mail Transfer Protocol (SMTP), Network News Transfer Protocol (NNTP), WAIS, Gopher, Telnet, etc. 4.6.4.4 Telnet Telnet is a protocol, or set of rules, that enables one computer to connect to another computer. This process is also referred to as remote login. The user’s computer, which initiates the connection, is referred to as the local computer, and the machine being connected to, which accepts the connection, is referred to as the remote, or host, computer. The remote computer can be physically located in the next room, the next town, or in another country.
Once connected, the user’s computer emulates the remote computer. When the user types in commands, they are executed on the remote computer. The user’s monitor displays what is taking place on the remote computer during the telnet session. The procedure for connecting for to a remote computer will depend on how your Internet access is set-up. Once a connection to a remote computer is made, instructions or menus may appear. Some remote machines may require a user to have an account on the machine, and may prompt users for a username and password. Many resources, such as library catalogs, are available via telnet without an account and password. Telnet also operates on the client/server principle. The local computer uses a telnet client program to establish the connection and display data on the local computer’s monitor. The remote, or host, computer uses a telnet server program to accept the connection and send responses to requests for information back to the local computer.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
112
COMPUTER FUNDAMENTAL & C PROGRAMMING Telnet allows the user to access Internet resources on other computers around the world. A variety of resources are available through telnet. For example: Library catalogs, Databases, other Internet tools such as FTP, Gopher, and the World Wide Web, etc.
4.6.4.5 Gopher Gopher is a protocol designed to search, retrieve, and display documents from remote sites on the Internet. In addition to document display, document retrieval, it is possible t initiate on-line connections with other systems via Gopher. It accomplishes this using the client/server model of users running “client” software on their local machines that provide an interface that interacts with remote “server” or computers that have information of interest. Information accessible via Gopher is stored on many computers all over the Internet. These computers are called Gopher servers.
Information stored on many kinds of non-
gopher servers is also available via special Gopher servers that act as gateways (protocol translators). Virtually any popular computer (Mac, NIX box, PC, or larger computer) can be used as a server. Servers do not just contain files, directories and searchable databases; they can also contain references to other servers. To retrieve and search this information, you need to run a Gopher client application on your computer. TurboGopher is a Gopher client application. Users interact with Gopher via a hierarchy of menus and can use full-text searching capabilities of Gopher to identify desired documents. Once an appropriate item is selected, Gopher retrieves it from whenever on the network it resides and (if it is text) displays it. The user may feel as if all the information available to Gopher resides on their local computer, when in fact Gopher is interacting with a large number of independently owned and operated computers around the world. Gopher client software exists for most computer platforms. 4.6.4.6 WAIS WAIS (pronounced “wayz”) stands for Wide Area Information Service. WAIS is an Internet search tool that is based on the z39.50 standard. The z39.50 standard describes a protocol, or set of rules, for computer-to-computer information retrieval.
WAIS also works on the client/server principle. A WAIS client program enables the user’s computer to contact a WAIS server, submit a search query, and receive a response to that query.
4.6.5 INTERNET ADDRESSING In general, Internet addressing is a systematic way identify people, computers and Internet resources. 4.6.5.1 IP Address If you want to connect to another computer, transfer files to or from another computer, or send an e-mail message, you first need to know where the other computer is – you need the computer’s “address”
.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
113
COMPUTER FUNDAMENTAL & C PROGRAMMING An IP (Internet Protocol) address is an identifier for a particular machine on a particular network; it is part of a scheme to identify computers on the Internet. IP addresses are also referred to as IP numbers and Internet addresses. An IP address consists of four sections separated by periods.
Each section contains a number ranging from 0 to 255.
Example 202.54.1.6. These four sections represent both the machine itself, or host, and the networks that the host is on.
The IP addresses have the following characteristics in common:
IP addresses are unique.
No two machines can have the same IP number.
IP addresses are also global and standardized.
All machines connected to the Internet agree to use the same scheme for establishing an address.
4.6.5.2 Domain Name A domain name is a way to identify and locate computers connected to the Internet. No two organizations can have the same domain name.
A domain name always contains two or more components separated by periods, called “dots’. Some examples of domain names are: Microsoft.com, lnl.net, ibm.com, nasa.gov, utexas.edu, tcs.co.in, etc. The major categories for top-level domain names are:
Com
- commercial entities
edu
- educational institutions
net
- organizations directly involved in Internet operations
org
- miscellaneous organizations that don’t fit any other category, such as non-
profit groups
gov
- United States Federal Government entities
mil
- United States military
Country codes- a two-letter abbreviation for a particular country. For example, “in” for India, “uk” for United Kingdom or “fr” for France, etc.
Each domain name corresponds to numeric IP (Internet Protocol) addresses. An IP address takes the form of 4 numbers, each one between 0 and 255, separated by periods.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
114
COMPUTER FUNDAMENTAL & C PROGRAMMING
The Internet uses the numeric IP address to send data. For instance, you may be connecting to a World Wide Web server with the domain name www.microsoft.com, but as far as the network is concerned, you are connecting to the Web server with the IP address associated with that domain name. The Domain Name System (DNS) completes the task of matching domain names to IP addresses. Domain names, and their corresponding IP addresses, must be unique. The domain name system is a collection of databases that contain information about domain names and their corresponding IP addresses. Domain name system servers are computers that translate domain names to IP addresses. 4.6.5.3 Electronic Mail Addresses Electronic mail or e-mail, allows information to be sent between computers and people on the Internet. The basic structure of an e-mail address is: username@host.subdomain.ssecond-level-domain.first-level-domain Two examples:
aleon@giasmd01.vsnlo.net.in
alexis@lnl.net
An e-mail address is read from left to right. For example: “alexis@lnl.net” is read as alexis at lnl dot net, where “alexis” is the name of the person sending or receiving the message; this is referred to as the
username and “lnl.net” is the domain name of the
organization.
4.6.5.4 Uniform Resource Locator (URL) A URL identifies a particular Internet resource; for example a Web page, a Gopher server, a library catalog, an image, or a text file.. URLs consist of letters, numbers, and punctuation. The basic structure of a URL is hierarchical, and the hierarchy moves from left to right:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
115
COMPUTER FUNDAMENTAL & C PROGRAMMING Protocol://server-name.domain-name.top-level-domain:port/directory/filename Examples are:
http://www.lnl.net/alexis/index.html
gopher://gopher.state.edu
ftp://ftp.xyz.com/
4.6.6 THE WORLD WIDE WEB (WWW) The World Wide Web, also referred to as the WWW or W3 or simply “the Web”, is the universe of information available via hypertext transfer protocol (HTTP). The World Wide Web and HTTP:
Allow you to create “links” from one piece of information to another
Can incorporate references to sounds, graphics, movies, etc.
Communicate with other Internet protocols, such as FTP, Gopher, and Telnet.
The Web presents information as a series of “documents”, often referred to as web pages that are prepared using the Hypertext Markup Language (HTML). Using HTML, the document’s author can specially code sections of the documents to “point” to other information resources. These specially coded sections are referred to as hypertext links.
Hypertext links can lead to other documents, sounds, images, databases (like library catalogs), e-mail addresses, etc. The World Wide Web is non-linear. There is not top, there is no bottom. Non-linear means you do not have to follow a hierarchical path to information resources. Thus
You can jump one link (resource) to another
You can go directly to a resource if you know the URL i.e. its address
You can even jump to specific parts of a document.
Since the Web is not hierarchical and can handle graphics, it offers a great deal of flexibility in organizing, presenting, and describing the information resources.
4.6.7 WEB PAGES & HTML A web page is a single unit of information, often called a document that is available via the World Wide Web (WWW). A web page is created using HTML.HTML stands for Hypertext Markup Language. HTML consists of standardized codes or “tags” that are used to define the structure of information on a web page.
4.6.8 HTML HTML defines several aspects of a web page including heading levels, bold, italics, images, paragraph breaks and hypertext links to other resources. HTML is a sub-language of SGML., or Standard Generalized Markup Language. SGML is a system that defines and
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
116
COMPUTER FUNDAMENTAL & C PROGRAMMING standardizes the structure of documents. Both SGML and HTML utilize descriptive markup to define the structure of an area of text. Therefore, in HTML, text is marked as a heading, numbered list, bold, italic, etc. 4.6.9 HTML Tags HTML is standardized and portable.
A document that has been prepared using
HTML markup “tags” can be viewed using a variety of web browsers, such as Netscape and Lynx. A browser interprets the tags in an HTML file and presents the file as a file as a formatted, readable web page.
HTML tags are used to define areas of a document as having certain characteristics. The tags used in HTML usually consist of a code in between two “wickets”. These codes are called container tags because the formatting described by the tag affects only the next contained between the tags. For example, <B> and </B> are the starting and ending tags used to indicate an area as bold. HTML tags are used to define heading levels, such as <H1> and </HI>. Heading levels can go to <H6>, with each successive number indicating a smaller heading size. Some other basic HYML tags are:
<I> and </I> are used to indicate italics.
<img src = ”name-of-picture”> used to place an image in a document file.
<P> used to create a paragraph break.
In HTML, some codes require end tags while some don’t. In the previous example, the <P> tags indicate a paragraph break. This type of code is called an empty tag because no end tag is required. The <P> tag does not need an end tag (like <B> and </B>)because a paragraph break is a single entity. A web page is transferred to a user’s computer via the hypertext transfer protocol (HTTP). HTTP is the method through which hypertext files, such as web pages, are transferred over the Internet. HTTP is a client /server based Internet protocol,. or set of rules. Web pages generally reside on HTTP servers. A users requests a web page from an HTTP (web) server through his or her web browser client software, either by clicking on a hypertext link or designating a particular URL (Uniform Resource Locator). The server then sends the requested information to the user’s computer.
The browser software interprets the HTML codes and presents the information contained in the web page in a readable format on the user’s computer. 4.6.10 WEB BROWSERS A browser is a piece of software that acts as an interface between the user and the inner-working of the Internet, specifically the World Wide Web. Browsers are also referred to as web clients, or Universal Clients, because in the client/server model, the browser functions as the client program.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
117
COMPUTER FUNDAMENTAL & C PROGRAMMING
118
The browser acts behalf of the user. The browser:
Contacts a web server and sends a request for information
Receives the information and then displays it on the user’s computer.
A browser can be graphical or text-based and can make the Internet easier to use and more intuitive. A text-based browser shows the user only textual matter. A graphical browser allows the user to see more of what the WWW has to offer such as graphics, photographs and multimedia. A graphical browser allows the user to view images on their computer, “point-and-click” with a mouse to select hypertext links, and uses drop-down menus and toolbar buttons to navigate and access resources on the Internet.
The WWW incorporates hypertext, photographs, sound, video, etc.
that can be fully
experienced through a graphical browser. Browsers often include “helper applications” which are actually software programs that are needed to display images, hear sounds or run animation sequences.
The browser
automatically invokes these helper applications when a user selects a link to a resource that requires them. A text-based browser allows a user to see only text. Graphic elements are not displayed and hypertext links are accessed by using the keyboard. Lynx is an example of a text-based browser. There are many different types of browsers and all of them perform the same basic functions (transferring hypertext) but many have specific features that are unique. Examples of some common browsers are:
Netscape Navigator
Microsoft Internet Explorer
Mosaic
Opera
Amaya
Hot Java
Lynx (Text-based)
Web Browsing Internet browsing or ‘netsurfing’, as it is often called, is the process of visiting different web sites on the Internet hosted by various companies, organizations institutions, magazines, individuals, etc.
4.6.11 SEARCHING THE WEB A number of new tools have been developed that enable information published on the Web to be searched and discovered more effectively. There are two main types of search tools: web indexes and search engines. We will now explore more details about these tools.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.6.11.1 Web Index A web index is designed to assist users in locating information on the World Wide Web. Web indexes are also referred to as catalogs or directories. A web index collects and organizes resources available via the World Wide Web. Some of the popular web indexes are:
Yahoo! (http://www.yahoo.com)
Magellan (http://www.mckinley.com)
Apollo (http://appolo.co.uk)
4.6.11.2 Searching Engines A web search engine is an interactive tool to help people locate information available via the World Wide Web. Web search engines are actually databases that contain references to thousands of resources. Users interact with the database, submitting questions that “ask” the database if it contains resources that match specific criteria.
, Some of the most popular search engines are:
Alta Vista (http://www.altavista.digital .com)
Excite (http://www.excite.com)
Lycos (http://www.lycos.com)
Yahoo! (http://www.yahoo.com)
4.6.11.2 Meta-search Engines A web meta-searcher is a tool that helps users locate information available via the Wide Web. Web meta-searchers provide a single interface that enables users to search many different search engines, indexes, and databases simultaneously. Examples of web meta-searchers include:
All-in-one Search (www.albany.net/allinone
c\net (http://www.search.com)
Cyber lands Web (http://www.cyberlands.com/resources /search/)
Eureka! (http://www.best.com/~mentorma/eruek.htm)
4.6.12 INTERNET CHART Internet chart lets you communicate with people from all over the world, in real-time. There are many ways to chat with other Internet users. You can use a large number of sites on the web, you can use the customized chat facilities of the on-line service providers, or you can connect to telnet services devoted to chat. Yu can also use client software to access one of the networks that host Internet Relay Chat (IRC).
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
119
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.6.12.1 Internet Relay Chat (IRC) IRC is a multi-user chat system that allows many people to communicate simultaneously across the Internet, in real time. The chats take place on channels. Channels are the virtual locations on IRC networks where users meet to talk to one another. The larger networks have thousands of channels and you have to join one of them before you can talk with other people. It is even possible to have conversations on several channels will be topic specific, but others are less rigid and will be having a general chat. Channels have different modes. Most channels are public, but you can talk on a private or secret channel, where it is possible to restrict access, for example, to ‘invite only’.
To take part in IRC you need to run a client program on your computer while connected to the Internet. IRC is organized in networks. Each network consists of a series of servers that constantly relay chat back and forth among themselves. You access IRC by connecting to a specific server and this automatically gives you access to the entire network.
If your ISP has not provided you with an IRC client program, you can download ay one of the client programs that are available on the web. Some of the IRC programs and the site from where they could be downloaded are given below:
mIRC (ftp://papa.indstate.edu.winsoc-i/Windows95/IRC/)
WSIRC (ftp://papa.indstate.edu/winsoc-i/Windows95/IRC)
PIRCH (http://www.bcpl.lib.mid.us/~frappa/)
VIRC (http://appollo.com/~acable/)
Once you join the IRC, you can browse through the help manual to find the list of commands. Some of the most frequently used commands are:
/help – To get the list of all commands
/list – To view all available channels
/join channel – To quit from the IRC server
/leave channel – To leave a channel
ELECTRONIC MAIL 4.7 INTRODUCTION It can take days to send a mail across the country an weeks to go around the world. That is why nowadays, it is referred to as the ‘snail mail’. To save time and money, we use the electronic mail. It’s mail is an electronic message sent from one computer to another.
4.7.1 HOW E-MAIL WORKS The working of the electronic mail is quite simple and we will explain it with the help of the figure 29.1.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
120
COMPUTER FUNDAMENTAL & C PROGRAMMING
The first thing you have to do is to type in your message, key-in the recipient’s e-mail address and press the send button of your e-mail program. Once you have addressed and sent the e-mail, it gets encoded by a modem and is sent down the phone line as an analog signal [A]. The e-mail message arrives at your service provider’s server. If it recognizes the email address as valid, the mail will be sent [B]. The mail is sent via the Internet [C]. It will be received by the recipient’s provider [D] and is sent to the provider’s, mail server [E] where it will be delivered to the recipient’s mail box [F] and it will remain there until the recipient next connects to the Internet. Finally, the recipient’s modem and computer decode the data, and he or she can your email message [G]. It is very important that you type-in the recipient’s address correctly. As with the normal postal delivery system, the address should be correct for the message to be delivered. If the computer trying to deliver your message does not recognize the mailing address, it will automatically send you a message informing that the mail could not be delivered.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
121
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.7.2 E-MAIL – NAMES & ADDRESSES Electronic mail or e-mail, allows information to be sent between computers and people on the Internet. It is the most widely used internet resource. Just as a written letter can be sent to multiple recipients, an electronic mail message can sent to one more e-mail addresses.
An e-mail address identifies a person and the computer for purpose of exchanging electronic mail messages. The basic structure of an e-mail address is: username@host.subdomain.second-level-domain.first-level-domain Two examples: 1. aleon@giasmd01.vsnl.net.in 2. alexis_leon@poboxes.com
An e-mail address is read from left to right. For example, alexis@poboxes.com is read as Alexis at poboxes dot com, where
“alexis” is the name of the person sending or receiving the message; this is referred to as the username.
“poboxes” is part of the domain name of the organization
“com” is also part of the domain name and indicates that “poboxes” is a commercial organization.
4.7.3 MAILING BAISCS We have seen how the e-mail works. In this section, we will learn how to compose, reply to and forward a mail. We will also see how to make use of the different features available with the mail programs.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
122
COMPUTER FUNDAMENTAL & C PROGRAMMING To compose an e-mail message, click on the ‘Compose new message’ button on the toolbar. You will get empty mail form, which have the following parts:
To- Enter the e-mail address of the person(s) to whom the message is sent
Cc – enter the e-mail address of the person(s) to whom the copy of the message is sent.
Subject – enter a brief description as to what the message is about.
Body – enter the actual message here.
Some mail programs allow the facility to send blind copies, if this feature is available the other recipients of the mail will not know that you have sent a blind copy to another person. Almost all e-mail programs have the following features: address book, signature, feature, and attachment facility. Address Book An address book is a place where you can store information about the people with whom you correspond. The advantage of having a person’s details in the address book is that you don’t have to key-in those details each and every time you send a message. Signature Are you tired of typing in your name and address at the end of each message that you send. Then you can make use of the signature option provided. You can store the information that you want to attach at the end of the messages as your signature. Then you can configure your system in such a way that all the out- going messages will have your signature at the end of the message. File Attachments One major drawback of e-mail is that you cannot send formatted text. For example, if I want to send a word document, which contains pictures lists,etc., and if I do a cut and paste,all the formatting, all the pictures,etc.will be lost. You will get only the text. The solution is to send the file as an attachment to the mail. you can attach any file to a mail. It is a good idea to compress the file you are attaching using utilities like pkzip, which will reduce the file size and save time and money during transmission. Replying and Forward E-Mail Message Just like you send and receive letters, you can send and receive electronic mails too. But e-mail programs give you many more options. You can reply to the author by pressing a button. You need not type in the address or the subject because the programs are intelligent enough to automatically put the electronic address of the person whose mail you are replying to, prefix the subject with ‘Re:’ to indicate that it is a reply. The programs will also include the original mail (if you sent that option) as part of the reply, which is a great help in identifying the mail, especially when a person receives hundreds of mails a day.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
123
COMPUTER FUNDAMENTAL & C PROGRAMMING
124
For example, if I want to reply to a mail that I had received from NASSCOM, I will highlight the mail by clicking on it and then, will press the reply button. The ‘TO’ address, the ‘Subject’ (with Re :) and the original message will automatically appear. I just have to type in my reply and send the mail. Notice that the original message is marked with ‘>’ sign.
Most e-mail programs will let you add any message you want. The message that is being forward will be indented with ‘>’ symbol as in the case of replying.
Most e-mail
programs will prefix the subject of the forward message with ‘Fw:’. 4.7.4 E-MAIL – ADVANTAGES & DISADVANTAGES It is difficult 24 hours a day from anywhere in the world to endless amounts of data and information. Global communication is easier. The technology also has opened the door for more types of professionals to work at home, because they can still tap into corporate information. Thus, work can now be done anywhere a computer can be plugged in.
But there is a dark side to the technology.
First, it has created an information
overload. People are swamped by junk mail and finding what is relevant and need to be read from the hundreds of mails that one receive can become a daunting task.
Second, the very existence of electronic communication has perpetuated the myth that it will lead to better communication. But that not true, if you are not a good communicator without electronic technology, you won’t become a good communicator just because you use the technology. Technology improves our ability to communicate, extends the reach of our communications, and reduces long-distance communications timelines, but
it is the
individual using the technology that makes the communications better or worse.
Another disadvantage of the e-mail is that it can become a distraction and can prevent people from doing any productive work.
TIPS FOR EFFECTIVE E-MAIL USE
To work more productively and to prevent e-mail interruptions, you can do the following:
If the mail is automatically delivered to your mailbox, shut off the computer beep that alerts you when you have an incoming message.
If your mail does not come to your in-box and you have to check for your mail by connecting to the mail server, then do it during non-peak hours, when you will get connected immediately.
Compose your message off-line. This will save on-line time and you will get a chance to review the mail.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
Organize the mails in different folders, so that it can be tracked easily and efficiently.
Keep the e-mail IDs of all the people with whom you correspond in the address book, so that each time, you don’t have to key it in. This will reduce the chances of error and will save time.
Tell your friends and colleagues what type of documents you want to receive and what you don’t.
And remember, don’t let technology wipe out oral communication!!!!
4.7.5 MAILING LISTS Electronic mail is far more flexible and powerful than you might at first imagine. As well as sending messages to other people on the Internet, you can also use the e-mail to run a program on a remote computer and have the results sent back to you. E-mail also effects a great way to stay in touch with special interest groups.
A mailing list is a way to share information via electronic mail with many people, usually on a specific topic or for a specific purpose. People choose to be part of a mailing list by subscribing to the list.
Once you have joined the list (or subscribed to the list), you will receive regular information by e-mail about the subject that particular list is concerned with. These emails are automatically delivered to you by a mailing list management software, which sends you the mails until you choose to unsubscribe.
How Mailing Lists Work This is how a mailing list works,
A message is sent to a single e-mail address, which is referred to as the mailing list address.
This same message is then re-distributed, or “reflected” to all of the people subscribed to the list.
The single, central e-mail address for the list is also referred to as a mail reflector. Mailing lists originated on a network called BITNET. BITNET was created to connect universities in the United States, and now connects over one thousand institutions throughout the world. Because mailing lists have their origins in the academic community, many mailing lists address academic and research oriented topics. However, many mailing lists exist for non-academic topics as well.
Managing a mailing list can be a lot of work. For example, keeping track of all the messages that are received and sent, and keeping track of the subscribers of the list and people who quit the list. Frequently, software is used that automates the management of
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
125
COMPUTER FUNDAMENTAL & C PROGRAMMING these mailing list functions. Some of the more common mailing list management programs are: 1. Lsoft’s LISTSERV
TM
2. Majordomo 3. ListPro by CREN (Corporation for Research and Educational Networking)
4.7.6 NEWSGROUPS Newsgroups on the Internet have very little to do with ‘news’, but everything to do with discussion and debate. Newsgroups are essentially public e-mail discussion forums where the participants ‘post’ their messages to be seen by all readers of the newsgroup. Anyone reading the message can choose to reply either publicly (to the newsgroup) or privately (to the originator of the message). Newsgroups provide a forum for interested people to discuss topics of common interest. As with e-mail messages, it is possible to attach sounds, video clips and multimedia in the newsgroup messages. Newsgroups offer the most stimulating, useful and controversial content on the Internet. Mailing Lists vs. Newsgroups Mailing lists relay the messages to your e-mail address. So you need to subscribe to them to read the messages. But the message posted on a newsgroup could be viewed by anyone as long as the service provider supplies the newsgroup. The Usenet Network Usenet or ‘User’s Network’s is not a computer network in the physical sense. It is a vast body of newsgroups that are distributed all around the world by computers called ‘news servers’. These news servers exchange information so that each one carries a copy of the most recent messages. Usenet is not actually a part of the Internet, although many Internet sites are used to carry and distribute its newsgroups. Reading Newsgroups There are many problems with which you can read newsgroups. You can even read them through the web browser, but the dedicated newsreaders have more and better features for following the discussions and are generally more flexible. The major browsers like the Internet Explorer and the Netscape Navigator have their own newsreaders. Many good newsreaders are available in the Internet. Whichever program you choose, you will need to provide some information like details of your Internet account, names of the news and mail servers, e-mail address, etc. Newsgroup Classifications Usenet newsgroups are divided into about 20 major subject classifications known as top-level categories. Some of the main subject classifications are :
news - Groups concerned with the News Network. Some examples are news. announce. new users, news.newusers.questions, etc.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
126
COMPUTER FUNDAMENTAL & C PROGRAMMING
comp - Computer oriented groups dealing with topic like technical advice, game hints, software information, etc. An example is comp.sys.ibm.pc.games.adventure
alt – Alternative group dealing with a wide range of subjects. Example are alt.astrology, alt.music.beatles
misc - Newsgroups that are difficult to classify. Examples include misc.invest.stocks, misc.education.multimedia
biz - Business newsgroups dealing with business subjects like marketing and advertising. An example is big.jobs.offered
rec – Groups that are devoted to recreational activities. Examples include rec.trave.aftrica, rec.music.makers.guitar
talk – Debate oriented forums on any topic. An example is talk. euthanasia
soc - Groups dealing with social issues and dealing with subjects like human rights, environments, etc. An example is soc.rights.human
sci – Groups devoted to scientific debate and research and development. Examples are sci.virutal-words, sci.med.diseases.cancer
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
127
COMPUTER FUNDAMENTAL & C PROGRAMMING
UNIT-V WINDOWS 5.0 Windows Basics 5.0.1 Introduction to Windows 5.0.2 Starting Windows 5.0.3 Using Mouse 5.0.4 Moving and Resizing Windows 5.0.5 Maximizing, Minimizing and Restoring Windows 5.0.6 Using Menus in Windows 5.0.7 Windows Groups 5.0.8 Opening Multiple Windows 5.0.9 Arranging Icons in a Window 5.0.10 Saving Windows Settings 5.0.11 Running Programs 5.0.12 Switching Tasks 5.1. Windows Accessories 5.2. Using File Manger and Program Manager WORD 5.3 Introduction to Word 5.3.1 What is Word Processing? 5.3.2 Advantages of Using Word Processing 5.3.3 What is Word 6.0? 5.3.4 Starting Word 5.3.5 Creating a Document 5.3.6 Saving the Document in a Disk File 5.3.7 Printing a Document 5.4 Editing a Document 5.4.1 Editing a Document 5.4.2 Selecting Text 5.4.3 Deleting Text 5.4.4 Replacing Text 5.4.5 Undoing and Redoing Chang 5.5 Move and Copy Text and Help System 5.6 Formatting Text and Paragraph 5.7 Finding and Replacing Text and Spelling Checking 5.8 Using Tabs 5.9 Enhancing Document 5.10 Tables & Columns
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
128
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.11 Using Graphics, Templates and Wizards 5.11.1 Using the Drawing Toolbar 5.11.2 Using Templates 5.11.3 Inserting Graphics 5.12 Using Mail Merge 5.12.1 What is Mail Merge? 5.12.2 Practical example of Mail Merge EXCEL 5.13 Introduction to Worksheet and Excel 5.13.1 What is an Electronic Worksheet or Spreadsheet? 5.13.2 Advantages of Using an Electronic Worksheet 5.13.3 What is Excel? 5.14 Getting Started With Excel 5.14.1 Starting Excel 5.14.2 The Excel Screen 5.14.3 Organization of the Worksheet Area 5.14.4 Entering Information in a Worksheet 5.14.5 Saving a Worksheet 5.15 Editing Cells and Using Commands and Functions 5.16 Moving and Copying, Inserting and Deleting Rows and Columns 5.17 Printing the Worksheet 5.18 Creating Charts 5.18.1Using Chart wizard to Create a Chart 5.18.2 Resizing and Moving the Chart 5.18.3 Displaying a 3-D Column Chart 5.18.4 Modifying and Deleting a Chart 5.18.5 Creating a Chart on a Chart Sheet 5.19 Using Date and Time and Addressing Modes 5.20 Using Statistical, Math and Financial Functions 5.20.1 Using Statistical Functions 5.20.2 Using Math Functions 5.20.3 Using Financial Functions 5.21 Database in a Worksheet 5.21.1 What is a Database? 5.21.2 Database in a Worksheet 5.21.3 Creating a Database 5.21.4 Sorting a Database DESKTOP PUBLISHING 5.22 Introduction to Desktop Publishing 5.22.1 What is Desktop Publishing (DTP)?
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
129
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.22.2 Common Features of DTP 5.22.3 Common DTP Programs POWERPOINT 5.23 Overview of Powerpoint 5.23.1 What is Powerpoint? 5.23.2 Creating a Presentation 5.23.3 Powerpoint Views 5.23.4 Slide Show 5.23.5 Printing a Presentation
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
130
COMPUTER FUNDAMENTAL & C PROGRAMMING
131
5.0 WINDOWS BASICS
5.0.1 INTRODUCTION TO WINDOWS It is a program or an Operating system (OS). Different versions of windows are available, such as – 1. windows 3.1 2. windows 95 3. windows NT Windows is only a program that runs over DOS. It enhances the power and use of a PC running DOS in the following three ways: 1. It converts the plain character based user interface provided by DOS into a Graphics User Interface (GUI). 2. It provides multitasking capabilities to the PC. 3. It provides the basis for a consistent user interface. Besides providing these capabilities to your PC, Windows comes with a number of useful programs. It has its own File manager that can help you to copy and move files and manage directories. Windows also comes with a number of useful applications, such as a mini word processor (Write), a drawing program (Paintbrush), Calendar, Clock, Calculator and Notepad. Hardware requirements for Running windows 3.1 To run Windows3.1, you should have a PC with 286(80268) or equivalent processor with 1-2 MB of RAM. However, for good performance and true multitasking capabilities, use a PC with 386 (80386) or equivalent processor and at least 2 MB of RAM. You must also have a hard disk with at least 10 MB of free space to install windows.
5.0.2 STARTING WINDOWS To start windows, perform the following steps:
Switch on your PC and load DOS in the usual way
Type WIN at the DOS prompt (C:\>) and press Enter.
Wait for a few seconds. The PC loads the windows program and displays a screen that may be similar to Figure 5.1. Figure 5.1 displays the Program Manger Window. Inside the Program Manager Window, it displays the Microsoft Office window. The Program Manager Window also contains a few minimized windows, such as Accessories, Games, Applications, Startup, etc.
Program
Manager is the Windows administrative program. All other applications are run from Program Manager. Let us have a quick look at the Program Manger Window shown in figure 5.2. The first row of the window is called the title bar. It contains the title (name) of the program running in the window. The title bar is also used to make the window active and to move it to a new position on the screen. On the extreme left, the title bar contains a box that
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING is called the control menu Box. On the extreme right of the title bar, there are two buttons â&#x20AC;&#x201C; Minimize and Maximize. These buttons are used to minimize and maximize the window, respectively. The box enclosing the window is called the window border or frame. You can reposition any window anywhere on the screen. You can also change the size of any window. Your window can be as large as the size of the screen or it can be as small as you like.
Figure 5.1 Windows opening screen
5.0.3 USING MOUSE The mouse is used to communicate with your PC. You can use the mouse to start or stop a program make selections, move objects, run commands, etc. The mouse comes in different shapes. Moving the mouse You hold the mouse with your hand and move it across the flat surface. When you move it across a flat surface, a pointer moves across the computer screen in the same direction. The pointer that moves on the screen is called the mouse pointer. The mouse pointer can be of different shapes depending on the application you are running and its position on the screen. The typical shape of the mouse pointer is a hollow arrow as shown
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
132
COMPUTER FUNDAMENTAL & C PROGRAMMING
133
Clicking the Mouse Pressing and releasing the mouse button is called clicking the mouse. In Windows, clicking is used to select an item, e.g. an icon or a command. Clicking is also used to select text. To select an item, say an icon in a window, you will move the mouse pointer on the item and click once. When you select an item by clicking, Windows highlights it and shows it in reverse background or different colour.
Double-Clicking the Mouse Rapidly clicking the mouse button twice is called double-clicking.
In Windows,
double-clicking is used quit frequently. Double-clicking is used for various purposes, such as to maximize a minimized window/application, close a window, execute a command, select text, etc.
Dragging the mouse Dragging the mouse means moving the mouse while keeping the left mouse button pressed. Dragging is generally used to move an item. For instance, you can move a window or an icon within a window by dragging. Dragging is also used in Windows applications to move or copy text, and to draw lines and other shapes.
MOVING AND RESIZING WINDOWS In windows, you can open multiple windows. You may have to open multiple windows when you want to run more than one application simultaneously. For instance, you can run Word in one Window and Excel in another. When you have multiple windows open on your screen, you may have to move resize windows on the screen. Windows allows you to move any window anywhere on the screen or in its parent window. Windows also allows you to change the size of any window. First, let us learn to move a window. You can move a window with the mouse or with the keyboard.
Moving a Window with the Mouse Moving a window with the mouse is very simple. Let us try to move the accessories window. ď&#x201A;ˇ
Double-click the Accessories icon to open the Accessories Window.
Your screen opens the Accessories window as shown in figure 5.4.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
134
Figure 5.4 Accessories Window open You can move a window by dragging its title bar with the mouse.
Let us move the
Accessories Window.
Move the mouse pointer on the Title bar of the Accessories window.
Press the left mouse button and keep it pressed.
Without releasing the mouse
button, move (drag) the mouse. As you drag the mouse, an outline of the window moves in the same direction along with the mouse pointer.
When the outline of the window appears where you want to position the Accessories window, release the mouse button.
Windows displays the Accessories window at the new location.
Moving a Window with a Keyboard Next, let us try to move the Program Manager window with the keyboard.
Press Alt+spacebar keys. (Do not press the ‘+’ key. ‘+’ has been used here to indicate that you have to press Alt and spacebar keys together.)
The control menu contains commands to perform various operations on the current (active) window. The move command is used to move the window. Other commands are used to change the size, restore size(Restore), minimize, maximize and close the window. Let us use the Move command.
Press M to select Move command.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
135
Now use the arrow key to move the window in the horizontal and vertical directions.
As you press the arrow keys, an outline of the Program
Manager Window moves in the same direction.
After you have positioned the outline of the window at the desired position, press the Enter key.
Windows displays the Program Manager window at the new position. Resizing a Window with the Mouse First, we will change the height of the Accessories window.
Move the mouse pointer on the top or the bottom border of the Accessories window until the shape of the mouse pointer changes to a double header arrow similar to .
While the mouse pointer is in the double-header arrow shape, drag the mouse up or down. As you drag the mouse, Windows resizes the border of the Accessories window.
After you have moved the border of the Accessories window a little bit, release the mouse button.
Windows resizes the Accessories window. If you want to change the width of a window, move the mouse pointer to its right or left side border. The shape of the cursor changes to a double-headed arrow similar to
. Then you
can drag the border left or right to change the width of the window.
Drag the right side border of the Accessories to change the width of the window.
Resizing a Window with the keyboard You can change the size of the Window very easily with the keyboard. Let us change the size of the Program Manager window.
Press Alt+spacebar to open the Control menu.
Press S to select the Size command from the size of the window. Finally, press the Enter key to ask Windows to display the Program Manager window with the new size.
5.0.5 MAXIMIZING, MINIMIZING AND RESTORING WINDOWS In windows, every window is in one of the following three states: normal, maximized and minimized. In the normal state, the window can have any size just less than the maximum size of the screen. In the maximized state, the window occupies the entire screen area. On the other hand, in the minimized state, the window is reduced to just an icon. To maximize, minimize or restore a window, you can use either the mouse or the keyboard. Using the Mouse to Maximize, Minimize and Restore a Window Look at figure 5.4. On the right side of the title bar of the program Manager window, there are
to buttons. The button with up pointing arrow, that looks like
is called the Maximize
button. You can click this button to maximize the corresponding window.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
The other button on the right side of the title bar looks like
136
. This button is
called the Minimize button. Clicking this button minimizes the corresponding window. Windows expands the Program Manager window.
Now it occupies the entire screen as
shown in figure 5.5.
Figure 5.5 Accessories Window With control menu
When Windows maximize a window, it replaces the Maximize button with the Restore button, as shown in figure 5.6.
This button has up and down pointing arrows. You can click the
Restore button to restore the window to its original size (prior to maximizing the window). Remember that the Restore button is displayed only when a window is in the maximized state.
Using the Keyboard to Maximize, Minimize and Restore a window You can minimize, maximize and window by using the keyboard. commands, you have to open the Control menu.
To use these
First of all, let us try to minimize the
Accessories window using the keyboard. ď&#x201A;ˇ
Press Alt + spacebar to open the Control menu. Windows open the control menu for the Program Manager window. Since we want to minimize the Accessories window, we have to select the Control menu for the Accessories window.
ď&#x201A;ˇ
Press the right arrow(
) on the keyboard.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
137
To minimize the Accessories window, select the Minimize command. You can select this command by pressing N. Alternatively, use the arrow keys to highlights Minimize and then press the Enter key.
Windows minimizes the Accessories window. In the same way, you can maximize any window. For doing that, open the Control menu of the corresponding window and then select the maximize command. Next, let us restore the Accessories window that we have just minimized.
If the Accessories icon is not selected, i.e. its label is not showing in reverse video, press Ctrl+F6 required number of times to select it.
Press Alt+spacebar to open the Control menu for the Program Manager window.
Press the right arrow key(
) on the keyboard to move the Control menu to the icon
for the minimized Accessories window.
Select the Restore command from the menu to restore the Accessories window.
5.0.6 USING MENUS IN WINDOWS The Program Manager Window contains a menu bar that contains menu labels, such as File, Options, Window and Help. On selecting a menu label in the menu, Windows displays a pull-down menu that usually contains a few commands.
You can then choose any
command from the menu. On selecting a command from the pull-down menu, Windows either executes the command or it may display another pull-down menu or a dialog box. The dialog box is a special window where you specify your options.
5.0.7 WINDOWS GROUPS Your Windows contains a few groups or groups windows, such as Accessories, Applications, Main, Games and Start up. When you install Windows, it creates these five group windows.
Later, if you install new software installation program may put the new
software in a new group window. The windows groups are used to keep a group of related programs together at one place. The group windows also help us to quickly locate and run the required program.
5.0.8 OPENING MULTIPLE WINDOWS Window is a multitasking environment. You can start several programs and each of these program run in their respective windows. You can show these windows simultaneously on the screen. Since you can change the size of a window, you can control the size of open windows.
5.0.9 ARRANGING ICONS IN A WINDOW You can change the position of windows on your screen , in the same way, you can reposition icons in a group window. You may like to move those icons that you use frequently
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
138
near the top of the window. You can arrange icons manually or ask Windows to automatically arrange icons when you resize the window.
5.0.10 SAVING WINDOWS SETTINGS
After setting arrangements of windows and icons in windows, open the Options menu.
If there is a tick mark(
) on the left of side of ‘Save Settings on Exit’, click any
where on the empty area of the window. This will close the menu without changing any option. The required option (Save Settings on Exit) is already selected.
If there is no tick mark(
) on the left of side of ‘Save Settings on Exit’, click ‘Save
Settings on Exit’ to select it. This selects the Save Settings on Exit option and closes the menu.
5.0.11 RUNNING PROGRAMS Windows allows you to run programs in many ways.
The easiest and the most
commonly adopted method to run a program is by double-clicking the icon of the program that you want to run.
5.0.12 SWITCHING TASKS When you started two programs – calculator and clock. In windows terminology, these are also called tasks. That is, at present these two tasks are running as minimized icons. In fact, Besides these two tasks, there is another task that is also running. That task is Program Manager. Program Manager is the Windows executive program that is always running. As long as Windows is running, Program Manager continues to run. So, at present, three tasks are running. As you know, in Windows, each task runs in it own Window, and any time, one Window is active. So, how do we switch to other Windows? If all Windows are visible on your screen, to activate any Window, all you need to do is to click anywhere in that Window. For instance, if the Clock Window is active, and you want to use the Calculator, Click anywhere in the Calculator window to make it active. However, if all windows are not visible and you want to switch to another window (task), you can take the help of the Task List dialog box. Alternatively, you can use Alt+Tab keys to switch tasks.
5.1 WINDOWS ACCESSORIES Write is a small word processor included in the Accessories window. Besides the usual text selection and editing commands, it includes character and paragraph formatting commands. You can change the paragraph alignment and line spacing. The character formatting commands enable you to select a new font and to change the font size and style.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Write also allows you change page margins, find and replace text, define tabs and insert graphics I the document. When you use the Copy command in any Windows application, Windows places the selected object (graphics, text, etc.) in Clipboard. Now, you can use the Paste command in the same or different Windows application to paste the information from Clipboard into the application. Paintbrush contains the basic drawing tools, such as line, circle, box, curve, etc. that you can use to create simple graphics. You can choose any color to fill these objects. Paintbrush also includes tools to erase, cut, copy and paste any part of the graphics. Compared to Write, Notepad is a simple text editor. It contains no text and paragraph formatting commands. It can be used to type simple memos.
5.2. USING FILE MANGER AND PROGRAM MANAGER File Manager: File Manager helps us to efficiently organize the file system on the hard disk as well floppy disks. It shows one or more directory windows where it displays the directory tree for a selected directory and the contents of the selected directory. To select a directory, click the mouse on the desired directory, or use the arrow keys to highlight the desired directory in the directory tree. It can sort the directory by name, file type, size and date of creation/modification. File Manager contains commands that can be used to format and copy diskettes, and copy, move, delete files or directories. You can copy or move the selected files/directories by dragging them with the mouse or by using the Copy or Move commands from the File menu. To delete the selected files, press the Del key or use the Delete commands from the File menu. You can run an executable file by double-clicking its filename in any File Manager window. Each file has four attributes â&#x20AC;&#x201C; read-only, hidden, system and archive. To change the attributes of the selected file(s), press Alt+Enter or use the Properties command from the File menu. You can move or copy an icon from one group window to another by dragging it with the mouse. To delete a selected icon, press the Del key. Similarly, to delete a group window, close that window, select its icon and press the Del key.
Program Manager: The File menu of Program Manager contains the necessary command to create a new group window and to add programs to a group window. To put Windows in the DOS prompt mode, choose the MS-DOS Prompt from the main window. If you are a left-handed person and find it difficult to press the left mouse button, you can swap the mouse buttons.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
139
COMPUTER FUNDAMENTAL & C PROGRAMMING Object Linking and Embedding: Object Linking and Embedding allows different windows applications to exchange information in an integrated manner. You can embed or link information from an application to another. If the information is linked, whenever the client (source) file changes and you open a file having a link to that file, Windows prompts the user to update links.
5.3 INTRODUCTION TO WORD 5.3.1 WHAT IS WORD PROCESSING? Word processing in computer terminology, refers to typing, editing and formatting of any kind of document, which could be a letter, memorandum, balance sheet, or something similar. As the term suggests, word processing simply processes words, i.e. textual information. You can use it to print letters, reports, booklets, and so forth, in a suitable layout. A word processor does this by simply formatting the information you or someone else has keyed into the computer. Some of the features available in most of the word processors are : -
Adjustable page size and margins.
-
Printing selected text in boldface, italic or underlined.
-
Printing selected text in superscript or subscript style.
-
Changing the font and the size of letters of the selected text.
-
Right justifying paragraphs (The last character of each line is aligned at the right margin.)
-
Adjustable line and characters spacing.
-
Moving selected text to another location within the document or to another document.
-
Facility to define headers and footers.
-
Facility to create footnotes and endnotes.
-
Facility to create multiple-column text.
-
Index and table of contents generation.
-
Spelling and grammar checking.
-
Thesaurus, etc.
5.3.2 ADVANTAGES OF USING WORD PROCESSING It helps in printing relatively error-free documents in the desired format. Any number of copies of the document can be printed without retyping, and all printouts look like the first copy. Most of the current word processors provide the facility of spelling checking and correction, grammar checking and correction, and thesaurus. Word processing helps in preparing such documents through its special features, such as boldface, underlined, different font and size of characters, centering of text, adjustable margins and tabs, spelling and grammar checking and correction, etc.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
140
COMPUTER FUNDAMENTAL & C PROGRAMMING Word processing is very convenient as it permits any number of revisions to be carried out in the document before printing the final version. Word processing also allows to move a block of text, say a paragraph from the first page to some other page.
5.3.3 WHAT IS WORD 6.0? Word 6.0 is a software program (package) designed by Microsoft Corporation, USA for word processing application. Word 6.0 is a very flexible and easy to use word processor. It is one of the most popular word processors in the World for the Windows platform on IBM and compatible PC.
5.3.4 STARTING WORD To start Word, complete the following steps:
Turn on your PC, load DOS and start Windows, if required.
Select Program Manager and then select the program group that contains, the Word icon. Usually, the Word icon is found in Microsoft Office group.
Double-click on the Word icon to start Word. If you do not have a mouse, use the arrow keys to highlight the Word icon and the then press the Enter key to start Word.
5.3.5 CREATING A DOCUMENT When you start Word, it automatically creates a new document-Document1. So, you can straightaway start typing the text. That is, there is no need to use any command to first create a document. After you have typed your document, when you save it, Word will ask for the filename. At that time, you can assign any filename to Document1 and save it any directory.
5.3.6 SAVING THE DOCUMENT IN A DISK FILE To save the document that you have typed in a disk file, you need to use the File, Save Command. You can use this command in three different ways: 1. Select the Save command from the File menu. 2. Click the mouse on the Save button on the Standard toolbar. 3. Press ^S, the keyboard shortcut keys for the File, Save command.
5.3.7 PRINTING A DOCUMENT If you wish to print a document, it must be open. You can execute the Print command in several ways, such as -
Open the File menu and then select Print from the menu.
-
Press ^P.^P are the shortcut keys for the Print command.
-
Click the Print button on the Standard toolbar.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
141
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.4 EDITING A DOCUMENT 5.4.1 EDITING A DOCUMENT The process of changing text to correct mistakes or to revise text in a document is called editing. There are three ways of correcting mistakes – Inserting, deleting and overtyping. Inserting Characters Word operates in the insert mode and anything you type gets inserted at the position of the cursor. Now the word reads ‘Ddelhi’. We need to delete the second ‘d’ from this word. Deleting Characters The Del key deletes the character to the right of the cursor position and Backspace deletes the character to the left of the cursor position.
Overtyping You can also change a character by typing over a character. Let us correct ‘sir’ by overtyping.
Move the cursor just before ‘s’ in the line ‘sir/Madam’
Let us select the overtype mode.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
142
COMPUTER FUNDAMENTAL & C PROGRAMMING
143
University Grants Commission National Education Testing F-48, South Extension – I New Delhi – 110048
No. F 5-32/98
Miss Ragini Sharma 77, Golf Links New Delhi – 110003
Sir/Madam,
With reference to
your application in response to our advertisement number 4/98
for the post of Junior Stenographer (English) in the office of the University Grants Commission, you are requested to appear for a written examination in General English and General Knowledge on the 24
th
February 1998 at 10.00 a.m. at the following examination centre:
Faculty of Arts, University of Delhi, Delhi – 100007.
Please note that
1. You should bring your own pen/ball pen. Answer books will be supplied by the
commission at the
examination hall. 2. You should report at least 15 minutes before the commencement of the examination on the date and place mentioned above. 3.
No Table/DA will be paid for the above examination.
4. Candidates qualifying the written examination will be called for the shorthand test at a later date. 5. The candidates may write to the undersigned for any clarification or for change of examination centre within two weeks of receipt of this letter.
(R K Chauhan)
Under Secretary
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
Press the Ins key once or double-click ‘OVR’ in the status bar. Word now selects the overtype mode. Notice that OVR in the status bar is being displayed in the normal intensity.
Now press S and Word changes ‘sir’ to ‘sir’.
Press the Ins key or double-click ‘OVR’ in the status bar to put Word back in the insert mode.
Splitting a Paragraph
Move the cursor at the end of the word in the sentence and press the Enter key.
Word splits the paragraph in two parts and pushes the second part to the next line.
5.4.2 SELECTING TEXT In word, it is very important to know to select text because you can do so many operations on the selected text. For instance, you can delete the selected text or format the selected text in bold or italic style. If you need to move text to some other part of the document, you need to select text. Because you may like apply the various Word commands on different length of text, such a word, sentence, paragraph, etc, you should know how to select the desired text. You can select text with the mouse or the keyboard.
5.4.3 DELETING TEXT To delete text, you need to perform the following two steps:
1.
Select the text you want to delete using any method (keyboard or mouse).
2.
Press the Del key.
5.4.4 REPLACING TEXT If you have to replace an existing word in a document with a new word, what steps would you follow? One may follow the following steps to replace a word: 1. Select the word that is to be replaced. 2. Delete the word. 3. Type the new word.
5.4.5 UNDOING AND REDOING CHANGES Word remembers all you actions. To use the undo command, you can use any of the following steps. 1. Press ^Z keys. 2. Open the Edit menu and then select the Undo command. 3. Click
, the Undo button on the Standard toolbar.
Word allows you to redo the actions that you have undone. To use the redo command, you can use any of the following steps.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
144
COMPUTER FUNDAMENTAL & C PROGRAMMING 1. Press ^Y keys. 2. Open the Edit menu and then select the Redo command. 3. Click
, the Redo button on the Standard toolbar.
5.5 MOVE AND COPY TEXT AND HELP SYSTEM Word allows you to move the text with the keyboard as well as the mouse. To move text with keyboard, cut the selected text, move the cursor where you want to move the text and then use the Paste command. To use the Cut and Paste, you can use the corresponding buttons on the Standard toolbar, select the corresponding commands from the Edit menu or use the keyboard-shortcut keys. The keyboard shortcuts to cut and paste text are ^X and ^V, respectively. To move text with the mouse, select the text that you want to move and then drag it wherever you like. If you need to use the same text at some other location in the document, you can use ‘Copy and Paste’. First, select the text that you want to copy and use the Copy command (^C) or click the Copy button on the Standard toolbar. Next, move the cursor where you wish to place the copy of the text and use the Paste command (^V) or click the Paste button. If you like, you can also copy text by dragging the selected text while keeping the Ctrl key pressed. Word provides very useful context-sensitive help information. Whenever you need help information, press F1.
5.6 FORMATTING TEXT AND PARAGRAPH
Formatting Text Word allows you to format the text by applying various text styles, such as boldface, underline, italic, superscript, subscript, strike – through, etc. For applying the bold, underline and italic styles, you can use the corresponding buttons on the Formatting toolbar. Alternatively, you can use ^B to apply the bold style; ^I to apply the italic; and ^U to apply the underline style. To change the size or font of the text, you can use the corresponding list boxes on the Formatting toolbar. The Font dialog box that is selected from the Format menu is used to apply other styles, such as strikethrough, subscript, superscript, all – caps, small – caps, etc. The Font dialog box also allows you to use different types of underlines and colour for the text in the document. Of course, to see the colours on the screen, you need to have the colour monitor, and to print colours, you need a colour printer or plotter.
Formatting Paragraph To change the alignment of a paragraph, you can use the alignment buttons on the Formatting toolbar. The paragraph dialog box is used to format paragraph(s). This dialog box is used to specify the left and right indent (margin), line – spacing and spacing before and after the paragraph. The paragraph indents are normally specified in inches and spacing
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
145
COMPUTER FUNDAMENTAL & C PROGRAMMING before and after paragraphs in points. 72 points are equal to one inch. The paragraph dialog box is also used to control the indent for the first line of the paragraph, as well as to create hanging paragraphs. To create numbered paragraphs, select the paragraphs to be numbered and click the Numbering button on the Formatting toolbar.
Similarly, you can show the selected
paragraphs in the bulleted style by using the Bullet button on the Formatting toolbar. These styles can also be selected by using the Format, Bullets and Numbering command. Word can also create a numbered list with other numbering styles, such as – 1),2),3),………I,II,III,………-A,B,C,…………
5.7 FINDING AND REPLACING TEXT AND SPELLING CHECKING Finding Text (^F) Word can search for specific word(s) in a document being edited. This command is available in the Edit menu. First of all, let us open this file.
If any file is open, save it if required and then close it.
Open the LETTER.DOC file.
Let us try to find ‘knowledge ’ in the LETTER document.
Open the Edit menu. Then select the Find command from the Edit menu.
Word displays the Find dialog box as shown in Figure 12.2.
Replace Command (^H) The Replace Command (^H) is used to find the search string and replace it with the specified text.
Open the Edit menu and select the Replace command. Alternatively, press ^H. Word displays the Replace dialog box as shown in figure .
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
146
COMPUTER FUNDAMENTAL & C PROGRAMMING
Figure Replacing dialog box
Spelling Checking and Correction Word comes with a very useful spelling checking and correction tool that can help you to produce error – free documents. Word comes with a very powerful dictionary that includes nearly all commonly used words. In addition to the built-in dictionary, you can also use a custom dictionary that can be used to store words not available in the Word dictionary. When you ask Word to check the spellings, it checks every word used in the document in its dictionaries.
If it cannot find any word in the standard or the custom
dictionaries, it prompts you and tries to give you a list of possible corrections that you can use. In most of the cases, Word is able to suggest the correct spelling for the misspelled word. Then, you can simply select the correct word and ask Word to replace the misspelled word in the document with the word you have selected.
Let us spell check the LETTER document.
Open the LETTER.DOC file.
Open the Tools menu and then select the spelling command.
Word starts checking the spellings of the words used in the document starting from the current position of the cursor. Soon, it locates a word that it could not find in its dictionaries and displays the Spelling dialog box as shown in Figure 12.4.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
147
COMPUTER FUNDAMENTAL & C PROGRAMMING
148
Ragini is spelled correctly, since this word is not there in word’s dictionary or in you custom dictionary, the spelling dialog box has stopped at this word. It also gives you two suggestions – Raging and Ragging. Now, the word ‘Ragini’is spelled correctly. So, we can ask Word to ignore it. On the right hand side of the dialog box, there are a few buttons. If you choose the Ignore button, Word will ignore ‘Ragini’ at the cursor position but will stop if it finds ‘Ragini’ again in the document. On the other hand, if you choose the Ignore All button, Word will ignore ‘Ragini’ throughout the document.
Using AutoCorrect to Automatically Fix Typing Errors It can automatically correct many common-typing errors.
Fox example, it can
automatically fix common mistakes sush as typing ‘teh’ instead of the’. Besides automatically correcting common spelling mistakes, AutoCorrect can also be used to quickly enter the phrases or names that you commonly use in you documents. Fox example, you may be using phrases, such as ‘ as soon as possible’, sincerely’,etc.quite regularly in our letters.
‘With best wishes’, ‘Yous
You can assign an entry for each of these
pharases in the AutoCorrect list. For instance, our can assign asap to ‘as soon as possible’ or ys to ‘Yours sincerely’. In that case, you just type asap and word automatically corrects (changes) it to ‘as soon as possible’.
Using AutoText to Insert Commonly used Text In AutoText too, you define a word and its replacement text as an AutoText entry. Later, when you type the AutoText entry.
Word replaces it with its replacement text.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
149
However, unlike in AutoCorrect, in AutoText the replacement is not automatic. After typing the Auto Text entry, if you want World to replace it with its replacement text, you need to press F3, clike the Auto Text button on the Standard toolbar or select the command from the menu. Normally, AutoText is used to insert relatively long but commonly used text ( or even graphics.) Fir ubstabcem University Grants Commission has to type its name and address in all letters that it sends. So, if it creates an AutoText entry. UGC that contains the name and address of University. Grands Commission, typing letters can become fast. In this section, you will create an Auto Text entry, UGC that will insert the following text: University Grands Commission National Education Testing F-48, South Extension – 1, New Delhi – 110048 Notice that we not only want to assign text, we also want to format the Auto Text entry UGC. We want to show all text in size 10 in the Arial font. We also want to show the first line of the address in bold letters and the last line of the address in underline. Let us define the Auto Text entry.
First of all, we need to type and format the text that we want to assign to an Auto Text entry Type the name and address of University Grants Commission and format it as shownabove.
Select (highlight) the complete name and address of University Grants Commission. If you also want to type one or more blank lines after the address, also select the blank lines.
After selecting the text to be assigned to the Auto Text entry, open the Edit menu and then select Auto Text from the EdiUniversity Grants Commission menu.
Word display the Auto Text dialog as shown in Figure 12.7.
Notice that word has
automatically transferred the selected text to the Selection box in the Auto Text dialog box. It has also picked the first word (university) from the selection and entered that in the Name text box. However, we want to assign UGC as the name for this Auto Text entry. Therefore, we need to change the name.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
‘University’ in the Name text is highlighted. Type UGC and it overwrites ‘University’.
Next, click the Add button to ask Word to accept the entry. Word creates the Auto Text entry UGC and closes the Auto Text dialog box. Now, let us use the UGC Auto Text entry to type the name and address of University Grants Commission.
Move the cursor to the end of the document. Press Enter to move the cursor to the beginning of a new line.
The UGC and Press F3 or click the
button on the Standard toolbar.
Word replaces UGC with the complete name and address of University Grants Commission. Notice that it has inserted the formatted text. In the same way, you can create Auto Text entries for all text that you routinely use in your documents. 5.8 USING TABS Consider the document shown in Figure 13.1. The figure contains a table. We need to create a similar document. To type such a table. You do not to use the spacebar to align columns. Instead, you should use tabs. When you start Word, it automatically sets tabs after every 0.5”. That is, the tabs are set at 0.5”, 1.0”, 1.5”, 2.0”, 2.5”, and so n positions. Therefore, you just need to press the Tab key to move the cursor to next 0.5” position. First, we will use the pre-defined the tab stop positions. Then we will learn to define out own tab stop positions (or simply ‘Tabs’)
If any file is open, save it if required and then close it.
Press ^N to create a new document.
Type Employee List.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
150
COMPUTER FUNDAMENTAL & C PROGRAMMING
Click the Centre button on the Formatting toolbar to centre the title.
Press Enter to move the cursor to the next line.
151
Press Enter to leave a blank line after the title.
Notice that the inserted lines are also centered. As you know, when you press the Enter key, word carries over the formatting of the previous paragraph to the next paragraph.
Since we want to type a left-aligned line (paragraph), click the Align Left button on the Formatting toolbar to left align the correct tine.
Type Pooja Chopra, the first name in the list.
Press the Tab key and Word moves the cursor to the next tab stop position.
Now type Assistant and then press the Tab key to move the cursor to the next tab stop position.
Type Sales and then press the Enter key to move the cursor to the next line.
In the same way, type Rajan Kumar, press Tab; Type Engineer; press Tab and then type Marketing.
Press the Enter key to move the cursor to the next line. Then type Sham Sunder; press Tab; type Engineer; press Tab and then type Sales.
Thus, you are also able to create a simple table with three columns by using the builtin tab stops.
5.9 ENHANCING DOCUMENT The Page Setup command available in the File menu enables you to define the page size, margins (top, bottom, left, right, header, footer, Gutter, etc.), orientation (portrait or landscape), etc. For your document.
On selecting the
Page Setup command, word displays the Page Setup dialog box that enables you to define the page setup. If you need to insert a page break in your document, you can press ^Enter or select the Break command from the Insert menu. To enhance the appearance of your document, you can show a border (box) around a paragraph, or even fill the box with a shade. To do so, you can either use the Borders and Shading command from the Format menu or use the Borders toolbar. Word has a number of toolbars. You can close or open any toolbar by selecting the Toolbars command from the View menu. You can also open or
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING close a toolbar by right-clicking the mouse on any toolbar and then selecting the toolbar that you want to close or open. If you want to define a header or footer for your document, choose the Header and Footer command from the View menu. Besides text, you can also use page number, date and time in header or footer. If you like, you can specify separate header and footer for even and odd pages, and for the first page of your document. If you want to see the complete page of your document on the screen, you can use the Print Preview button on the standard toolbar or the Print Preview command on the File menu. In the Print Preview mode, Word can also show multiple pages on the screen. Normally, your page size is too large to be shown completely on the screen. To see more area of your page on the screen, you can change the zoom percentage on the Standard toolbar or the Zoom dialog box. Word also supports the command to change the case of the selected text to upper case, lower case, title case and proper case; or you can just toggle the case of the selected text. 5.10 TABLES & COLUMNS You can easily create a table having specified number of rows and columns in Word. When you enter text in the cell of a table, Word automatically changes the cell height to accommodate the text you type. Use the Tab key to move the cursor to the next cell and Shift+Tab keys to move the cursor to the previous cell. Text entered in the table can be formatted using the normal text formatting commands. You can format the table by showing a border around cells. To change the width of any column in the table, you can drag the grid line between columns by using the mouse or use the Cell Height and Width command from the Table menu. To automatically select the column width that can accommodate the widest entry in the column, use the AutoFit button in the Cell Height and Width dialog box. To automatically format a table, use the Table AutoFormat command from the Table menu. If you want to use newspaper style columns in your document, you can use the Columns button on the Standard toolbar. Alternatively, use the Columns command on the Format menu. Then you can choose the number of columns that you want to have. If you want to convert an existing text into multiple columns, select the text and then use the Columns command. You can use any number of columns in your document. The columns can be of different width. You can use any number of columns in your document. The columns can be of different width. You can also show a line between columns. If you want to sort a list, use the Sort Text command from the Table menu. The list can be sorted in ascending or descending order. If you want to insert text
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
152
COMPUTER FUNDAMENTAL & C PROGRAMMING from an existing document into the current document, use the Insert, File command. This command can also be used to insert a graphic file. To copy the format of text, use the Format Painter button. And, to automatically format your document, you can use the AutoFormat command from the Format toolbar. After Word formats your document, you can accept or reject changes. You can even select a new style sheet to be applied with AutoFormat. USING GRAPHICS, TEMPLATES AND WIZARDS Using the Drawing Toolbar Word includes a set of drawing tools that you can use to create simple graphics. These drawing tools are available in the Drawing toolbar.
Click the Drawing button
on the Standard toolbar to open the
Drawing toolbar.
Word open the Drawing toolbar as shown. First of all, let us create a new document.
Press ^N to open a new document.
Drawing a Line Let us draw a line. To use any drawing tool, first of all you need to select that tool.
Click the Line tool (button) on the Drawing toolbar and move the mouse to your document area. The shape of the cursor changes to a ‘cross hair’. Now you can draw a line.
Move the mouse pointer where you want to start the line. Press the mouse button, and without releasing the mouse button, drag the mouse in any direction.
Word draws a line as you drag the mouse. As long as you do not release the mouse button, you can change the direction and the length of the line.
Release the mouse button and Word freezes the position of the line of the document.
Drawing a Rectangle, Square, Ellipse and Circle Next, let us Rectangle tool in the Drawing toolbar.
Click the Rectangle tool on the Drawing toolbar.
Move the mouse pointer where you want to place the rectangle. Press the mouse pointer at the starting point of the rectangle, and then drag the
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
153
COMPUTER FUNDAMENTAL & C PROGRAMMING mouse to draw the rectangle. After you have got the rectangle of the desired size, release the mouse button.
Drawing a Text Box The Text Box is a very useful drawing tool. It enables you to create a box. You can type and format text in the text box. Besides text, you can also includes other Word objects, such as a picture file or other drawing objects in the text box.
Click the Text Box button on the Drawing toolbar.
Move the mouse pointer to the document area and draw a box of about 10 cms x 4 cms. Word draws a box on your screen and places the cursor in the box.
Type some text in the text box. Try to change the formatting of some words in the text box. The following illustration displays a text box that contains four lines of text.
You can enter any text in the text box. To format the text entered in the text box, select the text that you want to format. Then use the usual text and paragraph formatting commands.
5.11.2 Using Templates In a business environment, most of the correspondence is repetitive in nature. For example, Sigma Associates sells computers and it has to correspond with its customers. Most of the sales letters that Sigma Associates sends contain the name, address and phone number of Sigma Associates, current date and subject. At the end of the letter, all letters contain the following text:
If you need any further information, please feel free to contact us. Yours truly, Sigma Associates In this situation, when Sigma Associates wants to type a sales letter, if the document already contains the name, address, phone number, date and the closing text, it can make typing sales letter fast. This can be done very easily by using a template. A template can store pre-defined text (also called boiler-plate text), page set – up, Auto Text entries, styles, etc. when you create a new document based on a template, Word automatically puts
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
154
COMPUTER FUNDAMENTAL & C PROGRAMMING all text and other definitions (e.g. page set-up) stored in the template in the document it creates. Then you can enter additional text in the document, and save and print it in the usual way. Word contains a few templates. Whenever you create a new document, it is always based on some template. When you press ^N or click the New button on the Standard toolbar, Word uses the Normal template. If you want to base your document on some other template, you have to select the New command from the File menu. Let use some other template.
If any document is open, save it, if required and then close it.
Open the File menu.
Select the New command form the File menu.
Word displays a list of templates, as shown in Figure 16.2.
By default, Word selects the Normal template. Therefore, if you press the Enter key or click OK without selecting a new template, Word creates a document based on the Normal template. Let us select the Memo 1 template. This template creates a memorandum.
Select the Memo 1 template from the Templates list box.
Click the OK button.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
155
COMPUTER FUNDAMENTAL & C PROGRAMMING Word creates a new document as shown in figure 16.3
Memorandum DATE : June 9, 1998 TO : [Names] FROM [Names] RE : [Subject] CC : [Names] [Type your memo text here] Figure 16.3 A document created by using the Memo 1 template As you see, this document already contains the structure of a memorandum. You can easily add additional text in the newly created document to quickly create a memorandum. Word also contains a few other general purpose templates that you can use. For your specific requirements, you can create your own templates.
5.11.3 Inserting Graphics Word can directly import graphics files created in most of the common graphics file formats. For example, if you create a drawing in PC Paintbrush, AutoCAD, CorelDraw, lotus 1-2-3, etc. and want to show it in your Word document, you can insert it very easily. Some of the common graphics file formats that Word can use are listed here (The default file extensions are listed in parenthesis): 1. AutoCAD (.DCX) 2. Computer Graphics Metafile (.CGM) 3. CorelDRAW (.CGM) 4. Encapsulated Postscript (.EPS) 5. Lotus 1-2-3 (.PIC) 6. PC Paintbursh (.PCX) 7. TIFF – Tagged Image File Format (.TIF) 8. Windows Bitmap (.BMP) 9. Windows Metafile (.WMF) Word includes a number of clipart that you can include in your document. Let us insert a clipart in a word document.
Open the Insert menu. Then select the Picture command from the insert menu. Word displays the Insert Picture dialog box on your screen.
Word selects the Clipart directory that contains the clipart files. It displays the list of files available in the Clipart directory in the File Name list box.
Click any file in the File Name list box and Word displays it in the preview box. If your computer does not display the picture in the Preview box, click the Preview Picture check box at the bottom – right corner of the dialog box.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
156
COMPUTER FUNDAMENTAL & C PROGRAMMING
Click the ANCHOR.WMF file and Word displays an anchor in the Preview box as shown in Figure 16.11
Click the OK button and Word inserts the clipart in your document.
Figure 16.11 inserting a picture file
5.12 USING MAIL MERGE
5.12.1 What is Mail Merge? Mail Merge is a very useful and powerful addition to the primary feature of word, word processing. You can use Mail Merge to print personalized form letters (bearing the addressee’s name and address on the letter), envelopes, mailing labels, etc. The form letters are those letters that have the same (or nearly same_ contents. These letters are sent to several persons. Business letters describing the launch of a new product, call letters for interview, notice for a meeting, invitation for a party, etc. are examples of form letters. When no computer is used to send form letters, one normally gets the letters printed, cyclostyled or photocopied, one way of printing similar letters of the kind discussed above is to first type a letter and then print it. Then, we can edit it and change the name, address and other details for the next letter and print it, and so on. Obviously, this is a very cumbersome method. The name, designation, address, etc. that differ from one letter to another are stored in another file. The Mail Merge of Word merges (combines) the two files at the time of printing. Since this is used to print letters for mailing, it is called Mail Merge.
Concept of Mail Merge We explain the concept of Mail Merge with the help of an example, Let us assume that we have to send an examination notice to three persons. We will use two files. The first file contains the complete text of the letter expect the name and address of the person. This file is called the main document or the master document. Another file that is called the data file or the data source is used to store the name and address of persons whom the letters are to be sent. Mail Merge uses the main document and then picks up the first address from the
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
157
COMPUTER FUNDAMENTAL & C PROGRAMMING
158
data file to print the first letter. Then it picks up the next address from the data file to print the second letter, and son. Symbolically, it can be explained as shown here. Master Document
Data File
Dear With reference to your application in response to our advertisement for the post of Stenographer
Ragini Sharma, 77, Golf Links, New Delhi, 110003 G Sundaram, 44, T Nagar, Madras, 600060 Sisir Roy, 16/4, Rabindra Nagar, Midnapore, 722101
Dear Ragini Sharma, Dear G Sundaram, Dear Sisir Roy, With reference to your application
In response to our advertisement For the post of Stenographer.
Thus, to use Mail Merge, we have to create two documents – a main document and a data source.
5.12.2
Practical Example of Mail Merge In chapter 8, you created a letter for University Grants Commission regarding an examination notice. Let us assume that we want to send the same letters to the following three persons:
Name
Address
City
PIN
Ragini Sharma
77, Golf Links
New Delhi
110003
G Sundaram
44, T Nagar
44, T Nagar
600060
Sisir Roy
16/4, Rabindra Nagar
Midnapore
722101
We will have to create a data file and store these address in that file. Before we use Mail Merge Helper, let us make a copy of LETTER.DOC since our master document will be based on this document.
Open LETTER.DOC document file.
Open the file menu, and then select the Save As command. Type UGCEXAM as the file name. Word creates the UGCEXAM.DOC document that is an exact copy of LETTER.DOC.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.13 INTRODUCTION TO WORKSHEET AND EXCEL
5.13.1 What is an Electronic Worksheet or Spreadsheet? An electronic worksheet (or spreadsheet) is used to store information in the memory of a computer, ask the computer to calculate results, and display the information and results on the computer screen in a desired manner. In other words, it replaces the normal paper sheet or ledger, pencil (or pen), eraser and calculator. In such a worksheet, information is entered through the keyboard and displayed on the computer screen. The information already entered on the screen can be changed very easily. The worksheet calculates results; for instance, it can calculate the total sales by multiplying the quantity sold with the unit price. If any information is changed, the worksheet program automatically recalculates all results. For instance, if the unit price changes, it will immediately recalculate and display the new total sales value. The worksheet program can also display the results in the form of graphs. The information entered in the worksheet can also be printed. The application of a spreadsheet is limited only by your imagination. You can store all kinds of information in the spreadsheet. Some common applications of a spreadsheet are in the following areas. -
Annual reports of business firms
-
Income statement and income tax calculations
-
Payrolls
-
Invoicing (Billing)
-
Accounts payable and receivable
-
Production and marketing analysis
-
Investment and loan analysis
-
Banking and other financial services
-
Inventory control
-
Tender evaluation
-
Scientific calculations
-
Cost â&#x20AC;&#x201C; effective analusis
5.13.2 Advantages of Using an Electronic Worksheet The electronic worksheet offers several advantages over the manual one. Consider the Profit and Loss Statement of a business firm sown in Figure 19.1
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
159
COMPUTER FUNDAMENTAL & C PROGRAMMING
Advantage of automatically recalculation of results, the electronic worksheet generally offers the following features too.
-
The results are accurate
-
The worksheet can be quite big in size and any part of it can be viewed of edited.
-
Data entered in a worksheet can be formatted in several ways to give it a professional look.
-
Several mathematically, trigonometric, financial and statistical functions are built – in. all sorts of complicated calculations can be performed using these functions, facilitating rapid operation.
-
Data can also be viewed in the form of graphs. These graphs, which can be of various types, can be printed.
-
The worksheet is saved in an electronic file. This file can be retrieved and modified later, if required.
-
An existing worksheet or any part of it can be merged with any existing or new worksheet.
-
The information entered in a worksheet can be sorted in a desired format.
-
With the electronic worksheet program, you can easily and quickly produce reports and get answers to ‘what – if’ questions. For instance, you can instantly determine what the sales target of the last quarter should be if you want to increase the net profit for the year by 15%.
-
The information stored in a worksheet can be transformed to other software programs, such as Word, WordStar, FoxPro, dBASE, etc. Similarly, information stored in other software programs can also be transferred to a worksheet.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
160
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.13.3 What is Excel? Excel is an integrated electronic worksheet (spreadsheet) program developed by Microsoft Corporation, USA. It includes three components – worksheet, graph (chart) and database management. It lets you create your worksheet and enter information. It performs all kinds of calculations and displays results on the screen in the form of figures of graphs. You can perform various database management functions on the data entered in the worksheet. A few other important features of Excel are: - Date – and time – related functions. - Manipulation of character data (string). - Database management. - Keyboard macros to automate tasks. - Drawing toolbar to create graphics. - each worksheet can have multiple sheets.
5.14 GETTING STARTED WITH EXCEL 5.14.1 Starting Excel Complete the following steps to load Excel.
If the Program Manager window is not open, double – click the icon for Program Manager to ask Windows to open this widow.
If you have installed Excel in a separate window, double – click the icon for that window to open the Window.
Locate the icon for Microsoft Excel in the Microsoft Excel or Microsoft Office window.
This icon look like.
To start Excel, double – click the Excel icon. If you want to use the keyboard to start Excel, use arrow keys to highlight the Excel icon’s label and press Enter.
5.14.2 The Excel Screen When you start Excel, it automatically creates a new worksheet – Book1. Notice that it is displaying the name of the program (Microsoft Excel) and the worksheet (Book1) in the title bar of the window. The next line of the Excel window is called the menu bar. The menu bar is used to select the various commands available in Excel. The Excel menu system is divided into nine menu items.
5.14.3 Organization of the Worksheet Area Rows and Columns A worksheet is made up of rows and columns. The worksheet contains 156 columns and 16,384 rows. Rows’ numbering in Excel is straightforward. The first row is called row1,
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
161
COMPUTER FUNDAMENTAL & C PROGRAMMING the second row is called row,2, the fifth row is called row 5 and the hundredth row is called row 100 and so on. The first 26 columns are called referred to by letters A trough Z. The th
th
27 column is called row AA, the 28 column AB, and so on. Cell and Cell Address The area formed by the intersection of a row and column is called a cell. The cell formed by the intersection of column D and row 12 (see Figure 20.3) is referred to by D12. D12’ is called the address of that cell. Each cell in the worksheet has a unique address. The cell address is very important in the worksheet as it is used in formulas to refer to a particular cell.
Active Cell In the worksheet, there is a thick border around one of the cells. Cell A1 has a border around it. This cell is called the active or current cell. Any data that you type is stored in the active cell.
5.14.4 Entering information in a Worksheet You can enter two types of data in a worksheet --- constant values and formulas. A constant value is a fixed value that you type directly in the cell. It can be a number or text, e.g. 12,5200, Rajan, New Delhi, Profit,etc. Once entered, these values remain fixed and do not change. When you enter a formula in a cell, Excel calculates the results the result of that formula and displays the result in the cell. A formula may refer to one or more cells in the worksheet and its results may change. A formula in Excel must begin with ‘=’. Excel ignores spaces in the formula. Therefore, if you like, you can type spaces in the formula. For instance, Excel will treat = B6(B4+B5) and =B6 – (B4+B5) as the same.
5.14.5 Saving a Worksheet In Excel, you can save a file in three different ways. 1. By using the Save button on the Standard toolbar. 2. By using the Save command from the File menu. 3. By pressing ^S, the shortcut keys for the Save command.
5.15 EDITING CELLS AND USING COMMANDS AND FUNCTIONS By default, Excel left aligns text entries and right aligns numeric entries. However, by using the Formatting toolbar. However, by using the formatting toolbar or the Format, Cells command, the cell data can be left aligned, right aligned or centered. Excel also allows aligning data with the help of label-prefix characters. To edit data in a cell, first we have to make it active. To initiate editing, press F2 or double – click in that cell. Then, use the normal editing keys to change the cell contents.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
162
COMPUTER FUNDAMENTAL & C PROGRAMMING Excel contains a number of built- in functions that can help you to perform complex operations on the worksheet data. For instance, you can use SUM to calculate the total of data in a range. While using a function, you can type range address or select it in the worksheet. To display the complete data in a cell, sometimes you may have to increase the column width. You can increase the width for a single column, a range of columns or even all columns in the worksheet. To change the column width, either use the Format, Column, Width command or use the mouse. After making changes in an existing worksheet file, when you use the File, Save (^S) command. Excel resaves the worksheet file. When you are finished with a file, close it using the File, Close command or double – click the Control Menu Box for the worksheet window. To create a new worksheet, press ^N, click the New button on the Standard toolbar or use the File, New command.
5.16 MOVING AND COPYING, INSERTING AND DELETING ROWS AND COLUMNS To open an existing worksheet file, we can use the File, Open (^O) command or the Open button the Standard toolbar. This command displays the Open dialog box and then we can select any worksheet file from any directory for opening. Any of the recently used files can be opened by selecting filename from the File menu. Excel allows you to move data from any part of the worksheet to another. You can move a single cell or multiple cells. To move data to a new location, you can use the Cut and Paste commands or buttons. You can use the Copy and Paste commands or buttons to copy data from one part of the worksheet to another. The Copy and move operations can also be accomplished with the help mouse. A single cell can also be copied to several cells. While working on a worksheet, if you make any mistake, you can use the Undo command from the Edit menu or press the Undo button (or ^Z) to undo the last action. If you need to make room to insert more data within an existing data, you can insert row(s) or column(s) anywhere in the worksheet. When you insert columns or rows, Excel automatically renumbers rows and columns. The commands to insert rows and columns are available in the Insert menu, or you can use the Shortcut menu. Similarly, you can delete rows and columns from your worksheet or erase the unwanted data from it. If you do not want to save the modified worksheet, close it and select ‘No’ when Excel prompts you to save changes.
Getting Help and Formatting a Worksheet Excel provides a very powerful, context-sensitive help system. You can get help about any menu command or toolbar button. The help system also allows you to search for any help topic. To give a professional look to your worksheet, you can use various formatting commands. Commonly used formatting styles, such as bold, italic and underline can be
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
163
COMPUTER FUNDAMENTAL & C PROGRAMMING applied by clicking the corresponding buttons on the Formatting toolbar. Alternatively, press the keyboard shortcut keys to apply these styles, e.g. ^B applies the bold, ^I applies italic and ^U applies underline style. Before applying any format on a range, you have to select it. Excel also allows you to change the size and font of the selected range through the Formatting toolbar as well as the Format Cell dialog box. The Format Cell dialog box also enables you to use effects, such as strikethrough, superscript, subscript, and to change the underline style. You can format the numeric data in several formats, such as comma, currency, fixed, percent and scientific. With these formats, you can also specify the number of decimal places to be used. You can show a border (ruler line) on any side of the selected range. To show a border around a range, select the range and choose the required border either from the Borders button or the Format Cells dialog box.
5.17 PRINTING THE WORKSHEET To print the current worksheet, you can use the File, Print command, press ^P or click the Print button in the Standard toolbar. On using File, Print or ^P, Excel displays the Print dialog box that enables you to select what you want to print. On the other hand, the Print button directly prints the worksheet. By default, Excel also prints the gridlines on the page. These gridlines can be removed by using the Sheet page of the Page Setup dialog box. To open the Page Setup dialog box, select the File, Page Setup command from the menu. The Print Preview command displays the complete page, including header and footer, as you would get it on printing it. The buttons in the Print Preview window enable you to change the page setup, i.e. page size and margins and column widths. The other way to setup the page is by using the Page Setup command from the File menu. In this dialog box, you can define top, bottom, left, right, header and footer margins and orientation. The Header/Footer page of this dialog box allows to define a custom header and footer. The header and footer are divided in three sections. You can define any text in any section of header or footer. Besides, you can use the buttons in the header/footer dialog box to insert the current date, time, page number, filename, sheet name, etc. in header/footer. The Page Setup dialog box also allows you to scale the printed page. At the time of printing a worksheet, if you want to print multiple copies of the worksheet or want to print a specified page range, you can specify these in the Print dialog box. The Printer Setup button in this dialog box allows selecting another printer. Excel automatically takes care of starting a new page. However, if you like, you can insert a page break anywhere in the worksheet by using the Insert, Page Break command. You can also include title rows and columns that are repeated on every page in your printouts.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
164
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.18 CREATING CHARTS A worksheet contains so much numeric data. The facility to represent data in the form of charts (graphs). Excel allows you to view graphs on the screen as well as to point them on a printer or plotter. It supports many types of charts, such as Line, Bar, Stacked – Bar, Pie, XY, Area, 3-D Bar, Radar, Doughnut, etc. In Excel, creating a chart is very simple. To create a chart, all you need to do is to select the range that you want to include in the chart and use a wizard called ChartWizard. ChartWizard asks a series of questions and creates a chart for you.
5.18.1 Using ChartWizard to Create a Chart Create a chart for the Profit and Loss Statement. 1. Select the range that you want to plot in the chart. 2. Click the ChartWizard button on the Standard toolbar and select the area where you want to show the chart. 3. ChartWizard asks a series of question regarding the type of chart that you want to create. Select the options that you want to use with your chart. 4. Finally, click the Finish button and your chart is ready! Later, if required, you can modify the chart very easily. In the chart that we want to create, we want to show the Cost, Overheads and Sales Figures for January, February and March to give a professional look to our chart, we want to show the month names on the X-axis. We also want to show Cost, Overheads and Sales as legend in our chart.
Click the Next button and ChartWizard displays the second step. Excel displays the various types of charts, such as Area, Bar, Column, Line, Pie, etc. that it can create, all you need to do is to click the chart type that you want to use. By default, Excel has selected the Column type.
Then click the Next button.
In this step, Excel is asking you to select one of the Column charts it can create.
Press the Next button, and Excel displays the next step of ChartWizard.
Excel displays a sample chart based on your selections in the previous steps. Based on the range selected by you for creating the chart, Excel has assumed that the data to be plotted is organized in rows. It is showing the x-axis labels and legend in the sample chart.
Click the Next button and Excel displays step 5 of ChartWizard.
You select if you want to show a legend in your chart. By default, ChartWizard displays legend in the chart. Accordingly, you find that the Yes radio button in the dialog box is selected. If you do not want to show legend, select the No radio button.
Click in the Chat Title box and type Budget 1998.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
165
COMPUTER FUNDAMENTAL & C PROGRAMMING The other boxes in the Step 5 dialog box are used to assign titles to the X, Y and Second Y – axes of the chart. For instance, you may like to show ‘Months’ as the title for Xaxis.
Press Enter or click the Finish button and ChartWizard display the completed column chart on your screen as shown.
If you take it outside the worksheet area, Excel docks the toolbar.
If you do not see the ChartWizard, click any where in the chart and Excel displays the Chart toolbar. (If you still do see the Chart toolbar, choose the View, Toolbars command from the menu; click the Chart check box in the Toolbars dialog box and press Enter. Excel will display the chart toolbar).
Click the drop-down pointing arrow on the right side of the first button in the Chart toolbar.
5.18.2 Resizing and Moving the Chart If you move the resizing handles located on the corners of the box, you can simultaneously change the height and width of the chart.
Let us try to move our chart.
If Excel is not displaying resizing the handles around the chart, click anywhere in the chart.
Move the mouse pointer anywhere on the chart and drag the mouse. As you drag the mouse, the border of the chart moves along with the mouse.
When you have positioned the border where you want to reposition the chart, release the mouse button and Excel repositions the chart on the worksheet.
5.18.3 Displaying a 3-D Column Chart To use the menu, first we have to put the chart in the edit mode.
Double – click anywhere in the chart. Excel puts the chart into the edit mode and changes its border into a striped pattern.
Open the Format menu and choose the Chart Type command from the menu. Excel display the Chart Type Dialog box as shown.
5.18.4 Modifying and deleting a Chart We need to select A4:A6, C4:C6 and E4:E6 as the range for our chart.
Move the cell pointer on cell A4 and drag the mouse to select the range A4:A6. Notice that as you drag the mouse, Excel displays the new range in the Range box of ChartWizard.
After you have selected the range A4:A6, move the mouse pointer on cell C4. Now press and hold the Ctrl key and drag the mouse to select the range C4:C6.
Next, move the cell pointer on cell E4. Keep the Ctrl key pressed and drag the mouse to select the range E4:E6.
At this stage, the Range box in ChartWizard should display the following range:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
166
COMPUTER FUNDAMENTAL & C PROGRAMMING =$A$4:$A$6, $C$4:$C$6, $E$4:$E$6
Now click the Finish button in ChartWizard.
5.18.5 Creating a Chart on a Chart Sheet Let us try to do this.
Select the range A4:A7 and C4:E7 as you did in Section 25.1. Your worksheet.
Open the Insert menu. Then select the Chart command from the Insert menu. Excel displays two options – on this sheet and as new sheet.
Choose ‘as new sheet’ to create the chart on a new sheet. Excel displays step 1 of ChartWizard. The Range box in the dialog box already contains the selected range.
Click the Next button and Excel displays step 2 of ChartWizard. The column chart type is selected by default.
Click the Next button and Excel step 3 of ChartWizard. By default, the format 6 of the column chart is selected.
Click the Next button and Excel displays step 4 of the ChartWizard. The default options are okay for our chart.
Click the Next button and Excel displays step 5.
Click in the Chart Title box and type Budget 1998 as the title for the chart.
Click the Finish button and Excel creates a new sheet, names it ‘Chart1’ and creates a chart in the inserted sheet. It automatically selects the inserted sheet. Your chart should look similar to Figure 25.29.
5.19 USING DATE AND TIME AND ADDRESSING MODES To enter the current date in a cell, the NOW and TODAY functions are used. Then, the entered date can be formatted in any of the several date formats supported by Excel by using the Format, Cells command. Internally, the date is stored as a date serial number that is equal to the number of days elapsed since January 1, 1900. By default, the Now function displays both date and time. However, to display only the date or time in the desired format, use the Format, cells command and choose the Date or Time category. The F9 key is used to freeze the current date or time in the cell. To enter a specific date in a cell, we can use any of the supported date formats, such as 14-Apr-99, 14/Apr/99. As, internally, dates are entered as date serial numbers, we can compare dates, or subtract one date, from another to find out the number of days between them. We can use the DAY, MONTH and YEAR functions to extract day, month and year information, respectively from a date. While copying a formula, Excel uses the relative cell addressing. It supports two other addressing modes. These are absolute and mixed. To convert a relative cell reference to absolute or mixed, we can use the F4 function key.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
167
COMPUTER FUNDAMENTAL & C PROGRAMMING To enter the current time, use the NOW function and choose the desired time format. To enter a specific time, enter it in any of the supported time formats, e.g.10:15; 11:10AM, 15:20, etc. The HOUR, MINUTE and SECOND functions can be used to extract the hour, minute, minute second information, respectively from the time entered in a cell.
5.20 NAMING RANGES, AND USING STATISTICAL, MATH AND FINANCIAL FUNCTIONS
5.20.1 Using Statistical Functions Excel supports more than 70 statistical functions it has many functions AVERAGE
Calculates the average of a list of values.
COUNT Counts the number of non â&#x20AC;&#x201C; blank numeric cells in a list. MAX
Finds out the maximum value in a list of values
MIN
Determines the minimum value in a list of values.
STDEV Calculates the standard deviation of a list of vales. VAR
Calculates the variance of a list of values.
5.20.2 Using Math Functions Math functions perform mathematical operations on numeric data entered in the worksheet. SUM The SUM function calculates the sum of values in a list. 1. SUM (C8:G8) 2. SUM (PROFIT) ABS Calculates the absolute value of a number. E.g. = ABS (-12.3) entered in a cell displays 12.3
EXP Returns e raised to the power of a given number. For example, EXP(1) returns 2.718282 and EXP (2) returns 7.389056. A fractional or negative number can also be used with the EXP function. INT This function rounds the number down to the nearest integer. For example, INT (20.87) returns 20, whereas and INT (-12.3) and INT (-12.9) return -13. LN, LOG10 and LOG The LN function calculates the natural logarithm (base e) of the specified positive number. For example, LN (10) returns 2.305850. The LOG10 function calculates the common logarithm (base 10), e.g. LOG 10(100) returns 10. The LOG function calculates the common logarithm (base 10) or to the base that you specify. For instance, LOG (100) calculates logarithm of 100 to base 10 and returns 2 as the answer.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
168
COMPUTER FUNDAMENTAL & C PROGRAMMING MOD This function calculates the modules (remainder) of two values. For example, MOD (1408, 10) returns 8. RAND This function returns an evenly distributed random number greater than or equal to 0 and less than. ROUND The ROUND function rounds off a number to the specified number of decimal places. =ROUND(A14,1) displayed value 1456.6 Remarks Cell A14 contains 1456.5863 SQRT The SQRT function calculates the square root of a positive number. E.g. SQRT (SUM(C1:C5))
Trigonometric Functions Excel supports a number of trigonometric functions. Some of the commonly used trigonometric functions in Excel Worksheet are ACOS, ACOSH, ASIN, ASINH, ATAN, ATAN2, ATANH, COS, DEGRESS, SIN and TAN. 5.20.3 Using Financial Functions Financial functions allow us to calculate loans, depreciation, cash flow, and so forth. Rate
Rate refers to the rate of interest per period.
Period Period refers to the time interval between payments. PMT
PMT refers to the periodic payments made to pay off a loan or into a deposit account.
NPER
NPER refers to the number of periods.
Using RATE The RATE function can be used to calculate the interest rate charged to pay off a loan. The RATE function has the following syntax: RATE (nper, pmt, pv, fv, type, guess) Here nper is the total number of payment periods. In our case, nper is 48. pmt is the payment made each period, which in our case is 3000. pv is the present value of the total amount that a series of future payments is worth now. In case of loan, Pv is equal to the total loan amount. Thus, in our case, PV is 100000. Fv is the future value at the end of the last payment. The future value of a loan is 0. Therefore, in this example, we can omit or use 0 for fv. Type is the number 0 or 1. It indicates when payments are due. If type is omitted or 0, it means that payments are made at the end of period. On the other hand, if payments are made at the beginning of period, use 1 for type. Guess is your guess for what the rate may be. If you do not use guess in the function, Excel assumes the guess to be 10%. While using the RATE function, the first three arguments, i.e. nper, pmt and fv are compulsory, and the other three parameters, i.e.fv, type and guess are optinal.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
169
COMPUTER FUNDAMENTAL & C PROGRAMMING Using FV to Calculate the Future Value The FV function returns the future value of an investment based on periodic, constant payments and a constant interest rate. This function has the following syntax: FV (rate, nper, pmt, pv, type) Using PV to Calculate the Present Value The PV function can be used to calculate the present value of a series of equal payments to be received in future. This function has the syntax: PV (rate, nper, pmt, fv, type) Here, rate is the periodic rate of interest. Using NPER The NPER function calculates the number of payment periods required to accumulate the investment to a specified future value. This function has the syntax: NPER (rate, pmt, pv, fv, type) Using PMT The PMT function can be used to calculate the equal periodic payments required to pay off a loan. This function has the following syntax: PMT (rate, nper, pv, fv, type). Here, fv and type are optinal. Calculating Net Present Value with NPV The NPV function is a slightly modified form of PV. It calculates the net present value of a series of cash flows discounted at a fixed interest rate. The syntax of the NPV function is: NPV(rate, value1, value2,â&#x20AC;Śâ&#x20AC;Ś) Calculating internal Rate of Return with IRR The IRR function calculates the internal rate of return (IRR) expected from a series of cash flows occurring at regular intervals. The IRR function has the following syntax. IRR (values, guess) Here, values includes the range of cash outflow (the initial investment) and cash inflows. Guess is optional.
5.21 DATABASE IN A WORKSHEET 5.21.1 What is a Database? A database may be defined as an organized collection of related information. Information pertaining to one set comprising a name and address, i.e.name, locality, city and PIN, is typed in one line on the paper. The second line contains the name and address of Priyanka. This line is called the record or Priyanka. One set of information (viz. name, locality, city and PIN) is stored in one row. This row is called a record. Information is entered in records of a worksheet database under different columns in the same manner. These columns in database terminology are called fields. Fields are also named in a worksheet database. These are called fieldnames and the row containing fieldnames is called the header row.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
170
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.21.2 Database in a Worksheet A database can be located anywhere in the worksheet. A database also contains labels, numbers, formulas, and so on. All worksheet commands and functions are available for use on a database. However, besides the regular commands and functions, a number of database â&#x20AC;&#x201C; related commands and functions are available for use only on a database. You can find out: -- the average, maximum or minimum salary paid to the employees of the sales department. -- a list of employees working in a particular department. -- a list of employees who draw a salary of more than Rs.3000 but less than Rs.5000 per month. You can also organize the information entered in a database in the desired order, e.g. in alphabetical order of names, or according to the department.
Field
Record Fieldname Database
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
171
COMPUTER FUNDAMENTAL & C PROGRAMMING
Figure 28.2 A database and its components
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
172
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.21.3 Creating a Database Let us create a database in a new worksheet. We will create an employees database according to Figure 28.3 in a new worksheet STAFF1.
Figure 28.3 STAFF1 worksheet
Press ^N to create a new worksheet.
Change the width of columns A, B and C to 11 and enter the data worksheet.
Save the worksheet with the filename STAFF1.
5.21.4
Sorting a Database Excel provides a very powerful command to sort the database, i.e. arrange the information stored in it in a desired order. For example, we can sort the employees’ database entered in the STAFF1 worksheet file in an alphabetical order of names. If you like, you can sort the employees database as per department or designation. You can also sort a database on multiple fields. For instance, you may like to arrange your database as per departments, and with in each department, you may like to arrange the employees in the alphabetic order of names. To sort a database on a single field, you can use the Sort buttons on the Standard toolbar or the Data, Sort command.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
173
COMPUTER FUNDAMENTAL & C PROGRAMMING
174
Using Sort buttons To quickly sort a database in ascending or descending order on any field
sort, Excel provides two buttons on the Standard toolbar. These are
Ascending ) and
(Sort
(Descending Sort).
5.22 INTRODUCTION TO DESKTOP PUBLISHING 5.22.1 What is Desktop Publishing (DTP)? Desktop Publishing (DTP) refers to designing and printing reports, brochure, catalogues, letters, books, manuals, etc. using DTP software on a personal computer (PC). With DTP, printing is usually done on a laser or inkjet (desk jet) printer to attain the professional grade quality. Document produced with DTP look like those produced with conventional printing (through printing press). With DTP, normally, the text entered with common word processors, such as Word, WordStar, Word Perfect, etc. is transferred to DTP either directly or in the form of an ASCII (American Standard Code for Information Interchange) text file. The various DTP commands
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING are used to format the text in a desired form by selecting the required font (shape and size of characters) for headings, sub-headings, footer, header and normal text. One also defines page size, margins, page number style and multiple â&#x20AC;&#x201C;column printing (like newspapers), if required. DTP displays the page in the WYSIWYG (What You See Is What You Get) mode. The page make-up or design is usually defined through a style sheet. In DTP, a style sheet is attached to each text file. The style sheet file contains information about the page size, number of columns and column width, margins, etc. it also contains information about the page size and the letter style (font) to be used with various paragraphs or letters of a paragraph, inter â&#x20AC;&#x201C; line spacing, margins to be left before and after each paragraph, etc. similarly, it also contains information regarding how to show the titles, headings, subheadings, running text, etc. used in a document. Each specific style in a style sheet file is defined in the form of a tag. By attaching different types of tags to different types of text in the document, the text can be printed in various fonts with the required spacing between paragraphs.
5.22.2 Common features of DTP In DTP, the user interface is good compared to a word processor. Generally, the user is just required to select the option with the help of a mouse. It can be used to select a block of text; move, copy or delete the selected text; draw, reposition or resize drawing objects (lines, circles, rectangles, etc.) and images, etc. On selecting an option, DTP may display a new menu or dialog box to enable the user to select additional related options. DTP is able to display the complete page with header(s) and footer(s) on the screen as it would appear when printed. Defining and Applying DTP allows defining and editing tags. For instance, one can define a tag to show the chapter heading in a big font with bold characters. Similarly, another tag can be used to centre the text. These tags are given specific tag names and are stored in a style sheet file. Once tags have been defined, one has to just select the text to be formatted and then select the desired tag. DTP will immediately apply the specified style on the selected text and display the formatted text on the screen. Using Figures, Pictures and Clip Arts DTP can automatically combine any kind of figure or picture with text. For instance, graphs generated with Excel or Lotus 1-2-3, or pictures created with AutoCAD, PC Paintbrush, etc. can be combined with text. It is also possible to get any kind of picture, e.g.the photograph of a person in a DTP document with the help of a scanner. The DTP program usually has the capability to create simple line drawings through the built-in features to draw a line, box, circle, triangle, etc. You can also select the line thickness for these shapes and fill these with different colours and patterns. Many DTP packages also come
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
175
COMPUTER FUNDAMENTAL & C PROGRAMMING equipped with number of ClipArts for common objects, such as buildings, equipment, flags, people, etc. You can include these in your document. Once a graphics or images has been drawn or transferred to DTP, it can be resized, i.e. you can enlarge (magnify), condense (reduce) or stretch it in one direction or the other. The pictures and images are generally enclosed in a special box called frame. The frame can be positioned anywhere on the page by just dragging it with the mouse. Page and Figure Numbering DTP can automatically number the pages and put page numbers at a desired place in a selected format. For example, page number 4 can be printed as 4, iv, IV, d, etc. Similarly, it can automatically number figures and tables. If a figure is deleted, all subsequent figures are automatically renumbered. Captions for Figures Besides automatically renumbering figures, DTP can also add a caption for each figure in a desired format at the top, left, right or bottom of the figure. One can also control the space to be left below and above the caption. Cut and Paste This feature of DTP allows users to delete, move or copy text or graphics from any part of the page to the same or another page. The area (block) to be moved, deleted or copied is marked with the help of the mouse. Once the area has been marked, use the appropriate command or mouse to move, copy or delete the block. Then, DTP automatically renumbers pages and reformats the file. Header, Footer, Footnotes and Endnotes Header is one or more lines of text and graphics that is printed at the top of every page. Similarly, footer is one or more lines of text and graphics printed at the bottom of every page. DTP supports different headers and footers for odd pages, even pages and the first page. DTP allows us to precisely define the position of header and footer on the page. Footnotes are printed at the bottom of the page above the footer and the endnotes are printed at the end of the page. DTP automatically numbers footnotes and endnotes. When you delete or add footnotes or endnotes, DTP automatically renumbers them. Combining Several Files in a Publication DTP allows you to combine several text files, which are called chapters to form a single publication file. Each chapter can have its own style sheet. This facility enables a large document, such as a book or manual to be divided into smaller files. These smaller files can store a chapter or section of the large document. The separate files allow easy editing and formatting. By combining several files into one publication file, you can get a uniform print style, consecutive page and figure numbering for all files. This also helps in preparing s single table of contents and index. Table of Contents and Index Based on the entries made in the text files, DTP can automatically create index and table of contents with correct page numbers for a publication file. The automatically index
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
176
COMPUTER FUNDAMENTAL & C PROGRAMMING and table of contents creation is very useful when you decide to delete, add or move material in any file, as no manual work is involved. Tables In addition to allow easy commands to create and type tables, DTP normally supports features to enclose the table in a variety of boxes and fill them with a suitable pattern/shade. Spelling Checking and Correction Many DTP programs are able to check and correct spelling mistakes. They can automatically hyphenate the document. Some DTP programs can also detect grammatical errors in the document. 5.22.3 Common DTP Programs A number of DTP software programs are available for use on the PC and Apple Macintosh. The following is the list of commonly used DTP programs. 1. Page Maker for DOS, Windows and Macintosh 2. Corel Ventura for DOS and Windows 3. Microsoft Publisher 4. Corel Draw 5. Harvard Professional Publisher 6. Linos 7. IBM Solutionpac Personal Publishing System 8. Ready, Set, Go 9. Spellbinder Desktop Publisher.
5.23 OVERVIEW OF POWERPOINT 5.23.1 What is PowerPoint? PowerPoint is a presentation software that can help you to quickly create effective ‘slide based’ presentations. The presentation consists of any number of slides. Each slide can have text and graphics. It can helps you to create the following types of presentations. 1. Black-and-white transparencies for the overhead projector. 2. Colour transparencies for the overhead projector. 3. 35mm slides for the slide projector. 4. Videos slide show on the computer screen. 5. Printed handouts. 6. Detailed speaker’s notes 7. Printed outline of the presentation. Power point comes with a number of sample slides. Depending on the type of slide you want to include in the presentation, you can choose an appropriate slide. In the slide show, PowerPoint shows the slides on the computer screen in a similar fashion as you get on a slide projector. You can advance to the next slide manually or automatically after a specified time. While showing the presentation on the computer screen, you can use an electronic pointer or pen to highlight any point in the slide.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
177
COMPUTER FUNDAMENTAL & C PROGRAMMING
5.23.2 Creating a Presentation When you start PowerPoint, you can work in it in many different ways, such as: AutoContent Wizard
The wizard asks a few simple questions and helps you Determine the content and organization of your Presentation
Pick a Look Wizard
It helps you choose the look and feel of your Presentation. For example, you can select if you want to create the presentation for black-and-white transparencies, colour transparencies, 35mm slides or on-screen presentation. You also select the slide background and other options, such as speakerâ&#x20AC;&#x2122;s notes, audience handouts, etc. that you want to include in your presentation
Template
It create a presentation based on an existing template that determines the colour scheme, fonts, and other design features of the presentation. It starts with a blank presentation with all values for the colour scheme, fonts, ad other design features set to the default values
Blank Presentation
Open an Existing Presentation
You open an existing presentation and work on that.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
178
COMPUTER FUNDAMENTAL & C PROGRAMMING
A presentation is not effective now a days without graphics. PowerPoint helps you to insert graphics in our slides in a number of ways. 1. You can use the Drawing and Drawing + toolbars to create your own line drawing. You can create any shape and fill it with the colour and pattern of your choice. The drawing tools can also help you to rotate or flip the object. You can create various types of lines with or without arrowheads. You can group various drawing objects so that you can move them together. 2. Use the insert, Picture command to import graphics created in most of the common Windows programs, such as AutoCAD (.dxt), Lotus 1-2-3(.pic), Windows bitmap (.bmp.dib), Windows Metafile (.wmf), Computer Graphics Metafile (.cgm), Encapsulated Postcript (.eps), Tagged Image Format (.tif), Corel Draw (.cdr), PC Paintbrush (.pcx), HP Graphics Language (.hgl), etc. 3. Use the insert, Object command to insert any Windows object, e.g. a Word or Word Perfect document or Excel Spreadsheet. 4. Use the insert, ClipArt command to insert a ClipArt from ClipArt Gallery. PowerPoint contains ready-made clip arts for several common objects, such as animals, building, flags, food, electronics, gestures, hardware, places, people at work, signs, etc. Figure B.3 shows a Clip Art being inserted in a slide. Power Point includes the facility to create graphs within the slide. Either you can insert a slide with graph, or use the Insert Graph button or command to insert a graph in an existing slide. The graph feature in PowerPoint helps you to enter the data ranges, labels and legend. You can easily resize or edit the graph.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
179
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.23.3 PowerPoint Views In PowerPoint, you can work in different views, such as Slide Sorter view, Outline view and Notes Page view. In Slide view, PowerPoint displays and edits a single slide on the screen. In Figure B.2 the Slide view is selected. You use this view when you are editing or formatting a slide. To select other views, you can either the View menu or click the buttons located at the bottom-left corner of the document window .(See Figure B.2.) The Slide Sorter view displays miniature versions of your slides. In this view, you see several slides on the screen. The number of slides you see on the screen depends on the type of display you are using. In the Slide Sorter view, it is easy to organize the slides within the presentation. Figure B.4 displays a presentation in the Slide Sorter view. For example, you can change the order of slides within the presentation. For instance, in Figure B.4, if you want to bring slide 3 to the 2
nd
position, just drag slide 3 to its new
position. This view also helps you to delete, add, copy and paste slides. The Slide Sorter view also helps us to set slide timings for a slide show. It also helps us to pick the transitions you want to use to advance from slide to side. These features are available on the Slide Sorter toolbar that appears just above the work area in Slide Sorter view. 5.23.4 Slide Show After you have create and edited your slides, you can run the slide show. The slide show can show all or selected slides one after the other on the computer screen. PowerPoint displays the first slide on the screen and you can speak about the slide. When you want to show the next slide, you can click the mouse or press the PgDn or N Key, and the new slide replaces the old slide. If you want to go back to the previous slide, you can click the right mouse button or press the PgUp or P Key. To give a professional look to you slide show, you can use various transition effects when the next slide replaces the previous slide. The various transition effects supported by PowerPoint include box in, box out, blinds vertical, random, cover up, wipe left, etc. Moreover, you can select a different transition effect for any or all slides of your presentation. To define the transition effect for any slide, perform the following steps; 1. Select the Slide Sorter view. 2. Select the slide for which you want to define the transition effect. 3. Click the transition button in the Slide Sorter Toolbar (See Figure B.4.) And PowerPoint displays the Transition dialog box as shown in Figure B.7. To select a transition effect, click the Effect drop-down arrow. Then PowerPoint displays the various transition effects supported by it. Click the desired transition effect and PowerPoint displays its effect in the sample picture in the dialog box. Besides the effect, you can also select the transition speed in the Speed box. If you want PowerPoint to automatically advance to the next slide after a specified time, click the Automatically After radio button and enter the required time in the Seconds box. In the same way, you can define the transition effect, speed and time for each slide of your presentation.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
180
COMPUTER FUNDAMENTAL & C PROGRAMMING Running a Slide Show To run a slide show for the current presentation, click the Slide Show button in the lower-left corner of the window. Alternatively, choose the View, Slide Show command. If you click the Slide Show button, PowerPoint starts the presentation starting from the first slide. On the other hand, the View, Slide Show command displays the Slide Show dialog box. In this dialog box, you can select the range of slides that you want to show as well as if you want to advance slides manually or using the automatic timings. After selecting options in the Slide Show dialog box, click the Show button to start the slide show. PowerPoint starts the slide show. It uses the entire screen to display the slide. If you selected automatic advance option and automatic advance time has been defined for the slide, PowerPoint displays the next slide after the specified time. Otherwise click the mouse or press the PgDn or N to display the next slide. If you want to display the previous slide, click the right mouse button or press PgUp or P. Other Features of PowerPoint You can change the slide background and colour for any or all slides. To give a consistent look to your presentation, you can apply the new slide background and colour scheme to all slides. Sometimes, you may like to show some graphics (e.g. the logo of the company or the picture of the product) on all slides. In that case, you can use the slide master. The slide master is selected from the View menu. Any text or graphics you show on the slide master is shown on all slides. 5.23.5 Printing a Presentation You can print your presentation in a the following ways; Slide
One slide is printed on each page
Notes Page
Each page prints one slide and the speakerâ&#x20AC;&#x2122;s notes.
Handouts (2 Slides per Page)
Two slides are printed on each page.
Handouts (3 Slides per Page)
Three slides are printed on each page.
Handouts (6 Slides per Page)
Six slides are printed on each page.
Outline View
Only text part of slides is printed.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
181
COMPUTER FUNDAMENTAL & C PROGRAMMING
To pint your slides, use the File, Print command or Press ^P. Then select what you want to print in the Print What selection box in the print dialog box. The Print dialog box also allows you to select the number of copies, the slide range or if you want to print on a black-andwhite printer.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
182
COMPUTER FUNDAMENTAL & C PROGRAMMING
UNIT – VI 6.0 Introduction This unit provides you with fundamental concepts of C language and its programming structures that will be used throughout this chapter. It also deals with process of the various data types, constants, variables, operators, expressions, and decision making with branching and looping in C programming. It assures you to understand general C programming concepts. 6.1 Objectives After studying this unit, you should be able to:
Understand the framework of a C program.
Understand the various data types available in C and qualifiers that can be applied to each.
Understand to create variables of each type, define constant and the typedef statement.
Understand and employ the control sequences used in formatted I/O and utilize the various escape sequences provides by C.
Understand about operators and expression concepts.
Understand about, how to making the decision with branching and looping statement.
6.2 Overview Of C History Of C ‘C’ is one of the most popular programming languages; it was developed by Dennis Ritchie at AT & T’s Bell Laboratories at USA in 1972. It is an upgraded version of two earlier languages, called ‘Basic Combined Programming Language’ (BCPL) and B, which were also developed at Bell Laboratories. ‘C’ was developed along with the UNIX operating system. This operating system, which was also developed at Bell Laboratories. C is running under a number of operating systems including MS-DOS. The root map for all modern computer languages are started through the ALGOL language, in early 1960’s after the COBOL was being used for commercial applications, FORTRAN was being developed for scientific applications. At this stage, people started thinking about the single language, which can perform all possible applications. A committee was formed to develop a new language called Combined Programming Language (CPL) at Cambridge University. It seemed to abstract too general another language called ‘Basic Combined Programming Language’ (BCPL) was developed by Martin Richards at Cambridge University. With some additional features than CPL. At the same time a language called ‘B’ was developed by Ken Thompson at AT & T’s Bell Laboratories. But like BCPL and B turned out to be very specific. Dennis Ritchie developed a language with some additional features of BCPL and B which is very simple, relatively good programming efficiency and good machine efficiency called ‘C’ language.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
183
COMPUTER FUNDAMENTAL & C PROGRAMMING 6.1.1 Importance Of C
‘C’ is a general purpose, structured programming language.
‘C’ is powerful, efficient, compact and flexible.
‘C’ is highly portable (i.e. It can be run in different operating systems environments).
‘C’ is robust language whose rich set of built in functions and operators can be used to write any complex program.
‘C’ has the ability to extend itself. We can continuously add our own functions to the existing library functions.
‘C’ is well suited for writing system software as well as application software.
‘C’ program can be run on different operating systems of the different computers with little or no alteration.
‘C’ is a middle level language, i.e. it supports both the low-level language and high level language features.
‘C’ language allows reference to a memory allocation with the help of pointers, which holds the address of the memory location.
‘C’ language allows dynamic memory allocation i.e. a program can request the operating system to allocate or release memory at runtime.
‘C’ language allows manipulation of data at the lowest level i.e. bit level manipulation. This feature is extensively useful in writing system software program.
‘C’ is widely available, commercial ‘C’ compilers are available on most PC’s.
‘C’ program are fast and efficient.
‘C’ has rich set of operators.
‘C’ can be applied in systems programming areas like Compilers, Interpreters and Assemblers etc.
6.1.2 Basic Structure Of C Programs A ‘C’ program may contain one or more sections given in Fig. 1.3.1.
Documentation Section: It consists a set of comment lines used to specify the name of program, the author and other details etc.
Comments: Comments are very helpful in identifying the program features and underlying logic of the program. The lines begins with ‘/*’ and ending with ‘*’ are known as comment lines. These are not executable, the compiler is ignored anything in between /* and */.
Preprocessor Section: It is used to link system library files, for defining the macros and for defining the conditional inclusion. Example: #include<stdio.h>, #define A 10, #if def, #endif…etc.
Global Declaration Section: The variables that are used in more than one function throughout the program are called global variables and declared outside of all the function i.e., before main ( ).
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
184
COMPUTER FUNDAMENTAL & C PROGRAMMING
Every ‘C’ program must have one main () function, which specify the starting of ‘C’ program. It contains the following two parts.
Declaration part: This part is used to declare all the variables that are used in the executable part of the program and these are called local variables.
Executable part: It contains at least one valid ‘C’ statement. The execution of a program begins with opening brace ‘{‘ and ends with closing brace ‘}’. The closing brace of the main function is logical end of the program.
Documentation Section Preprocessor Section Definition Section Global Declaration Section main( ) {
Function Section
Declaration Part }
Executable Part
SubProgram Section Function 1 Function 2 . . . Function n
Fig. 1.3.1 Overview of a C program
Programming Rules: The following rules should follow while writing a ‘C’ program.
All statements in ‘C’ program should be written in lower case letters. Upper case letters are only used for symbolic constants
Blank spaces may be inserted between the words. It is not used while declaring a variable, keyword, constant and function.
The program statement can write anywhere between the two braces following the declaration part.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
185
COMPUTER FUNDAMENTAL & C PROGRAMMING
186
The user can also write one or more statements in one line separating them with a semicolon (;)
6.2 Self Assessment Questions Fill in the blank 1. C language was developed by ___________________. 2. C language is ______________________programming language. True / False 1. All statements in ‘C’ program should be written in upper case letters. 2. In C language, each line of program ends with semicolon. Multiple Choice 1. C language was developed at AT & T’s Bell Laboratories at USA in a) 1976
b) 1972
c) 1975
d) 1973
Short Answer 1. Define local variable. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7
Constants, Variables and Data Types
7.1 Constants Constants in C refer to fixed values that do not change during the execution of a program. Types of constant are as shown in Fig.1.4.1. Constants
Numeric constants
Integer Constants
Non-Numeric constants
Real constants
Character constants
String
constants Fig.1.4.1 C Constants (a) Numeric Constants (b) Integer Constants A whole number is called integer constants. An integer constant refers to a sequence of digits. There are three types of integers, namely, decimal, octal and hexadecimal integer. Decimal integers consist of a set of digits, 0 through 9, preceded by optional minus sign. Valid examples are: 123
-231
0
253444
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
187
Embedded spaces, commas, and non-digit characters are not permitted between digits. For example 36
5689
20.000
$777456 are invalid numbers
An octal integer constant consists of any combination of digit from the set 0 through 7, with leading 0. Valid examples are: 046
123
0
0675
A hexadecimal integer constant consists of any combination of digit from the set 0 through 9 and A through F and preceded by 0x or 0X Valid examples are: 0x3Bf7 0X27
0x (c) Real Constants
Number containing with decimal point is called real constants. There are two types of notation, namely, decimal notation and Exponential (or scientific) notation. In decimal notation a whole number followed by a decimal point and the fractional part, which is an integer. Valid examples are: 0.376
.57
-.46
23.68
The general form of an Exponential notation is: mantissa
e
exponent
The mantissa is either a real number expressed in decimal notation or an integer. The exponent is an integer with an optional plus or minus sign. The letter e separating the mantissa and the exponent can be written in either lowercase or uppercase. Valid examples are: 0.47E2 12e-7
1.8e+3
7.3E2
-6.0e-2
Non-Numeric Constants: Character constants A single character constant contains a single character enclosed within a pair of single quote marks. Valid examples are: ‘6’
‘s’
‘W’
‘;’ 1)
‘’ String constants
A string constant is a sequence of characters enclosed between double quotes. The characters may be alphabets, digits special characters and blank spaces. Valid examples are: “Hello” “3566”
“%---$” “22-7” (d) Backslash character constants
C supports some special backslash character constants that are used in output methods. The characters combinations are known as escape sequences. i)
Table 2.6.3 Backslash character constants Constants
Meaning
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING ‘ \ b’
back space
‘\f’
form feed
‘ \ n’
new line
‘ \r’
carriage return
‘ \ t’
horizontal tab
‘ \ ‘’
single quote
‘ \ “’
double quote
‘ \ \’
back slash (e) Symbolic constants
We often use certain unique constants in a program. These constants may appear repeatedly in a number of places in the program. For example of such a constant is 3.142 representing the value of the mathematical constant “pi”. We face two problems in the subsequent use of program. They are: 1. Problem in modification of the program. 2. Problem in understanding the program. (f)
Modifiability
We may like to change the value of “pi” from 3.142 to 3.14159 to improve the accuracy of calculation. In this case, we will have to search throughout the program and explicitly change the value of the constant wherever it has been used. If any value is left unchanged, the program may produce incorrect outputs. (g) Understandability Assignment of a symbolic name to numeric constants frees us problems like same value means different things in different places. For example, the number 40 may mean the number of students at one place and the “pass marks” at another place of the same program. We may use the name STRENGTH to denote the number of students and PASS_MARK to denote the pass marks required in subject. Constant values are assigned to these names at the beginning of the program. A constant is declared as follows: #define symbolic-name value of constant; Valid examples are: #define STRENGTH = 40; #define PASS_MARK = 40; #define PI = 3.1459; Rules for forming the symbolic constants are: Symbolic names take the same form as variable names. But, they are written in CAPITALS. No blank space between the pound sign ‘#’ and word define is permitted. ‘#’ must be the first character in the line. A blank space required between #define and symbolic name and between the symbolic name and the constant.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
188
COMPUTER FUNDAMENTAL & C PROGRAMMING
189
#define statement must not end with a semicolon. After declaration of symbolic constants, they should not be assigned any other value within a program. Symbolic names are NOT declared for data types. #define may appear anywhere in the program but before it referenced in the program. 7.2 Variables A variable is an identifier that denotes a storage location used to store a data value. A variable may take different values at different times during the execution of the program. 1)
Rules for naming the variables
1. Variable names may consist of alphabets, digits, the underscore ( _ ) and dollar characters. 2. They must not begin with a digit. 3. Uppercase and lowercase are distinct. This means that the variable Total is not the same as total or TOTAL. 4. It should not be a keyword. 5. White space is not allowed. 6. The length of the variable names cannot exceed 8 characters and some of the ‘C’ compilers can be recognized up to 31 characters. 7. No commas or blank spaces are allowed within a variable name (h) Declaration Of Variables (i)
Variables are the names of the storage locations. A variable must be declared before it is used in the program. A variable can be used to store a value of any data type.
After
designing the variable names, we must declare them to the complier. Declaration does three things: 1. It tells the compiler what the variable name is 2. It specifies what type of data the variable will hold. 3. The place of declaration decides the scope of the variables. Primary Type Declaration: The general form of declaration of a variable is: data_type variable1, variable2,……, variableN; where data_type – is the type of the data. variable1, variable2,….. variableN – are the list of variables. Variables are separated by commas. A declaration statement must end with a semicolon. Some valid declarations are: int
rollno;
float
average;
double pi;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING byte
b;
char
c1, c2;
User-Defined Type Declaration: ‘C’ language provides a feature to declare a variable of the type of user-defined type declaration. Which allows users to define an identifier that would represents an existing data type and this can later be used to declare variables. typedef cannot create a new data type. The general form is typedef data_type identifier; where typedef – is the user defined type declaration. data_type – is the existing data type. identifier – refers to the ‘new’ name given to the data type. Some valid declarations are: typedef int marks; marks m1, m2, m3; Another user-defined data type is defined as enum identifier{value1, value2,…….valueN}; where enum - is the key word. identifier - is a enumerated data type which can be used to declare variables that can have one of the values enclosed within the braces (known as enumeration constants). After this definition, we can declare variables to be in this ‘new’ type as enum identifier variable1, variable2……; The enumerated variables variable1, variable2……. can only have one of the values value1, value2…………. Example: enum day {Monday, Tuesday,…….., Sunday}; enum day week_st, week_end; week_st = Monday; week_st = May;
// enum definition
// enum declaration // valid
// invalid
Declaring a Variable as Constant:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
190
COMPUTER FUNDAMENTAL & C PROGRAMMING The value of certain variables to remain constant during the execution of a program. We can achieve this by declaring the variable with the qualifier const at the time of initialization. Example: const int class_strength = 40; (j)
Giving Values To Variables
(k)
A variable must be given a value after it has been declared that before it is used in an expression. This can be achieved in two ways:
1. By using an assignment statement 2. By using a read statement Assignment Statement A simple method of giving value to a variable is through the assignment statement as variableName = value; For Example: rollno = 1; c1
= ‘ x ‘;
Another method to assign a value to a variable at the time of its declaration as data_type variableName = value;
For Example: int
rollno
=
1;
float
average
=
68.66;
The process of giving initial values to variables is known as the initialization. The following are valid C statements: float
x, y, z;
// declares three float variables
int
m = 3, n = 6; // declares and initializes two int variables
Reading data from Keyboard We may also give values to variables through the keyboard using the scanf function. The general form of scanf is: scanf(“control string”, &variable1, variable2…..); The control string contains the format of data being received. The ampersand symbol & before each variable name is an operator that specifies the variable name’s address. Example: scanf (“%d”, &number); When this statement is encountered by the computer, the execution stops and waits for the value of the variable number to be typed in. Since control string “%d” specifies that an
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
191
COMPUTER FUNDAMENTAL & C PROGRAMMING
192
integer value is to be read from the terminal. Once the number is typed in and the ‘Return’ key is pressed, the computer then proceeds to the next statement. (l)
Scope Of Variables
(m) ‘C’ variables are classified into two kinds:
Global/ External variables
Local variables The global/ external variables are declared before the function main( ). These are
available for all the functions inside the program. Example: int a, b =2;
fun()
main()
{
{
int sum; …….
Sum = a +b;
fun();
}
} The integer variables a, b are global/external variables, as they are declared before the function main( ). These variables are later used in the function fun( ). Variables declared and used inside functions are called local variables. They are not available for use outside the functions definition. Local variables can also be declared inside program blocks that are defined between an opening brace { and a closing brace }. These variables are visible to the program only from the beginning of its program block to the end of the program block. When the program control leaves a block, all the variables in the block will cease to exist. The area of the program where the variable is accessible (ie. Usable) is called its scope. Example: fun( ) { int i, j; ……… } 7.3
Data Types The size and type of values that can be stored in variable is called as Data type.
Data types in C under various categories are shown in Fig.1.4.2.
The
user-
defined types, derived types such as arrays, functions, structures and pointers are discussed in concern chapters. Integer Primary
Floating Point Character
User defined Functions Data types
Derived
Arrays Structures
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
193 Pointers
Empty data set Fig 1.4.2. Data types in C under various categories Primary Data Types: The primary data types otherwise is called as fundamental data types. It can be classified into three types are
Integer data type
Float type
Character type
Integer Types Integer types can hold whole numbers. C supports three types of integers are short int, int and long int, in both signed and unsigned forms as in Fig.2.6.2. Integer types
Signed
Unsigned
short int int long int
short int
int long int
Fig.2.6.3 Integer data types The integer occupies one word of storage typically 16 or 32 bits. The size of the integer depends upon the system. If we use 16 bit word length, the size of integer value is limited to the range –32768 to + 32767. 1)
Floating Point Types
Integer types can hold only whole numbers and therefore we use another type known as floating point or real type to hold numbers containing fractional parts such as 27.59 and 1.375. There are two kinds of floating point storage in C as shown in Fig.2.6.3 Floating Point
float
double
long double
Fig.2.6.3 Floating-point data types The float type values are single-precision numbers while the double types represent double-precision numbers. To extend the precision further, we may use long double. Table 2.6.2 gives the size of these two types. Table 2.6.2 Type And Size Of Floating Point Type
Size
float
4 bytes
double
8 bytes
Example: 1.23
7.56923e5
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Double-precision types are used when we need greater precision in storage of floating point numbers. All mathematical functions such as sin, cos and sqrt return double type values. Character Type In order to store character constants in memory, C provided a character data type called char. The char type assumes a size of 1 byte so it can hold only a single character. The qualifier signed or unsigned may be explicitly applied to char. While unsigned char have values between 0 and 255, signed char have values from –128 to 127. Empty Data Set The void is the empty data type in C language. This is generally specified with the function, which has no arguments. 7.4
Self Assessment Questions
Fill in the blank 1. ___________ function is used to read data through keyboard. 2. The global / external variables are declared before the ____________ function. True / False 1. The scanf( ) is used to display the values on the screen. 2. The void data type represents empty. Multiple Choice 1. Which of the following is not a valid identifier a) averave c) Total
b) sum_S d) 2ABC
Short Answer 1. What is meant by variable? --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2. Define Data type. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8
Operators and Expression
8.1 Introduction C supports a rich set of operators. An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations. Operators are used in programs to manipulate data and variables. C operators can be classified into a number of types are: Arithmetic operators Relational operators Logical operators Assignment operators
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
194
COMPUTER FUNDAMENTAL & C PROGRAMMING Increment and decrement operators Conditional operators Bitwise operators Special operators Special operators
8.2 Arithmetic Operators C provides all the basic arithmetic operators are listed in Table1.51. The operators + , - , * , and / all work the same way as they do in other languages. These can operate on any built-in numeric data type of C. We cannot use these operators on Boolean type. The unary minus operator, in effect, multiplies its single operand by -1. Therefore, a number preceded by a minus sign changes its sign. Table1.5.1 Arithmetic Operators Operator
Meaning
+
Addition or unary plus
-
Subtraction or unary minus
*
Multiplication
/
Division
%
Modulo division (Remainder)
Integer division truncates any fractional part. The modulo division produce the remainder of an integer division. Arithmetic operators a-b
a+b
a*b
a / b
a%b
-a+b
are used as
Integer Arithmetic When both the operands in single arithmetic expression such as a + b are integers, the expressions is called an integer expression, and the operation is called integer arithmetic. Integer arithmetic yields an integer value. In above examples if a and b are integers the a =2 and b = 2 we have the following results: a–b
=
0
a+b
=
4
a*b
=
4
a /b
=
1
(decimal part truncated)
a%b
=
0
(remainder of integer division)
For modulo division ( % ), the sign of the result is always the sign of the first operand. Real arithmetic An arithmetic operation involving only real operands is called real arithmetic. A real operand may assume values either in decimal or exponential notation. The floating- point modulus operator returns the floating-point equivalent of an integer division. What this means
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
195
COMPUTER FUNDAMENTAL & C PROGRAMMING is that the division is carried out with both floating-point operands, but the resulting divisor is treated as an integer, resulting in a floating-point remainder. The operator % cannot be used with real operands. Example Program: Program for Arithmetic operator works on Floating values #include <stdio.h> void main( ) { int a = 10, b= 3; printf(" a + b = % d\n", (a + b)); printf(" a - b = % d\n " , (a - b)); printf(" a * b = % d\n " , (a * b)); printf(" a / b = % d\n" , (a / b)); printf(" a modulo b = % d\n" , (a % b)); } Output Of Program a + b = 13 a-b =7 a * b = 30 a/b =3 a modulo b = 1 Mixed-mode Arithmetic When one of the operand is real and the other is integer, the expression is called a mixed-mode arithmetic expression. If either operand is of the real type, then the other operand is converted to real and the real arithmetic is performed. The result will be a real. Thus 16 / 5
produce the result
3.1
16 / 5
produce the result
1
Whereas
8.3 Relational Operators We often compare two quantities, and depending on their relation, take certain decisions. For example, we may compare the age of two persons, or the price of two items, and so on. These comparisons can be done with the help of relational operators. C supports six relational operators as shown in Table 1.5.2. Table 1.5.2 Arithmetic Operators Operator
Meaning
<
is less than
<=
is less than equal
>
is greater than
>=
is greater than equal
==
is equal to
!=
is not equal to
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
196
COMPUTER FUNDAMENTAL & C PROGRAMMING
197
A simple relational expression contains only one relational operator and is of the following form:
ae -1
relational operator
ae – 2
When arithmetic expressions are used on either side of a relational operator, the arithmetic expressions will be evaluated first and then the results compared. That is, arithmetic operators have a higher priority over relational operators. Example Program: Program to use various relational operators and display their return values. #include<stdio.h> void main( ) { int a = 5 , b = 5, c = 50; printf(“\n Condition : Return values ”); printf(“\n a != b : %d”, a != b); printf(“\n a = = b: %d”, a == b); printf(“\n a >= c : %d”, a >= c); printf(“\n a <= c : %d”, a <= c); getch( ); } Output Of Program Condition : Return values a != b
: 0
a==b : 1 a >= c
: 0
a <= c
: 1
In the above program, the condition is true it return 1and the condition false it returns 0. 8.4 Logical Operators C has three logical operators as shown in Table 1.5.3. The logical operators && and || are used when we want to form compound conditions by combining two or more relations. Example: a > b &&
x
= = 10
An expression combines two or more relational expression is called as logical expression or compound relational expression. Logical expression also yields a value of true or false. Table 1.5.3. Logical Operators Operator &&
Meaning is logical AND
||
is logical OR
!
is logical NOT
Example Program: Program to demonstrate logical operator. #include<stdio.h>
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
198
#include<conio.h> void main( ) { int c1, c2, c3; clrscr( ); printf(“ Enter values of c1, c2 & c3: “); scanf(“%d%d%d”, &c1, &c2, &c3); if( (c1 < c2) && (c1 < c3) ) printf(“\c1 is less than c2 & c3”); if( ! (c1 < c2)) printf(“\n c1 is greater than c2”); if( (c1 < c2) | | (c1 < c3) ) printf(“\nc1 is less than c2 or c3 or both”); getch( ); } Output Of Program Enter values of c1, c2 & c3: 45 32 98 c1 is greater than c1 is less than c2 or c3 or both 8.5 Assignment Operators Assignment operators are used to assign the value of an expression to a variable. The form v op= exp; Where v is a variable, exp is an expression and op is a C binary operator. The operator op=is known as the shorthand assignment operator. The shorthand assignment operators are illustrated in Table 1.5.4. Table 1.5.4. Shorthand Assignment Operators Statement with simple Assignment operator
Statement with Shorthand operator
a = a +1
a +=1
a = a -1
a -=1
a = a * ( n + 1) a = a % b
a *= n+1 a %= b
a = a / ( n + 1)
a /= n+1
The use of shorthand assignment operators has three advantages: 1. What appears on the left-hand side need not be repeated and therefore it becomes easier to write. 2. The statement is more concise and easier to read Use of shorthand operator results in a more efficient code. Example Program: Program to demonstrate assignment operator. #include<stdio.h> void main( )
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING { int i, j, k; k = (i = 4, j = 5); printf(“ k = %d”, k); getch( ); } Output Of Program k = 5 The above program prints the value of variable that it contains but that variable in terms assigned by two assignment variables. Such as k = ( i= 4, j= 5 ) means first i value is assigned to k, then j value assigned and replaced the value of i. so the latest assignment value only contains the variable k.
8.6 Increment And Decrement Operators (n)
The increment and decrement operators:
++ and - The operator ++ adds 1 to the operand while -- subtracts 1. Both are unary operators and are used in the following form: ++m;
or
m++;
--m;
or
m--;
We use the increment and decrement operators extensively in for and while loops. Example: m = 5;
y
= ++m;
In this case, the value of y and m would be 6. Suppose, if we rewrite the above statements m = 5; y
= m++; Then, the value of y would be 5 and m would be 6. Prefix operator adds
1 to the operand and then the result is assigned to the variable on left. Postfix operator first assigns the value to the variable on left and then increments the operand. Similar is the case, when we use ++( or --) in subscripted variables. That is the statement a[i++] = 10 is equivalent to a[ i ]
=
10
i
=
i+1
Example Program: Program for using increment and decrement operators. #include<stdio.h> void main( ) { int a = 10; printf(“a++ = %d\n”, a++); printf(“++a = %d\n”, ++a); printf(“--a = %d\n”, --a); printf(“a-- = %d\n”, a--); getch( );
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
199
COMPUTER FUNDAMENTAL & C PROGRAMMING } Output Of Program a++ = 10 ++a = 12 --a = 11 a-- = 11 where a + + - post increment, first do the operation and then increment. + + a - pre increment, first increment and then do the operation. --a
- pre decrement , first decrement and then do the operation.
a--
- post decrement , first do the operation and then decrement.
Note : Do not use increment and decrement operator on floating point variables.
8.7 Conditional Operators The conditional pair ? : is a ternary operator available in C. This operator is used to construct conditional expressions of the form exp1 ? exp2 : exp3 Where exp1,exp2, exp3 are expressions. The operator ? : works as follows : exp1 is evaluated first. If it is nonzero (true), then the expression exp2 is evaluated and becomes the value of the conditional expressions. If exp1 is false, exp3 is evaluated and is value becomes the value of the conditional expression. For Example: a
=
10;
b
=
15;
x
=
(a > b) ? a : b
In this example, the value of x is the value of b. Example Program: #include<stdio.h> void main( ) { int a, b, c, d; a = 5; b = 2; c = 3; d = ( a > b ) ? a : b + c; printf(â&#x20AC;&#x153;Output is : %dâ&#x20AC;?, d); getch( ); } Output Of Program Output is : 5 8.8 Bit Wise Operators C has a special operators is known as bitwise operators or manipulation of data at values of bit level. These operators are used for testing the bits, or shifting them to the right or left as shown in Table 1.5.5.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
200
COMPUTER FUNDAMENTAL & C PROGRAMMING Table 1.5.5. Bitwise Operators Operator
Meaning
&
bitwise AND
!
bitwise OR
^
bitwise Exclusive OR
~
oneâ&#x20AC;&#x2122;s Complement
<<
shift left
>>
shift right
8.9 Special Operators C supports some special operators of interest such as comma operator, sizeof operator, pointer operators (& and *) and member selection operators (. and ->). The pointer and member selection operators are discussed in the pointers concepts. 1)
The comma Operator
The comma operator can be used to separate the statement elements such as variables, constants or expression etc., and this operator is used to link the related expressions together, such expressions can be evaluated from left to right and the value of right most expressions is the value combined expression. Example: value = (x = 10, y= 5, x + y); first assigns the value 10 to x, then assigns 5 to y, and finally assigns 15 to value. The sizeof operator The sizeof is a compile time operator and, when used with an operand, it returns the number of bytes the operand occupies. The operand may be a variable, a constant or a data type qualifier.
Examples: m= sizeof(sum); n = sizeof(long int); k = sizeof(123L); 8.10 Arithmetic Expressions An arithmetic expression is a combination of variables, constants, and operators. Example of C expression is shown in Table 1.5.6. Table 1.5.6. Expressions Algebraic Expression
C Expression
ab-c
a*b-c
ab
a*b/c
c 8.11 Evaluation Of Expressions Expressions are evaluated using assignment statement of the form
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
201
COMPUTER FUNDAMENTAL & C PROGRAMMING
202
variable = expression;
variable is any valid C variable name. When the statement is encountered, the expression is evaluated first and the result then replaces the previous value of the variable on the left-hand side. Examples of evaluation statements are l = x*y-z ; m = y/z*x ; The blank space around an operator is optional. 8.12 Precedence of Arithmetic Operators An arithmetic expression without any parentheses will be evaluated from left to right using the rules of precedence of operators. There are two distinct priority levels in C: High priority
* /
Low priority
+ -
%
The basic evaluation procedure includes two left-to-right passes through the expression. During the first pass, the high priority operators are applied and second pass; the low priority operators are applied. Consider the following evaluation statement: x = a-b/3 When a = 9 and b = 6, the statement becomes x =9–6/3 and evaluated as First pass x = 9–2
( 6 / 3 evaluated )
x =7
( 9 - 2 evaluated )
Second pass
Introducing parentheses into expression can change the order of evaluation. Parentheses may be nested, and in such cases, the expression will proceed out from innermost set of parentheses. Every opening parenthesis has a matching closing one. Parentheses allow us to change the order of priority. 8.13 Type Conversions In Expressions Automatic Type Conversion C permits mixing of constants and variables of different types in an expression, but during evaluation it adheres to very strict rules of type conversion. If the operands are of different types, the ‘lower’ type is automatically converted to the higher type before the operation proceeds. The result is of the higher type. Table 1.5.7. provides a reference chart for type conversion. Table 1.5.7. Automatic Type Conversion Chart
char
char
byte
short
int
long
float double
int
int
int
int
long
float double
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING byte
int
int
int
short
int
int
int
int
int
int
int
int
long
long
long
long
long
long
float double
float
float
float
float
float
float
float double
double double double
double
double double double double
int int
long
203
long long
float double float
double
float double
The final result of an expression is converted to the type of the variable on the left of the assignment sign before assigning the value to it. The following changes are occurs in final assignment. 1. float to int causes truncation of the fractional part. 2. double to float causes rounding of digits. 3. long to int causes dropping of the excess higher order bits. Casting a Value We need to store a value of one type into a variable of another type. In such situation, we must cast the value to be stored by proceed it with the type name in parentheses. The general form of a cast is: ( type_name ) expression
Where type_name is one of the standard C data types. The expression may be constant, variable or an expression. Examples of casts and their actions are X = ( int ) 7.5
7.5 is converted to integer by truncation
A = ( int ) 21.3 / ( int )4.5
Evaluated as 21/4 and the result would be 5
8.14 Operator Precedence And Associativity Each operator in C has precedence associated with it. The operator at the higher level of precedence is evaluated first. The operator of the same level of precedence is evaluated from left to right or from right to left, depending on level. This is known as the associativity property of an operator. Table 1.5.8 provides a complete lists of operators, their precedence levels, and their rules of association. Table 1.5.8. C Operators precedence and associativity Operator
Meaning
Associativity
Rank
()
Function call
Left to Right
1
[]
Array element reference
-
Unary minus
Right to left
2
++
Increment
--
Decrement
!
Logical Negation
~
Oneâ&#x20AC;&#x2122;s complement
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
204
*
Pointer reference (indirection)
&
Address
sizeof
Size of an object
(type)
Casting
*
Multiplication
/
Division
%
Modulus
+
Addition
-
Subtraction
<<
Left shift
>>
Right shift
<
Less than
<=
Less than or equal to
>
Greater than
>=
Greater than or equal to
==
Equality
!=
Inequality
&
Bitwise AND
Left to Right
8
^
Bitwise XOR
Left to Right
9
|
Bitwise Or
Left to Right
10
&&
Logical AND
Left to Right
11
||
Logical OR
Left to Right
12
?:
Conditional operator
Right to Left
13
=
Assignment operator
Right to Left
14
Comma operator
Left to right
15
Left to Right
3
Left to Right
4
Left to Right
5
Left to Right
6
Left to Right
7
*= /= %= += -= &= ^= |= <<= >>= ,
8.15 Mathematical Functions C support basic math function through #include <math.h>. Table 1.5.9 lists the math functions defined math.h . Example: int a = mod(10,15); Table 2.7.9 Math Function Function
Action
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Section 1.02
Trigonometric
Section 1.03
sin( x )
205
Returns the
sine value of the angle x in radians Section 1.04
cos(x )
Returns the
cosine value of the angle x in radians Section 1.05
tan( x )
Returns the tangent
value of the angle x in radians Section 1.06
asin( y )
Returns the angle
acos( y )
Returns the
whose sine is y Section 1.07
angle whose cosine is y Section 1.08
atan( y )
Returns the
angle whose tangent is y Section 1.09
atan2( x,y )
Returns the
angle whose tangent is x/y Hyperbolic sinh( x )
Returns the Hyperbolic sine value of the angle x in radians
cosh(x )
Returns the Hyperbolic cosine value of the angle x in radians
tanh( x )
Returns the Hyperbolic tangent value of the angle x in radians
Other Functions pow( x,y )
Returns x raised to y( xy)
exp( x )
Returns e raised to x(ex)
log( x )
Returns the natural logarithm of x
sqrt( x )
Returns the square root of x
ceil( x)
Returns the smallest whole number greater than or equal to x ( rounding up )
floor( x )
Returns the largest whole number less than or equal
to x
(Rounded down ) mod(x,y )
Returns the remainder of x/y
abs( x )
Returns the absolute value of x.
Note: x and y are double type parameters.
8.16
Self Assessment Questions
Fill in the blank 1. _____________ are used in programs to manipulate data and variables.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
206
2. _____________ mathematical function return the smallest whole number greater than or equal to parameter x. True / False 1. The logical operators do not return true and false value. Multiple Choices 1. Suppose m=5,y=m++, what is value of m and y? a) 5 & 6
b) 6 & 5
c) 5 & 5 d) 6 & 6
b) 3
c) 0
2. What is value of 5%2? a) 2
d) 1
Short Answer 1. Define integer arithmetic. ---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------2. What is called arithmetic expression? ---------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------9
Managing Input And Output Operations
9.1 Introduction Most computer program that take some data as input and display the processed data, often known as information or results.
In
â&#x20AC;&#x2DC;Câ&#x20AC;&#x2122; language, two types of Input/Output
statements are available. All input/output operations are carried out through function calls such as scanf and printf.
These functions are collectively known as the standard I/O
library. Each program that uses a standard input/output function must contain the statement #include <stdio.h> at the beginning. The file name stdio.h is an abbreviation for standard input-output header file. #include <stdio.h> tells the compiler to search for a file named stdio.h and place its content at this point in the program. The contents of the header file become part of the source code when it is compiled. 9.2 Reading And Writing A Character Reading a Character using getchar( ) or getc( )function Reading a single character can be done by using the function getchar( ) or getc( ). The general form of getchar( ) or getc( ) function is
variable_name = getchar( ); or char variable_name = getchar( );
variable_name = getc( ); or char variable_name = getc( );
where variable_name is a valid C name that has been declared as char type.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
207
When this statement is executed, the computer waits until a key is pressed and then assigns this character as a value to getchar( ) function or getc( ) function. The character value of getchar( ) or getc( ) is in turn assigned to the variable_name on the left. For Example char name;
char name;
name = getchar( );
name = getc( );
or char name = getchar( );
or char name = getc( );
will assign the character ‘D’ to the variable name when we press the key D on the keyboard. Writing a Character using putchar( ) or putc( ): Function putchar( ) or putc( ) for writing characters one at a time to the screen. The general form of putchar( ) or putc( ) function is putchar(variable_name); or putc(variable_name);
where variable_name is a valid C name that has been declared as char type variable containing a character. This statement displays the character contained in the variable_name at the screen. For Example putchar(name); or putc(name); will display the character ‘D’ contained in the name at the screen. Example Program1: Program for converting a character from lower to upper and vice versa. #include<stdio.h> #include<ctype.h> void main( ) { char ch; printf(“ Enter any alphabet either in lower or upper case….”); ch = getchar( ); if (islower(ch)) putchar(toupper(ch)); else putchar(tolower(ch)); getch( ); }
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Output Of Program: Enter any alphabet either in lower or upper case….s S The gets( ) and puts( ) function The gets( ) is used to read the string (is a group of characters) from the standard input device(keyboard). The general form of gets() function is gets(array_variable);
where array_variable is a valid C variable declared as one dimension char type. For Example gets(s); The puts( ) is used to display/write the string to the standard output device (monitor). The general form of puts( ) function is puts(array_variable); where array_variable is a valid C variable declared as one dimension char type. For Example s = ‘Harsh’; puts(s); Example Program2: Program for illustrating gets( ) and puts( ). #include<stdio.h> #include<ctype.h> void main( ) { char name[20]; printf(“ Enter the name:”); gets(name); puts(“ \n Name is :”); puts(name); getch( ); } Output Of Program: Enter the name: Harshini Name is : Harshini
Character Test Functions C language many of character test functions (See Table 1.6.1) that are used to test the character taken from the input. These character functions are contained in the file ctype.h and therefore the statement
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
208
COMPUTER FUNDAMENTAL & C PROGRAMMING #include < ctype.h > must be included in the program. Table 1.6.1 Character test function Function
Test
isalnum ( c )
is c an alphanumeric character?
isalpha ( c )
is c an alphabetic character?
isdigit ( c )
is c a digit?
islower ( c )
is c a lower case letter?
isprint ( c )
is c a printable character?
ispunct ( c )
is c a punctuation mark?
isspace ( c )
is c a white space character?
isupper( c )
is c an upper case letter?
tolower ( c )
convert c to lower case letter?
toupper ( c )
convert c to upper case letter?
9.3 Formatted Input And Output Formatted Input: Formatted input refers to input data that has been arranged in a particular format. For example, consider the following data: 14.67
345
Harsh
This contains three pieces of data, that is arranged in a format, such data can be read to the format of its appearance, as the first data should be read into a variable float, the second into int, and the third into char. This is possible in C using the formatted input (scanf( )) statement. The scanf( ) function is used to read information from the standard input device(keyboard). The general form of scanf( ) is scanf(“control string”, &variable1, variable2…..); The control string contains the format of data being received. The ampersand symbol & before each variable name is an operator that specifies the variable name’s address where the data is stored. The control string contains the field or format specification, which direct the interpretation of input data. It may include
Field or format specification, consisting of the conversion character %, a data type character (or type specifier), and an optional number, specifying the field width.
Blanks, tabs, or new lines.
The data type character indicates the type of data that is to be assigned to the variable associated with corresponding variable. The field width specifier is optional. Inputting Integer Numbers The field specification for reading an integer number is: %wd
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
209
COMPUTER FUNDAMENTAL & C PROGRAMMING The % indicates that a conversion specification follows. w is an integer number that specifies the field width of the number to be read and d, known as data type character, indicates that the number to be read is in integer mode. Example 1: scanf(“%2d %5d, &n1, &n2); Data line: 40
45323
The value 40 is assigned to n1 and 45323 to n2. Suppose the input data is as 45323
40
The variable n1 will be assigned 45 (because of %2d) and n2 will be assigned 323. The value 40 that is unread will be assigned to the first variable in the next scanf call. This error may be eliminated if we use field specification without the field width specifications. That is, the statement scanf(“%d %d, &n1, &n2); will read the data 45323
40
correctly and assign 45323 to n1 and 40 to n2. Example 2: The scanf may skip reading further input. An input field may be skipped by specifying * in the place of field width. scanf(“%d %*d %d”, &a, &b); will assign the data 10
20
30
10
to
a
20
skipped (because of *)
30
to
as follows:
b
The data type character d may be preceded by ‘l’ to read long integers. What happened if enter a floating-point number instead of an integer? The fractional part may be omitted away. Spaces, tabs or new lines must separate input data items. Punctuation marks do not count as separators. Inputting Real Numbers The field width of real numbers is not to be specified and therefore scanf reads real numbers using the simple specification %f for both the notations, namely, Decimal point notation and exponential notation. Example: scanf(“%f %f %f”, &x, &y , &z); With the input data 456.56
24.56E-2
will assign the value 456.56 to x, 0.245 to y
789 and 789.0 to z.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
210
COMPUTER FUNDAMENTAL & C PROGRAMMING
211
The number to be read is of double type, then the specification should be %lf instead of simple %f. a number may be skipped using %*f specification. Inputting Character strings A scanf function can input strings containing more than one character. The specification for reading character string is %ws or
%w
The corresponding argument should be a pointer to a character array. However, %c may be used to read a single character when argument is a pointer to a char variable. When th
we use %wc for reading a string, the system will wait until the w character is keyed in. The specification %s terminates reading at the encounter of a blank space. Reading Mixed data types: The scanf statement to input a data line containing mixed mode data. For example scanf(“%d %c %f %s”, &n, &ch, &fl, &str); will read the data 10
k
4.64
hai
and assign the values to the variables in the order in which they appear. Rules for writing the scanf statement:
The control string must be preceded with % sign and must be given within double quotation.
All function arguments, except the control string, must be pointers to variables.
If there is a number of input data items must be separated by commas and must be preceded with & sign except for string input.
The control string and the variables going to input should match with each other.
It must be terminate with semicolon.
The scanf reads the data values until the blank space in numeric input or maximum number of character have been read, or an error is detected.
Formatted Output: The printf statement provides certain features to effectively control the alignment and spacing of print outs on the screen. The general form of printf statement is printf(“control string” , variable1, variable2…..); Control string consists of the three types of items:
Characters that will be printed on the screen as they appear.
Format specifications that define the output format for display of each item.
Escape sequence characters such as \n, \t, and \b.
where control string - indicates how many arguments follow and what their types. Arguments variable1, variable2….. are the variables whose values are formatted andprinted according to the specifications of the control string. The arguments should match in number, order and type with the format specification A simple format specification has the following form:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
212
% w.p type-specifier where w – is an integer number that specifies the total number of columns for the output value p – is another integer number that specifies the number of digits to the right of the decimal point or the number of characters to be printed from string. Both w and p are optional. Output of Integer Numbers The format specification for printing an integer number is %wd where w - specifies the minimum field width for the output d - specifies that the value to be printed to an integer If the field width is not specified, it will be printed in full, without blank space in the right side. Example: printf(“%d”, 1234);
1
2
3
4
If the number is greater than specified field width, it will be printed in full. Example: printf(“%2d”, 1234);
1
2
3
4
If the number is less than specified field width, the number will be printed with right justified. Example: printf(“%6d”, 1234);
1
2
3
4
The number can be left justified using the hyphen (-) after % character in the field width specification. Example: printf(“%-6d”, 1234);
1
2
3
4
To pad with zeros the leading blanks by placing a 0 (zero) before the field width specifier. Example: printf(“%06d”, 1234);
0
0
1
2
3
4
Long integers may be printed by specifying ld in the place of d in the format specification. Output of Real Numbers The format specification for printing a real number in decimal notation is % w.p f where
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
213
w – is an integer number that specifies the total number of columns for
the
output value p – is another integer number that specifies the number of digits to be displayed after the decimal point . The value, when displayed, is rounded to p decimal places and printed right justified in the field of w columns. Example: The value x = 39.6755 printf(“%7.4f”, x);
3
9
.
6
7
5
5
The precision is 6 decimal places. Leading blanks and trailing zeros will appear as necessary. The negative numbers will be printed with the minus sign.
Example: The value x = 39.6755 printf(“%7.3f”, -x);
-
3
9
.
6
7
6
Padding the leading blanks with zeros and printing with left-justification is also possible by introducing 0 or – before the field width specification. Example: The value x = 39.6755 printf(“%07.2f”, x);
0
0
3
9
.
6
.
6
8
8
Example: The value x = 39.6755 printf(“%-7.2f”, x);
3
9
If the field width and precision is not specified, it will be printed in full, without blank space in the right side. Example: The value x = 39.6755 printf(“%f”, x);
3
9
.
6
7
5
5
The format specification for printing a real number in exponential notation is % w.p e Examples: The value x = 39.6755 printf(“%9.2e”, x);
3
.
9
7
e
6
e
+
0
1
The value x = 39.6755
3
.
9
6
7
+
0
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
1
COMPUTER FUNDAMENTAL & C PROGRAMMING
214
printf(“%10.4e”, x); Printing of a Single Character The format specification for printing a single character in a desired position is %wc
The character will be displayed right-justified in the field of w columns. We can make display left justified by placing a – before the integer w. the default value for w is 1. Example: The value x = ‘A’
A
printf(“%5c”, x); The value x = ‘A’ printf(“%-5c”, x);
A
Printing of String
The format specification for printing strings to that of real numbers is % w.p s where w specifies the field width for display p instructs that only the first p characters of string are to be displayed. The display is right justified. The character will be displayed right justified in the field of w columns. We can make display left justified by placing a – before the integer w. the default value for w is 1. Examples: The value x = ‘ Good Luck’ printf(“%s”, x);
G
o
o
d
G
o
o
G G
o o
o o
d d
G
o
o
d
L
u
c
k
L
u
c
L L
u
c
k
L
u
c
k
printf(“%10s”, x);
d
k
printf(“%-10s”, x); printf(“%.6s”, x); printf(“%5”, x); printf(“%10.6s”, x);
Mixed Data Output
G
o
o
d
L
It is permitted to mix data types in one print statement.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Example: printf(“%d %f %s %c”, a, b, c , d); is valid. The printf uses its control string to decide how many variables to be printed and what their types are. Therefore, the format specifications should match the variables in number, order, and type. If there are not enough variables or if they are of the wrong type, incorrect results will be output. Commonly use printf format are Code
Meaning
%c
print a single character
%d
print a decimal integer
%e
print a floating point value in exponent form
%f
print a floating point value without exponent
%g
print a floating point value either exponent type or floating point type depending on value
%i
print a signed decimal integer
%o
print an octal integer without leading zero
%s
print a string
%u
print a unsigned decimal integer
%x
print an hexadecimal integer without leading 0x
Enhancing the readability of output If we print the variables always with the field width and format specification the output will be unambiguous and can be difficult to identify and read. The clarity and correctness of output is all most important, so follow the given steps to enhance the readability of output.
Specify the blank spaces in between the data items whenever necessary and applicable.
Specify the appropriate headings and names for variables.
Give the blank lines as and when required.
Specify new line character whenever necessary.
Print special text messages depending on necessary.
9.4 Self Assessment Questions Fill in the blank 1.All input and output functions are collectively known as the ______________. 2. We can make display _________ justified by placing a – before the integer w. True / False 1. The puts( ) function is used to read the string from the standard input device. 2. The function getc( ) and getchar( ) both are used read a single character. Multiple Choice 1. Which format specification is used to print double type data?
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
215
COMPUTER FUNDAMENTAL & C PROGRAMMING a) %f
b) %d
c) %lf
d) %df
Short Answer 1. What is the purpose using control string in scanf function?. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10
Decision Making with Branching and looping
10.1
Branching
10.1.1.1
Introduction
We have a number of situations, where we may have to change the order of execution of statements based on certain conditions, or repeat a group of statements until certain specified conditions are met. This involves a kind of decision making to see whether a particular condition has occurred or not and then direct the computer to execute certain statements accordingly. Control or decision making statements are 1. if statements 2. switch statement 3. Conditional operator statement 10.1.1.2
Decision Making with IF statement
The if statement is a decision making statement and is used to control the flow of execution of statements. The general form is
if ( test expression)
It allows the computer to evaluate the expression first and then, based on the value of expression is ‘true’ or ‘false’, it transfers the control to a particular statement (See Fig 1.7.1.1)
Entry
Test expression?
False True Fig. 1.7.1.1. Two-way branching The if statement may be implemented in different forms based on condition to be tested. 1. Simple if statement 2. if …else statement 3. Nested if…else statement 4. else if ladder.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
216
COMPUTER FUNDAMENTAL & C PROGRAMMING 10.1.1.3
Simple If Statement
The general form is if ( test expression) { statement-block; } statement-x; The ‘statement-block’ may be single or group of statements. If the test expression is true, the statement-block will be executed; otherwise the execution will to the statement-x. (See Fig 1.7.1.2) Entry
Test expression ?
True
Statement- Block
False StatementX Fig.1.7.1.2.Flowchart of simple if control
Example Program: To find a smallest value among two numbers /* Smallest Among Two numbers Using if statement */ #include<stdio.h> void main( ) { int a = 0,b=0; int small = 0; printf("\nEnter the two values"); scanf(“%d”, &a); scanf(“%d”, &b); small = a; if ( small > b ) small = b; printf("\nSmallest Among Two No.is : %d" , small); getch( ); } Output Of Program Enter the two values 23 17 Smallest Among Two No.is : 17
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
217
COMPUTER FUNDAMENTAL & C PROGRAMMING 10.1.1.4
218
The If-Else Statement
The general form is if ( test expression) { statement-block1; } else { statement-block2; } statement-x;
If the test expression is true, the statement-block1 will be executed; otherwise, the statement-block2 will be executed, not both. In both the cases, the control is transferred to the statement-x. (See Fig.1.7.1.3) Entry
True
False
Test expression ?
True-block Statements
False-block Statements
Statement Fig.1.7.1.3. Flowchart of -x if….else control Example Program: To Find a smallest value among three numbers. /* Smallest Among Three numbers Using if – else statement */ #include<stdio.h> void main( ) { int a = 0,b=0,c=0; int small = 0; printf("\n Enter the three values"); scanf(“%d”, &a); scanf(“%d”, &b); scanf(“%d”, &c);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING small = a; if ( small > b ) small = b; else small = c; printf("\n Smallest Among Three No.is : %d " , small); getch( ); } Output Of Program Enter the three values 23
17
56
Smallest Among Three No.is : 17 10.1.1.5
Nesting Of If-Else Statement
The general form is if ( test expression1) { if ( test expression2) { statement-block1; } else { statement-block2; } } else { statement-block3; } statement-x;
If the test expression1 is false, the statement-block3 will be executed; otherwise it continues to perform the second test. If test expression2 is true, the statement-block1 will be executed; other wise the statement-block2 will be executed and then control is transferred to the statement-x. (See Fig.1.7.1.4)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
219
COMPUTER FUNDAMENTAL & C PROGRAMMING
False
220
True Test condition 1
? False
True Test condition 2
?
Statement 2
Statement 3
Statement
Statement 1
x
Fig.1.7.1.4. Flowchart of Nesting Of If…Else Statement Example Program: To Find a largest value among three numbers /* Largest Among Three numbers Using nested if-else statement */ #include<stdio.h> void main( ) { int a = 0,b=0,c=0; int large = 0; printf("\nEnter the three values"); scanf(“%d”, &a); scanf(“%d”, &b); scanf(“%d”, &c); if ( a > b ) { if ( a > c ) { large = a; } else { large = c; } }
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING else { if (c > b) { large = c; } else { large = b; } } printf("\nLargest Among Three Number is : %d", large); getch( ); } Output Of Program Enter the three values 23
17
56
Largest Among Three Number is : 56
10.1.1.6
The Else-If Ladder
This construct is known as the else if ladder. The test conditions are evaluated from the top, downwards. As soon as true test-condition is found, the statement associated with it is executed and control is transferred to the statement-x. When all test n conditions become false, then the else containing default-statement will be executed. (See Fig.1.7.1.5)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
221
COMPUTER FUNDAMENTAL & C PROGRAMMING
222
The general form is if ( test expression1) statement-block1; else if ( test expression2) statement-block2; -----------------------else if (test expression n) statement-block-n; else default -statement; statement-x;
True
Test
False
condition 1 ?
True
False Test Condition 2 ?
True
False Test Condition n ?
Statement 1 Statement 2 Statement n
Default Statement
Next Statement Statement
x Fig.1.7.1.5 Flowchart of Else â&#x20AC;&#x201C; if Ladder Statement
Example Program: To Find a largest value among three numbers /* Largest Among Three numbers Using else - if ladder statement */ #include<stdio.h>
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING void main( ) { int a = 0,b=0,c=0; int large = 0; printf("\nEnter the three values"); scanf(“%d”, &a); scanf(“%d”, &b); scanf(“%d”, &c); large = a; if ( large < b ) large = b; else if (large < c) large = c; printf("\nLargest Among Three No.is : %d" ,large); getch( ); } Output Of Program Enter the three values 23
17
56
Largest Among Three No.is : 56
10.1.1.7
The Switch Statements
The general form of the switch statement is switch ( expression) { case value-1: block-1 break; case value-2: block-1 break; ----------------------default: default-block break; } statement-x;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
223
COMPUTER FUNDAMENTAL & C PROGRAMMING
224
The expression is an integer expression or characters. value-1, value-2---- are constants or constant expressions and are known as case labels. Each of these values should be unique within a switch statement. block-1, block-2, ------ are statement lists and may contain zero or more statement. There is no need to put braces around these blocks, case labels end with a colon ( : ). When the switch is executed, the value of expression is compared with the values value-1, value-2,………if a case is found then the block of statements that follows the case are executed. The break statement at the end of each block signals the end of the particular block and control is transferred to the statement-x. The default is an optional case. When the values of expression not match with any of the case, the default case will be executed. If default statement not present, no action takes place when all matches fail and the control goes to the statement-x. (See Fig.1.7.1.6)
Switch Expression
Expression = value1
Expression = value2 Block1 (No match) Default
Block2
Default Fig.1.7.1.6 Flowchart of Switch statement block (a) Example Program1: To demonstrate switch-case statement Statement -x
/* Demonstration of switch-case statement */ #include<stdio.h> #include<conio.h> void main( ) { int choice = 0; printf("\nEnter the choice value"); scanf(“%d”, &choice);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
225
switch(choice) { case 1: printf("I am in case 1\n"); break; case 2: printf("I am in case 2\n"); break; case 3: printf("I am in case 3\n"); break; default: printf("I am in default case\n"); } getch( ); } Output Of Program Enter the choice value 2 I am in case 2 Enter the choice value 5 I am in default case Example Program 2: To find whether the given number is even or odd using switch-case statement /* Program for Even or Odd number using switch-case statement
*/
#include<stdio.h> #include<conio.h> void main( ) { int n = 0; printf("\nEnter the number n"); scanf(“%d”, &n); switch(n % 2) { case 0: printf("The given number %d is even", n); break; case 1: printf("The given number %d is odd", n); break; }
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING getch( ); } Output Of Program Enter the number n 35 The given number 35 is odd 10.1.1.8
The Goto Statements
C supports the goto statement to branch unconditionally from one place to another in the program. The goto requires a label in order to identify the place where the branch is to be made. A label is any valid variable name, and must be followed by a colon. The label is placed immediately before the statement where the control is to be transferred. The general forms of goto and label statements are goto label; ---------------
label: statement; ------------------goto label;
label: statement;
The label: can be anywhere in the program either before or after the goto label; statement. If the label: is before the statement goto label; a loop will be formed and some statements will be executed repeatedly. Such a jump is called as a backward jump. On the other hand, if the label: is placed after the goto label; some statement s will be skipped and jump is called as forward jump. Example Program: To find the sum of positive numbers using goto statement /* Program for sum of positive number using goto statement */ #include<stdio.h> #include<conio.h> void main( ) { int n = 0,sum =0, i; printf("\nEnter the 5 numbers "); for(i=1;i<=5;i++) { scanf(â&#x20AC;&#x153;%dâ&#x20AC;?, &n); if (n < 0) goto endsum ; else sum = sum + n; } endsum: printf("\nSum of positive numbers is : %d" ,sum); getch( ); }
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
226
COMPUTER FUNDAMENTAL & C PROGRAMMING
227
Output Of Program Enter the 5 numbers 12 34 56 -78 Sum of positive numbers is :102 10.1.2 Looping 10.1.2.1
Introduction
The process of repeatedly executing a block of statements is known as looping. The statements in block may be executed any number of times, from zero to infinite number is called an infinite loop. The program loop consists of two segments are Body of the loop Control statement (tests certain conditions and then directs the repeated execution of the statements in the body of the loop) A Control structure may be classified either into two types are Entry-controlled loop: The control conditions are tested before the start of the loop execution. If conditions are not satisfied, the body of the loop will not be executed. (See Fig.1.7.2.1) Exit-controlled loop: The test is performed at the end of the body of the loop and therefore body is executed unconditionally for the first time. (See Fig.1.7.2.2) Entry
Entry
False Body of the loop
Text Expression True ? False
Body of the loop
Text Expression ? True
Fig.1.7.2.1 Entry control
Fig.1.7.2.2 Exit control
A looping process will follow four steps: 1. Setting and initialization of a counter. 2. Execution of the statements in the loop.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING 3. Test for a specified condition for execution of the loop. 4. Incrementing the counter. They are three types looping construct are: 1. while construct 2. do construct 3. for construct
10.1.2.2
The While Statement
The general form is Initialization; while ( test condition ) { Body of the loop } The while is an entry-controlled loop statement. The test condition is evaluated and if the condition is true, then the body of the loop is executed. After execution of the body, the test condition is once again evaluated and if it is true, the body is executed once again. These processes of repeated execution of the body continue until the test condition finally becomes false and the control is transferred out of the loop. On exit, the program continues with the statement immediately after the body of the loop. Example Program: To reverse the given number using while loop /* Reverse of the given number using while loop statement */ #include<stdio.h> #include<conio.h> void main( ) { int number= 0, digit = 0 , rev =0; printf("\nEnter the number"); scanf(â&#x20AC;&#x153;%dâ&#x20AC;?, &number); while (number != 0) { digit = number %10; rev = rev*10+digit; number = number / 10; } printf("\nReverse of the given number is: %d " , rev); getch( ); } Output of Program Enter the number 1234
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
228
COMPUTER FUNDAMENTAL & C PROGRAMMING
Reverse of the given number: 4321 10.1.2.3
The do – while Statement
The general form is Initialization; do { Body of the loop } while ( test condition ) The do-while is an exit-controlled loop statement. On do statement; the body of the loop will be executed first. At the end of the loop, the test conditions in the while statement is evaluated. If condition it true, the program proceed to continues to evaluate the body of the loop once again. This process continues as long as condition is true. When the condition become false, the loop will be terminated and control goes to statement after the while statement. Example Program: To find the summation of ‘n’ numbers using do–while statement /* Summation of ‘n’ numbers using do–while statement */ #include<stdio.h> #include<conio.h> viod main( ) { int n = 0, i = 1, sum = 0;; printf("\nEnter the value of n"); scanf(“ %d”, &n); do { sum = sum + i; i = i + 1; } while (i <= n); printf("\nSummation of n numbers is : %d" ,sum); getch( ); } Output Of Program Enter the value of n 11 Summation of n numbers is: 66 10.1.2.4
The For Statement.
The for loop is an entry-controlled loop. The general form is for (initialization ; test condition ; increment)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
229
COMPUTER FUNDAMENTAL & C PROGRAMMING { Body of the loop } The execution of the for statement is as 1.
Initialization of the control variables is done using assignment statements.
2.
The value of the control variable is tested using the test condition.
3.
When the body of the loop is executed, the control is transferred back to the for statement after evaluating the last statement in the loop. Now, the control variable is incremented
using an assignment statement.
Example Program: To find the summation of ‘n’ numbers using for statement /* Summation of n numbers using for statement */ #include<stdio.h> #include<conio.h> void main( ) { int n = 0, i = 1, sum = 0;; printf("\nEnter the value of n"); scanf(“ %d”, &n); for(i = 1 ; i <= n ; i++) { sum = sum + i; } printf("\nSummation of n numbers is : %d" ,sum); getch( ); } Output Of Program Enter the value of n 10 Summation of n numbers is: 55 Additional features of for loop The for loop has several capabilities that are not found in other loop constructs. For example more than one variable can be initialized at a time in the for statement. p = 1; for (n = 0 ; n<17; ++n) can be rewritten as for (p =1, n = 0 ; n<17; ++n) Increment section may also have more than one part. For example for (n = 0, m = 50 ; n<17; ++n, --m) The test condition may have any compound relation and testing need not be limited only to the control variable. Nesting of for loops
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
230
COMPUTER FUNDAMENTAL & C PROGRAMMING Nesting of loops, that is one for statement within another for statement, is allowed in C. For example
--------------------------------------------for (n = 1 ; n<17; ++n) { ------------------------------------------------for (m = 1 ; m< 10; ++m) { --------------------------------------} Inner Loop -------------------} Outer Loop ------------------------
10.1.2.5
Jumps in loops
C permits a jump from one statement to the end or beginning of a loop as well as jump out of a loop. Jumping Out of a Loop An early exit from a loop can be accomplished by using break statement. The general form is break ; The break statement can be used within while, do, for loops. When the break statement is encountered inside a loop, the loop is immediately exited. When the loops are nested, the break would exit from containing it. The use of the break statement in loops is illustrated in Fig 1.7. 2.3. A goto statement can transfer the control to any place in a program; it is useful to provide branching within a loop is illustrated in Fig.1.7.2.4. while (test-condition) { -----------if (------------) break; -----------} ------------
do { -----------if (------------) break; -----------} while (test-condition); ------------
for(initialization; test condition; increment) { -----------if (------------) break; // Exit from loop ----------------------}
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
231
COMPUTER FUNDAMENTAL & C PROGRAMMING
232
------------
for(initialization; test condition; increment) { -----------for(initialization; test condition; increment) { if (------------) break; // Exit from inner loop ----------------------} -----------} Fig 1.7. 2.3 Bypassing and continuing in loops
while (test-condition) { if (------------) goto stop; ------if (------------) goto abc; -----------abc: -----------} stop: ------------
// Exit from loop
-----
// Jump within loop
Fig 1.7.2.4 Jumping within and exiting from the loops with goto statement
Example Program: To find the sum of positive numbers using break statement /* Program for sum of positive number using break statement */ #include< stdio.h> #include<conio.h> void main( ) { int n = 0,sum =0, i; printf("\nEnter the 5 numbers "); for(i=1;i<=5;i++) { scanf(“%d”, &n); if (n < 0) break; else
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
233
sum = sum + n; } printf("\nSum of positive numbers is : %d", sum); getch( ); } Output Of Program Enter the 5 numbers 12 34 56 -78 Sum of positive numbers is :102 Skipping a Part of a Loop During the loop operations, it may be necessary to skip a part of the body of the loop under certain conditions by using continue statement. The general form is continue; The use of the continue statement in loops is illustrated in Fig 1.7.2.5. In while and do loops, continue causes the control go to directly test condition and then to continue the iteration process. In the case of for loop, the increment section of the loop is executed before the test condition is evaluated.
while (test-condition) { -----------if (------------)
do { if (------------)
continue; continue;
-----------
}
} while (test-condition);
for(initialization; test condition; increment) { -----------if (------------) continue; ----------------------} Fig 1.7.2.5 Bypassing and continuing in loops Example Program: To find the sum of positive numbers using continue statement /* Program for sum of positive number using continue statement */ #include< stdio.h> #include<conio.h>
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING void main( ) { int n = 0,sum =0, i; printf("\nEnter the 5 numbers "); for(i=1;i<=5;i++) { scanf(“%d”, &n); if (n < 0) continue; else sum = sum + n; } printf("\nSum of positive numbers is : %d" sum); getch( ); } Output Of Program Enter the 5 numbers 12
34
56
-78
10
Sum of positive numbers is :112 10.1.3 Self Assessment Questions 1. if statements returns either_________ or _________. 2.One loop within a loop is called ________________. True / False 1. When the break statement is encountered inside a loop, the loop is immediately exited 2. for loop is an exit controlled loop statement. Multiple Choices 1. Which is one of exit controlled loop? a) do-while
b) while loop
c) for loop
d) none of the above
2. The segment of a program is x=1; sum=0; while ( x<=5) { sum=sum+x; x++; } what is the value of sum? a) 13
b) 14
c) 10
d) 15
Short Answer 1. List out branching control statement.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
234
COMPUTER FUNDAMENTAL & C PROGRAMMING --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2. Define infinite loop --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------11
Summary In this unit we have introduced some of the most fundamental parts of C language
and the framework of C program. You have also discussed about how to use variable, expression, and operators. You have also learnt how the precedence rules work with arithmetic statements and how the integer and floating point conversions take place. Among input/output statements you have learnt to use scanf( ) and printf(), and how to handle input/output of different types of variables using these. You have learnt how to create and use decisions making looping and branching statements in variety of situations
12
Answers for Self Assessment Questions
Answer 1.3.4 Fill in the blank 1. Dennis Ritchie
2. Structured programming language
True / False 1. False 2. True Multiple Choice 1. b Short Answer 1. Variables declared and used inside functions are called local variables.
Answer 1.4.4 Fill in the blank 1. scanf ( ) function
2. main( ) function
True / False 1. False
2. True
Multiple Choice 1. d Short Answer 1. A variable is an identifier that denotes a storage location used to store a data value. 2. The size and type of values that can be stored in variable is called as Data type. Answer 1.5.16 Fill in the blank 1. Operators.
2. ceil( ) function
True / False
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
235
COMPUTER FUNDAMENTAL & C PROGRAMMING 1. False Multiple Choice 1. a
2. d
Short Answer 1. When both the operands in single arithmetic expression such as a + b are integers, the expressions is called an integer expression, and the operation is called integer arithmetic. 2. An arithmetic expression is a combination of variables, constants, and operators Answer 1.6.4 Fill in the blank 1. standard I/O library
2. left
True / False 1. False
2. True
Multiple Choice 1. %lf Short Answer 1. The type of data that the user going to accept via scanf function. This can be formatted and always preceded with a ‘%’ sign. Answer 1.7.3 Fill in the blank 1. true or false 2. Nested loop True / False 1. True
2. False
Multiple Choice 1. a
2. d
Short Answer 1. if statements, switch statement, Conditional operator statement 2. The statements in block may be executed any number of times, from zero to infinite number is called an infinite loop.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
236
COMPUTER FUNDAMENTAL & C PROGRAMMING
237
UNIT – VII 7
Introduction Structure and union, which is method for placing data of different types. A structure is
convenient tool for handling a group of logically related data items. But arrays can be used to represent a group of data items that belong to the same type. In this unit we shall introduce three different derived data types such as structure & union, arrays and functions. We discuss how structure & union, arrays and functions can be defined and used in C.
8
Objectives After studying this unit, you should be able to
Create a structure & union and reference each of its members.
Create and manipulate various types of array.
Create and manipulate function in C.
Understand the term scope, local and global and how each will affects
variables
within functions. 9
Structure And Unions 9.2
I ntroduction C provides a constructed data type known as structure, which is a method for packing
data of different types. A structure contains one or more data items of different data type in which the individual elements can differ in type. The individual element in structure is called members. Example: You might want to process information on students, in the category of names and marks. Here we can declare the structure ‘student’ with the fields, names and marks and we can assign their appropriate data types. These fields are called members of the structure. 9.3
S tructure Definition or Template Declaration The structure creates a format that may be used to declare structure variables. The
general form for defining the structure as struct structure_name { type structure_element 1; type structure_element 2; -----------type structure_element n; };
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
238
where struct – is the keyword that declares a structure. struct_name – is the name of the structure and is called the structure tag. type – specifies the data type of the structure elements. structure_element 1,structure_element 2… - are the structure elements or members. Each element may be belonging to a different type of data. Example: struct student { char student_name; int
student_rno;
int
student_mark1;
int
student_mark2;
}; Rules for defining a structure
A structure must be end with semicolon ( ; ).
A structure appears at the top of the source program.
While entire declaration is considered as a statement, each member is declared independently for its name and type in separate statement inside the structure.
The tag name, such as struct_name can be used to declare the structure variables of its type.
The structure elements or members must be accessed with structure variable with dot ( . ) operator.
9.4
D eclaration of Structure Variable We can declare structure variables using the tag name any where in the program.
The general form of structure variable declaration is struct struct_name struct_var1, struct_var2…….struct_varn; where struct – is the keyword struct_name - is the name of the structure struct_var1, struct_var2…..- are the structure variables Example: struct student s1, s2 …. sn; C also supports to combine both the template declaration and variables declaration in one statement. The general form is struct structure_name { type structure_element 1; type structure_element 2;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
239
-----------type structure_element n; } struct_var1, struct_var2…….struct_varn;
Example: struct student { int
student_rno;
char
student_name;
int
student_mark1;
int
student_mark2;
}s1, s2 …. sn;
9.5
G iving Values To Members
We can assign values to the members of a structure in a number of ways. The link between a member and a variable is established using the member operator ‘.’ Which is also known as dot operator. Example s1.student_rno; is the variable representing the roll number of student and it treated like ordinary variable. We assign values to the members of student: s1.student_rno = 1000; strcpy(s1.student_name, ‘Harsh’); s1.student_mark1 = 100; s1.student_mark2 = 99; we can also use scanf to give the values through the keyboard. scanf(“%d\n”, s1.student_rno); scanf(“%s\n”, s1.student_name); are valid input statements.
9.6
t ructure Initialization
Like any other data type, a structure variable can be initialized, but this initialization can be made at the compile time. This type of initialization can be done in two ways. Example1: struct student { int
student_rno;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING char
student_name;
int
student_mark1;
int
student_mark2;
240
} s1 = {1000, ‘Harsh’,100, 99}; There is one-to-one correspondence between the members and their initializing values. Example2: struct student { int
student_rno;
char
student_name;
int
student_mark1;
int
student_mark2;
}; main() { struct student s1 ={1000, ‘Harsh’,100, 99}; } 9.7
C omparison Of Structure Variable Two variables of the same structure type can be compared the same way as ordinary
variables. If student1 and student2 belong to the same structure, then the following operations are valid: Operation
Meaning
student1 = student2
Assign student2 to student1.
student1 = = student2
Compare all members of student1 and student2 and
return 1 if they are equal, 0 otherwise. student1 ! = student2
Return 1 if all the members are not equal, 0 otherwise.
9.8
A rrays Of Structures
We may declare an array of structures, each element of the array representing a structure variable. For example struct
class student[100];
defines an array called student, that consists of 100 elements. Each element is defined to be of the type struct class. struct student { int char
student_rno; student_name;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING int
student_mark1;
int
student_mark2;
241
}; main() { struct student s1[2]= {{1000, ‘Harsh’,100, 99},{1001, ‘Raj’,78, 97}}; } This declares the s1 as an array of two elements s1[0] and s1[1] and initializes their members as s1[0] .rno = 1000; s1[0].name = ‘Harsh’; . . s1[1].mark2= 97; 9.9
A rrays Within Structures
C permits the use of arrays as structure members.
We have already used arrays of
characters inside a structure. Similarly, we can use single or multi dimensional arrays of type int or float. For example struct student { int
student_rno;
char
student_name[20];
int
student_mark[2];
} s1[2]; Here, the member mark contains two elements, mark[0] and mark[1].These elements can be accessed using appropriate subscripts. For example s1[1].mark[1]; would refer to the marks obtained in the second subject by the second student. Example Program: Program to illustrate structure with arrays #include<stdio.h> main( ) { struct student { int
student_rno;
char
student_name[10];
int
student_mark[2];
} s1[2]; int i, j;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
242
printf("\nEnter roll no, name and marks"); for( i = 0; i < 2; i++) { scanf("%d%s", &s1[i].student_rno, s1[i].student_name); for(j = 0; j<2; j++) { scanf("%d", &s1[i].student_mark[j]); } } printf("R.No Name Mark1 Mark2"); for( i = 0; i < 2; i++) { printf("\n%d\t%s", s1[i].student_rno, s1[i].student_name); for(j = 0; j<2; j++) { printf("\t%d",s1[i].student_mark[j]); } } getch( ); } Output Of the Program Enter roll no, name and marks 1000 Ramu 100 90 2000 Gopi 89 78 R.No Name Mark1 Mark2 1000
Ramu
100
90
2000
Gopi
89
78
9.10
S
tructures Within Structures Structure within a structure means nesting of structures. For example struct salary { char name[20]; char dept[10]; struct { int dearness;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING int house_rent; } allowance; } employee; The salary structure contains a member named allowance which itself is a structure with two members. The members contained in the inner structure namely dearness and house_rent can be referred to as employee.allowance.dearness employee.allowance.house_rent An inner-most member in a nested structure can be accessed by chaining all the concerned structure variables (from outer-most to inner-most) with the member using dot operator. An inner structure can have more than one variable. For example struct salary { -------------struct { int dearness; int house_rent; } allowance; arrears; }employee; The inner structure has two variables, allowance and arrears. We can also use tag names to define inner structures. For example srtuct pay { int dearness; int house_rent; }; struct salary { char name[20]; char dept[10]; struct pay allowance; struct pay arrears; }; struct salary employee[100]; pay template is defined outside the salary template and is used to define the structure of allowance and arrears inside the salary structure.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
243
COMPUTER FUNDAMENTAL & C PROGRAMMING 9.11 Structures and Functions C supports the passing of structure values as arguments to functions. There are three methods by which the values of a structure can be transferred from one function to another.
The first method is to pass each member of the structure as an actual argument of the function call. The actual arguments are then treated independently like ordinary variables.
The second method involves passing of a copy of the entire structure to the called function.
The third approach employs a concept called pointers to pass the structure as an argument. In this case, the address location of the structure is passed to the called function. In this section, we discuss about the second method, while the third approach using
pointers is discussed in the pointer chapter. The general form of sending a copy of a structure to the called function is function_name ( structure_variable_ name) the called function takes the following form:
data_type function_name(structure_name) struct_type st_name; { --------------return(expression); } Example Program: #include<stdio.h> struct std { int a; char b; }; void fun( struct std s); void main( ) { struct std a1; a1.a = 10; a1.b = ‘H’; fun(a1); getch( ); } void fun(struct std s);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
244
COMPUTER FUNDAMENTAL & C PROGRAMMING { printf(“The value of a is :%d\n”, s.a); printf(“The value of b is :%c\n”, s.b); } Output Of Program: The value of a is :10 The value of b is :H 9.12 Size Of Structure We may use the unary operator sizeof to tell us the size of a structure (or any variable). The expression Sizeof (struct a will evaluate the number of bytes required to hold all the members of the structure a.
9.13 Unions Unions are a same concept of structures and therefore follow the same syntax as structures. However, there is major distinction between them in terms of storage. In structures each member has its own storage location, whereas all the members of a union use the same location. This implies that, although a union may contain many members of different types, it can handle only one member at a time. Like structures a union can be declared using the keyword union as union item { int a; float b; char c; } code; This declares a variable code of type union item. The union contains three members, each with a different data type. However, we can use only one of them at a time. Fig.2.3.1 shows how all three variables share the same address. The compiler allocates a piece of storage that is large enough to hold the largest variable type in the union. To access a union member, we can use same syntax that we use for structure members. That is, code.a code.b code.c Unions may be used in all places where a structure is allowed.
1000
Storage of 4 bytes 1001 1002 1003
a FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
b
245
COMPUTER FUNDAMENTAL & C PROGRAMMING
Fig.2.3.1 Sharing of storage location by union members Example Program 1: Program for summation of three numbers using Union. #include <stdio.h> union sum { int a; int b[2]; }; main( ) { union sum s; int s1; s.a = 10; s.b[0] = 20;
s.b[1] = 30;
s1 = s.a + s.b[0] + s.b[1]; printf(“The sum of three numbers is : % d\n”, s1); getch( ); } Output Of Program: The sum of three numbers is : 70 Example Program 2: Program to find number bytes reserved for union and structure. #include <stdio.h> main( ) { union result { int mark; char grade; }; struct res { char name[15]; int age; char sex; union result perf; }res1; printf(“Size of Union : %d\n”, sizeof(res1.perf)); printf(“Size of Structure : %d\n”, sizeof(res1));
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
246
COMPUTER FUNDAMENTAL & C PROGRAMMING getch( ); } Output Of Program: Size of Union : 2 Size of Structure : 20 9.14
Self Assessment Questions
Fill in the blank 1._______________ keyword is used to declare the structure. 2. The link between a member and a variable of structure is established using the _______________member operator.
True / False 1. All structure elements are stored in contiguous memory locations. 2. An array should be used to store dissimilar elements and a structure to store similar element. Multiple Choice 1. Given the statement student.result.mark = 60; a) structure mark is nested within structure result b) structure result is nested within structure student c) structure student is nested within structure result d) structure student is nested within structure mark Short Answer 1. How structure elements can be accessed? ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2. Define union. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------10
Arrays
10.2 Definition An array is a group of related data items that share a common name. An array of value can be accessed by index or subscript enclosed in square brackets after array name. th
For example, a[5] represents the 5 element in an array. The subscript can begin with number 0. The value of each subscript can be expressed as an integer constant or integer variable or an integer expression. Arrays can be classified into ď ś
One-Dimensional arrays
ď ś
Two-Dimensional arrays
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
247
COMPUTER FUNDAMENTAL & C PROGRAMMING
Multi-Dimensional arrays
Features of arrays:
An array is derived data type. It is used to represent a collection of elements of the same type.
The elements can be accessed with base address (index) and the subscripts define the position of the element.
In array the elements are stored in continues memory location. The starting memory location is represented by the array name and it is known as the base address of the array.
It is easier to refer the array elements by simply incrementing the value of the subscript.
Any reference to the arrays outside the declared limits would not necessarily cause an error. Rather, it might result in unpredictable program results.
10.3 One Dimensional Arrays A list of data items can be stored under a one variable name using only one subscript and such a variable is called a single-subscripted variable or one-dimensional array. For example, if we want to represent a set of four numbers, by array variable a then we may declare the variable a as int
a [ 4 ];
and computer reserves four memory locations as a[0] a[1] a[2] a[3]
The values to the array elements can be assigned as a[0]
= 10 ;
a[1]
= 20 ;
a[2]
= 30 ;
a[3]
= 40 ;
This would cause the array a to store the values as a[0]
10
a[1]
20
a[2]
30
a[3]
40
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
248
COMPUTER FUNDAMENTAL & C PROGRAMMING This element may be used in programs just like any other C variable. For example, the following are valid statements: b = a[0] + 10; a[3] = a[0] + a[2];
10.4 Declaration Of One Dimensional Arrays Declaration of arrays The general form of array declaration is: type arrayname[size];
The type specifies the type of element that will be contained in the array, such as int, float, or char and the size indicates the maximum number of elements that can be stored inside the array. Examples: int a[10]; declares the a to be an array containing 10 integer elements. Any subscript 0 to 9 are valid. float b[5]; declares the b to be an array containing 5 real elements. Any subscript 0 to 4 are valid. char c[8]; declares the c as a character array containing 7 character elements. Any subscript 0 to 6 are valid. Suppose we read the following string constant into the string variable c. “WELCOME” Each character of the string is treated as an element of the array c and is stored in the memory as follows:
‘W’ ‘E’ ‘L’ ‘C’ ‘O’ ‘M’ ‘E’ ‘\0’ When the compiler sees a character string, it terminates it with an additional null character. Thus, the element c[8] holds the null character ‘\0’ at the end. 10.5 Initialization Of One-Dimensional Arrays Initialization of arrays
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
249
COMPUTER FUNDAMENTAL & C PROGRAMMING To put values into array created is known as initialization. This is done using array subscripts as arrayname[subscript] = value Example: a[0]
=
28;
----------------------------------a[3]
=
57;
C creates arrays starting with subscript of 0 and ends with a value one less than the size specified. We can also initialize arrays automatically when they are declared, as type arrayname[ ] = { list of values }; The array initializer is a list of values separated by commas and surrounded by curly braces. Example: int a[ ] = { 10, 20,30,40}; char c[ ] = {‘W’,’E’,’L’,’C’,’O’,’M’,’E’}; Loops may be used to initialize large size arrays. Example: ------------------------------for(int i = 0;
i<10;
i++)
{ a[i] = i; } ---------------------------------Example Program /* Sorting the n given number in Descending order */ #include<stdio.h> void main( ) { int a[ ] = {10 , 45 , 100, 37, 25}; int i, j, t; for (i=0; i<5; i++) { for (j=i+1; j<5; j++) { if (a[i] <= a[j] ) { t = a[i]; a[i] = a[j]; a[j] = t;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
250
COMPUTER FUNDAMENTAL & C PROGRAMMING
251
} } } printf(“Descending Order\n”); for (i=0;i<5;i++) { printf(“%d\n”,a[i]); } getch( ); } Output Of Program Descending Order 100 45 37 25 10 10.6 Two-Dimensional Arrays We may create a two-dimensional array as type array_name [row_size][column_size]; The type specifies the data type of element that will be contained in the array, such as int, float, or char and C place each size in its own set of brackets. Each dimension of the array is indexed from zero to its maximum size minus one:
The first index selects the row and
The second index selects the column within that row.
Example: int
table[3] [3];
This creates a table that can store 9 integer values, three across (row) and three down (column). C1
C2
C3
R1 R2 R3 The individual elements are identified by index or subscript of an array from the above example. table[0][0]
table[0][1]
table[1][0] table[2][0]
table[0][2]
table[1][1]
table[2][1]
table[1][2]
table[2][2]
10.7 Initializing Two Dimensional Arrays A two-dimensional array may be initialized by following their declaration with a list of initial values enclosed in braces. For example,
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING int table[2] [3] = {0,0,0,1,1,1};
//initialize the elements row by row
or int table[2] [3] = {{0,0,0},{1,1,1}}; //separate the element of each row by braces or int table[2] [3] = { {0,0,0}, {1,1,1} }; If the values are missing in an initializer, they are automatically set to zero. For example: int table[2] [3] = { {1,1}, {2} }; will initialize the first two elements of the row to one, the first element of the second row to two, and all other elements to zero. Example Program: Program for Addition of Two Matrix using TwoDimensional
Array
/* Matrix Addition Using Two Dimensional Array */ #include<stdio.h> void main( ) { int a[ 5 ][ 5 ] , b[ 5 ][ 5 ] ,c[ 5 ][ 5 ] ; int n = 0, i = 0, j = 0; printf("Enter the order of matrix"); scanf(“%d”, &n); printf("\nEnter the A matrix"); for(i=0; i<n; i++) { for(j=0; j<n; j++) { scanf(“%d”, &a[i][j] ); } } printf("\nEnter the B matrix"); for(i=0; i<n; i++) { for(j=0; j<n; j++) { scanf(“%d”, &b[i][j] ); } }
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
252
COMPUTER FUNDAMENTAL & C PROGRAMMING printf("\nThe A matrix\n"); for(i=0; i<n; i++) { for(j=0; j<n; j++) { printf(“%d\t”, a[i][j]); } printf(“\n”); } printf("\nThe B matrix\n"); for(i=0; i<n; i++) { for(j=0; j<n; j++) { printf(“%d\t”, b[i][j]); } printf(“\n”); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { c[i][j] = a[i][j] + b[i][j]; } } printf("\nThe Resultant Matrix is\n"); for(i=0; i<n; i++) { for(j=0; j<n; j++) { printf(“%d\t”, c[i][j]); } printf(“\n”); } getch( ); } Output Of Program Enter the order of matrix 2 Enter the A matrix 2 2 2 2
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
253
COMPUTER FUNDAMENTAL & C PROGRAMMING Enter the B matrix 2 2 2 2 The A matrix 2
2
2
2
The B matrix 2
2
2
2
The Resultant Matrix is 4
4
4
4
10.8 Multidimensional Arrays C allows arrays of three or more dimensions. The compiler determines the exact limit. The general form of a multidimensional array is type array_name [s1][s2]-------[sn]; where th
sn is the size of the n dimension. Example: int d[3][5][12]; where d is a three dimensional array declared to contain 180 integer type elements. 10.9 Dynamic Arrays C language requires the number of elements in an array to be specifies at compile time. But we may not be able to do so always. Our initial judgement of size, if it is wrong, may cause failure of the program or wastage of memory space. Many languages permit a programmer to specify an arrayâ&#x20AC;&#x2122;s size at run time. The process of allocating memory at run time is known as dynamic memory allocation or it is called as dynamic arrays. Although C does not inherently have this facility, there are four library routines known as memory management functions that can be used for allocating and freeing memory during program execution. They are listed in Table 2.4.1. Table 2.4.1 Memory Allocation Functions Function
Task
malloc
Allocates requested size of bytes and returns a pointer to the first byte of the allocated space.
calloc
Allocates space for an array of elements, initialize them to zero and then returns a pointer to the memory.
free
Frees previously allocated space.
realloc
Modifies the size of previously allocated space.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
254
COMPUTER FUNDAMENTAL & C PROGRAMMING
Allocating a Block of Memory A block of memory may be allocated using the function malloc. The malloc function reserves a block of memory of specified size and return a pointer of type void. This means that we can assign it to any type of pointer. The general form is ptr = (cast-type *) malloc(byte-size); Where ptr - is a pointer of type cast-type. malloc – returns a pointer to an area of memory with size byte-size. Example: x = (int *) malloc(100 * sizeof(int)); On successful execution of this statement, a memory space equivalent to “100 times the size of an int” bytes is reserved and the address of the first byte of the memory allocated is assigned to the pointer x of type of int. Similarly, the statement cptr = (char *) malloc(5); allocates 5 bytes of space for the pointer cptr of type char. This illustrated below: cptr
Address of first byte 5 bytes of space We may also use malloc to allocate space for complex data types such as structure. Example st_var = (struct store *) malloc(sizeof(struct store)); Where st_var is a pointer of type struct store. Example Program: Program to print values from memory address #include<stdio.h> #include<stdlib.h> main( ) { int *a, *n, size; printf(“Enter the size..”); scanf(“%d”, &size); n = (int *)malloc(size * sizeof(int)); printf(“Address of the first byte is %u \n“, n); printf(“Enter the values”); for(a = n; a < n + size; a++) scanf(“%d”, a); printf(“Printing the values \n”);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
255
COMPUTER FUNDAMENTAL & C PROGRAMMING for(a = n; a < n + size; a++) printf(â&#x20AC;&#x153;%d is stored in address %u\nâ&#x20AC;?, *a, a); getch( ); }
Output Of The Program Enter the size..5 Address of the first byte is 2402 Enter the values
1
2
3
4
5
Printing the values 1 is stored in address 2402 2 is stored in address 2404 3 is stored in address 2406 4 is stored in address 2408 5 is stored in address 2410 Allocating Multiple Block of Memory The calloc is another memory allocation function that is normally used for requesting memory space at run time for storing derived data types such as arrays and structures. calloc allocates multiple block of storage, each of the same size, and then sets all bytes to zero. The general form of calloc is ptr = (cast-type *) calloc(n, elem-size); The above statement allocates contiguous space for n blocks, each of size elem-size bytes. All bytes are initialized to zero and a pointer to the first byte of the allocated region is returned. If there is not enough space, a NULL pointer is returned. Example: --------------------struct student { char name[20]; float age; long int id_num; }; typedef struct student rec; rec * st_ptr; int class_size = 30; st_ptr = (rec *)calloc(class_size, sizeof(rec)); -------------------
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
256
COMPUTER FUNDAMENTAL & C PROGRAMMING rec is of type struct student having three members: name, age and id_num. the calloc allocates memory to hold data for 30 such records. We must be sure that the requested memory has been allocated successfully before using the st_ptr. For example if(st_ptr = = NULL) { printf(“Available memory not sufficient”); exit(1); } Releasing the Used Space Compile time storage of a variable is allocated and released by the system in accordance with its storage class. With dynamic run time allocation, it is our responsibility to release the space when it is not required. The release of storage space becomes important when the storage is limited. We may release that block of memory for future use, using the free function: free(ptr); ptr is a pointer to a memory block which has already been created by malloc or calloc. Altering the Size of a Block The previously allocated memory is not sufficient and we need additional space for more elements. It is also possible that the memory allocated is much larger than necessary and we want to reduce it. In both the cases, we can change the memory size already allocated with the help of the function realloc. This process is called as the reallocation of memory. For example ptr = malloc(size); Then reallocation of space may be done by the ptr = realloc(ptr, newsize); This function allocates a new memory space of size newsize to the pointer variable ptr and returns a pointer to the first byte os the new memory block. The newsize may be larger or smaller than the size. Example Program: Program to altering the allocated memory #include<stdio.h> #include<stdlib.h> main( ) { char *p; p = (char *)malloc(6); strcpy(p, “MADRAS”); printf(“Memory contains: %s\n”, p); p =(char *)realloc(p, 7); strcpy(p, “CHENNAI”); printf(“Memory now contains: %s\n”, p); free(p);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
257
COMPUTER FUNDAMENTAL & C PROGRAMMING
258
getch( ); } Output Of The Program Memory contains: MADRAS Memory now contains:CHENNAI
10.10 Self Assessment Questions Fill in the blank 1. To put values into array created is known as _______________. 2. In two dimensional array the second index refers ________________. True / False 1. Index value of arrays can begin with the number 1. 2. An array should be used to store dissimilar elements .
Multiple Choice 1. Dimension of the array is indexed from a) zero to its maximum size to its maximum size
b) one to its maximum size minus one
c) one
d) zero to its maximum size minus one
Short Answer 1. Define arrays. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------11
Functions
11.2 Introduction C functions can be classified into two types.
Library functions: Library functions are not required to be written by us. For example printf and scanf
and other library functions are sqrt, cos, strcat etc.,
User-defined functions: A user-defined function has to be developed by user at the time of writing a program.
For example main is a user-defined function. 11.3 Need for user defined functions Every program must have a main function to indicate where the program has to begin its execution. While it is possible to write any complex program under the main( ) function and it leads to a number of problems, such as
The program becomes too large and complex
The users can’t go through at a glance.
The task of debugging, testing and maintenance becomes difficult.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING If a program is divided into functional parts, then each part may be independently coded and later combined into a single unit. These subprogram is called ‘functions’ are much easier to understand, debug, and test. The advantages of using subprograms are
The length of the source program can be reduced by dividing it into the smaller functions.
By using functions it is very easy to locate and debug an error.
The user defined functions can be used in many other source programs whenever necessary.
Functions avoid coding of repeated programming of the similar instructions.
Functions facilitate top-down programming approach.
How functions works?
Once a function is called, it takes some data from the calling function and return back some value to the called function.
Whenever function is called control passes to the called function and working of the calling function is temporarily stopped, when the execution of the called function is completed then control returns back to the calling function and execute the next statement.
The function operates on formal and actual arguments and sends back the result to the calling function using return statement.
11.4 The form of C functions The general form of functions is datatype
function_name(argument list)
argument declaration; { local variable declarations; ---------------------
// body of the function
----------return(expressions); } where datatype – is the type of data that the function is going to return to its main program. function_name – is the name of the function. argument list
- is the list of arguments that are transferred to the function from
the main program. The argument list must be separated by commas and has no termination (semi colon) after the parenthesis. The argument list and its associated argument declaration parts are optional.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
259
COMPUTER FUNDAMENTAL & C PROGRAMMING
260
The declaration of local variables is required only when any local variable are used in the function. The function can have any number of executable statements. The function that does nothing may not include any executable statement at all. For example do_nothing( ) {} The return statement is used to for returning a value to the calling function. This is optional, when no value is being transferred to the calling function. 11.5 Return values and their types A function may or may not send back any value to the calling function. If it does, it is done through the return statement. While it is possible to pass to the called function any number of values, the called function can only return one value per call at the most. The general form of return statement is return; or return(expression); The first form does not return any value; it acts much as the closing brace of the function. When return is encountered, the control is immediately passed back to the calling function. For example if(error) return; The second form of return with an expression returns the value of the expression. For example add(x,y)
add(x,y)
int x,y;
int x,y;
{
{ int z;
or
z = x + y;
return(x + y) ; }
return(z) ; } A function may have more than one return statement. For example if x < y retrun(x); else return(y); 11.6 Calling a function A function can be called by using the function name in a statement. For example main()
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING { int a; a = add(10, 20); printf(“%d\n”, a); } When the compiler encounters a function call, the control is transferred to the function add(x, y). This function is then executed line by line and a value is returned when a return statement is encountered. This value is assigned to a. A function that does not return any value may not be used in expressions; but can be called to perform certain tasks specified in the function. 11.7 Category of functions A function, depending on whether arguments are present or not and whether a value is returned or not, it can be classified into four types are
Functions with no arguments and no return values
Functions with arguments and no return values
Functions with arguments and return values
Functions with no arguments and return values
Functions with no arguments and no return values In this type, no data transfer takes place between the calling function and called function. That is the called function does not receive any data from the calling function and does not send back any value to the calling function. The general form is main( )
fun1( )
{
{
---------
-----------
---------
-----------
fun1( );
-----------
---------
-----------
---------
-----------
}
}
Note: The dotted line indicates that, there is only transfer of control but no data transfer. The solid line or continuous indicates that, there is transfer of data. Example Program: Function call without parameter #include<stdio.h> main( ) { message( ); printf(“Main Message”);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
261
COMPUTER FUNDAMENTAL & C PROGRAMMING }
message( ) { printf(“Function Message\n”); } Output Of The Program Function Message Main Message Functions with arguments and no return values In this type, data is transferred from calling function to called function. That is the called function does receive some data from the calling function and does not send back any values to the calling function.(one way communication) The general form is main( )
fun1(x,y)
{
{
---------
-----------
---------
-----------
fun1(a,b);
-----------
---------
-----------
---------
-----------
}
}
Example Program: Function with arguments and no return values #include<stdio.h> main( ) { add( 10, 20); getch( ); } add(int a, int b ) { int c; c = a + b; printf(“\nAddition of two number is :%d”, c); } Output Of The Program Addition of two numbers is :30 Functions with arguments and return values
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
262
COMPUTER FUNDAMENTAL & C PROGRAMMING In this type, data is transferred between calling function and called function. That is the called function does receive some data from the calling function and send back a value to the calling function.(one way communication)
The general form is
main( )
data_type fun1(x,y)
{
{
---------
-----------
---------
-----------
c = fun1(a,b);
-----------
---------
-----------
---------
return(z);
}
}
Example Program: Function with arguments and return values #include<stdio.h> main( ) { int x; x = add( 10, 20); printf(“\nAddition of two number is :%d”, x); getch( ); } int add(int a, int b ) { int c; c = a + b; return(c); } Output Of The Program Addition of two numbers is :30 Functions with no arguments and return values In this type, calling function cannot pass any data to the called function but the called function may send some value to the calling function.(one way communication)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
263
COMPUTER FUNDAMENTAL & C PROGRAMMING
The general form is main( )
data_type fun1()
{
{
---------
-----------
---------
-----------
c = fun1();
-----------
---------
-----------
---------
return(z);
}
}
Example Program: Function with no arguments and return values #include<stdio.h> main( ) { int x; x = add( ); printf(“\nAddition of two number is :%d”, x); getch( ); } int add( ) { int a, b, c; a = 10; b = 20; c = a + b; return(c); }
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
264
COMPUTER FUNDAMENTAL & C PROGRAMMING
265
Output Of The Program Addition of two numbers is :30
11.8
Nesting of function C permits to write one function within another function is called nesting of functions.
main( ) function can call function1, which calls function2, ……… and so on. The general form is main( )
fun1( )
fun2( )
{
{
{
---------
-----------
-----------
---------
-----------
-----------
fun1( );
fun2();
-----------
---------
-----------
-----------
---------
-----------
-----------
}
}
11.9
}
Recursion
A function calls itself is called as recursion. In order to write a recursive program, the user must satisfy the following.
The problem must be analyzed and written in recursive form.
The problem must have stopping condition.
The general form is function1( ) { function1( ); } The above function the function1( ) is called itself continuously, so the above function is in recursive manner. Example Program: Program to find the factorial of a given number. #include<stdio.h> void main( ) { int a;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING printf(“\nEnter the number:”); scanf(“%d”, &a); printf(“The factorial of %d is : %d”, a, recur(a)); getch( ); } recur(int x) { int fact; if( x = = 1) fact = 1; else fact = x * recur(x – 1); return(fact); } Output Of Program: Enter the number 5 The factorial of 5 is : 120 In the above program the variable a is read through the keyboard. The user defined function recur( ) is called from the main( ) function. Here the condition checked x = 1, if condition satisfied then control transfer to the main program and prints the value. Otherwise else part is executed and calculated the factorial value it returns the value to the main program. The function recur( ) is called as a recursive function.
11.10 Functions with arrays In C, it is possible to pass the values of an array to a function. To pass an array to a called function, it is sufficient to list the name of the array without any subscripts and the size of the array as arguments. For example, the call smallest( a , n); will pass all elements contained in the array a of size n. the called function expecting this call must be appropriately defined. The smallest function header might look like float smallest(array, size) float array[ ]; int size; The function smallest is defined to take two arguments, the array name and the size of the array to specify the number of elements in the array. Example Program: Program to find smallest among n numbers #include<stdio.h> main( ) { int i, n, s, a[10]; printf(“\nEnter the value of n”);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
266
COMPUTER FUNDAMENTAL & C PROGRAMMING scanf(“%d”, &n); printf(“Enter the %d numbers of values”, n); for(i = 0; i <n; i++) scanf(“%d”, &a[i]); s = smallest(n, a); printf(“Smallest among %d number is :%d”, n , s); getch( ); } int smallest(int n , int x[]) { int i, small = x[0]; for(i = 1; i < n; i++) { if( small > x[i] ) small = x[i]; } return(small); } Output Of The Program Enter the value of n 5 Enter the 5 numbers of values 45 37 28 68 40 Smallest among 5 number is : 28 11.11 Self Assessment Questions (b) Fill in the blank 1. Every called function must contain a _____________ statement. 2. A function calls itself is called as ________________. True / False 1. The same variable names ca used in different functions without any conflict. Multiple Choice 1. Each function must contain return statement, which returns a) only one value
b) three values
c) more than one value d) none of the above Short Answer 1.What is meant by functions with no arguments and no return values?
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
267
COMPUTER FUNDAMENTAL & C PROGRAMMING ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------12
Summary The first lesson of this unit you have learnt the use of structures, which allow us to
combine several variables of different types into a single entity. We have also examined the features of structures, which lead to programming convenience. The second lesson of this unit you have learned how to handle arrays in a variety of forms. We have learnt how to declare arrays, how to initialize them and how to access array elements using subscript. The third lesson of this unit you have learnt how to use function, how to write them, how to functions interact with one another how to send them information using arguments and how to use them to return values. You also learnt how recursive functions work.
13
Answers for Self Assessment Questions
Answer 2.3.13
Fill in the blank 1. struct keyword
2. dot ( . ) operator
True / False 1. True 2. False
Multiple Choice 1. True 2. False
Short Answer 1. After declaring the structure type, variables and members, the member of the structure can be accessed by using the structure variable along with the dot( . ) operator. 2. Unions are a same concept of structures and therefore follow the same syntax as structures. However, there is major distinction between them in terms of storage. In structures each member has its own storage location, whereas all the members of a union use the same location
Answer 2.4.9 Fill in the blank 1.initialization
2. column
True / False 1. False
2. False
Multiple Choice 1. d)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
268
COMPUTER FUNDAMENTAL & C PROGRAMMING Short Answer 1.An array is a group of related data items that share a common name. An array of value can be accessed by index or subscript enclosed in square brackets after array name.
Answer 2.5.9 Fill in the blank 1. return statement
2. recursion
True / False 1. True Multiple Choice 1. a) Short Answer 1. No data transfer takes place between the calling function and called function.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
269
COMPUTER FUNDAMENTAL & C PROGRAMMING
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
270
COMPUTER FUNDAMENTAL & C PROGRAMMING
UNIT-VIII 8.1 Introduction In this unit we introduce character arrays & string, pointers and file concepts in C language. An array of character is called character array or string. Character strings are often used to build meaningful and readable programs. We shall discuss about the common operation performed on character strings. Pointer is a important feature of C language. In the second lesson of this unit, we examine the pointers in details and learn how to use them in program. In the last lesson of this unit, we shall discuss about file concept in detail. 8.2 Objectives After studying this unit, you should be able to:
Understand string variables and the utilization of the NULL character (\0)
Understand the various string handling functions.
Understand the concept of a pointer and create pointers to each type of variable, to character strings, to functions and to structures.
Open files in three modes (read, write and append), understand where each mode places the file pointer and appreciate how each affects the data previously contained in the file.
Understand the various file handling functions and command line arguments concept in C.
9
Character Arrays & Strings 9.1
Introduction
A string is an array of characters. Any group of characters defined between double quotation marks (“ “) is a string constant. Example “welcome” If we want to include a double quote in the string, then we may use it with a back slash. For example printf(“\”welcome !\” ”); will output the string ”welcome !” The common operations performed on character strings are:
9.2
Reading and Writing strings.
Combining strings together.
Copying one string to another.
Comparing strings for equality.
Extracting a portion of a string.
Declaring And Initializing String Variables
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
271
COMPUTER FUNDAMENTAL & C PROGRAMMING A string variable is any valid C variable name and is always declared as an array. The general form of declaration of a string variable is char string_name[ size ]; The size determines the number of characters in the string_name. Example char name[20]; char dept[10]; When the compiler assigns a character string to a character array, it automatically supplies a null character (‘\0’) at the end of the string. Therefore, the size should be equal to the maximum number of characters in the string plus one. Character arrays may be initialized when they are declared. C permits a character array to be initialized in either of the two forms: char name[5] = ”Raja”; char name[5] = {‘R’,’a’,’j,’a’,’\0’} C also permits us to initialize a character array without specifying the number of elements. In such cases, the size of the array will be determined automatically, based on the number of elements initialized. Example char string [ ] = {‘R’,’a’,’j,’a’,’\0’} Defines the array string as a five elements array.
9.3
Reading Strings From Terminal
Reading words The input function scanf can be used with %s format specification to read in a string of characters. Example: char address[15]; scanf(“%s”, address); The problem with the scanf function is that it terminates its input on the first white space it finds (A white space includes blanks, tabs, carriage returns, form feeds and new lines). Therefore, if the following line of text is typed in at the terminal, NEW YORK Then only the string “NEW” will be read into the array address, since the blank space after the word “NEW” will terminate the string. Example Program: Program for reading words from terminal. #include<stdio.h> void main( ) { char address[50]; printf(“Enter the address\n”); scanf(“%s”, address); printf(“The address is %s”, address);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
272
COMPUTER FUNDAMENTAL & C PROGRAMMING getch( ); }
Output Of Program Enter the address NEW YORK The address is NEW Reading a line of text We can use getchar function repeatedly to successive single characters from input and place them into a character array. Thus, an entire line of text can be red and stored in an array. The reading is terminated when the new line character (‘\n’) is entered and the null character is then inserted at the end of the string. Example Program: Program for reading words from terminal. #include<stdio.h> void main( ) { char address[50], ch; int n = 0; printf(“Enter the address\n”); do { ch = getchar( ); address[n] = ch; n++; } while (ch ! = ‘\n’); n = n – 1; address[n] = ‘\0’; printf(“The address is %s”, address); getch( ); } Output Of Program Enter the address NEW YORK The address is NEW YORK
9.4
Writing Strings To Screen
The printf function with %s format is used to print strings to the screen. The format %s can be used to display an array of characters that is terminated by null character. For example printf(“%s”, name); can be used to display the entire contents of the array name.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
273
COMPUTER FUNDAMENTAL & C PROGRAMMING We can also specify the precision with which the array is displayed. For example, the specification %10.4 indicates that the first four characters are to be printed in a field width of 10 columns. Example Program: Program for display the string under various format specifications. #include<stdio.h> void main( ) { char address[] = “NEW YORK”; printf(“\nThe address is\n “); printf(“ %10s\n”, address); printf(“ %4s\n”, address); printf(“ %10.5s\n”, address); getch( ); } Output Of Program Enter the address NEW YORK The address is NEW YORK NEW YORK NEW Y 9.5
String Handling Functions
The C library supports a large number of string handling functions that can be used to manipulate the strings. strlen ( ) Function The strlen ( ) function is used to count and return the number of characters in the string. The general form is var = strlen(string); where var - is the integer variable, which accept the length of the string. string - is the string constant or string variable in which the length is going to be found. The counting ends with first null (‘\0’) character. strcpy ( ) Function The strcpy ( ) function is used to copy the contents of one string to another and almost works like string assignment operator. The general form is strcpy(string1, string2); where string1 and string2 are character array variable or string constant. It will assign the contents of string2 to string1. For example
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
274
COMPUTER FUNDAMENTAL & C PROGRAMMING strcpy(name, “Harsh”); will assign the string “Harsh” to the string variable name. strcpy(name1, name2); will assign the contents of the string variable name2 to the string variable name1. The size of the array name1 should be large enough to receive the contents of name2. strcmp ( ) Function The strcmp ( ) function is used to compares two strings identified by the arguments and has a value 0 if they are equal. If they are not, it has the numeric difference between the first non matching characters in the strings.. The general form is strcmp(string1, string2); where string1 and string2 are character array variable or string constant. For example strcmp(name1, name2); strcmp(name1, “John”); strcmp(“Raja”, “raja”); strcat ( ) Function The strcat ( ) function is used to combine or join or concatenate two strings together. The general form is strcat(string1, string2);
where string1 and string2 are character array variable or string constant. When the function strcat is executed, string2 is appended to string1. For example strrev ( ) Function The strrev ( ) function is used to reverse a strings . The general form is strrev(string1); where string1 is character array variable or string constant.
---------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------10 Pointers o
Introduction Generally, computer uses memories for storing instruction and values of the variables
with in the program, but the pointers have memory address as their values. The memory address is the location where program instructions and data are stored, pointers can be used to access and manipulate data stored in the memory.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
275
COMPUTER FUNDAMENTAL & C PROGRAMMING
276
The computer’s memory is a sequential collection of storage cells as shown in Fig. In, computer’s memory each cell is one byte, and it has a number called address, this address is numbered consecutively starting from zero to last address (depends on the memory size). While declaring variable, the computer allocates appropriate memory to hold the value of the variable. Since every memory has a unique address, this address location will have its own address number somewhere in the memory area. o
Understanding pointers The computer’s memory is a sequential collection of storage cells as shown in
Fig.3.4.1. Each cell, commonly known as a byte, has a number called address associated with it. The addresses are numbered consecutively starting from zero. The last address depends on memory size. For example 64K memory will have its last address as 65535. Whenever declare variable the system allocates, somewhere in the memory, an appropriate location to hold the value of the variable. Consider following statement int x = 100; This statement instructs the system to find a location for integer variable x and puts the value 100 in that location.(See Fig 3.4.2) Memory cell
. .
Address
0 1 2 . . . 65535
X
Fig. 3.4.1 Memory Organization
Variable
100
Value
5000
Address
Fig. 3.4.2 Representation of a variable
Memory addresses are simply numbers; they can be assigned to some variables, which can be stored in memory, like any other variable. Such variable that hold memory addresses are called pointers. Suppose, we assign the address of x to a variable p. the link between the variable p and x can be visualized as shown in Fig.3.4.3. Variable X
Value
Address
100
5000
5000 P 5048 Fig. 3.4.3 Pointer as a variable o
Accessing the address of a variable The operator & immediately preceding a variable returns the address of the variable
associated with it. For example, the statement p = &q;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING would assign the address 4000( the location of q) to the variable p. the & operator can remembered as ‘address of’. The & operator can be used only with a simple variable or an array element. The following are illegal use of address operator: 1. & 450 (pointing at constant) 2. int x[10]; & x (pointing at array names) 3.&(x+y) (pointing at expressions) Example Program: Program for accessing addresses of variables #include<stdio.h> main( ) { int a; char c; float f; a = 100; c = ‘A’; f = 20.56; printf(“%d is stored at address %u\n”, a, &a); printf(“%c is stored at address %u\n”, c, &c); printf(“%f is stored at address %u\n”, f, &f); getch( ); } Output Of The Program 100 is stored at address 65494 A is stored at address 65497 20.559999 is stored at address 65498 o
Declaring and initializing pointer
Declaration The general form for declaration of a pointer variable is data_type
*pointer_name;
where data_type – is specifies the type of data to which the pointer points asterisk (*) – that tells the variable pointer_name is a pointer variable pointer_name- is specifies the name of the pointer. For example int *p;
//declares the variable p as a pointer variable that points to an integer data type.
float *f //declares x as a pointer to a floating point variable. char *c //declares c as a pointer to a character variable
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
277
COMPUTER FUNDAMENTAL & C PROGRAMMING
278
Initialization: Once a pointer variable has been declared, it can be made to point to a variable using an assignment statement such as p = &q; which causes p point to q. That is, p now contains the address of q. This is known as pointer initialization. Before a pointer is initialized, it should not be used. The pointer variable can be initialized in its declaration itself. For example int x, *p = &x; //valid initialization It declares x as an integer variable and p as a pointer variable and then initializes p to the address of x. o
Accessing a variable through its pointer Once the pointer is declared and assigned to the address of another variable, the
variable can be accessed through its pointers. This is done by using another unary operator *(asterisk), usually known as the indirection operator. Another name for the indirection operator is the de-referencing operator. For example int *p , x, a; // declares two integer variable x & a and one pointer variable p x = 15;
// assigns the value 15 to variable x
p = &x; // assigns the address of x to the pointer variable p a = *p;
// it returns the value of the variable x, because p contains
the
address of the variable x Another example The statement p = &x assigns the address of x to p and y = *p assigns the value pointed to by the pointer p to y. *p = 25; This statement puts the value 25 at the memory location whose address is the value of p. we know that the value of p is the address of x and therefore the old value of x is replaced by 25. Example Program: Program for accessing variables using pointers #include<stdio.h> main( ) { int a, b; int *ptr; a = 30; ptr = &a; b = *ptr; printf(“Value of a is %d\n”, a); printf(“%d is stored at address %u\n”, a , &a); printf(“%d is stored at address %u\n”, *&a , &a); printf(“%d is stored at address %u\n”, *ptr , ptr);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING printf(“%d is stored at address %u\n”, b , &*ptr); getch( ); } Output Of The Program Value of a is 30 30 is stored at address 65502 30 is stored at address 65502 30 is stored at address 65502 30 is stored at address 65502 o
Pointer expressions Pointer variables can be used in expressions. Here, the pointers are preceded by the
* (indirection operator) symbol. Example c = *a + * b;
can be written as
c = (*a) + (*b);
s = s + *a/ * b; can be written as *p = *a**b;
s = s + (*a) / (*b);
can be written as
*p = (*a) * (*b);
Note that there is a blank space between / and * in above expression. The following is wrong. s = s + *a/* b; The symbol /* is considered as the beginning of a comment and therefore the statement fails. So we leave the space between / and * operator. C allows us to add or subtract integers from one pointer to another. In addition to that the pointer can also be compared using relational operators. But comparisons can be used mainly in handling arrays and strings. Example p1 + 4
p2 - 2
p1 > p2 p1 = = p2
and and
p1 – p2 are valid
p1 ! = p2
are valid
We may also use shorthand operators with pointers. Example p1 + +; - - p2; s += *p2; We may not use pointers in division and multiplication. Example p1 / p2 p1 * p2 p1 / 3
p2*6
are invalid
Similarly, two pointers cannot be added. That is, p1 + p2 is illegal. Example Program: Program for pointer expression #include<stdio.h> main( ) { int a, b , x, y; int *ptr1, *ptr2;
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
279
COMPUTER FUNDAMENTAL & C PROGRAMMING a = 10; b = 3; ptr1 = &a; ptr2 = &b; x = *ptr1 + *ptr2 – 2; y = *ptr1 * *ptr2 + 1; printf(“Address of a is %u\n”, ptr1); printf(“Address of b is %u\n”, ptr2); printf(“a = %d, b = %d\n”, a, b); printf(“x = %d, y = %d\n”, x, y); *ptr2 = *ptr2 + 3; *ptr1 = *ptr2 * 2; printf(“a = %d, b = %d\n”, a, b); printf(“x = %d, y = %d\n”, x, y); getch( ); } Output Of The Program Address of a is 65496 Address of b is 65498 a = 10, b = 3 x = 11, y = 31 a = 12, b = 6 x = 11, y = 31 o
Pointers and array Array is a collection of similar data items, which is stored under common name.
When an array is declared, the compiler allocates a base address and sufficient amount of storage locations for all elements of an array. The base address is the location of the first element (index 0) of the array. The compiler also defines the array names as a constant pointer to the first element. For example int x[5]
={1, 2, 3, 4, 5};
Suppose the base address of x is 2000 and assuming that each integer requires 2 bytes, the five elements will be stored as The name x is defined as a constant pointer pointing to the first element, x[0] and therefore the value of x is 2000, the location where x[0] is stored. That is x = &x[0] = 2000 If we declare p as integer pointer, then we can make the pointer p to point to the array x by the assignment p = x; This is equivalent to p = &x[0]; Now, we can access every value of x using p++ to move from one element to another. The relationship between p and x is
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
280
COMPUTER FUNDAMENTAL & C PROGRAMMING p = &x[0]
(=2000)
p+1 = &x[1]
(=2002)
p +2= &x[2]
(=2004)
p +3= &x[3]
(=2006)
p +4= &x[4]
(=2008)
The address of an element is calculated by using its index and the scale factor of the data type. For example
Address of x[2] =
base address + (2 x scale factor of int) =
2000 + (2 x 2)
=
2004
When handling arrays, instead of using array indexing, we can use pointers to access array elements. For example *(p + 2) gives the value of x[3]. This is much faster than array indexing. Example Program: Program to print the array values and address of the array elements using pointer #include<stdio.h> main( ) { int arr[5] = { 10, 20, 30, 40, 50}; int i, *ptr_arr; ptr_arr = arr; for(i = 0; i < 5; i++) { printf(“Address = %u\t”, &arr[i]); printf(“Element = %d\t”, arr[i]); printf(%d\t”, *(arr+i)); printf(“%d\t”, ptr_arr[i]); printf(“%d\t\n”, *(ptr_arr+i)); } getch( ); } Output Of The Program Address = 65494 Element = 10
10
10
10
Address = 65496 Element = 20
20
20
20
Address = 65498 Element = 30
30
30
30
Address = 65500 Element = 40
40
40
40
Address = 65502 Element = 50
50
50
50
In the above program, the variable arr[] is declared as integer array, the elements are displayed using different syntax. 1. arr[i], 2. *(arr + i), 3. ptr_arr[i] , 4. *(ptr_arr + i)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
281
COMPUTER FUNDAMENTAL & C PROGRAMMING Pointers can be used to manipulate two-dimensional arrays. An element in a twodimensional array can be represented by the pointer expression as *(*(a+i)+j)
or
*(*(p+i)+j)
The base address of the array a is &a[i][j] and starting at this address, the compiler allocates contiguous space for all the elements, row-wise. That is, the first element of the second row is placed immediately after the last element of the first row, and so on. o
Pointers and character strings A string is an array of characters, terminated with a null character. Like one-
dimensional arrays, we can use a pointer to access the individual characters in a string. Example Program: #include<stdio.h> main( ) { char *s1 = “abc”; char s2[ ] = “xyz”; printf(“%s %16lu \n”, s1, s1); printf(“%s %16lu \n”, s2, s2); s1 = s2; printf(“%s %16lu \n”, s1, s1); printf(“%s %16lu \n”, s2, s2); getch( ); } Output Of The Program abc
12976536
xyz
13041628
xyz
13041628
xyz
13041628
In C, a constant character string always represents a pointer to that string. And therefore the following statements are valid: char *city; city = “Salem”; These statements will declare city as a pointer to character and assign to city the constant character string “Salem”. One important use of pointers is in handling of a table of strings. For example array of strings: char name[3][20]; This array that the name is a table containing three names, each with a maximum length of 20 characters (including null character). Total storage requirements for the name table are 60. Instead of making each row with fixed number of characters, we can make it a pointer to a string of varying length. For Example char *city[3] = { “Chennai”
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
282
COMPUTER FUNDAMENTAL & C PROGRAMMING “Covai” “Salem” }; declares city to be an array of three pointers to characters, each pointer pointing to a particular city as shown below: city[0] -> Chennai city[1] -> Covai city[2] -> Salem The following statement would print out all three cities: for(i = 0; i< 3; i++) printf(“%s\n”, city[i]); th
th
To access the j character in the i name, we may write as *(city[i] + j)
o
Pointer and functions When we pass addresses to a function using pointers to pass the addresses of
variable is known as call by reference. The function, which is called by reference can change the value of the variable used in the call. Example Program: Program for pointer and function main() { int x; x = 20; change(&x); printf(“%d\n”, x); getch( ); } change(p) int *p; { *p = *p +10; } Output Of The Program 30 When the function change( ) is called, the address of the variable x, not its value, is passed into the function change( ). Inside change( ), the variable p is declared as a pointer and therefore p is the address of the variable x. The statement *p = *p +10; means ‘add 10 to the value stored at the address p’. Since p represents the address of x, the value of x is changed from 20 to 30.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
283
COMPUTER FUNDAMENTAL & C PROGRAMMING
Pointer to Functions A function, like variable, has an address location in the memory. To declare a pointer to a function, which can be used as an argument in another function. The pointer to a function is declared as type (*fprt) ( ); This tells the compiler that fprt is a pointer to a function, which returns type value. We can make a function pointer to point to a specific function by simply assigning the name of the function to the pointer. For example double (*p1) ( ), mul( ); p1 = mul; declare p1 as a pointer to a function and mul as a function and then make p1 to point to the function mul. To call function mul, we may use the pointer p1 with the list of parameters. That is (*p1) (x, y) is equivalent to mul(x, y) o
Pointer and structures
The general form is struct structure_name { type structure_element 1; type structure_element 2; -----------type structure_element n; } struct_var , *ptr; where struct_var is the structure type variable and ptr as a pointer to data objects of the type struct structure_name. For example struct student { int
student_rno;
char
student_name;
int
student_mark1;
int
student_mark2;
} s1[2] , *s2 ; This statement declares s1 as an array of two elements, each of the type struct student and s2 as a pointer to data objects of the type struct student.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
284
COMPUTER FUNDAMENTAL & C PROGRAMMING The assignment s2 = s1; th
would assign the address of the zero element of s1 to s2. That is pointer s2 will now point to s1[0]. Its members can be accessed using the following notation s2 - > student_name s2 - > student_rno s2 - > student_mark1 s2 - > student_mark2 The symbol -> is called the arrow operator and is made up of a minus sign and a greater than sign. We also use the notation (*s2).rno to access the member rno. The parentheses around *s2 are necessary because the member operator “. “ has a higher precedence than the operator *. While using structure pointers, we should take care of the precedence of operators.
For example ++ p -> c; increments c, not p. however, (++p) -> c; increments p first, and then links c. Example Program: Program for pointers to structure variables #include<stdio.h> main( ) { struct student { int char int
rno; *name[20]; mark;
} *s2 ; printf(“Enter student Roll no., Name, Mark\n”); scanf(“%d%s%d”, &s2->rno, s2->name, &s2->mark); printf(“Student Roll no.:%d”, &s2->rno); printf(“Student Name:%s”, s2->name); printf(“Student Mark:%d”, &s2->mark); getch( ); } Output Of The Program Enter student Roll no., Name, Mark 2000 Harshinni
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
285
COMPUTER FUNDAMENTAL & C PROGRAMMING
286
100 Student Roll no.:2000 Student Name:Harshinni Student Mark:100
o
Self Assessment Questions
Fill in the blank 1. The address of an element is calculated by using its ______________ and the scale factor of the _______________. 2.When we pass addresses to a function using pointers to pass the addresses of variable is known as ___________________. True / False 1. Address of a floating-point variable is always a whole number. Multiple Choice 1.Which of the following is the correct way of declaring a float pointer a) float ptr;
b) float *ptr;
c) *float ptr;
d) none of the above
2. If int s[5] is a one dimensional array of integers, which of the following refers to the third element in the array? a) *(s+2)
b) *(s+3)
c) s+ 3
d) s+2
Short Answer 1. What is mean by pointer expression? ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------2. What is the purpose of using & operator in pointers? -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
11
Files 11.1
Introduction
A file is a collection of related information, that is permanently stored on the disk and allows us to access and alter the information whenever necessary. We can perform the following basic operations on files.
Naming a file
Opening a file
Reading data from a file
Writing data to a file
Closing a file
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
287
There are large numbers of standard library functions available for performing disk files.
High level file I/O functions
Low level file I/O functions
High-level file I/O functions do their own buffer management, whereas in low level file I/O functions buffer management has to be done by the programmer. Some of the high level file I/O functions listed in Table. 11.2
Opening/Closing Files
Defining a file We want to store data in a file in the secondary memory; we must specify the following things about file, to the operating system. They include File name Filename is a string of characters that make up a valid filename for the operating system. It may contain two parts, a primary name and optional period with the extension. For example Input.data store stud.c Empl.out Data structure Data structure of a file is defined as FILE in the library of standard I/O function definitions. Therefore, all files should be declared as type FILE before they are used. FILE is a defined data type. Purpose When we open a file, we must specify what we want to do with the For
file.
example, we may write data to the file or read the already exiting data.
Opening a file The general form for declaring and opening a file is FILE
*fp;
fp = fopen(“filename, “mode”); The first statement declares the variable fp as a “pointer to the data type FILE”. The second statement opens the file named filename and assigns an identifier to the FILE type pointer fp. This pointer, which contains all information about the file and it, is used as a communication link between the system and the program. The second statement also specifies the purpose of opening this file. The mode does this job. Mode can be one of the following
r open the file for reading only.
w open the file for writing only.
a open the file for appending or adding data to it.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING The filename and mode is treated as string, so it should be enclosed in double quotation marks ( “ “ ). When trying to open a file, one of the following things may happen. When the mode is ‘writing’, a file with specified name is created if the file does not exist. The contents are deleted, if the file already exists. When the purpose is ‘appending’, the file is opened with current contents safe. A file with specified name is created if the file does not exist. If the purpose is ‘reading’ and if it exists, then the file opened with current contents safe; otherwise an error occurs. Example FILE *p1, *p2; p1 = fopen(“stud.out”, “r”); p2 =fopen(“results”, “w”); The file stud.out is opened for reading and a result is opened for writing. In case, the results file already exists, its contents are deleted and the file is opened as a new file. If stud.out file does not exist, an error will occur. Closing a file A file must be closed after all the operation of the file has been completed. The general form for closing a file is fclose(file_pointer); This would close the file associated with the FILE pointer file_pointer. Example --------------------FILE *p1; p1 = fopen(“input”, “w”); --------------------fclose(p1); ----------This program opens a file and closes a file after all operations on the files are completed. Once a file is closed, its file pointer can be reused for another file. All files are closed automatically whenever a program terminates. 11.3
Input/Output files
Once a file is opened, reading out of or writing to it is accomplished using the standard I/O routines that are listed in Table. The getc and putc functions The function getc is used to read a character from a file that has opened with read mode r. Example c = getc(fp1)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
288
COMPUTER FUNDAMENTAL & C PROGRAMMING would read a character from the file whose file pointer is fp1. The function putc is used to write the character contained in the character variable to the file associated with FILE pointer that has been opened with write mode w. Example putc(c, fp2);
would write a character contained in the variable c to the file associated with FILE pointer fp2. The file pointer moves by one character position for every operation of getc or putc. The getc will return an end-of-file marker EOF, when end of the file has been reached. Therefore the reading should be terminated when EOF is encountered Example Program: Program for writing to and reading from a file. #include<stdio.h> main( ) { FILE *f1; char c; printf(“Data input\n”); f1 = fopen(“Test”, “w”);
/* Open the file Test*/
while((c = getchar( ) ) != EOF) /* Get a character from keyboard */ putc(c, f1); fclose(f1);
/* Write a character to Test file */ /* Close the file Test*/
printf(“Data Output\n”); f1 = fopen(“Test”, “r”); while((c = getc(f1)) != EOF) printf(“%c”, c);
/* Read a character from Test file */
/* Display a character on screen */
fclose(f1); getch( ); }
Output Of The Program Data Input Dog Cat Rat ^Z Data Output Dog Cat Rat We enter the input data via keyboard and the program writes it, character by character, to the file Test. Entering an EOF character, which is control-Z, indicates the end of the data. The file Test is closed at this signal.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
289
COMPUTER FUNDAMENTAL & C PROGRAMMING The file Test is reopened for reading. The program then reads its content character by character, and displays it on the screen. Reading is terminated when getc( ) encounters the end-of-file mark EOF. The getw and putw functions The getw and putw are integer-oriented functions. They are similar to the getc and putc functions and are used to read and write integer values. The general forms of getw and putw are putw(integer, fp); getw(fp); Example Program: Program to illustrate the use of putw and getw functions. #include<stdio.h> main( ) { FILE *f1, *f2, *f3; int number, i; printf(“Contents of Data file \n”); f1 = fopen(“DATA”, “w”); for(i = 1; i <=20; i++) { scanf(“%d”, &number); if( number = = -1) break; putw(number, f1); } fclose(f1); f1 = fopen(“DATA”, “r”); f2 = fopen(“ODD”, “w”); f3 = fopen(“EVEN”, “w”); while((number = getw(f1)) != EOF) { if (number % 2 == 0) putw(number, f3); else putw(number, f2); } fclose(f1); fclose(f2); fclose(f3); f2 = fopen(“ODD”, “r”); f3 = fopen(“EVEN”, “r”); pintf(“\nContents of ODD file\n”); while((number = getw(f2) != EOF) printf(“%4d”, number); pintf(“\nContents of EVEN file\n”);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
290
COMPUTER FUNDAMENTAL & C PROGRAMMING while((number = getw(f3) != EOF) printf(“%4d”, number); fclose(f2); fclose(f3); getch( ); } Output Of The Program Contents of Data file 1 2 3 4 5 6 7 8 9 10 -1 Contents of ODD file 1 3 5 7 9 Contents of EVEN file 2 4 6 8 10 The fprintf and fscanf functions These functions are used to handle a group of mixed data simultaneously. The functions fprintf and fscanf perform I/O operations those are identical to the familiar printf and scanf functions except that they work on files. The general form of fprintf is fprintf(fp, “control string”, list); where fp
- is a file pointer associated with a file that has been opened for writing.
control string list
- contains output format specifications for items in the list.
- may include variables, constants and strings.
Example fprintf(fp1, “%s%d”, name, age); Here, name is an array variable of type char and age is an int variable. The general form of fscanf is fscanf(fp, “control string”, list); would cause the reading of the items in the list from file specified by fp, according to the specifications contained in the control string. Example fscanf(fp2, “%s%d”, name, &age ); fscanf returns the number of items that are successfully read. When the end of file is reached, it returns the value EOF. Example Program: Program to Handling of files with mixed data types #include<stdio.h> main( ) { FILE *f1; int rno, i; char name[20]; f1 = fopen(“STUDENT”, “w”); printf(“Input Student data\n\n”);
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
291
COMPUTER FUNDAMENTAL & C PROGRAMMING printf(“Roll No. Name\n”); for(i = 0; i < 3; i++) { fscanf(stdin, “%d%s”, &rno, name); fprintf(f1, “%d%s\n”, rno, name); } fclose(f1); fprintf(stdout, “\n\n”); f1 = fopen(“STUDENT”, “r”); printf(“Output Student data\n\n”); printf(“Roll No. Name\n”); for(i = 0; i < 3; i++) { fscanf(f1, “%d%s”, &rno, name); fprintf(stdout, “%d\t\t%s\n”, rno, name); } fclose(f1); getch( ); } Output Of The Program Input Student data Roll No. Name 1000
aaa
2000
bbb
3000
ccc
Output Student data Roll No.
Name
1000
aaa
2000
bbb
3000
ccc
In the above program the data is read using function fscanf from the file stdin, which refers to the terminal and it is then written to the file that is being pointed to by file pointer f1. After closing the file STUDENT, it again reopened for reading. The data from the file, along with the item values are written to the stdout, which refers to the screen. While reading from a file, care should be taken to use the same format specifications with which the contents have been written to the file.
11.4
Error Handling During I/O Operations
It is possible that an error may occur during I/O operations on a file. Typical error situations are
Trying to read beyond the end-of-file mark.
Device overflow.
Trying to use a file that has not been opened.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
292
COMPUTER FUNDAMENTAL & C PROGRAMMING
Trying to perform an operation on a file, when the file is opened for another type of operation.
Opening a file with an invalid filename.
Attempting to write to a write-protected file. If we fail to check such read and write errors, a program may behave abnormally
when an error occurs. An unchecked error may result in a premature termination of the program or incorrect output. C library has two functions, feof and ferror that can help us to detect I/O errors in the files. feof function The feof function can be used to test for an end of file condition. It takes a FILE pointer as its only argument and return a nonzero integer value if all of the data from the specified file has been read, and returns zero otherwise. If fp is a file pointer to file that has just been opened for reading, then the statement if(feof(fp)) printf(“end of data”); would display the message “end of data” on reading the end of file condition. ferror function The ferror function reports the status of the file indicated. It also takes a FILE pointer as it’s argument and returns a nonzero integer if an error has been detected up to that point, during processing. It returns zero otherwise. The statement if(ferror(fp)) printf(“an error has occurred”);
would print the error message, if reading is not successful. We know that whenever a file is opened using fopen function, afile pointer is returned. If the file cannot be opened for some reason, then the function returns a null pointer. Example if(fp = NULL) printf(“file could not be opened”); Example Program: Program to illustrate error handling in file operations. #include<stdio.h> main( ) { char filename[20]; FILE *f1, *f2; int i, number; f1 = fopen(“TEST”, “w”); for(i = 10; i<= 100; i +=10)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
293
COMPUTER FUNDAMENTAL & C PROGRAMMING putw(i, f1); fclose(f1); printf(“\nInput File name\n”); open_file:
scanf(“%s”, filename);
if((f2 = fopen(filename, “r”)) == NULL) { printf(“Cannot open the file \n”); printf(“Type filename again\n”); goto open_file; } else for(i = 1; i <= 20; i++) { number = getw(f2); if(feof(f2)) { printf(“Ran out of data\n”); break; } else printf(“%d\n”, number); } fclose(f2); } Output Of The Program Input File name TETS Cannot open the file Type filename again TEST 10 20 30 40 50 60 70 80 90 100 Ran out of data
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
294
COMPUTER FUNDAMENTAL & C PROGRAMMING 11.5
Random Access To Files
In case of random access to file, we can access only a particular part of a file and not in reading the other parts. This is achieved with the help of the fseek, ftell, and rewind functions available in the I/O library. ftell function: The ftell function is used to specify the current position of a file. It takes the file pointer and returns a number of types long, that corresponding to the current position. The general form is n = ftell(fp); where n would give the relative offset ( in bytes ) of the current position. rewind function: The rewind takes the file pointer and resets the position to the start of the file. For example rewind(fp); n = ftell(fp); would assign 0 to n because the file position has been set to the start of the file by rewind. The first byte in the file is numbered as 0, second as 1, and so on. This function helps us in reading a file more than once, without having to close and open the file. fseek function: The fseek function is used to move the file position to a desired location within the file. The general form is fseek(file_pointer, offset, position);
where file_ pointer is a pointer to the file offset is a number or variable of type long, and position is an integer number The offset specifies the number of positions to be moved from the location specified by position. The position can take one of the following three values. Value
Meaning
0
Beginning of file
1
Current position
2
End of file
The offset may be positive, it moves forwards or negative, it moves backwards. The following examples illustrate the operation of the fseek function: Statement
Meaning
fseek(fp, 0L, 0); Go to beginning . fseek(fp, 0L, 1); Stay at the current position fseek(fp, 0L, 2); Go to end of the file, past the last character of the file. fseek(fp, m, 0); Move to (m+1) th byte in the file.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
295
COMPUTER FUNDAMENTAL & C PROGRAMMING fseek(fp, m, 1); Go forward by m bytes. fseek(fp, -m, 1); Go backward by m bytes from the current position. fseek(fp, -m, 2); Go backward by m bytes from the end. When the operation is successful, fseek returns a zero. If we attempt to move the file pointer beyond the file boundaries, an error occurs and fseek returns –1. Example Program: Program to illustrate of fseek & ftell functions #include<stdio.h> main( ) { FILE *f1; int n; char c; f1 = fopen(“RANDOM”,”w”); while(( c = getchar( ) ) != EOF) putc(c, f1); printf(“No. of characters entered = %d\n”,ftell(f1)); fclose(f1); f1 = fopen(“RANDOM”,”r”); n = 0; while(feof(f1) == 0) { fseek(f1, n, 0); /* Position to (n+1)
th
character */
printf(“Position of %c is %d\n”, getc(f1), ftell(f1)); n = n + 5; } putchar(‘\n’); fseek(f1, -1, 2); /* Position to the last character */ do { putchar(getc(f1)); } while(fseek(f1, -2, 1)); fclose(f1); } Output Of The Program ABCDEFGHIJKLMNOPQRSTUVWXYZ^Z No. of characters entered = 26 Position of A is 0 Position of F is 5 Position of K is 10 Position of P is 15 Position of U is 20 Position of Z is 25 Position of
is 30
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
296
COMPUTER FUNDAMENTAL & C PROGRAMMING
11.6
Command Line Arguments
Command line argument is a parameter supplied to a program when the program invoked. This parameter may represent a filename the program should process. For example if we want to execute a program to copy the contents of a file named xfile to another file name yfile, then we may use command line like c>program
xfile
yfile
program is the filename where the executable code of the program is stored. In C program should have one main function and that it marks the beginning of the program. The main function take two arguments called argc and argv and the information contained in the command line is passed on to the program through these arguments, when main is called up by the system. The variable argc is an argument counter that counts the number of arguments on the command line. The argv is an argument vector and represents an array of character pointers that point to the command line arguments. The size of the array will be equal to the value of argc. For the above example, argc is three and argv is an array of three pointers to strings as argv[0] -------> program argv[1] ------->xfile argv[2] ------->yfile In order to access the command line arguments, we must declare the main function and its parameters as main(argc, argv) int argc; char *argv[]; { ------------} the first parameter in the command line is always the program name and therefore argv[0] always represents the program name. Example Program: Program to illustrate command line arguments #include<stdio.h> main(int argc, char argv[ ])
/* Main with arguments */
{ FILE *f1; int i; char word[15]; f1 = fopen(argv[1], “w”); /* Open the file with name argv[1] */ printf(“ \nNo. Of argument in command line = %d\n”, argc); for(i = 2; i < argc; i++)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
297
COMPUTER FUNDAMENTAL & C PROGRAMMING fprintf(f1, “%s”,argv[i]); fclose(f1); /* Writing content of the file to screen */ printf(“content of %s file \n”, argv[1]); f1 = fopen(argv[1], “r”); for(i = 2; i <argc; i++); { fscanf(f1, “%s”, word); printf(“%s”, word); } fclose(f1); printf(“\n”); /* Writing argument from memory */ for(i = 0; i < argc; i++) printf(“%*s\n”, i*5, argv[i]); } Output Of The Program C:\TC>file6 TEST aaa bbb ccc No. Of argument in command line = 5 content of TEST file aaabbbccc C:\TC\FILE6.EXE TEST aaa bbb ccc
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
298
COMPUTER FUNDAMENTAL & C PROGRAMMING
299
UNIT QUESTIONS UNIT – I Self Assessment Questions Fill in the blank 1.
____________ is a programmable machine.
2.
The Actual machinery in a computer is called __________ and the instructions and data are called _____________.
3.
The number of bits that a computer can process at a time in parallel is called its ____________.
4.
The name of the first digital computer is ___________ and built the first digital computer using parts called____________.
5.
The second generation computers contained __________ in place of vacuum tubes.
6.
The use of operating systems in computer was introduced in the _______ generation computers.
7.
___________ Computers aim to solve highly complex problems, ones which require reasoning, intelligence and expertise when solved by people.
8.
The Three categories of digital computers are ___________, ______________, and ______________.
9.
The base of the octal number system is ___________.
10.
BCD stands for _______________ _______ ______________.
11.
Binary number system uses only two digital ______ and ________.
12.
The 9’s complement of a decimal number is obtained by subtracting each digit from _________.
True or False 1.
Main frame is a powerful multi user computer capable of supporting many hundreds of users simultaneously.
2.
GIGO stands for Garbage In Garbage out
3.
PDA stands for portable digital assistant.
4.
Second generation computers replaced machine language with assembly language.
5.
Third generation computers replaced transistors with vacuum tubes.
6.
The radix of the hexadecimal number system is 8.
7.
When add 1 to the 9’s complement you will get the 10’s complement.
Multiple Choice 1.
A set of prerecorded instructions executed by a computer is called the a). Action
b) Hardware
c) Program
d) None of the above
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING 2.
300
Which is the part that transmits data from one part of the computer to another? a). Bus b) CPU c) Hard disk
3.
4.
d) none of the above
LSI stands for a)Light sensitive Instrument
b)Large scale Integration
c) Logical sample Integration
d) none of the above
The BCD of 123 is a)0001 010 0011
b) 0001 0011 0010
c)0011 0010 0001
d)none of the above 5.
The Binary equivalent of 20 is a) 1111 b). 10100
c) 10101
d) 10011
Unit Questions 1.
What are the different types of Computers?
2.
What are major components of a computer?
3.
What are the characteristics of computer?
4.
What are the different generations of computers?
5.
What are the features of the third generation computers?
6.
What are the different categories of digital computers?
7.
What are the different types of portable computers?
8.
What is the difference between a minicomputer and a microcomputer?
9.
Explain the decimal number system and the binary number system?
10.
Explain
1. 1’s complement
2. 2’s complement
3. 9’s complement 4. 10’s complement with Examples. 11.
Explain (i). Hexadecimal (iii). BCD
12.
(ii). Octal number system with Examples.
What are the Excess-3 and Gray codes?
.
Self Assessment Answers
Fill in the blanks 1. Computer 2. Hardware, Software 3. Word Length 4. ENIAC, Vacuum 5. Transistors
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
301
6. III 7. V Generation 8. Mini, Mainframe & Super computers 9. 8 10. Binary Coded Decimal 11. 0 12. 9 True / False 1. True 2. True 3. False 4. True 5. False 6. False 7. True Multiple Choice 1. C 2. A 3. B 4. A 5. B
UNIT â&#x20AC;&#x201C; II Self Assessment Questions Fill in the blank 1.
The + and . operations are physically realized by two types of electronic circuits called ___________ and ______________.
2.
The complementation operation is physically realized by a gate or circuit called an __________.
3.
NAND gate is a combination of _________ and __________ gates.
4.
The _____________ on the Output of the NAND and NOR gates represents complementation.
True or False 1.
In the derivation of Boolean expression when both X and Y are 0s, the output Z is to be 1.
2. The symbol
is not used to indicate complementation . m
s
3. A subcube is a set of exactly 2 adjacent cells containing 1 .
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
302
Multiple Choice 1. Gating networks can now be made with many gates in a single contains by using the manufacturing technique. a). MSI b) LSI
c) CSI
d) SSI
2.
This Logical diagram is for the gate. a)AND b) OR
3.
c) NOT
d) NOR
According to Boolean algebra rules X + XZ = ? a) X
b)Y
c) XZ
d) XY.
Unit Questions
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
Self Assessment Answers
Fill in the blanks 1. OR, AND 2. Inverter 3. AND,NOR 4. Bubble
True / False 1. True 2. False
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
303
COMPUTER FUNDAMENTAL & C PROGRAMMING
304
3. True
Multiple Choice 1. B 2. D 3. A
UNIT â&#x20AC;&#x201C; III Self Assessment Questions
Fill in the blank 1.
Computer hardware falls into two categories ___________ and ____________ devices.
2.
Computers have several additional storage locations called _______________
3.
Every computer comes with a certain amount of physical memory, usually referred to as _______________
4.
The memory unit that holds instructions for starting up the computer is ________________
5.
_______________ is the input device consisting of a set of keys that enables you to enter data into a computer.
6.
The three basic types of mice are _______________ , ________ and _____________.
7.
SVGA stands for ___________ graphics array.
8.
Colour monitors are some times called _________ monitors.
9.
There are two types of auxiliary storage devices ________, ____________.
10.
CD â&#x20AC;&#x201C; ROM stands for ___________________.
True or False 1.Hardware is the mechanical and electronic device 2.Static RAM is slower than Dynamic RAM. 3.An EEPROM can be erased by exposing it to an electrical charge. 4.Track ball is another pointing device. 5.Light pen is not an Input device.. 6.A Gray scale monitor is a special type of colour monitor capable of
displaying different
shades of gray. 7. On colour monitors, each pixel is composed of 3 dots - red, blue, green. 8 Auxiliary storage is long term, volatile memory. 9 Zip disk can hold 100 MB,
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
305
10CD –R drive is short for compact disk Recordable drive.
Multiple Choice 1.
The two parts of the CPU are a). Control Unit Memory
b) Addresses and registers
c). Addresses and ALU d) Control Unit and ALU 2.
The different types of memory units are a). RAM
3.
b) PROM
c) ROM
d)All of the above
Which of the following loses it contents when the computer is turned off? a)RAM b)ROM c) PROM
4.
d) All of the above
Which is the technology used in the evaluation of aptitude tests
a)OCR b)OMR c) MICR 5.
d)MCR
The different types of printers are a) daisy – wheel
b). Dot matrix
c) Laser & Ink – jet
d) All of the above 6.
Which of the following is a sequential access device. a). Hard disk
b) Floppy disk
c) Magnetic tape
d) all of the above
CD – RW stands for
7.
a) CD – Recordable
b) CD – Reusable
c) CD – Rewritable
d) None of the above
Unit Questions
1.
What are the major functions of a computers.
2.
Explain how the CPU and memory work.
3.
What are the different types of memory.
4.
What is the difference between RAM & ROM
5.
What are the different kinds of input devices.
6.
Explain MICR, OCR and OMR
7.
What are the major output devices for a computer.
8.
What do you mean by VGA, SVGA & XGA
9.
What are the major auxiliary storage devices for a computer
10.
What is the difference between random access device and sequential access device.
11.
Describe Zip disk, Jaz disk and Super disk.
12.
Explain CD –ROM, CD – R Drive & CD – RW Disks.
.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
Self Assessment Answers Fill in the blanks 1. CPU, Pheripheral 2. Registers 3. The Main Memory (Or) The RAM 4. ROM 5. Keyboard 6. Mechanical, Optomechanical, Optical 7. SVGA 8. RGB 9. Magnetic Tapes, Magnetic Disks 10. Compact Disc – Read Only Memory True / False 1. True 2. False 3. True 4. True 5. False 6. True 7. True 8. False 9. True 10. True Multiple Choice 1. D 2. D 3. A 4. B 5. D 6. C 7. C
UNIT – IV Self Assessment Questions Fill in the blank 1. Dos stands for ______________.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
306
COMPUTER FUNDAMENTAL & C PROGRAMMING 2. _______________ is the extension for a batch file in Dos. 3. ____________ is the first and still one of the most popular word processing package. 4. The extension of DBMS ______________. 5. The five database models are _______, __________, __________, __________, __________. 6. The command used to exit from dbase is ________. 7. The extension of a dbase III plus data base file _________. 8. In a spread sheet, the rows are labeled with numbers and _______ with __________ 9. Lotus 1-2-3 is a product if ___________. 10. ____________ is the @ function that is used to calculate the average of a set of Nos. 11. TCP / IP stands for __________. 12. HTML stands for ____________. 13. _____________ is an electronic message sent from one computer to another. 14. _________________ identifies a person and the computer for purposes of exchanging electronic mail message. 15. There are two main types of search tools : _________ and __________
True or False 1. Copy is the Dos command used to copy files. 2. Data in a database can be shared among different users and applications. 3. DBMS is not a software. 4. dBase III plus is a DBMS. 5. LIST command will not display all records in a database. 6. The intersection of a row and a column is called a cell. 7. Spreadsheet packages have capabilities to create graphs and charts. 8. Lotus 1-2-3 is not a spreadsheet 9. FTP is a protocol, which allows files to be transferred between two computers 10. MIME stands for multi purpose Internet mail Exploration.
Multiple Choice 1.
What is the Dos command for listing all the files in a directory? a). List b) DIR c). Deltree
d) None
2. What is the Dos command for remaining a file? a). Change 3.
b) CHG c) REN d)REM
The service provided by a DBMS are
c) Recovery
d) All of the above
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
307
COMPUTER FUNDAMENTAL & C PROGRAMMING 4.
308
What is the uniform interface for users providing a collection of standard expression for storing and retrieving data in a relational database. a). SQL b) Virtual storage access method c). filtering
d) none of the above.
5. The logical operators of dbase III plus are a) .AND. 6.
b). .OR. c) .NOT.
d) All of the above
The valid field types in dbase III plus are a). Characters b) Numeric
7.
c) Logical
d) All of the above
Which of the following is a spreadsheet a) Word b) Excel
c) Power Point
d) All of the above 8. Calculated entries are computed using A). Formulas 9.
b). Functions
c). Macros
d). None
Which of the following chart types are possible in Lotus 1-2-3. a) line
10.
b) Bar
c) pie
d) All of the above
World wide Web is made of documents created with a language called a). HTML
11.
b) URL c) HTTL
d) HTRL
Which of the following is a character based browser. a) mosaic
12.
b). Netscape c) Internet Explorer
d) Lynx
Which of the following is a graphical browser. a) mosaic
b). Netscape c) Internet Explorer
d) none of the
above 13.
HTTP refers to a). Hyper Text transfer protocol b) Hyper text transfer pocedure c) Home text translating process
14.
d) none of the above
Which of the following is a mailing list management program a) LISTSERV
b) Major demo
c) List proc 15.
d) All of the above
Which of the following is a valid use net news group classification. a) news b) comp c) alt
d) All of the above
Unit Questions 1. 2.
What is Dos? What are Dos files, files name & file extensions. What are Dos Commands?
3.
Write short notes on WordStar?
4.
What is DBMS? What are the services provided by a DBMS?
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING 5.
What are the different types of DBMS.
6.
What is dbase plus? What are the advantages of using it?
7.
How will you create a database in dbase III plus and how will you add data in it?
8.
How is a report created in dbase III plus?
9.
What are the characteristics of a spreadsheet?
10.
What is an electronic spreadsheet? What are the advantages of electronic spreadsheet?
11.
What is Lotus 1-2-3? What are the advantages of using lotus 1-2-3?
12.
What are @ function? What are macros and how are they created?
13.
What is the internet? How does the Internet work?
14.
What is the difference between a dial â&#x20AC;&#x201C; up connection and a direct connection?
15.
List some of the activities that you can do on the Internet?
16.
What are the different protocols available on the Internet?
17.
How are addresses defined on the internet?
18.
What is e-mail? How does an e-mail work?
19.
What are mailing lists and how do they work?
20.
What is the purpose of news group and how do they work?
Self Assessment Answers
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
309
COMPUTER FUNDAMENTAL & C PROGRAMMING Fill in the blanks 1. Disk Operating System 2. Bat 3. WordStar 4. Database Management System 5. Hierarchical, Network, Relational, Object – Oriented, Deductive 6. Quit 7. Dbf 8. Numbers , Alphabets 9. Microsoft 10. AVG 11. Transmission Control Protocol, Internet Protocol 12. Hyper Text Markup Language 13. E – Mail 14. E – Mail Address 15. Yahoo, AltaVista
True / False 1. True 2. True 3. False 4. True 5. False 6. True 7. True 8. False 9. True 10. False
Multiple Choice 1. B 2. C 3. D 4. A 5. D 6. D 7. B 8. A 9. D
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
310
COMPUTER FUNDAMENTAL & C PROGRAMMING 10. A 11. D 12. D 13. A 14. D 15. D
UNIT â&#x20AC;&#x201C; V Self Assessment Questions Fill in the blank
1.
Three commonly used versions of windows are _________ , _________ and ____________.
2.
On pressing ^B, write changes the selected text to the _________style.
3.
To delete the selected files in the file manager windows , press the _________ key.
4.
When you start word, it automatically creates a document and names it ___________.
5.
Each cell in the worksheet has a _____________ address.
6.
TO exit Excel, select the ____________ command from the file menu (or) press Alt + F4 key(s).
7.
DTP stands for __________________.
8.
PowerPoint is a _____________ software that can help you quickly create effective slide based presentation.
True or False
1.
Windows can run several tasks simultaneously.
2.
The copy command copies the contents of clipboard into the current document
3.
Formatting erases all files on the diskette.
4.
The cut text can be pasted any number of times anywhere in the current (or) a new document.
5.
Data source is used to store the name and address of passion.
6.
Corel Draw & page makes are DTP software programs.
7.
In power point, each slide not have text and graphics.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
311
COMPUTER FUNDAMENTAL & C PROGRAMMING
312
Multiple Choice
1.
Moving the mouse with the mouse button is called a). Clicking
b) Double Clicking
c) Dragging
d) None of the
above 2.
When you cut or copy text, it is saved in a temporary memory area that is called a). File b) Clipboard
3.
c) Memory
d) none of the above
The ^I keys format the selected text in a)Italic letters
b) Bold letters
c) Underline letters
d) None of the above 4.
The shortcut key for the file, open command in Excel is a) ^S
5.
b)^P
c) ^O
d) ^V.
What are the DTP software programs a) COBOL, FORTRAN and Basic b). HTML, DHTML & XML c) Micro Publisher Linos & PageMaker
d) None of the above
Unit Questions 1.
How will you start Windows
2.
How will you minimize, maximize and Restore a window.
3.
How will you edit a document in write.
4.
Explain short notes on File Manager and Program Manager
5.
What are the Advantages of word processors.
6.
Write down the commands to editing a document in MS- Word
7.
Write down the various numbering styles you can use with the numbered paragraph.
8.
What are the various options you can use while searching for text with the Find command
9.
Explain in brief the use of the table in word.
10.
What is mail merge? Explain the concept of mail merge.
11.
Explain the Day, Month & Year functions in Excel.
12.
Explain statistical, math & financial functions in Excel.
13.
Explain database in a Worksheet Excel
14.
What is Excel? Explain important features of excel.
15.
Write features of DTP software? Explain creating a presentation & printing a presentation.
16.
Explain Slide show & Running a Slide show.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING
Self Assessment Answers Fill in the blanks 1. Window 3.1, Window 95, Window NT 2. Bold 3. Del 4. Document 1 5. Unique 6. Exit 7. Desktop Publishing 8. Presentation True / False 1. True 2. False 3. True 4. True 5. True 6. True 7. False Multiple Choice 1. C 2. B 3. A 4. C 5. C
UNIT- VI Unit questions 1. Explain the structure of C program. 1. Define data types. Explain its types with example. 2. Discuss various types constant with example. 3. Explain in detail about a) Formatted Input /Output statements b) Unformatted Input / Output statement 4. Distinguish between if-else and switch-case statement. 5. Briefly explain conditional or decision making statement. 6. Find the output of the following expressions. a) 4 + 8/2 * 7 + 4
b) 4%3 * 5/2 + (5*5)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
313
COMPUTER FUNDAMENTAL & C PROGRAMMING
314
7. Write a program to find the sum of digits of an integer using while-loop. 8. Write a program to print a name using gets( ) and puts( ) function. 9.
Briefly explain different types operator in C.
UNIT-VII Unit Questions 1. Write a program to print student name and marks using structure. 2. Compare structure and union in C. 3. Explain structure concept in C with suitable example. 4. Define array. Explain different types of arrays with example. 5. Write a program to multiple two matrices using two-dimensional array. 6. Write a program to sort the given n numbers in descending order using array. 7. Discuss the categories of functions used in C. 8. What is called recursion? Explain it needs. 9. Write a program to generate fibonacci series upto n numbers using recursion. 10.Write a program, which performs the following tasks: a) initialize an integer array of 10 elements in main( ) b) pass the entire array to a function modify( ) c) in modify( ) multiply each element of array by 2 d) return the control to main( ) and print the new array elements in main( )
UNIT-VIII
Self Assessment Questions Fill in the blank 1. A string is an ____________ of characters. 2. The __________function is used to copy the contents of one string to another. True / False 1. The length( ) function is used to find the string length. 2. When the compiler assigns a character string to a character array, it
automatically
supplies a null character (â&#x20AC;&#x2DC;\0â&#x20AC;&#x2122;) at the end of the string. Multiple Choice 1.Which is more appropriate for reading in a multi-word string? a) gets( )
b) printf( )
c) scanf( )
d) puts( )
2. The array char name[10] can consist of maximum of a) 10 characters c) 11 characters
b) 9 characters d) none of the above
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
COMPUTER FUNDAMENTAL & C PROGRAMMING Short Answer 1. What is the purpose of strrev( ) function?
Self Assessment Questions Fill in the blank 1. The __________________is used to move the file position to a desired location within the file. 2. Command line argument is a _______________supplied to a program when the program invoked. True / False 1. If a file is opened for writing already exists its contents would be overwritten. 2. The getw and putw are integer-oriented functions Multiple Choice 1. fscanf( ) function is used to reading of the items from a) file
b) keyboard
c) monitor
d) All of the above
Short Answer 1. What is mean by file? ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Summary In the first lesson of this unit we have examined strings, which are nothing but arrays of characters. We have seen how the strings are stored in memory, how initialize strings, and how to access elements of a string using subscript. We learnt two new functions to input and output strings: gets( ) and puts( ); more functions strlen( ), strcpy( ), strcat( ) and strcmp( ) which can manipulate strings. We also explored topic of two-dimensional array of characters. In the second lesson of this unit we have examined pointers, which is the variable contains address. We have seen how the pointers can be processed, and how to use the pointer arithmetic. In the third lesson of this unit we have examined files, which is the collection related information. We have seen how the files accessed in sequential and random access method with the help various file handling functions.
Unit Questions 1.List out various string handling functions. Explain each function with example. 2. How to reading and writing strings in C language? Explain. 3. Define pointers. Explain how are pointers accessed, declared and initialized?
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
315
COMPUTER FUNDAMENTAL & C PROGRAMMING 4. Write a program for arrays with pointers. 5. Discuss the structures & pointers with example program. 6. What are the advantages while using pointers? 7. Explain command line arguments. 8. Discuss random access file with related functions. 9. How the error will be handled during input / output operation? Explain. 10. Discuss reading out of or writing to it is accomplished using the standard I/O routines. Answers for Self Assessment Questions (c) Answer (d) Fill in the blank 1. array of characters
2. strcpy ( )
True / False 1. False
2. True
Multiple Choice 1. c)
2. b)
Short Answer 1. The strrev( ) function is used to reverse a string.
Answer Fill in the blank 1. index, data type 2. call by reference True / False 1. True Multiple Choice 1. b)
2. d)
Short Answer 1. Pointer variables can be used in expressions is called as pointer expression. 2. The operator & immediately preceding a variable returns the address of the variable associated with it. Answer Fill in the blank 1. fseek function
2. parameter
True / False 1. True
2. True
Multiple Choice 1. a) Short Answer 1. A file is a collection of related information, that is permanently stored on the disk and allows us to access and alter the information whenever necessary.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
316
COMPUTER FUNDAMENTAL & C PROGRAMMING
--------------------------------------------THE END-------------------------------------------------------------------
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
317
COMPUTERFUNDAMENTAL & CPROGRAMMI NG
Publ i s he dby
I ns t i t ut eofManage me nt& Te c hni c alSt udi e s Addr e s s:E4 1 , Se c t o r 3 , No i da( U. P) www. i mt s i ns t i t ut e . c o m| Co nt a c t :9 1 +9 2 1 0 9 8 9 8 9 8