Mechanical BE (Computer Programming and Information Technology)

Page 1

I ns t i t ut eofManage me nt & Te c hni c alSt udi e s Comput erPr ogr ammi ng andI nf or mat i onTechnol ogy

500

BACHELORI NMECHANI CALENGI NEERI NG www. i mt s i n s t i t u t e . c o m


IMTS (ISO 9001-2008 Internationally Certified) COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

COMPUTER

PROGRAMMING

&

INFORMATION TECHNOLOGY

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

CONTENTS:

UNIT – I

01-08

Information Technology: Definition, Need and Scope – Impact of Information Technology and Library and Information Services UNIT – II

09-36

Generation of Computers- Storage Devices – Operating Systems – Types- Single – Multiuser – Functions of OS – WINDOWS, LINUX, UNIX. UNIT – III

37-52

Networking: Need- Purpose- Types – LAN, WAN, MAN, TopologiesBus- Star- Ring- Network Servers UNIT – IV

53-78

Network Protocols: TCP/IP, IP, HTTP – Hypertext – HypermediaMultimedia – ISDN- OSI. Accessories – Bridges – Routers - Switches UNIT – V

79-105

Internet: Historical Development – Types of Connectivity- ISP – Web Resources – Web Portals – Browsers- Search Engines – Internet Tools - FTP UNIT-VI

106-117

Principles of Object-Oriented Programming: Software Evolution – A Look at Procedure-Oriented Programming – Object Oriented Programming Paradigm – Basic Concepts of Object Oriented Programming – Benefits of OOP – Object-Oriented Languages – Applications of OOP.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


UNIT-VII

118-155

Beginning with C++: What is C++ - Applications of C++ - Structure of C++ Program – A Simple C++ Program – More C++ Statements – An Example with class.

Tokens, Expressions and Control Structures: Introduction –

Tokens – Keywords – Identifiers and Constants – Basic Data Types –Userdefined Data Types – Derived Data Types – Symbolic Constants – Type Compatibility – Declaration of Variables – Dynamic Initialization of Variables – Reference Variables – Operators in C++ - Scope Resolution Operator – Member Dereferencing Operators – Memory Management Operators – Manipulators – Type Cast Operators – Expressions and Their Types – Special Assignment Expressions – Implicit Conversions – Operator Overloading – Operator Precedence – Control Structures – Functions in C++: Introduction – The Main Function – Function Prototyping – Call By Reference – Return By Reference – Inline Functions – Default Arguments – Const Arguments – Function Overloading – Friend and Virtual Functions. UNIT-VIII

`

156-177

Classes and Objects: Introduction – Specifying A Class – Defining Member Functions – A C++ Program with Class – Making an Outside Function Inline – Nesting of Member Functions – Private Member Functions – Arrays within a Class – Memory Allocation For Objects – Static Data Members - Static Member Functions - Arrays Of Objects – Objects as Function arguments – Friendly Functions – Returning Objects – Const Member Functions – Pointers to Member – Local Classes. Constructors and Destructors: Introduction – Constructors - Parameterized Constructors- Multiple Constructors in a Class – Constructors with Default Arguments –Dynamic Initialization of Objects – Copy Constructor – Dynamic Constructors – Constructing Two Dimensional Arrays – Const Objects – Destructors . UNIT – IX

178-231

Operator Overloading and Type Conversions: Introduction – Defining Operator Overloading – Overloading Unary Operators - Overloading Binary Operators -Overloading Binary Operators using Friends - Manipulation of FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


strings using Operators –Rules for Overloading Operators – Type Conversions – Inheritance Extending Class : Introduction - Defined Derived Classes – Single Inheritance – Making A Private Inheritable - Multilevel Inheritance – Multiple Inheritance – Hierarchical Inheritance –Hybrid Inheritance – Virtual Base Classes – Abstract Classes

- Constructors in Derived Classes

-

Member Classes : Nesting of Classes. Pointers, Virtual Functions and Polymorphism : Introduction – Pointers to Objects - This pointer – Pointer to Derived Classes – Virtual Functions – Pure Virtual Functions. UNIT –X

232-245

Managing Console I/O Operations: Introduction – C++ Streams – C++ Stream Classes – Unformatted I/O Operations – Formatted Console I/O Operations – Managing Output with Manipulators. Working With Files: Introduction – Classes For File Stream Operations – Opening and Closing a File – Detecting End of a File – More about Open(): File Modes – File Pointers and their Manipulations - Sequential Input and Output Operations – Updating a File: Random access – Error handling During File Operations – Command Line Arguments. Templates: Introduction – Class Templates – Class Templates With Multiple Parameters – Function Templates – Function Templates with Multiple Parameters – Overloading of Template Functions – Member Function Templates Exception Handling: Introduction – Basics of Exception Handling – Exception Handling Mechanism – Throwing Mechanism – Catching Mechanism – Rethrowing An Exception – Specifying Exceptions.

UNIT QUESTIONS-

246-249

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFROMATION TECHNOLOGY

1

UNIT I INFORMATION TECHNOLOGY 1.1 1.2 1.3 1.4 1.5 1.6 1.7

Objectives What is Information Information Science as Discipline Information Technology Impact of Information Technology Other branches of Information Technology References

1.1 OBJECTIVES This lesson gives a brief description about Information Technology. After completing this lesson one should be able to 

Understand the Information Technology

Describe the need of Information Technology

Impact of Information Technology on Library and information Science

Different Branches of Information Technology

1.2 WHAT IS INFORMATION Information is an essential ingredient in decision making and the need for improved information systems in recent years has been made critical by the steady growth in size and complexity of organization and data. Information is an all pervasive resource in every human activity and helps in establishing a continuum from the past to the present and ultimately to the future. The natural consequence of all activities tends to generate large amounts of data/information. This information is recorded and stored only when it is expected to have potential importance. Thus Information is some meaningful message recorded in conventional or nonconventional media and stored and processed by systems and services with a view to providing a more or less permanent memory of the messages and their dissemination to users. Information has a synergizing effect in several areas of human activities. These can be categorized broadly as 

Research and Development activities, particularly, knowledge creation, innovation, invention, diffusion, dissemination, distribution use, technology transfer, adaptation and product development.


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

2

Educational – learning and teaching at all level, both academic and professional publishing.

Economic – employment patterns, income, prices, value, inflation, growth dynamics, development at macro and micro-levels, etc.

Political – political organizations, political systems bureaucratic systems, activities, levels of power devolution, regional and institutional development.

Social – population pressure, urbanization, rural infrastructural development, mobility group dynamics, etc.

1.3 INFORMATION SCIENCE AS A DISCIPLINE Information science is a discipline that deals with the processes of storing and transferring information. It attempts to bring together concepts and methods from various disciplines such as library science, computer sciences and engineering, linguistics, psychology, and other technologies in order to develop techniques and devices to aid in the handling — that is, in the collection, organization, storage, retrieval, interpretation, and use — of information. The transfer of information through time requires the existence of some storage medium, which is designated a document — hence the term documentation. The discipline grew in response to the growth of the periodical and the journal as the prevalent media for scientific reports. Whereas books required control through cataloguing and classification, periodicals required indexes and abstracts that would bring together for the researcher primary information originally published in divergent sources. 1.4 INFORMATION TECHNOLOGY Information technology has made the major contribution of opening up the use of computer technology to people other than computer professionals. Interactive applications in the office and home have been made possible by the development of easy-to-use software products for the creation, maintenance, manipulation, and querying of files and records. The database has become a central organizing framework for many information systems, taking advantage of the concept of data independence, which allows data sharing among diverse applications. Database management system (DBMS) software today incorporates high-level programming facilities that do not require one to specify in detail how the data should be processed. Modern information systems also bring new efficiency to the organization, retrieval, and dissemination of recorded information. The control of the world's information store has been truly revolutionized, revealing its diversity in hitherto unattainable detail. Information

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

3

services provide mechanisms to locate documents nearly instantaneously and to copy and move them electronically. New digital storage technologies make it economical for some to obtain for personal possession those collections equivalent to the holdings of entire libraries and archives. Alternately, access to information resources on electronic networks permits the accumulation of highly individualized personal or corporate collections in analog or digital form or a combination of both. As the imprint of technology expands, some of the fundamental concepts of the field, which often took centuries to evolve, are strained. For instance, information technology forces an extension of the traditional concept of the document as a fixed, printed object to include bodies of multimedia information. Because of their digital form, these objects are easy to manipulate; they are split into parts, recombined with others, reformatted from one medium to another, annotated in real time by people or machines, and readied for display in many different formats on various devices. Control of these "living" documents, which mimic human association and processing of ideas and are expected to become one of the most common units of the digital information universe, is but one of the challenges for the emerging virtual library of humankind.

1.5 IMPACT OF INFORMATION TECHNOLOGY An equally significant new dimension of modern information systems lies in their ability to manipulate information automatically. This capability is the result of representing symbolic information in digital form. Computer-based information systems are able to perform calculations, analyses, classifications, and correlations at levels of complexity and efficiency far exceeding human capabilities. They can simulate the performance of logical and mathematical models of physical processes and situations under diverse conditions. Information systems also have begun to mimic human cognitive processes: deductive inference in expert systems, contextual analysis in natural-language processing, and analogical and intuitive reasoning in information retrieval. Powerful information-transforming technologies now available or under development — data or text to graphics, speech to printed text, one natural language to another — broaden the availability of information and enhance human problem-solving capabilities. Computer visualization is dramatically altering methods of data interpretation by scientists; geographic information systems help drivers of the latest automobiles navigate cities; and interactive applications of networked multimedia computers may, for some, replace newspapers, compete with commercial broadcast television, and give new dimensions to the future of education and training at all levels of society.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

4

Information systems applications are motivated by a desire to augment the mental information-processing functions of humans or to find adequate substitutes for them. Their effects have already been felt prominently in three domains: the economy, the governance of society, and the milieu of individual existence. Information systems may be divided into two categories: 

organizational systems and

public information utilities.

Information systems in formal organizations may be further distinguished according to their main purpose: support of managerial and administrative functions or support of operations and services. The former serve internal functions of the organizations, while the latter support the purposes for which these organizations exist. 

Management-oriented information systems

Administration-oriented information systems

Service-oriented information systems

Transaction-processing systems

Expert systems

1.5.1 Management-oriented information systems The most important functions that top executives perform include setting policies, planning, and preparing budgets. Depending on the nature of the organization's business, such indicators may relate to the status of high-priority programmes; health of the economy; inventory; and cash levels; performance of financial markets; relevant efforts of competitors; utilization of manpower; legislative events; and so forth. 1.5.2 Administration-oriented information systems Administrative functions in formal organizations have as their objective the husbanding and optimization of corporate resources — namely, employees and their activities, inventories of materials and equipment, facilities, and finances. Administrative information systems support this objective. Commonly called management information systems (MIS), they focus primarily on resource administration and provide top management with reports of aggregate data. Executive information systems may be viewed as an evolution of administrative information systems in the direction of strategic tracking, modelling, and decision making.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

5

Typically, administrative information systems consist of a number of modules, each supporting a particular function. The modules share a common database whose contents may, however, be distributed over a number of machines and locations. Financial information systems have evolved from the initial applications of punched cards before World War II to integrated accounting and finance systems that cover general accounting, accounts receivable and payable, payroll, purchasing, inventory control, and financial statements such as balance sheets. Functionally close to payroll systems are personnel information systems, which support the administration of the organization's human resources. Job and salary histories, inventory of skills, performance reviews, and other types of personnel data are combined in the database to assist personnel administration, explore potential effects of reorganization or new salary scales (or changes in benefits), and match job requirements with skills. 1.5.3 Service-oriented information systems Such information systems provide support for the operations or services that organizations perform for society. The systems are vertically oriented to specific sectors and industries

(manufacturing,

financial

services,

publishing,

education,

health,

and

entertainment). Rather than addressing management and administrative functions, they support activities and processes that are the reason for an organization's existence —in most cases, some kind of manufacturing activity or the rendering of services. Systems of this kind vary greatly, but they tend to fall into three main types: manufacturing, transaction, and expert systems. The conceptual goal of modern factories is computer-integrated manufacturing (CIM). The phrase denotes data-driven automation that affects all components of the manufacturing enterprise: design and development engineering, manufacturing, marketing and sales, and field support and service. Computer-aided design (CAD) systems were first applied in the electronics industry. Today they feature three-dimensional modelling techniques for drafting and manipulating solid objects on the screen and for deriving specifications for programmes to drive numerical-control machines. Once a product is designed, its production process can be outlined using computer-aided process planning (CAPP) systems that help to select sequences of operations and machining conditions. Models of the manufacturing system can be simulated by computers before they are built. The basic manufacturing functions — machining, forming, joining, assembly, and inspection — are supported by computer-aided manufacturing (CAM) systems and automated materials-handling systems. Inventory control systems seek to maintain an optimal stock of parts and materials by tracking inventory movement, forecasting requirements, and initiating procurement orders.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

6

1.5.4 Transaction-processing systems In non-manufacturing service organizations the prevalent type of information system supports transaction processing. Teleprocessing transaction systems constitute the foundation of service industries such as banking, insurance, securities, transportation, and libraries. They are replacing the trading floor of the world's major stock exchanges, linking the latter via online telecommunications into a global financial market. Again, the core of a transaction system is its integrated database. The focus of the system is the recipient of services rather than the system operator. Because of this, a local travel agent is able to plan the complete itinerary of a traveller — including reservations for airlines, hotels, rental cars, cultural and sports performances, and even restaurants, on any continent — and to tailor these to the traveller's schedule and budget. 1.5.5 Expert systems A relatively new category of service-oriented information systems is the expert system, so called because its database stores a description of decision-making skills of human experts in some narrow domain of performance, such as medical image interpretation, taxation, brickwork design, configuration of computer system hardware, troubleshooting malfunctioning equipment, or beer brewing. The motivation for constructing expert systems is the desire to replicate the scarce, unstructured, and perhaps poorly documented empirical knowledge of specialists so that it can be readily used by others. Expert systems have three components: 1. a software interface through which the user formulates queries by which the expert system solicits further information from the user and by which it explains to the user the reasoning process employed to arrive at an answer, 2. a database (called the knowledge base) consisting of axioms (facts) and rules for making inferences from these facts, and 3. a computer programme (dubbed the inference engine) that executes the inference-making process. The building of information systems falls within the domain of engineering. As is true with other engineering disciplines, the nature and tools of information systems engineering are evolving owing to both technological developments and better perceptions of societal needs for information services. Early information systems were designed to be operated by information professionals, and they frequently did not attain their stated social purpose. Modern information systems are increasingly used by persons who have little or no previous

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

7

hands-on experience with information technology but who possess a much better perception about what this technology should accomplish in their professional and personal environments. A correct understanding of the requirements, preferences, and "information styles" of these end users is crucial to the design and success of today's information systems. 1.6 INFORMATION TECHNOLOGY BRANCHES Internet is a network connecting many computer networks and based on a common addressing system and communications protocol called TCP/IP (Transmission Control Protocol/Internet Protocol). From its creation in 1983 it grew rapidly beyond its largely academic origin into an increasingly commercial and popular medium. Electronic mail (e-mail) is messages transmitted and received by digital computers through a network. An e-mail system allows computer users on a network to send text, graphics, and sometimes sounds and animated images to other users. Cryptology (from the Greek kryptos, "hidden", and logos, "word") is the science of secure (generally secret) communications. The need to protect sensitive data ( for national security) has led to extensive research in cryptography and the development of encryption standards for providing a high level of confidence that the data is safe from decoding by even the most powerful computer attacks. This security obtains from legitimate users, the transmitter and the receiver, being able to transform information into a cipher by virtue of a key — that is, a piece of information known only to them. Cryptography (from the Greek kryptos and graphein, "to write"), is the study of the principles and techniques by which information can be concealed in ciphers and later revealed by legitimate users employing the secret key, but in which it is either impossible or computationally infeasible for an unauthorized person to do so. Cryptanalysis (from the Greek kryptos and analyein, "to loosen" or "to untie") is the science (and art) of recovering information from ciphers without knowledge of the key. Cryptography was concerned initially with providing secrecy for written messages. Its principles apply equally well, however, to securing data flow between computers, to digitized speech, and to encrypting facsimile and television signals. Most communications satellites, for example, routinely encrypt the data flow to and from ground stations to provide both privacy and security for their subscribers. Because of this broadened interpretation of cryptography, the field of cryptanalysis has also been enlarged to include the recovery of information from ciphers concealing any form of data.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

8

Applied computer technologies and more recently, the theoretical areas of study of information science have since permeated many other disciplines and have even been appropriated by new fields, each preferring a more descriptive designation of its subject domain. The institutionalization of information science as a discrete discipline thus has not occurred, and the number of its scientist-practitioners is low. Computer science and engineering tend to absorb the theory- and technology-oriented subjects of the field, and management science tends to absorb the information systems subjects. Hundreds of professional associations do exist that are concerned with information-related disciplines, providing a forum where people can exchange ideas about information processing. The proliferation of automatic data-logging devices in scientific laboratories, hospitals, transportation, and many other areas has created a huge body of primary data for subsequent analysis. Machines even generate new information: original musical scores are now produced by computers, as are graphics and video materials. Electronic professional workstations can be programmed to carry out any of a variety of functions. Some of those that handle word processing not only automatically look for spelling and punctuation errors but check grammar, diction, and style as well; they are able to suggest alternative word usage and rephrase sentences to improve their readability. Machines produce modified versions of recorded information and translate documents into other languages. 1.8 CONCLUSION Thus Information Technology provides a dominating face in each and every profession. The boundaries of Information Technology gets expanded from Science, Medical, Engineering, Technology to Society and find intrusion in day to day offers of the human life cycle.

It created an instinct in such a manner that now-a-days, most of the computer

illiterates rush to learn the development of Information Technology and to finding the possibilities of applying the same in their day to day activities.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

9

UNIT II OVER VIEW OF COMPUTER TECHNOLOGY 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10

Objectives Introduction to Computers Generation of Computers Storage Devices Software and its types Operating system – types and functionality Unix Linux Windows References

2.1 OBJECTIVES After studying this lesson, you should be able to 

Understand the computer technology

Describe the various storage devices

What is Operating System

Different types of Operating System

Functionality of Windows, Unix, Linux

2.2 INTRODUCTION TO COMPUTERS

A computer is an electronic machine. It can do variety of jobs at a faster rate. It is being used in many places, like offices, industries, medical centres, banks, schools etc. It is basically a calculating machine.

It is capable of performing the operations like addition,

multiplication, subtraction, division etc. The computer is also capable of storing information which can be used for the future use.

2.2.1Definition for Computer:

Computer is a machine which is able to accept data in a prescribed form, process the data and supply the results of the processing in a specified format as information or as signals for controlling automatically some other process or function. The word computer has been derived from the Latin Word “computare” which means “to calculate”. The word Computer according to the Oxford English Dictionary is a “automatic

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

10

electronic apparatus for making calculations or controlling operations that are expressible in numerical or logical terms.”

Computers can also be defined as under: 

Computer is an electronic data processing device.

Computer is a machine for storing, communicating and manipulating information.

2.3 CLASSIFICATION OF COMPUTER Functions Analog Digital Hybrid Optical Quantum

Size & Capacity Embedded Mainframe Mini Computer Micro Computer Personal Computer PC PC/XT PC/AT PS/2 PC Clone Portable Laptop Note Book Palmtop SUPER COMPUTER

Generation FIRST SECOND THIRD FORTH FIFTH

2.3.1 COMPUTERS BASED ON FUNCTION Generally computers are classified into four broad categories based on their functions. They are

1. ANALOG COMPUTERS 2. DIGITAL COMPUTERS 3. HYBRID COMPUTERS 4. OPTICAL COMPUTERS 2.3.1.1 ANALOG COMPUTERS The analog machine does not compute directly with numbers, rather it measures physical measurements. (eg. Pressure, Temperature, voltage etc.). Speedometer in a vehicle, and fluid flow meters are some of the good examples of this kind. 2.3.1.2 DIGITAL COMPUTERS. It operates directly on numbers expressed as digits in the familiar decimal system or some other numbering system. It gives results in greater accuracy. It can produce results with

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

11

10000th decimal places in a short period. According to the purpose of digital computers we can classify them into two types.

(i) Special purpose computers (ii) General purpose computers

(i) Special purpose computers.

As the very name implies, it is designed to perform a specific task. We cannot use it for some other purpose. Computers installed in process control equipments; computers used in pilot cabins are some of the examples of this kind.

(ii) General purpose computers. It

has the ability to store different programs of instructions and thus to perform a

variety of operations.

It is used for both scientific and business applications.

Now it is

available for reduced price, and used commonly.

2.3.1.3 HYBRID COMPUTERS Machines that combine both analog and digital capabilities are called Hybrid computers.

Much business, scientific and Industrial computer applications rely on the

combination of analog and digital devices. The ultrasonic diagnostic system in a hospital is a good example of this system.

Analog signals generated by the Scanner as continuous

voltage are `digitized' and supplied to a small digital computer that monitors patient’s condition.

2.3.1.4 OPTICAL COMPUTERS A super high speed computer which will work on optical system i.e light signals.

2.4 GENERATION OF COMPUTERS The generation of computers can be categorized as Pre Generation and Generation Period. 2.4.1 PRE GENERATION STAGE The development of computers to Pre generation stage comprises of eight major stages of developments. 1. ABACUS

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

Used mainly to add and substract numbers

First used by the Babylonians.

Used in many forms. i.e. Pebble tray, Knotted strings, Frame of beads.

Frame of beads was the most popular form.

Chinese perfected it.

This form is used in Japan & China. Even to-day it is used in Japan.

12

2. NAPIER'S BONES 

Used for multiplying any two selected numbers.

Developed by John Napier, a Scottish mathematician.

Series of rods carved out of bones were used.

11 rods were used. Each rod is divided into nine parts. Each part is divided into two half’s.

3. PASCALINE MACHINE 

Devised by Blaise Pascal, a French mathematician.

Could perform only addition and subtraction.

4. DIFFERENCE ENGINE 

Designed by Charles Babbage.

Calculate the results of two 28 digits number.

5. ANALYTICAL ENGINE 

Charles Babbage designed this machine.

This machine was not fully build.

This mechanical computer contains five components. They are: 1. a store to hold numbers 2. an arithmetic unit to perform arithmetic operations 3. a control unit to co-ordinate the various activities in a sequence. 4. an input device to transfer both numbers and instructions into the machine. 5. an output device to display the results.

It is a first scale model for the present day computers

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

13

6. CENSUS TABULATOR [PUNCHED CARD] 

Designed by Herman Hollerith.

Data are recorded in punched holes.

This is used to record and tabulate the US census.

7. MARK - I COMPUTER - Built by Howard H.Aiken. Supported by IBM. 8. ENIAC - Stands for Electronic Numeric Integrator And Calculator 

Designed by Eckert and Mauckly.

18,000 vacuum tubes were used in their model.

It generates over heat.

It could do 5000 additions per second.

2.4. 2 GENERATION OF COMPUTERS GENERATION FIRST

SECOND

THIRD

FOURTH

FIFTH

CHARACTERISTICS Vacuum tubes for internal operation Low primary memory Magnetic drums & Punched cards Slow input, processing and output Low level language for programming Heat and maintenance problem eg. - EDSAC, EDVAC, LEO, UNIVAC are different computer Transistor for internal operations Primary memory: Magnetic core memory Magnetic tapes and disks were used Increase in processing speed Use of high level language started Reduction in heat and reliability eg. - IBM 7000, LEO MARK III, ATLAS Integrated circuit [IC] for operation Increased Primary memory capacity Increased speed and reliability Increased use in computers Reduction in size and cost. eg. - IBM 360, ICL 1900. Large Scale Integration [LSI], Very Large Scale Integration [VLSI] for internal operation. Introduction microprocessors Increase in speed, power and storage eg.. - DEC 10, Star 1000, PDP 11 Super Large Scale Integration [SLSI] technology Parallel processing Artificial Intelligence[AI] & Expert Systems Robotics, Multimedia etc

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 2.4. 3 COMPUTER BASED ON SIZE DESCRIPTION FEATURES MAINFRAME very large in size used for general purpose very extensive Input/ output facilities MINICOMPUTER

smaller than mainframe greater than micro performs better than mainframe

MICROCOMPUTER

Microprocessors are used reduction in size Special purpose computers

SUPERCOMPUTER

VLSI technology Speed of operation more eg. 10000M flops (floating operations)

14

COMPUTER NAME IBM 360, IBM 370 ICL 1900 ICL 2900 DEC 10 PDP11 VAX range

APPLE Commodore PET Model 4004 CRAY Cyber PARAM 2000

2.5 INPUT, OUTPUT & I/O DEVICE INPUT DEVICE Punched card Paper tapes Key Board MICR Mouse Optical Mark reader Optical Character Recogniser Light Pen Joy stick Track Ball Scanners Touch Screen

OUTPUT DEVICE VDU Printer Plotter COM Teledata/View data system

I/O DEVICE Magnetic tapes Magnetic Disks Floppy Disks Disk Pack Magnetic cards & OCR strips Magnetic drum Thumb drives Optical Storage devices - CD-Rom - DVD Technology

2.6 DIRECT ACCESS STORAGE DEVICES Storage Devices also called Direct Access Storage Devices and Secondary Access Storage Devices or Auxiliary Storage Devices Some of the storage devices are used for both offline and online purpose. These storage devices can further be categoried as Magnetic Storage devices and Opticacl Storage Devices. They are: 

Magnetic drums.

Magnetic disks.

Magnetic cards and strips.

2.6.1 MAGNETIC DRUMS

Magnetic drum is a cylinder that has an outer surface plated with a metallic magnetizable film. A motor rotates the drum on its axis at a constant speed. Data are

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

15

recorded on the rotating drum and read from the drum by read-write head. We can also erase the older data and write a new one on the surface.

2.6.2 MAGNETIC DISKS

Magnetic disks were invented to overcome the sequential processing requirements of magnetic tapes. They are the most popular direct access storage medium. They are made of thin metal plates coated on both sides with a magnetizable recording material. These disks may remain permanently fixed in side the cabinet.

This is called Hard disk or Winchester

disk. It can hold Memory capacity from 20 mb to 400 mb. The other one is portable and removable type. This is called Floppy Diskette.

2.6.3 FLOPPY DISKS

Floppy disks were introduced in early 1970's and have become very popular with the invention of the microcomputer. A diskette is permanently covered by a plastic envelope. The envelope is rigid and smoothly lined and serves as a protective covering for the diskette. Data are recorded in specific locations as magnetized spots in these diskettes.

Once

recorded, the stored data remain intact even if the power fails in the system. This disk is placed on a vertical rotating shaft and rotates at constant speed. The read-write head above this disk may read or write according to our instructions.

Varieties of Floppy disks Floppy disk size 1 8 inch, low 2 5 1/4 inch, low 3 5 1/4 inch, high 4 3 1/2 inch, low 5 3 1/2 inch, high 6 3 1/2 inch, extended

Capacity Low capacity, 128 K Low capacity, 360 K, or DS/DD High capacity, high-density, 1.2 MB Low capacity, 720 K, or DS/DD High capacity, high-density, 1.4 MB Extended capacity, 2.8 MB

2.6.4 MAGNETIC CARDS AND STRIPS A magnetic card is considered to be a length of flexible plastic material upon which short strips of magnetic tape have been mounted. A number of cards may be placed in a cartridge which, like disk packs, may be removed and stored offline.

Cards and strips

equipment has high storage capacity and data are erasable, but access speed is slow when compared with drums and disks.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

16

2.6.4.1 THUMB DRIVE/PEN DRIVE

Towards the development of magnetic strips, today there exist a pen drive. Sometime it is also termed as thumb drive. These thumb drives are having a minimum storage capacity of 256 MB to 10 GB. These thumb drives are easily portable and attachable to any system with USB port. This technology certainly replace the concept of hard disk shortly.

2.6.5 DISK PACK A disk Pack consists of a number of inseparable disks joined together as a single unit, the number usually being either 6 or 11.

Each disk can store 30 - 60 million characters and

the capacity of a disk pack is around 200 million characters. But for the outer-most two surfaces, all the other surfaces in a pack are used for recording. So in a 6 disk pack, there are 10 recording surfaces [(6 x 2) - 2] and in a 11 disk pack there are 20 recording surfaces [(11 x 2) - 2].

2.6.6. FLOPTICAL DISK & DRIVE Floptical disk or drive which uses the optical principle of storage rather than the magnetic will become a new standard. Floptical drives cost nearly 10 times as much as the conventional 3.5 inch variety - but the flopical disk too store about 10 times as much.

2.6.7 OPTICAL STORAGE DEVICES 2.6.7.1 CD ROM CD ROM is a powerful peripheral for personal computers emerging in the PC marked in 1985 and gaining momentum ever since.

CD ROM or Compact Disk - Read Only Memory, is a significant new technology that enables millions of bytes of data to be stored on an ordinary compact disc. CD ROM provides numerous benefits compared with other form of information storage and retrieval.

CD ROM discs are circular, 120mm diameter objects made from bulletproof polycarbonate, with a shiny under layer that stores digital information. Only one side of the disc is used for data storage.

CD ROM disc can store up to 660 mega bytes of information. This is about 260,000 pages of text or 74 minutes of music or video.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

17

Another way of looking at the storage capacity is to compare CD ROM to its ubiquitous relative, the floppy disc. Squeezing 660,000 bytes on to a single floppy disc using the 9 tracks per inch format of a standard MS DOS 360 k diskette would require a diskette approximately 800 ft. across. ADVANTAGES OF CD-ROM 1.

Permanent storage - it cannot be erased, scratched or mutilated.

2.

High density storage - more than 2,50,000 pages can be recorded

3.

The drive head does not touch the plate when scanned for retrieval. Hence the drive head will not crash or no wear and tear.

4.

Physically portable and can be mailed in cover.

5.

Data recorded can easily be transferred to any other medium through PC.

6.

Low cost.

7.

Text, Image and Multimedia based information storage and retrieval gets gaining momentum.

DISADVANTAGES 1.

As the name implies the discs are read only, data cannot be written into them. For retrieval systems this may, however, be an advantage as users are prevented from accidentally or deliberately erasing data.

2.

The information on the discs cannot be as current as is possible with an on-line retrieval system using magnetic storage.

3.

Access time as compared with hard magnetic disc is more

4.

The systems single-user, the data base(s) on a disc may be accessed only by one user.

5.

Although the capacity is large, it is still not nearly large enough for the largest data bases.

2.6.7.2 DIGITAL VIDEO TECHNOLOGY DVD, which is once stood for Digital Video Disc and later Digital Versatile Disc, is now just "DVD". It is no longer an acronym that it once was. DVD is today's premiere format for video, audio, and data storage. The Disc As a disc, DVD looks very much like the CD. Both are shiny discs that are 4 3/4 inches (12.0 cm) in diameter. Both are optical formats containing digital information. This means a laser pickup is used to read the digital data encoded on the disc. But that's where the similarities end.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

18

DVD is actually a family of physical and application formats. As far as the physical format, DVD can hold anywhere from seven times to over 25 times the digital data on a CD, depending on the disc's construction. Additionally, the DVD may be used for video, audio, or data storage applications as a DVD-Video, DVD-Audio, or DVD-ROM application format, respectively.

DVD Physical Specifications Specification Diameter Thickness Numerical aperture Readout wavelength Track pitch Pit length Capacity (per side) Scanning speed Rotational speed (1x) Reflectivity User data rate (1x)

CD 12 cm 1.2 mm .60 780nm 1.6 micrometers

DVD 12 cm 1.2 mm (.6 mm x2) .38 to .45 650 or 635 nm .74 micrometers .400 to 1.866 micrometers .440 to 2.054 .822 to 3.560 micrometers micrometers 4.7 GB (single layer), 8.5 GB (dual 650 MB layers) 1.2 to 1.4 m/s 3.49 m/s 3.84 m/s 200 to 500 rpm 570 to 1600 rpm 70% minimum 45 to 85% 1.41 Mbps 11.08 Mbps Physical Format

There are three reasons for DVD's greater data capacity: 1. Smaller pit size 2. Tighter track spacing 3. Multiple layer capability Application Formats The various application formats of DVD are:

DVD-Video, DVD-Audio, and DVD-ROM.

Each of these three application formats are based on the physical specifications are discussed.

DVD-Video. The DVD-Video format is by far the most widely known, as it is the first DVD application format to really take off. As the name indicates, DVD-Video is principally a video and audio format used for movies, music concert videos, and other video-based

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

19

programming. This format first emerged in the spring of 1997 and is now considered mainstream.

DVD-Audio. The DVD-Audio format features high-resolution 2-channel stereo and multi-channel (up to 6 discrete channels of) audio. The format made its debut much later, in the summer of 2000, due to delay in squaring away the copy protection issue. To date, DVDAudio titles are still very few in number and have not reach mainstream status, even though DVD-Audio/Video players are numerous and widely available. DVD-ROM. DVD-ROM is a data storage format just like CD-ROM. DVD-ROMs can only be used in DVD-ROM drives in computer systems. They allow for data archival and mass storage, as well as interactive and/or web-based content.

It should be noted that a DVD disc might contain any combination of DVD-Video, DVD-Audio, and/or DVD-ROM application content. For example, some DVD movie titles contain DVD-ROM content portion on the same disc as the movie. This DVD-ROM content provides additional interactive and web-based content that can be accessed when using a computer with a DVD-ROM drive. As another example, some DVD-Audio titles are actually DVD-Audio/Video discs that actually have additional DVD-Video content that provide videobased bonus programming such as artist interviews, music videos, or a Dolby Digital and/or DTS surround soundtrack that can be played back by any DVD-Video player (in conjunction with a 5.1-channel surround sound home theater system). Recordable DVD Formats?

DVD is actually a family of formats. As such, the DVD format also includes recordable formats. The DVD specifications define three different recordable DVD formats: 

DVD-R (and DVD-RW, the re-writeable version of DVD-R, like CD-RW is to CD-R)

DVD+R (and DVD+RW, the re-writeable version of DVD+R)

DVD-RAM (re-writeable by definition)

Each of these recordable DVD formats are slightly different. Their differences are enough to create mutually incompatibility issues. In other words, one recordable format can not be used interchangeably with the other two recordable formats. And one of these recordable formats is not even compatible with most of the 17 million existing DVD-Video players. The benefits of DVD The major advantages are: 

Pure Digital Format

Improved Picture Quality and Color

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

State-of-the-Art Surround Sound

Multiple Language Dialogues and Soundtracks

Multiple Angles Option

Random Access To Scenes

Durable Disc Format

20

2.7 WHAT IS SOFTWARE? Software is the brain of the operation. The instruction, which tell the computer what to do, how to act. SOFTWARE

SYSTEM SOFTWARE

APPLICATION SOFTWARE (PROGRAMMING LANGUAGE)

OPERATING SYSTEM TRANSLATORS & CONTROL PROGRAMS

ASSEMBLERS COMPILERS INTERPRETERS | | | | | | COMMERCIAL SCIENTIFIC SPECIAL COMMAND UTILITIES LANGUAGE LANGUAGE LANGUAGE LANGUAGE eg COBOL eg. BASIC eg. PL/1 eg. JCL FORTRAN PASCAL | DBMS

| | | TEXT SPREED GRAPHICS EDITOR SHEET eg. dBASE eg. WS eg.LOTUS eg. AUTOCAD

2.7.1 PROGRAMMING LANGUAGES As mentioned earlier, programming languages are mainly of two types: (a) LOW-LEVEL LANGUAGES These languages are machine-oriented and hence are called low-level languages. Assembly language is an example of a low level language.

(b) HIGH-LEVEL LANGUAGES These languages have been developed to make programming easier. languages are very close to the English language and

are more sophisticated.

These

They move

away from machine dependence, unlike the low-level languages. They have an extensive

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY vocabulary of words, symbols and sentences.

21

All instructions have to be written adhering to

some rules known as the syntax of the language. These correspond to the grammatical rules in English.

The high-level languages are also translated into the machine code and the

translators used may be Compilers or Interpreters. There are many types of high-level languages. (i)

COMMERCIAL LANGUAGES:

As their name suggests,

well suited for all commercial applications.

these languages are

The most common commercial language,

introduced in 1961, is COBOL which means COmmon Business Oriented Language. This language is very close to the English language and can be understood by all.

(ii)

SCIENTIFIC LANGUAGES: These high-level languages are used for scientific

and engineering purposes.

They have very powerful mathematical facilities.

FORTRAN,

ALGOL & BASIC are examples of scientific languages.

(iii)

SPECIAL-PURPOSE LANGUAGES:

These languages cater to some specific

problems like simulation and control of experiments. eg. Ada

(iv) COMMAND LANGUAGES FOR OPERATING SYSTEMS: These languages are required to control the operation of the computer system.

An example of the command

language is JCL (Job Control Language).

(v)

MULTIPURPOSE LANGUAGES: These languages have a very wide range of

applications and can be used for scientific, engineering, commercial and other purposes. eg. PL/1, PASCAL

2.8 WHAT IS OPERATING SYSTEM? Operating System is a computer program that manages the resources of a computer. In other words Operating system is a program or set of programs which co-ordinates the running of all the units of a computer, and provides communication between the computer and the person operating it.

It reads the command from keyboard, mouse; displays the information on screen and prints to a printer.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

22

2.8.1 FUNCTIONS OF AN OPERATING SYSTEM

The functions of the operating system include assignment of system resources; scheduling of resources and jobs, and monitoring activities of a computer system. It carries out following four major management functions.

1. Task management 2. Data management 3. Program management 4. System management

2.9 DIFFERENT TYPES OF OPERATING SYSTEMS

Generally Operating systems are two different types. They are 

Single User Operating system

Multi User operating system

Single User Operating System It is a single user single programming system eg. MSDOS, PCDOS, CP/M

Multi User Operating System It is a multi-user, multi programming and multitasking system eg. UNIX, ZENIX, OS/2

Different operating systems and the descriptions are given below: S.No. 1

OPERATING SYSTEM MSDOS, PCDOS

2 3 4 5 6

CP/M UNIX APPLE DOS, APPLE PRODOS XENIX, VENIX TRS-DOS

7 8 9 10 11

Amiga DOS MVS,OS/VS,VM GCOS VAX/VMS AOS/VS

DESCRIPTION Most common PC operating system 8 bit Microcomputer OS Multiuser multitasking OS Apple II series of computer Two Unix like Operating System Tandy’s TRS-80 series micro computer Commodore Amiga IBM Mainframe Honeywell mainframe DEC’s VAX series Data general minicomputer

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

23

WHAT IS FILENAME? If any information is stored in the computer it is to be given a specific name for identifying the information. This specific name is known as FILENAME.

Single User Operating Systems filename mostly comprises of 11 characters. For example in the case of MSDOS File name should not exceed 11 characters.

These 11

characters forms two part. The first part is known as User defined which comprises of 8 characters. The second part is known as file extension which comprises of 3 characters. The first part and second part is separated by a DOT. eg. RAMAN.TXT. It also holds good for MSDOS commands and the commands are stored in the form of file.

Multi User Operating Systems file name mostly comprises of 14 characters. For example In UNIX, Sco Unix one can have file name up to the maximum of 14 characters. The features of file name are 

Any amounts of file extensions are allowed.

File names are case sensitive.

File extension depends on Programming languages

Any character can be used as file name.

File name must be in the form of string.

It is not advisable to begin the file name with period ie. Dot. The file name begins with “dot” then the file is hidden.

In Windows, one can have file name to the maximum extension of 254 characters. The other characteristics of the file name in windows are 

The file name can have any character.

Space is also allowed between the letters.

Windows provide first line of the program/text as file name.

The same file name occurs, instead of over writing the file, it adds chorological number with the file name

2.9.1 MSDOS OPERATING SYSTEM MS-DOS stands for Microsoft Disk Operating System. This is a must for working with IBM Personal Computers or compatibles that help to manage the peripherals i.e. system board, disk storage, printers, keyboard, visual display unit etc. It is a disk operating system for

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

24

80xx family of 16 bit computers. MS-DOS now runs on 8088, 80186, 80286, 80386, 80486, PENTIUM based systems etc.

Features: 

It is a single user single programming environment

It supports both floppies and hard disks

It can coexist with other operating systems on a hard disk

It supports a hierarchical file system

It supports a variety of languages.

WHAT ARE THE IMPORTANT FILES IN DOS?

There are five important files in DOS. Two of them are MSDOS.SYS and IO.SYS, almost always hidden. They are also called system files. Other files are COMMAND.COM, CONFIG.SYS and AUTOEXEC.BAT

There are different version of DOS are available. Among the different version that are used are version 5, 6 and 6.22 etc.

MS-DOS COMMANDS: There are two types of MS-DOS commands, 

Internal

External

INTERNAL COMMANDS

The internal command gets loaded automatically in the memory of PC as and when the system is switched on. The switching on the system is known as Booting. These commands are available so long as the machine is kept on. Internal commands are stored in TWO hidden files and in COMMAND.COM. Some of the internal commands are given in Table 1.

TABLE 1: LIST OF INTERNAL COMMANDS CD or CHDIR CLS MD or MKDIR RD or RMDIR REN or RENAME LOADHIGH or LH

COPY DEL DIR DATE CALL BREAK ERASE ECHO EXIT DATA EXIT GOTO IF PAUSE PROMPT SET VOL VERIFY TYPE REM CHCP

PATH VER SHIFT

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

25

EXTERNAL COMMANDS External commands are on disk as program files. So, they must be read from the disk before they are executed. This means that the disk containing the commands must be in a drive. The external commands normally stored in the command name itself as the file name with extension either .BAT or .EXE or .COM. The external commands are shown in Table 2. TABLE 2: SOME EXTERNAL COMMANDS FORMAT DISKCOPY XCOPY BACKUP SCANDISK DOSSHELL

CHKDSK PRINT TREE MODE MORE RESTORE ATTRIB FDISK EDIT FIND UNDELETE UNFORMAT KEYBxx DOSKEY SHELL

2.9.2 UNIX UNIX is the most popular operating system on multi-user. It can be defined as a collection of programs that coordinates the operations of computer hardware and software. It has the following main features. 

Multiuser, time sharing operating system

Multi-tasking operating system

Portability

Modularity

System security

File structure and security

I/O Redirection and piping

I/O independence

Communication

The major functions are 

Command interpreting

Resource management

House Keeping

Program development aids

Communication

2.9.2.1 HISTORY OF UNIX Unix is also known as UNIPLEXED Information and Computing system. It is evolved from Multics. It is developed by Ken Thompson and Kernighan in 1969. It is first loaded in to PDP-7. Originally it is written in Assemply language. In 1973 UNIX was written in ‘C’. Initally Unix was used in academic environment but quickly spread to commercial environment.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

26

2.9.2.2 VERSIONS OF UNIX The flexibility of UNIX, which allows it to be shaped to meet a variety of needs, has always, been of its major attractions. This flexibility led to a proliferation of different version of UNIX. The different types of UNIX are -

AT & T version

-

BSD Version

-

Derivatives of UNIX – XENIX from Microsoft; UNIPLUS from UNISOFT

-

Unix looks alike – Sco Unix; Solarix, cromix, UNOS

2.9.2.3 STRUCTURE OF UNIX SYSTEMS The structure comprises of 

the Kernel – implements Unix file system

the Shell – component interacts directly with user-interaction

Utilities/tools and application

User programs

2.9.2.4 TYPES OF USER Unix supports three different type of users. They are (i) Supervisor; (ii) Group user and (iii) Ordinary User. Every user has a home directory. To find out the user home directory the command is - $echo$home

2.9.2.5 FILES AND FILE SYSTEM Files can be categorized as follows: 

Ordinary files – completely under user control – also called as flat files.

Directory files – contains information about files like ordinary file

Device files – represents all hardware devices.

Unix file systems can be viewed as inverted tree.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

27

*/

Bin

dev

etc

lib

tmp

usr

Bin : consist of user related command file Dev : special file associated with various devices Etc : files essentially required for system administrator Lib : library routines Tmp: buffer files Usr : user defined files

User can provide their file name to the maximum of 14 characters. Unix is a case sensitive system. 2.9.2.6 SIMPLE UNIX COMMANDS The syntax of the Unix commands are $ command [options] [arguments] The options are usually preceded by “-“

2.9.2.7 FEW UNIX COMMANDS $ who - List current users of the system, terminal number, login date and time $ who am I - provides information about the user $ whoami - will display only user name $ date - will display date $ cal 2002 - displays calendar for entire year 2002 $ cal 03 2002 - displays calendar for 2002 March $ mkdir <name> - creates the directory under the given name $ cd/<name> - changes to the particular directory $ rmdir<name> - removing the directory $ cp file1 file 2 - copying file $ cp file1,file2 dir1 - coping all files in a particular sub directory $ ls[options][dir] - displays the list of files $ ls – l - displays the list of files – long listing format $ ls – a - displays all files including hidden files

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

28

$ ls – d - displays directories alone $ ls:pg or ls|more - lists file name in pause format $ man [command] - displays the manual for the command $ diff file1 file2 - difference between file1 and file2 $ mv file1 file2 - renaming a file1 as file2 $ pr file1 - print a file $ pr –l25 filename - prints 25 lines for the page – default value is 66 lines $ pr – t - suppresses the header and trailer $ pr –h “text” - replaces the header with a string $ pr –n - produces multicolumn output $ pr –d - double spaces the output $ cat file1 file2 - compares the two files $ cat file1 - to see the contents of the file $ cat>filename - to create the file $ rm filename - delete the file $ pwd - to see the present working directory $ wc filename - to count the number of words in a given file $ cut –c1-c12 file - cuts first twelve letters of the given file $ tail -5 filename - displays last 5 lines th $ tail +6 filename - displays from 6 line onwords $ clear - clear the screen $ comm. File1,file2 - compares file1 and file2 $ grap “raman” file1 - displays occurrence of the word “raman” in the said file $ sort file1 - sorts the contents of a file into alphabetical or numerical order $ split –n filename - splits the indicated file into parts of “n” lines

2.9.3 WINDOWS

Microsoft Windows is a series of software operating systems produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces (GUIs).

[1]

Microsoft Windows came to dominate the world's personal computer market, overtaking Mac OS, which had been introduced previously. At the 2004 IDC Directions conference, IDC Vice President Avneesh Saxena stated that Windows had approximately 90% of the client [2]

operating system market.

The most recent client version of Windows is Windows Vista. The

current server version of Windows is Windows Server 2008. Windows is an operating system, which controls the program and hardware. Working in Windows is more fun and productive than ever. The World Wide Web is easily accessible from anywhere in Windows. Enhancements to the desktop, taskbar, and start menu help you

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

29

open shortcuts and programs quickly. New features help to work faster and more efficiently, while the new design of Windows makes it the most customizable, usable version of Windows. 2.9.3.1 Different versions of Windows Product name

Version

Release date

Last IE

Windows 1.01

1.01

November 1985

-

Windows 2.03

2.03

November 1987

-

Windows 2.11

2.11

March 1989

-

Windows 3.0

3.0

May 1990

-

Windows 3.1

3.1

March 1992

5

Windows For Workgroups 3.1

3.1

October 1992

5

Windows NT 3.1

NT 3.1

July 1993

5

Windows For Workgroups 3.11

3.11

December 1993

5

Windows 3.2 (released in Simplified Chinese only)

3.2

January 1994

5

Windows NT 3.5

NT 3.5

September 1994

5

Windows NT 3.51

NT 3.51

May 1995

5

Windows 95

4.0.950

August 1995

5

Windows NT 4.0

NT 4.0

July 1996

6

Windows 98

4.10.1998

June 1998

6

Windows 98 SE

4.10.2222

May 1999

6

Windows 2000

NT 5.0.3700.6690

February 2000

6

Windows Me

4.90.3000

September 2000

6

Windows XP

NT 5.1.2600

October 2001

8

Windows XP 64-bit Edition 2003

NT 5.2.3790

March 2003

6

Windows Server 2003

NT 5.2.3790

April 2003

8

Windows XP Professional x64 Edition

NT 5.2.3790

April 2005

8

Windows Fundamentals for Legacy PCs

NT 5.1.2600

July 2006

-

Windows Vista

NT 6.0.6000

November 2006 (volume licensing)/January 2007 (retail)

8

Windows Home Server

NT 5.2.4500

July 2007

-

Windows Server 2008

NT 6.0.6001

February 2008

8

Windows 7 (codenamed Blackcomb, then Vienna)

NT 7.0

2010 (planned)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

30

2.9.3.2 FEATURES OF WINDOWS Easier To Use 

Navigation around the computer is easier than ever, because which made single clicking to open files and the addition of Browse buttons in every window.

Multiple monitors with a single computer, dramatically increases the size of your workspace.

Installing new hardware is easy because Windows supports the Universal Serial Bus (USB) standard, which allows users plug in new hardware and use it immediately-without restarting the computer.

Windows also helps to use digital cameras and other digital imaging devices.

More Reliable 

Windows supports Online Web site for answers to common questions and

help to

keep the copy of Windows up-to-date. 

Windows tools help in regular testing of hard disk and check the system files-and even automatically fix some problems.

The troubleshooters and the Dr. Watson diagnostic tool also help to solve computer problems.

Faster 

By the use of Maintenance wizard, the speed and efficiency of the computer is easily improved.

The power management feature allows newer computers to go into hibernation mode and awaken instantly, instead of requiring shutting down and restarting the computer.

FAT32 file system provides the usage to store files more efficiently and save the hard disk.

The speed system performance which makes Windows 98 more stable and reliable which includes: 

Preemptive multitasking and multithreading support. This allows multiple applications and system tasks to run well concurrently.

32-bit device drivers for all system components, ensuring better resource management.

True Web Integration 

Windows makes the accessing speed of WWW more easily and faster than ever. The Internet Connection Wizard makes connecting to the Web simple.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

31

Using the Web-Style Active Desktop, we can view Pages in any window and we can even make our own favorite Web page as the desktop wallpaper.

Through Microsoft Outlooks Express, we send e-mail and post messages to Internet newsgroups.

By using Microsoft Net Meetings, we can collaborate on documents and hold conferences over the Internet.

Windows Media Player plays live “streaming” media over the Internet.

More Entertaining 

Windows supports DVD, digital audio, and VRML, so that we can play high-quality digital movies and audio on the computer with full effect of web pages that use virtual reality features.

We can also watch television broadcasts and check TV program listings by using Microsoft Web TV for windows.

Applying a theme can change the look and sound of the desktop. Several themes are included with Windows.

Each desktop theme includes unique Wallpaper, screen savers, 3-D icons, sounds, fonts, color schemes and mouse pointer.

More on Windows Windows supports the new Win32 Driver Model (WDM). WDM is a unified driver model that will allow developers to write drivers that work on both Windows and Windows NT 5.0. This is possible because Microsoft added selected NT Kernel services into Windows via a virtual device driver (ntkern.vxd). This allows Windows to maintain full support for legacy device drivers while adding support for new WDM drivers. The 32-bit kernel in Windows provides improved memory management and process scheduling, improved system-wide robustness, and better cleanup after an application closes or fails.

2.9.3.3 RESOURCES INCLUDED WITH WINDOWS The additional Microsoft resources are: 

Support Online Web Site: This interactive site does the work like gathering resources likely to solve the problem, such as technical articles from the Microsoft Knowledge Base, troubleshooting tools, patches can be download, drivers and so on. The connection to Support Online is done by clicking the Web Help button in Windows help or by connecting to: http://support.microsoft.com/support

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

32

Windows Update Web Site: Windows will also ship with a hyperlink on the Start menu that takes users directly to a new Windows Update Web Site. Registered users who visit the site can download the latest Windows drivers and operating system files there, ensuring that their copy of Windows stays up to date. The Web site launches software that automatically scans each system to determine what it needs, and then prompts users to download the appropriate updates. Network administrators who don't want employees updating their own systems can remove this link to the site.

Hardware Compatibility List: The most sweeping change in Windows is the vast support for new hardware. This built-in support may not become obvious until next year, when many of the hundreds of new devices supported by Windows reach market.

This includes many types of PC peripherals that didn't exist when Windows 95 was released, such as AGP graphics cards, DVD drives, and USB devices of every class. Windows will also support yet-to-be-released devices that will connect through an IEEE 1394 high-speed bus. Finally, the new operating system will provide users with the latest drivers for many of their existing cards and peripherals.

2.9.3.4 WINDOWS HELP

Windows help is your principal source of information about windows. Helps, provides with the links to the online version of the Windows, the online tutorial, the troubleshooters, the Read me files, and the Web-based resources. Importantly, help provides how to perform a wide variety of tasks - from setting up a printer to connecting to the Internet and it also locates topics, the Index tab to look up keywords, and the search tab to search for text.

2.9.3.5 TROUBLESHOOTERS

Windows includes a wide range of helpful troubleshooters that assist the users with many common computer problems. The troubleshooters are available through the contents tab in Windows Help, and they’re constantly updated and supplemented on the Support Online Web site.

2.9.4 LINUX

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

33

Linux is the name usually given to any Unix-like computer operating system that uses the Linux kernel. Linux is one of the most prominent examples of free software and open source development: typically all underlying source code can be freely modified, used, and redistributed by anyone. The name "Linux" comes from the Linux kernel, started in 1991 by Linus Torvalds. The system's utilities and libraries usually come from the GNU operating system, announced in 1983 by Richard Stallman. The GNU contribution is the basis for the alternative name GNU/Linux. Predominantly known for its use in servers, Linux is supported by corporations such as Dell, Hewlett-Packard, IBM, Novell, Oracle Corporation, Red Hat, and Sun Microsystems. It is used as an operating system for a wide variety of computer hardware, including desktop computers, supercomputers, , and embedded devices such as E-book readers, video game systems (PlayStation 2, PlayStation 3 and XBox), mobile phones and routers.

2.9.4.1 History of Linux The Unix operating system was conceived and implemented in the 1960s and first released in 1970. Its wide availability and portability meant that it was widely adopted, copied and modified by academic institutions and businesses, with its design being influential on authors of other systems.

The GNU Project, started in 1984, had the goal of creating a "complete Unixcompatible software system" made entirely of free software. In 1985, Richard Stallman created the Free Software Foundation and developed the GNU General Public License (GNU GPL). Many of the programs required in an OS (such as libraries, compilers, text editors, a Unix shell, and a windowing system) were completed by the early 1990s, although low level elements such as device drivers, daemons, and the kernel were stalled and incomplete. Linus Torvalds has said that if the GNU kernel had been available at the time (1991), he would not have decided to write his own.

MINIX, a Unix-like system intended for academic use, was released by Andrew S. Tanenbaum in 1987. The source code for MINIX 1.0 was printed in his book Operating Systems: Design and Implementation. While easily available, modification and redistribution were restricted (though that is not the case today). The code was covered by the copyrights of the textbook, published by Prentice Hall. In addition, MINIX's 16-bit design was not well adapted to the 32-bit design of the increasingly cheap and popular Intel 386 architecture for personal computers.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

34

In 1991, Torvalds began to work on a non-commercial replacement for MINIX while he was attending the University of Helsinki. This eventually became the Linux kernel.

In 1992, Tanenbaum posted an article on Usenet claiming Linux was obsolete. In the article, he criticized the operating system as being monolithic in design and being tied closely to the x86 architecture and thus not portable, which he described as "a fundamental error". Tanenbaum suggested that those who wanted a modern operating system should look into one based on the microkernel model. The posting elicited the response of Torvalds, which resulted in a well known debate over the microkernel and monolithic kernel designs.

Linux was dependent on the MINIX user space at first. With code from the GNU system freely available, it was advantageous if this could be used with the fledgling OS. Code licensed under the GNU GPL can be used in other projects, so long as they also are released under the same or a compatible license. In order to make the Linux kernel compatible with the components from the GNU Project, Torvalds initiated a switch from his original license (which prohibited commercial redistribution) to the GNU GPL. Linux and GNU developers worked to integrate GNU components with Linux to make a fully functional and free operating system.

Commercial and popular uptake Today Linux is used in numerous domains, from embedded systems to supercomputers, and has secured a place in web server installations with the popular LAMP application stack. Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components. These third-party components comprise a vast body of work and may include both kernel modules and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.

Design Linux is a modular Unix-like operating system. It derives much of its basic design from principles established in Unix during the 1970s and 1980s. Linux uses a monolithic kernel, the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Much of Linux's higher-level functionality is provided by separate projects which interface with the kernel. The GNU userland is an important part of most Linux systems, providing the shell and Unix tools which carry out many basic operating system tasks. On top

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

35

of the kernel, these tools form a Linux system with a graphical user interface that can be used, usually running in the X Window System. Linux can be controlled by one or more of a text-based command line interface (CLI), graphical user interface (GUI) (usually the default for desktop), or through controls on the device itself (common on embedded machines).

On desktop machines, KDE, GNOME and Xfce are the most popular user interfaces,

[19]

though a variety of other user interfaces exist. Most popular user interfaces run

on top of the X Window System (X), which provides network transparency, enabling a graphical application running on one machine to be displayed and controlled from another.

Other GUIs include X window managers such as FVWM, Enlightenment, Fluxbox and Window Maker. The window manager provides a means to control the placement and appearance of individual application windows, and interacts with the X window system.

A Linux system usually provides a command line interface of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A “headless system� run without even a monitor can be controlled by the command line via a protocol such as SSH or telnet.

Most low-level Linux components, including the GNU Userland, use the CLI exclusively. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.

A summarized history of Unix-like operating systems showing Linux's origins. Note that despite similar architectural designs and concepts being shared as part of the POSIX standard, Linux does not share any non-free source code with the original Unix or Minix. The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is the best-known and most widely used. Some free and open source software licences are based on the principle of copyleft, a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

36

Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible. To date, however, only the Linux-FT distribution has been POSIX.1 certified. Free software projects, although developed in a collaborative fashion, are often produced independently of each other. However, because the software licenses explicitly permit redistribution there is a basis for larger scale projects that collect the software produced by stand-alone projects and make this software available together in a Linux distribution. A Linux distribution, commonly called a “distro�, is a project that manages a remote collection of Linux-based software, and facilitates installation of a Linux operating system. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. They include system software and application software in the form of packages, and distribution-specific software for initial system installation and configuration as well as later package upgrades and installs. A distribution is responsible for the default configuration of installed Linux systems, system security, and more generally integration of the different software packages into a coherent whole. 2.10 CONCLUSION The Information Technology primarily depends on computer and their accessories. Every development in computer technology, either in hardware or in software will have a high impact in the development of Information Technology. Similarly the development Communication Technology will also have the substantial impact in information technology. These two things together, today we are terming it as ICT implications.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

37

UNIT III COMPUTER NETWORKING 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10

Objectives Networking – Need, Purpose, Type LAN MAN WAN Wireless LAN Network Topologies Basic Elements in Networking Network Cabling Network Operating System

3.1 OBJECTIVES

After studying this lesson, you should be able to 

Understand the concept of Computer Networking

Describe the various Type of Network

What is Operating System

Different types of Networking Topologies

Network Servers

3.2 NETWORKING

A computer network is the linking together of CPUs and terminals via a communication system. A network allows users at different locations to share files, devices and programs. Many terminals may share the resources of one CPU, or multiple CPUs may be linked together.

Terminals and CPUs may be geographically dispersed or situated within the

physical constraints of a single office or building. The computer network means an interconnected collection of autonomous computers. Two computers are said to be interconnected if they are able to exchange information. With a network, users must log onto one machine, submit jobs remotely, move files around explicitly. It is nothing but an interconnection of computer systems and/or peripheral devices with carriers and data communications devices for the purpose of exchanging data and information

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

38

Uses of computer networks

The main uses of computer network are 

Resources sharing

High reliability

Saving money

Communication medium

Access to remote information

Person to person communication

Interactive transfer of information

Components of network

The different components of networks are

S.No.

Components

Description

1.

Signals

Analog signals, Digital signals

2.

Communication Media

Bounded media, Un-bounded media

3.

Communication Channels

Simplex, Half-duplex, Full-duplex

4.

Topology

Bus, Ring, Hierarchical, Star

Types of network Network can be divided into following types 

Local Area Networks – LAN

Metropolitan Area Networks – MAN

Wide Area Networks – WAN

Wireless Networks

Internet

3.3 LOCAL AREA NETWORKS (LAN) A Local Area Networks (LAN) is two or more computers directly linked within a small well defined area such as room, building, or a campus. The main benefit of a LAN is the reduction

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

39

of hardware and software costs because users can share several computers, peripheral devices such as laser printers, colour-printers, Scanners, Softwares. Another benefit is that the users can share the same data.

A LAN is a geographically small network of computers and supporting components used by a group or department to share related software and hardware resources.

Some LANs specifically require all the computers to be of a certain brand, while others allow a variety of brands to be connected. The number of computers in LAN varies widely from small LANs that connect two to twenty five computers, to large LANs that may connect more than 10,000 computers.

LAN must get the data to its destination, transmit the data correctly, and prevent unauthorized users from gaining access to that data.

The length of the cable connecting to computer through a LAN also varies. Most of the LANs permit cables of about one thousand feet, but some permit cables of several miles to be used. The speed of data transfer ranges from several thousand bits per second to 10 million bits per second.

A LAN generally consists of the following: 

Two or more computers

Software to control the operation of the computers

Peripheral devices such as modems, printers, plotters

Coaxial or fiber optic cables are usually used to connect the computers and other devices

Ports and hubs for connecting computers

3.4 METROPOLITAN AREA NETWORK (MAN)

A Metropolitan Area Network (MAN) is a network that is larger than a LAN.

It is called

metropolitan since it normally covers the area of a city. Different hardware and transmission media are often used in MANs because they must efficiently cover these distances or because they don’t require complete access to locations between the networked sites.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

40

3.5 WIDE-AREA NETWORKS (WAN)

A Wide-Area Network (WAN) is two or more geographically dispersed computers, linked by communication facilities such as telecommunication or microwave relays. In other words, one of the most significant aspects of a wide-area network while comparing it with the freedom of a local-area nework, is the involvement of a public telecommunications authority. WAN is usually limited to use by the large organizations and government agencies due to high costs involved in building and maintaining them.

A special designation has also been given to two specific WAN categories: 

Enterprise : An enterprise network connects all LANs of a single organization. The term is normally used for networks connecting extremely large organizations, or for those that cross regional boundaries.



Global : A global network is one that spans the earth. While global networks may not cover the entire globe, they cross multiple national boundaries and may include the networks of several organizations.

3.6 WIRELESS LANS

Not all networks are connected with cabling; some networks are wireless. Wireless LANs use high frequency radio signals, infrared light beams, or lasers to communicate between the workstations and the file server or hubs. Each workstation and file server on a wireless network has some sort of transceiver/antenna to send and receive the data. Information is relayed between transceivers as if they were physically connected. For longer distance, wireless communications can also take place through cellular telephone technology, microwave transmission, or by satellite.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

41

Wireless networks are great for allowing laptop computers or remote computers to connect to the LAN. Wireless networks are also beneficial in older buildings where it may be difficult or impossible to install cables.

The two most common types of infrared communications used in schools are line-ofsight and scattered broadcast. Line-of-sight communication means that there must be an unblocked direct line between the workstation and the transceiver. If a person walks within the line-of-sight while there is a transmission, the information would need to be sent again. This kind of obstruction can slow down the wireless network. Scattered infrared communication is a broadcast of infrared transmissions sent out in multiple directions that bounces off walls and ceilings until it eventually hits the receiver. Networking communications with laser are virtually the same as line-of-sight infrared networks.

Wireless LANs have several disadvantages. They are very expensive, provide poor security, and are susceptible to interference from lights and electronic devices. They are also slower than LANs using cabling.

3.7 NETWORK TOPOLOGY

The arrangement of computer resources, remote devices, communication facilities is known as network topology.

The different types of topologies are 

Bus topology

Ring topology

Star topology

Mesh topology

Hierarchical topology

3.7.1 BUS TOPOLOGY

In bus topology, each computer is connected to a single communication cable via an interface and every computer can directly communicate with every other computer or device in the network. This topology is commonly used along with the local area networks.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

42

Advantages of Bus topology

The advantages of bus topology are 

Short cable length and simple wiring layout: Because there is a single common data path connecting all nodes, the bus topology allows a very short cable length to be used. This decreased the installation cost, and also leads to a simple, easy to maintain, wiring layout.

Easy to extend: Additional nodes can be connected to an existing bus network at any point along its length. More extensive additions can be achieved by adding extra segments such as amplifiers, hubs, repeaters.

Simple architecture: It is simple, reliable in very small networks, easy to use and easy to understand. It requires the least amount of cable to connect the computers together. There is a single cable through which all data passes and to which all nodes are connected.

3.7.2 RING TOPOLOGY

This layout is similar to the linear bus, except that the nodes are connected in a circle using cable segments. In this layout, each node is physically connected to only two others. Each node passes information along to the next, until it arrives at its intended destination. Since each computer re-transmits what it receives, a ring is an active network and is not subject to the signal loss problems which a bus topology experiences. There is no termination because there is no end to the ring. Performance is faster on this system because each portion of the cabling system is handling only the data flow between two machines.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

43

Advantages of the Ring Topology 

Short cable length : The amount of cabling involved in a ring topology is comparable to that of a bus and is small relative to that of a star.

This means that less

connections will be needed, which will in turn increase network reliability. 

Suitable for optical fibers : Optical fibres offer the possibility of very high speed transmission. Because trffic on a ring travels in one direction. It is easy to use optical fibres as a medium fo transmission.

Disadvantages of the Ring topology 

Node failure causes network failure

Difficult to diagnose faults

3.7.3 STAR TOPOLOGY

Each computer on a star network communicates with a central hub that re-sends the message either to all the computers or only to the destination computer. The star topology can be classified in to two types such as: -

Broadcast star network

-

Switched star network

The hub in a broadcast star network can be active or passive. An active hub regenerates the electrical signal and sends it to all the computers connected to it. This type of hub is often called a multi port repeater. Active hubs and switches require electrical power to run. A passive hub merely acts as a connector point and does not amplify or regenerate the signal. Passive hubs do not require electrical power to run.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

44

Advantages of Star Topology 

Ease of service

Centralised control/problem diagnosis

One device per connection

Simple access protocols

Disadvantages of the Star Topology 

Long cable length

Difficult to expand

Central node dependency

3.7.4 HIERARCHICAL TOPOLOGY

Several computers or devices are linked in a hierarchical fashion. The hierarchical topology is also called Tree topology. This type of distribution system is commonly used in the organization where headquarters communicate with regional offices and regional offices communicate with district offices and so on.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

45

Advantages of Hierarchical Topology 

Easy to extend

Fault isolation

Disadvantages of the Hierarchical Topology 

Dependent on the root

3.7.5 MESH TOPOLOGY

A mesh topology has point-to-point connections between every device in the network. Each device requires an interface for every other device on the network. Necessity for this type of topology arises only when each station sends messages frequently to all other stations.

Advantages of Mesh topology 

Ease of installation

Ease of troubleshooting

Disadvantages of Mesh topology 

Units affected by media failure.

3.8 BASIC ELEMENTS IN NETWORKING

All networks require the following three elements:

1. Network Services : At least two individuals who have something to share 2. Transmission Media : A method or pathway for contacting each other 3. Protocols: Rules so that two or more individual can communicate

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

46

1. Network Services

Network services are provided by numerous combinations of computer hardware and software. Depending upon the task, network services require data, input/output resources and processing power to accomplish their goals.

The three types of service providers and requestors are as follows: 

Servers : Servers are only allowed to provide services

Clients : Clients are only allowed to request services from others.

Peers

: Peers may do both concurrently.

Computer networks are often classified as one of the following types 

Peer-to-Pee network

Server-Centric network

Peer-to-peer networks allow any entry to both request and provide network services. Peer-to-peer network software is designed so that peers perform the same or similar functions for each other.

A server-Centric network involves strictly defined roles. A Server-Centric network places restrictions upon which entity may make requests or service them. In the current trend, the most popular personal computer networks are Server-Centric networks

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

47

3.9 Network Cabling

Cable is the medium through which information usually moves from one network device to another. There are several types of cable which are commonly used with LANs. In some cases, a network will utilize only one type of cable, other networks will use a variety of cable types. The type of cable chosen for a network is related to the network's topology, protocol, and size. Understanding the characteristics of different types of cable and how they relate to other aspects of a network is necessary for the development of a successful network. The following sections discuss the types of cables used in networks and other related topics. 

Unshielded Twisted Pair (UTP) Cable

Shielded Twisted Pair (STP) Cable

Coaxial Cable

Fiber Optic Cable

Wireless LANs

Cable Installation Guides

3.9.1 Unshielded Twisted Pair (UTP) Cable

Twisted pair cabling comes in two varieties: shielded and unshielded. Unshielded twisted pair (UTP) is the most popular and is generally the best option for school networks (See fig. 3.9.1).

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

48

Fig.3.9.1. Unshielded twisted pair The quality of UTP may vary from telephone-grade wire to extremely highspeed cable. The cable has four pairs of wires inside the jacket. Each pair is twisted with a different number of twists per inch to help eliminate interference from adjacent pairs and other electrical devices. The tighter the twisting, the higher the supported transmission rate and the greater the cost per foot. The EIA/TIA (Electronic Industry Association/Telecommunication Industry Association) has established standards of UTP and rated five categories of wire.

Categories of Unshielded Twisted Pair Specification

Cable Type

Maximum length

10BaseT

Unshielded Twisted Pair

100 meters

10Base2

Thin Coaxial

185 meters

10Base5

Thick Coaxial

500 meters

10BaseF

Fiber Optic

2000 meters

100BaseT

Unshielded Twisted Pair

100 meters

100BaseTX

Unshielded Twisted Pair

220 meters

Buy the best cable you can afford; most schools purchase Category 3 or Category 5. If you are designing a 10 Mbps Ethernet network and are considering the cost savings of buying Category 3 wire instead of Category 5, remember that the Category 5 cable will provide more "room to grow" as transmission technologies increase. Both Category 3 and Category 5 UTP have a maximum segment length of 100 meters. In Florida, Category 5 cable is required for retrofit grants. 10BaseT refers

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

49

to the specifications for unshielded twisted pair cable (Category 3, 4, or 5) carrying Ethernet signals.

3.9.1.2 Unshielded Twisted Pair Connector

The standard connector for unshielded twisted pair cabling is an RJ-45 connector. This is a plastic connector that looks like a large telephone-style connector (See fig. 2). A slot allows the RJ-45 to be inserted only one way. RJ stands for Registered Jack, implying that the connector follows a standard borrowed from the telephone industry. This standard designates which wire goes with each pin inside the connector.

Fig. 3.9.2. RJ-45 connector

3.9.2 Shielded Twisted Pair (STP) Cable

A disadvantage of UTP is that it may be susceptible to radio and electrical frequency interference. Shielded twisted pair (STP) is suitable for environments with electrical interference; however, the extra shielding can make the cables quite bulky. Shielded twisted pair is often used on networks using Token Ring topology.

3.9.3 Coaxial Cable

Coaxial cabling has a single copper conductor at its center. A plastic layer provides insulation between the center conductor and a braided metal shield (See fig. 3.9.3). The metal shield helps to block any outside interference from fluorescent lights, motors, and other computers.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

50

Fig. 3.9.3. Coaxial cable Although coaxial cabling is difficult to install, it is highly resistant to signal interference. In addition, it can support greater cable lengths between network devices than twisted pair cable. The two types of coaxial cabling are thick coaxial and thin coaxial. Thin coaxial cable is also referred to as thinnet. 10Base2 refers to the specifications for thin coaxial cable carrying Ethernet signals. The 2 refers to the approximate maximum segment length being 200 meters. In actual fact the maximum segment length is 185 meters. Thin coaxial cable is popular in school networks, especially linear bus networks. Thick coaxial cable is also referred to as thicknet. 10Base5 refers to the specifications for thick coaxial cable carrying Ethernet signals. The 5 refers to the maximum segment length being 500 meters. Thick coaxial cable has an extra protective plastic cover that helps keep moisture away from the center conductor. This makes thick coaxial a great choice when running longer lengths in a linear bus network. One disadvantage of thick coaxial is that it does not bend easily and is difficult to install.

3.9.3.1 Coaxial Cable Connectors

The most common type of connector used with coaxial cables is the BayoneNeill-Concelman (BNC) connector (See fig. 3.9.4). Different types of adapters are available for BNC connectors, including a T-connector, barrel connector, and terminator. Connectors on the cable are the weakest points in any network. To help avoid problems with your network, always use the BNC connectors that crimp, rather than screw, onto the cable.

Fig. 3.9.4. BNC connector

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY i.

51

Fiber Optic Cable Fiber optic cabling consists of a center glass core surrounded by several

layers of protective materials (See fig. 3.9.5). It transmits light rather than electronic signals eliminating the problem of electrical interference. This makes it ideal for certain environments that contain a large amount of electrical interference. It has also made it the standard for connecting networks between buildings, due to its immunity to the effects of moisture and lighting. Fiber optic cable has the ability to transmit signals over much longer distances than coaxial and twisted pair. It also has the capability to carry information at vastly greater speeds. This capacity broadens communication possibilities to include services such as video conferencing and interactive services. The cost of fiber optic cabling is comparable to copper cabling; however, it is more difficult to install and modify. 10BaseF refers to the specifications for fiber optic cable carrying Ethernet signals.

Fig.3.9.5. Fiber optic cable

Facts about fiber optic cables: 

Outer insulating jacket is made of Teflon or PVC.

Kevlar fiber helps to strengthen the cable and prevent breakage.

A plastic coating is used to cushion the fiber center.

Center (core) is made of glass or plastic fibers.

3.9.4.1 Fiber Optic Connector

The most common connector used with fiber optic cable is an ST connector. It is barrel shaped, similar to a BNC connector. A newer connector, the SC, is becoming more popular. It has a squared face and is easier to connect in a confined space.

3.10 Network Operating System

Unlike operating systems, such as DOS and Windows95, that are designed for single users to control one computer, network operating systems (NOS) coordinate the

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

52

activities of multiple computers across a network. The network operating system acts as a director to keep the network running smoothly.

3.10.1 Examples of network operating systems

The following list includes some of the more popular peer-to-peer and client/server network operating systems. 

AppleShare

LANtastic

Microsoft Windows for Workgroups

Microsoft Windows NT Server

Novell Netware

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

53

UNIT IV NETWORK TECHNOLOGY 4.1

Objectives

4.2

Network Protocol

4.3

Hyper Text

4.4

Hyper Media

4.5

Multi Media

4.6

ISDN

4.7

OSI

4.8

Network Accessories

4.9

References

4.1 OBJECTIVES After studying this lesson, you should be able to 

Describe the Network Protocol

Differentiate different types of protocol

Define Hyper Text, Hyper Media and Multimedia

Different types of types of Network Accessories

4.2 NETWORK PROTOCOL

Networking evolved from the basic principle of moving data from one computer to another. The first method involved coping data to a storage media such as a floppy disk and then taking that storage media to another computer and copying the data.

This was

charmingly referred to as sneaker-net. As more efficient means were discovered – namely, electricity on a copper wire – networking became more popular. However, there were no standards in place. This meant that one network manufacturer implemented a different means of data transfer than another. If one had an IBM network, then they must have only IBM network device. In order to have a uniform pattern among computer network there evolved a protocol.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

54

4.2.1 WHAT IS PROTOCOLS

It is asset of rules for sending information over a network. Protocols can include rules concerning any or all of the following functions. 

Data transmission mechanisms

Communication session initialization and termination

Addressing and routing

Authentication and verification

Encryption and compression

Error correction

Protocols are usually classified according to the layer they correspond to in the Open Systems Interconnection (OSI) reference model for networking.

The seven layers of the

protocol are as follows:

Layer 7

Application

Layer 6

Presentation

Layer 5

Session

Layer 4

Transport

Layer 3

Network

Layer 2

Data Link

Layer 1

Physical

Types of protocols include the following: 

Data-link protocols: Govern the framing of data, physical addressing of network nodes, and media access control methods.

For local area networks (LANs), these primarily include Ethernet, Token Ring, and Fiber distributed Data Interface (FDDI).

For wide area networks (WANs), they include Point-to- Point Protocol (PPP), High-level Data Link Control (HDLC), frame relay, Asynchronous Transfer Mode (ATM), and X.25.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

55

Network protocols: Handle link services and are responsible for addressing, routing, and error checking.

Eg: NetBEUI, Internet work Packet Exchange (IPX), NW Link, and Internet Protocol (IP). 

Transport protocols: Enable the establishment of sessions and ensure reliable flow of data.

Eg: NetBEUI, Sequenced Packed Exchange (SPX), NWlink, and Transmission Control Protocol (TCP) 

Application layer protocols: Enable applications to access network services. Eg.: Hypertext Transfer Protocol (HTTP) File Transfer Protocol (FTP) Telnet, Simple Mail Transfer Protocol (SMTP) Simple Network Management Protocol (SNMP) Network News Transfer Protocol (NNTP) X.400, X.500 Server Message Block (SMB) Network File System (NFS)

Some protocols have been developed by specific vendors and then accepted as de facto standards by the industry, while others initially formulated by independent standards bodies and then accepted and implemented by vendors. The most widely implemented protocols are those relating to TCP/IP and the Internet.

4.2.1.1 Hyper Text Transfer Protocol (HTTP) The Hypertext Transfer Protocol (HTTP) is an application –level protocol with the lightness and speed necessary for distributed, collaborative, hypermedia information systems. HTTP has been in use by the World Wide Web global information initiative since 1990.

Practical information systems require more functionality than simple retrieval, including search, front-end update and annotation.

HTTP allows an open-ended set of

methods to be used to indicate the purpose of a request.

It builds on the discipline of

reference provided by the Uniform Resource Identifier (URI), as a location (URL) or name (URN) for indicating the resource on which a method is to be applied. Messages are passed

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

56

in a format similar to that used by Internet Mail and the Multipurpose Internet Mail Extensions (MIME).

HTTP is also used as a generic protocol for communication between user agents and proxies/gateways to other Internet protocols, such as SMTP, NNTP, FTP, Gopher and WAIS, allowing basic hypermedia access to resources available from diverse applications and simplifying the implementation of user agents.

4.2.1.2 TCP/IP

TCP/IP stands for Transmission Control Protocol/Internet Protocol.

The TCP/IP

reference model is a set of protocols that allow communication across multiple diverse networks.

TCP/IP is normally considered to a four layer system.

Layers of TCP/IP

Application layer, Transport layer, Internet layer, Host to network layer. Host to network layer is also called physical and data link layer. The application layer in TCP/IP can be equated with the combination of session, presentation, application layer of the OSI reference model. TCP/IP defines two protocol at transport layer: TCP and UDP (User Datagram Protocol)

4.3

HYPER TEXT

Hyper Text is used for branching and responding text, but the corresponding word "hypermedia," meaning complexes of branching and responding graphics, movies and sound - as well as text - is much less used. Instead they use the strange term "interactive multimedia" - four syllables longer, and not expressing the idea that it extends hypertext. - Nelson, Literary Machines 1992. 4.3.1

Types and uses of hypertext

Hypertext documents can either be static (prepared and stored in advance) or dynamic (continually changing in response to user input). Static hypertext can be used to cross-reference collections of data in documents, software applications, or books on CDs. A well-constructed system can also incorporate other user-interface conventions, such as menus and command lines. Hypertext can develop very complex and dynamic systems of linking and cross-referencing. The most famous implementation of hypertext is the World Wide Web.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

57

4.3.2 History of hypertext 4.3.2.1 Early precursors to hypertext Recorders of information have long looked for ways to categorize and compile it. Early on, experiments existed with various methods for arranging layers of annotations around a document. The most famous example of this is the Talmud. Various other reference works (for example dictionaries, encyclopedias, etc.) also developed a precursor to hypertext, consisting of setting certain words in small capital letters, indicating that an entry existed for that term within the same reference work. Sometimes the term would be preceded by a pointing hand dingbat. Later, several scholars entered the scene who believed that humanity was drowning in information, causing foolish decisions and duplicating efforts among scientists. These scholars proposed or developed proto-hypertext systems predating electronic computer technology. For example, in the early 20th century, two visionaries attacked the crossreferencing problem through proposals based on labor-intensive, brute force methods. Paul Otlet proposed a proto-hypertext concept based on his monographic principle, in which all documents would be decomposed down to unique phrases stored on index cards. In the 1930s, H.G. Wells proposed the creation of a World Brain. Michael Buckland summarized the very advanced pre-World War II development of microfilm based on rapid retrieval devices, specifically the microfilm based workstation proposed by Leonard Townsend in 1938 and the microfilm and photoelectronic based selector, patented by Emmanuel Goldberg in 1931. Buckland concluded: "The pre-war information retrieval specialists of continental Europe, the 'documentalists,' largely disregarded by post-war information retrieval specialists, had ideas that were considerably more advanced than is now generally realized." But, like the manual index card model, these microfilm devices provided rapid retrieval based on pre-coded indices and classification schemes published as part of the microfilm record without including the link model which distinguishes the modern concept of hypertext from content or category based information retrieval.

4.3.2.2 The Memex All major histories of what we now call hypertext start in 1945, when Vannevar Bushwroteanarticle in The Atlantic Monthly called "As We May Think," about a futuristic device he called a Memex. He described the device as a mechanical desk linked to an extensive

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

58

archive of microfilms, able to display books, writings, or any document from a library. The Memex would also be able to create 'trails' of linked and branching sets of pages, combining pages from the published microfilm library with personal annotations or additions captured on a microfilm recorder. Bush's vision was based on extensions of 1945 technology - microfilm recording and retrieval in this case. However, the modern story of hypertext starts with the Memex because "As We May Think" directly influenced and inspired the two American men generally credited with the invention of hypertext, Ted Nelson and Douglas Engelbart.

4.3.2.3 The invention of hypertext Ted Nelson coined the words "hypertext" and "hypermedia" in 1965 and worked with Andries van Dam to develop the Hypertext Editing System in 1968 at Brown University. Engelbart had begun working on his NLS system in 1962 at Stanford Research Institute, although delays in obtaining funding, personnel, and equipment meant that its key features were not completed until 1968. In December of that year, Engelbart demonstrated a hypertext interface to the public for the first time, in what has come to be known as "The Mother of All Demos". Funding for NLS slowed after 1974. Influential work in the following decade included NoteCards at Xerox PARC and ZOG at Carnegie Mellon. ZOG started in 1972 as an artificial intelligence research project under the supervision of Allen Newell, and pioneered the "frame" or "card" model of hypertext. ZOG was deployed in 1982 on the U.S.S. Carl Vinson and later commercialized as Knowledge Management System. Two other influential hypertext projects from the early 1980s were Ben Shneiderman's The Interactive Encyclopedia System (TIES) at the University of Maryland (1983) and Intermedia at Brown University (1984).

4.3.2.4 Applications The first hypermedia application was the Aspen Movie Map in 1977. In 1980, Tim Berners-Lee created ENQUIRE, an early hypertext database system somewhat like a wiki. The early 1980s also saw a number of experimental hypertext and hypermedia programs, many of whose features and terminology were later integrated into the Web. Guide was the first hypertext system for personal computers. In August 1987, Apple Computer released HyperCard for the Macintosh line at the MacWorld convention. Its impact, combined with interest in Peter J. Brown's GUIDE (marketed by OWL and released earlier that year) and Brown University's Intermedia, led to broad interest in and

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

59

enthusiasm for hypertext and new media. The first ACM Hypertext academic conference took place in November 1987, in Chapel Hill NC. Meanwhile Nelson, who had been working on and advocating his Xanadu system for over two decades, along with the commercial success of HyperCard, stirred Autodesk to invest in Nelson's revolutionary ideas. The project continued at Autodesk for four years, but no product was released. 4.3.2.5 Hypertext and the World Wide Web In the late 1980s, Berners-Lee, then a scientist at CERN, invented the World Wide Web to meet the demand for automatic information-sharing among scientists working in different universities and institutes all over the world. In 1992, Lynx was born as an early Internet web browser. Its ability to provide hypertext links within documents that could reach into documents anywhere on the Internet began the creation of the web on the Internet. Early in 1993, the National Center for Supercomputing Applications (NCSA) at the University of Illinois released the first version of their Mosaic web browser to supplement the two existing web browsers: one that ran only on NeXTSTEP and one that was only minimally user-friendly. Because it could display and link graphics as well as text, Mosaic quickly became the replacement for Lynx. Mosaic ran in the X Window System environment, which was then popular in the research community, and offered usable window-based interactions. It allowed images

[2]

as well as text to anchor hypertext links. It also incorporated other protocols intended

to coordinate information across the Internet, such as Gopher. After the release of web browsers for both the PC and Macintosh environments, traffic on the World Wide Web quickly exploded from only 500 known web servers in 1993 to over 10,000 in 1994. Thus, all earlier hypertext systems were overshadowed by the success of the web, even though it originally lacked many features of those earlier systems, such as an easy way to edit what you were reading, typed links, backlinks, transclusion, and source tracking. In 1995, Ward Cunningham made the first wiki available, which built on the web by adding easy editing, and (within a single wiki) backlinks and limited source tracking. Wikis continue to be a medium where features are implemented, which were developed or imagined in the early explorations of hypertext.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

60

4.3.2.6 Hyper text Implementations

Besides the already mentioned Project Xanadu, Hypertext Editing System, NLS, HyperCard, and World Wide Web, there are other noteworthy early implementations of hypertext, with different feature sets: 

FRESS — A 1970s multi-user successor to the Hypertext Editing System.

Electronic Document System — An early 1980s text and graphic editor for interactive hypertexts such as equipment repair manuals and computer-aided instruction.

Information Presentation Facility — Used to display online help in IBM operating systems.

Intermedia — A mid-1980s program for group web-authoring and information sharing.

Storyspace — A mid-1980s program for hypertext narrative.

Texinfo — The GNU help system.

XML with the XLink extension — A newer hypertext markup language that extends and expands capabilities introduced by HTML.

MediaWiki, the system that powers Wikipedia, and other wiki implementations — Relatively recent programs aiming to compensate for the lack of integrated editors in most Web browsers.

Adobe's Portable Document Format — A widely used publication format for electronic documents including links.

Windows Help

PaperKiller - A document editor specifically designed for hypertext. Started in 1996 as IPer (educational project for ED-Media 1997).

4.4

Amigaguide - released on Amiga Workbench 1990.

HYPER MEDIA [1]

Hypermedia is a term first used in a 1965 article by Ted Nelson.

It is used as a

logical extension of the term hypertext in which graphics, audio, video, plain text and hyperlinks intertwine to create a generally non-linear medium of information. This contrasts with the broader term multimedia, which may be used to describe noninteractive linear presentations as well as hypermedia. Hypermedia should not be confused with hypergraphics or super-writing which is not a related subject. It is also related to the field of Electronic literature. The World Wide Web is a classic example of hypermedia, whereas a non-interactive cinema presentation is an example of standard multimedia due to the absence of hyperlinks. The first hypermedia work was, arguably, the Aspen Movie Map. Atkinson's Hypercard popularized hypermedia writing, while a variety of literary hypertext and hypertext works, fiction and nonfiction,

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

61

demonstrated the promise of links. . Most modern hypermedia is delivered via electronic pages from a variety of systems including Media players, web browsers, and stand-alone applications. Audio hypermedia is emerging with voice command devices and voice browsing.

4.4.1 Hypermedia development tools Hypermedia may be developed a number of ways. Any programming tool can be used to write programs that link data from internal variables and nodes for external data files. Multimedia development software such as Adobe Flash, Director, Authorware, and MatchWare Mediator may be used to create stand-alone hypermedia applications, with emphasis on entertainment content. Some database software such as Visual FoxPro and FileMaker Developer may be used to develop stand-alone hypermedia applications, with emphasis on educational and business content management. Hypermedia applications may be developed on embedded devices for the mobile and the Digital signage industries using the Scalable Vector Graphics (SVG) specification from W3C (World Wide Web Consortium). Software applications such as Ikivo Animator and Inkscape simplify the development of Hypermedia content based on SVG. Embedded devices such as iPhone natively support SVG specifications and may be used to create mobile and distributed Hypermedia applications. Hyperlinks may also be added to data files using most business software via the limited scripting and hyperlinking features built in. Documentation software such as the Microsoft Office Suite allows for hypertext links to other content within the same file, other external files, and URL links to files on external file servers. For more emphasis on graphics and page layout, hyperlinks may be added using most modern desktop publishing tools. This includes presentation programs, such as Microsoft Powerpoint, add-ons to print layout programs such as Quark Immedia, and tools to include hyperlinks in PDF documents such as Adobe InDesign for creating and Adobe Acrobat for editing. Hyper Publish is a tool specifically designed and optimized for hypermedia and hypertext management. Any HTML Editor may be used to build HTML files, accessible by any web browser. CD/DVD authoring tools such as DVD Studio Pro may be used to hyperlink the content of DVDs for DVD players or web links when the disc is played on a personal computer connected to the internet.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 4.5

62

MULTI MEDIA

Multimedia in computer systems means, from the user point of view, using many input media (i.e. text, speech, gestures, direct manipulation) and output media (text, sound, graphics, video) in the same application. Multimedia has grown out of a variety of media disciplines. For example, if one has the choice of picking up film clips frame-wise from video tapes, sound sequences from CD-ROM disks, adding a touch of animation and throwing in data or statistics scanned from OHP slides and all these controlled by personal computer is called multimedia. Multimedia is immensely useful as publishing and information distribution system. Multimedia is media that utilizes a combination of different content forms. The term can be used as a noun (a medium with multiple content forms) or as an adjective describing a medium as having multiple content forms. The term is used in contrast to media which only utilize traditional forms of printed or hand-produced text and still graphics. In general, multimedia includes a combination of text, audio, still images, animation, video, and interactivity content forms. Multimedia is usually recorded and played, displayed or accessed by information content processing devices, such as computerized and electronic devices, but can also be part of a live performance. Multimedia (as an adjective) also describes electronic media devices used to store and experience multimedia content. Multimedia is similar to traditional mixed media in fine art, but with a broader scope. The term "rich media" is synonymous for interactive multimedia. Hypermedia can be considered one particular multimedia application.

Multimedia contains a combination of content forms:

Text

Audio

Still Images

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

Animation

Video

Interactivity

Multimedia is the combination of two or more media. graphics, audio and video.

63

The medias can be text,

The medias are to be played during some well defined time

interval with user interaction. Normally two medias are audio and video. i.e. sound and moving pictures. Multimedia is the integration of several media for presentation or distribution over Internet.

Multimedia Publishing includes ordering, correlating representations, organizing

(layout, order) hypermedia linking, adding interactive scripts. It uses the computer to integrate and control diverse electronic media such as computer screens, video displays, CD ROM and speech and audio synthesizer. Further information distribution and using includes network distribution, optical publishing, on-line use, hypermedia enhancement by users.

Before transmission of multimedia signals it is compressed then at destination the signal is recovered. While compressing the data it is necessary that no data should be lost. Many compression techniques and algorithms make multimedia transmission feasible.

4.5.1 CATEGORIZATION OF MULTIMEDIA Multimedia may be broadly divided into linear and non-linear categories.

Linear

active

content

progresses

without

any

navigation control for the viewer such as a cinema presentation. Non-linear content offers user interactivity to control progress as used with a computer game or used in self-paced computer based

Linear

Non-linear

training. Non-linear content is also known as hypermedia content. Presentation Interactive Multimedia presentations can be live or recorded. A recorded presentation may allow interactivity via a navigation system. A live multimedia presentation may allow interactivity via an interaction with the presenter or performer.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

64

4.5.2 MAJOR CHARACTERISTICS OF MULTIMEDIA Multimedia presentations may be viewed in person on stage, projected, transmitted, or played locally with a media player. A broadcast may be a live or recorded multimedia presentation. Broadcasts and recordings can be either analog or digital electronic media technology. Digital online multimedia may

Local

Online

be downloaded or streamed. Streaming multimedia may be live or

Recorded

Streaming

on-demand.

4.5.3 HISTORY OF THE TERM MULTIMEDIA In 1965 the term Multi-media was used to describe the Exploding Plastic Inevitable, a performance that combined live rock music, cinema, experimental lighting and performance art.In the intervening forty years the word has taken on different meanings. In the late 1970s the term was used to describe presentations consisting of multi-projector slide shows timed to an audio track. In the 1990s it took on its current meaning. In common usage the term multimedia refers to an electronically delivered combination of media including video, still images, audio, text in such a way that can be accessed interactively.

[1]

Much of the content on

the web today falls within this definition as understood by millions. Some computers which were marketed in the 1990s were called "multimedia" computers because they incorporated a CD-ROM drive, which allowed for the delivery of several hundred megabytes of video, picture, and audio data.

4.5.4 Word usage and context Since media is the plural of medium, the term "multimedia" is a pleonasm if "multi" is used to describe multiple occurrences of only one form of media such as a collection of audio CDs. This is why it's important that the word "multimedia" is used exclusively to describe multiple forms of media. The term "multimedia" is also ambiguous. Static content (such as a paper book) may be considered multimedia if it contains both pictures and text or may be considered interactive if the user interacts by turning pages at will. Books may also be considered non-linear if the pages are accessed non-sequentially. The term "video", if not used exclusively to describe motion photography, is ambiguous in multimedia terminology. Video is often used to describe the file format, delivery format, or presentation format instead of "footage" which is used to

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

65

distinguish motion photography from "animation", motion illustrations. Multiple forms of information content are often not considered multimedia if they don't contain modern forms of presentation such as audio or video. Likewise, single forms of information content with single methods of information processing (e.g. non-interactive audio) are often called multimedia, perhaps to distinguish static media from active media. 4.5.5 Creative industries

Creative industries use multimedia for a variety of purposes ranging from fine arts, to entertainment, to commercial art, to journalism, to media and software services provided for any of the industries listed below. An individual multimedia designer may cover the spectrum throughout their career. Request for their skills range from technical, to analytical, to creative. Commercial

Much of the electronic old and new media utilized by commercial artists is multimedia. Exciting presentations are used to grab and keep attention in advertising. Industrial, business to business, and interoffice communications are often developed by creative services firms for advanced multimedia presentations beyond simple slide shows to sell ideas or liven-up training. Commercial multimedia developers may be hired to design for governmental services and nonprofit services applications as well. Entertainment and fine arts In addition, multimedia is heavily used in the entertainment industry, especially to develop special effects in movies and animations. Multimedia games are a popular pastime and are software programs available either as CD-ROMs or online. Some video games also use multimedia features. Multimedia applications that allow users to actively participate instead of just sitting by as passive recipients of information are called Interactive Multimedia. In the Arts there are multimedia artists, whose minds are able to blend techniques using different media that in some way incorporates interaction with the viewer. One of the most relevant could be Peter Greenaway who is melding Cinema with Opera and all sorts of digital media. Another approach entails the creation of multimedia that can be displayed in a traditional fine arts arena, such as an art gallery. Although multimedia display material may be volatile, the survivability of the content is as strong as any traditional media. Digital recording material may be just as durable and infinitely reproducible with perfect copies every time.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

66

Education In Education, multimedia is used to produce computer-based training courses (popularly called CBTs) and reference books like encyclopedia and almanacs. A CBT lets the user go through a series of presentations, text about a particular topic, and associated illustrations in various information formats. Edutainment is an informal term used to describe combining education with entertainment, especially multimedia entertainment. Learning theory in the past decade has expanded dramatically because of the introduction of multimedia. Several lines of research have evolved (e.g. Cognitive load, Multimedia learning, and the list goes on). The possibilities for learning and instruction are nearly endless.

Engineering Software engineers may use multimedia in Computer Simulations for anything from entertainment to training such as military or industrial training. Multimedia for software interfaces are often done as a collaboration between creative professionals and software engineers.

Industry In the Industrial sector, multimedia is used as a way to help present information to shareholders, superiors and coworkers. Multimedia is also helpful for providing employee training, advertising and selling products all over the world via virtually unlimited web-based technologies. Mathematical and Scientific Research In Mathematical and Scientific Research, multimedia are mainly used for modelling and simulation. For example, a scientist can look at a molecular model of a particular substance and manipulate it to arrive at a new substance. Representative research can be found in journals such as the Journal of Multimedia.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

67

Medicine In Medicine, doctors can get trained by looking at a virtual surgery or they can simulate how the human body is affected by diseases spread by viruses and bacteria and then develop techniques to prevent it. Miscellaneous In Europe, the reference organization for Multimedia industry is the European Multimedia Associations Convention (EMMAC). An observatory for jobs in the multimedia industry provides surveys and analysis about multimedia and ITC jobs.

Structuring information in a multimedia form Multimedia represents the convergence of text, pictures, video and sound into a single form. The power of multimedia and the Internet lies in the way in which information is linked.Multimedia and the Internet require a completely new approach to writing. The style of writing that is appropriate for the 'on-line world' is highly optimized and designed to be able to be quickly scanned by readers. A good site must be made with a specific purpose in mind and a site with good interactivity and new technology can also be useful for attracting visitors. The site must be attractive and innovative in its design, function in terms of its purpose, easy to navigate, frequently updated and fast to download. When users view a page, they can only view one page at a time. As a result, multimedia users must create a ‘mental model of information structure’.Patrick Lynch, author of the Yale University Web Style Manual, states that users need predictability and structure, with clear functional and graphical continuity between the various components and subsections of the multimedia production. In this way, the home page of any multimedia production should always be a landmark, able to be accessed from anywhere within a multimedia piece. 4.6

ISDN (Integrated Services Digital Network)

The telephone service has been the major telecommunications service.

The telephone

system, an analog voice transmission system, is not adequate for various other types of modern communication services like data transmission, facsimile, video transmission etc. The necessity of a new digital system to cater to these requirements led to the evaluation of

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

68

Integrated Services Digital Network (ISDN). The main aim of ISDN is to integrate voice and other telecommunications services over a digital system.

The first type of ISDN service will be voice transmission with several added features. Some of these features are instant call setup locally or worldwide, display of caller’s telephone number, name of address, call transfer worldwide, conferencing world wide etc. The ISDN data communication services included facilities for connecting user’s ISDN terminal to that of any other user anywhere in the world, simultaneous connections to many terminals, establishing closed groups of users with the group members communicating among themselves only etc.

A recent service being offered is called videotext, an interactive access service to remote data base like on-line telephone directory, on-line yellow pages on so on. Using this service, teleshopping, reservations in trains, airlines and hotels and a host of other applications may become possible. Another recent service being offered by ISDN is called teletex. It is a mailing system for domestic and commercial purposes. It can be used on simple computer terminals for text and simple graphics transmission. Facsimile or Fax is another ISDN service in which an image is scanned digitized transmitted as a bit stream, received by the receiving terminal and the original image reproduced.

Other types of services included telemetry or alarm services. For example, electricity meters or water consumption meters may be made on-line and read directly by the electricity or water distribution companies. Smoke or fire detectors in residential apartments or business organizations may automatically call fire services when necessary, using alarm services. Few of these services are available in elementary form. ISDN is still evolving to integrate the proposed services and make them suitable for widespread usage.

The user has access to ISDN by means of user ISDN interface. The user interface connects telephones, computers, telephone exchanges, computer networks and so on to the digital pipe of the ISDN. The digital pipe is the channel used for connecting various users’ interfaces to the ISDN exchange. Digital pipes of different sizes, or capacities are used for different needs. A non-commercial user may require only telephone and videotext services with a smaller capacity pipe. A business organization may wish to connect its private branch exchanges or local area networks to ISDN with a larger capacity pipe.

The pipe to the

customer’s premises has got a fixed capacity. The load on the pipe i.e. traffic on it may be any mix upto the maximum capacity. A user may use smaller capacity than the maximum capacity of the digital pipe. The user will be charged according to the capacity usage.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

69

The subscriber loop or local loop is the connection between the user interface and the ISDN exchange. In other words it is a part of digital pipe. The ISDN exchange provides access to various types of networks, databases and so on. The digital pipe between the exchange and the user carries a number of communications channels. The pipe capacity and the number of channels carried will differ from user to user.

4.6.1 ISDN Channels

ISDN channels are classified as 

B Channel (64 kbps)

D Channel (16 or 64 kbps)

H Channel (384 or 1536 or 1920 kbps)

In addition, A channel consists of 4 kHZ analog telephone channel and C channel consists of 8 or 16 kbps digital channel.

B Channel is the basic channel used to carry digital data, digitized voice or any mixture of data and voice. If the traffic is a mixture, then it must be transmitted to the same destination. Using this B channel, four types of connections may be setup.

1. Circuit Switched Network 2. Packet Switched Network 3. Frame Mode Connection 4. Establishing connection through a leased line.

The D channel is used to carry control signals for the associated B channel. It is also used for low speed data transfer like videotext, teletex, telemetry and alarm service.

H channels are used for high speed applications like fast facsimile, video, high speed data or multiple transmissions at lower rates.

These channels are grouped into various access schemes for differing user needs. They are 

Basic Access Scheme : 2 B channel + 1 D channel

Primary Access Scheme : 23 B Channel + 1 D channel ( in the USA and Japan) or 30B + 1 D channel (in Europe)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

70

The major uses of ISDN are (i) Video Conferencing and (ii) Graphic World Wide Web.

4.6.2 PRINCIPLES OF ISDN

Principles of ISDN are

1. The main feature of the ISDN concept is the support of a wide range of voice and non-voice applications in the same network. 2. ISDN support a variety of applications including both switched and nonswitched connections. Switched connection in an ISDN include both circuit switched and packet switched connections and their concatenations. 3. An ISDN will contain intelligence for the purpose of providing service features maintenance and network management functions. 4. A layered protocol structure should be used for the specification of the access to an ISDN. 5. It is recognized that ISDN may be implemented in a variety of configuration according to specific national situations. 6. New services introduced into an ISDN should be arranged to be compatible with 64k bit/s switched digital connections.

4.7

OSI MODEL

In 1984, a group known as the International Organisation for Standardization (ISO) created a model called the Open Systems Interconnect (OSI). This model defined guidelines for interoperability between network manufacturers. This ISO 7498 – OSI Protocol is also termed as Open System Interconnection Reference Model. OSI model is the most widely used model for networking. A company could now mix and match network devices and protocols from various manufacturers in its own network without being locked into using a single vendor.

Although the OSI model defined a set of standards, it is important to note that it is merely a model. Many other models exist in the networking industry; however, understanding a single model gives us the capability of understanding other models in the future. The OSI model is the most widely taught as the foundation for this knowledge.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

71

The OSI model does not specify the communication standard or protocols to be used to perform networking tasks. OSI model provides following services.

1. Provide peer to peer logical services with layer physical implementation 2. Provide standards for communication between system. 3. Define point of interconnection for the exchange of information between systems. 4. Each layer should perform a well defined function. 5. Narrow the options in order to increase the ability to communicate without expansive conversions and translations between products.

The OSI model is divided into seven layers. The following table lists the name and order of each layer.

Application

Layer 7

Presentation

Layer 6

Session

Layer 5

Transport

Layer 4

Network

Layer 3

Data Link

Layer 2

Physical

Layer 1

The bottom layer is identified as the first layer. It is important to remember the order of the layers in the OSI model.

Each layer is separated, or encapsulated, from each other

layer. This means that each layer can function on its own. Each layer thinks it is talking directly to the same layer on there mote computer through a virtual link. Further more, each layer can only communicate with the layers above and below it. In fact, the layer doesn’t know that any other layers even exist.

These seven layers can be grouped as follows: 

Reliable Transmission of Information – Layers 1 to 4

Meaningful exchange of information – Layers 5 to 6

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

72

Layers and Their Functions

LAYER

FUNCTIONS

7. Application

Can exchange meaningful information to other open system Eg. Bibliographic information system – ISO 2709, UNIMARC Electronic ordering – BISAC – Book Industry System Advisory Committee; SISAC – Serial Industry System

Advisory

Committee. 6. Presentation

Transformation of data from the format of one application to the format acceptable to another open system applications. Eg .ASCII bit to EBCDIC bit User’s interface to network user negotiates with this layer to

5. Session

establish connection with a process on another machine. Once connection is established session layer can handle the dialog in an orderly manner. Session layer is used to allow a user to remotely login to a time sharing system or to transfer a file between two computers. 4. Transport

Accepts data from session layer, splits up into smaller units, if required and pass them to the network layer. It may either create multiple network connections if high throughput is required or may multiplex several transport connections into a simple network. This also decides type of network service to be provided – point-to-point, sequential delivery of messages or data-gram service or broadcast service etc.

3. Network

Controls the operations

2. Data link

Accepts input data for network layer, breaks it layer into data frames transmits the frames sequentially and processes acknowledgement frames sent by receiver.

1. Physical

4.8

Transmits the raw bits over the communication layer.

NETWORK ACCESSORIES Networking Accessories includes all computers, peripherals, interface cards and other

equipment needed to perform data-processing and communications within the network.

The different network accessories, besides conventional wires, cables, cards, are 

File Servers

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

Workstations

Network Interface Cards

Concentrators/Hubs

Repeaters

Routers

Bridges

73

4.8.1 FILE SERVERS

A file server stands at the heart of most networks. It is a very fast computer with a large amount of RAM and storage space, along with a fast network interface card. The network operating system software resides on this computer, along with any software applications and data files that need to be shared. The file server controls the communication of information between the nodes on a network. For example, it may be asked to send a word processor program to one workstation, receive a database file from another workstation, and store an e-mail message during the same time period. This requires a computer that can store a lot of information and share it very quickly. File servers should have at least the following characteristics: 

166 megahertz or faster microprocessor (Pentium, PowerPC)

A fast hard drive with at least nine gigabytes of storage

A RAID (Redundant Array of Inexpensive Disks) to preserve data after a disk casualty

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

A tape back-up unit (i.e. DAT, JAZ, Zip, or CD-RW drive)

Numerous expansion slots

Fast network interface card

At least of 32 MB of RAM

74

4.8.2 WORKSTATIONS

All of the computers connected to the file server on a network are called workstations. A typical workstation is a computer that is configured with a network interface card, networking software, and the appropriate cables. Workstations do not necessarily need floppy disk drives or hard drives because files can be saved on the file server. Almost any computer can serve as a network workstation. 4.8.3 NETWORK INTERFACE CARDS The network interface card (NIC) provides the physical connection between the network and the computer workstation. Most NICs are internal, with the card fitting into an expansion slot inside the computer. Some computers, such as Mac Classics, use external boxes which are attached to a serial port or a SCSI port. Laptop computers can now be purchased with a network interface card built-in or with network cards that slip into a PCMCIA slot. Network interface cards are a major factor in determining the speed and performance of a network. It is a good idea to use the fastest network card available for the type of workstation you are using. The three most common network interface connections are Ethernet cards, LocalTalk connectors, and Token Ring cards. According to a International Data Corporation study, Ethernet is the most popular, followed by Token Ring and LocalTalk (Sant'Angelo, R. (1995). NetWare Unleashed, Indianapolis, IN: Sams Publishing). 4.8.3.1 Ethernet Cards Ethernet cards are usually purchased separately from a computer, although many computers (such as the Macintosh) now include an option for a pre-installed Ethernet card. Ethernet cards contain connections for either coaxial or twisted pair cables (or both) (See fig. 1). If it is designed for coaxial cable, the connection will be BNC. If it is designed for twisted pair, it will have a RJ-45 connection. Some Ethernet cards also contain an AUI connector. This can be used to attach coaxial, twisted pair, or fiber optics cable to an Ethernet card. When this method is used there is always an external transceiver attached to the workstation. (See the Cabling section for more information on connectors.)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

75

Fig. 1. Ethernet card. From top to bottom: RJ-45, AUI, and BNC connectors 4.8.3.2 LocalTalk Connectors

LocalTalk is Apple's built-in solution for networking Macintosh computers. It utilizes a special adapter box and a cable that plugs into the printer port of a Macintosh (See fig. 2). A major disadvantage of LocalTalk is that it is slow in comparison to Ethernet. Most Ethernet connections operate at 10 Mbps (Megabits per second). In contrast, LocalTalk operates at only 230 Kbps (or .23 Mbps).

Ethernet Cards vs. LocalTalk Connections Ethernet

LocalTalk

Fast data transfer (10 to 100 Mbps)

Slow data transfer (.23 Mbps)

Expensive - purchased separately

Built into Macintosh computers

Requires computer slot

No computer slot necessary

Available for most computers

Works only on Macintosh computers

4.8.3.3 TOKEN RING CARDS

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

76

Token Ring network cards look similar to Ethernet cards. One visible difference is the type of connector on the back end of the card. Token Ring cards generally have a nine pin DIN type connector to attach the card to the network cable.

4.8.4 Concentrators/Hubs A concentrator is a device that provides a central connection point for cables from workstations, servers, and peripherals. In a star topology, twisted-pair wire is run from each workstation to a central concentrator. Hubs are multislot concentrators into which can be plugged a number of multi-port cards to provide additional access as the network grows in size. Some concentrators are passive, that is they allow the signal to pass from one computer to another without any change. Most concentrators are active, that is they electrically amplify the signal as it moves from one device to another. Active concentrators are used like repeaters to extend the length of a network. Concentrators are: • Usually configured with 8, 12, or 24 RJ-45 ports • Often used in a star or star-wired ring topology • Sold with specialized software for port management • Also called hubs • Usually installed in a standardized metal rack that also may store netmodems, bridges, or routers

4.8.5 Repeaters

Since a signal loses strength as it passes along a cable, it is often necessary to boost the signal with a device called a repeater. The repeater electrically amplifies the signal it receives and rebroadcasts it. Repeaters can be separate devices or they can be incorporated into a concentrator. They are used when the total length of your network cable exceeds the standards set for the type of cable being used.

A good example of the use of repeaters would be in a local area network using a star topology with unshielded twisted-pair cabling. The length limit for unshielded twisted-pair cable is 100 meters. The most common configuration is for each workstation to be connected by twisted-pair cable to a multi-port active concentrator. The concentrator amplifies all the signals that pass through it allowing for the total length of cable on the network to exceed the 100 meter limit.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

77

4.8.6 Bridges A bridge is a device that allows you to segment a large network into two smaller, more efficient networks. If you are adding to an older wiring scheme and want the new network to be up-todate, a bridge can connect the two. A bridge monitors the information traffic on both sides of the network so that it can pass packets of information to the correct location. Most bridges can "listen" to the network and automatically figure out the address of each computer on both sides of the bridge. The bridge can inspect each message and, if necessary, broadcast it on the other side of the network.

The bridge manages the traffic to maintain optimum performance on both sides of the network. You might say that the bridge is like a traffic cop at a busy intersection during rush hour. It keeps information flowing on both sides of the network, but it does not allow unnecessary traffic through. Bridges can be used to connect different types of cabling, or physical topologies. They must, however, be used between networks with the same protocol.

4.8.7 Routers

A router translates information from one network to another; it is similar to a super intelligent bridge. Routers select the best path to route a message, based on the destination address and origin. The router can direct traffic to prevent head-on collisions, and is smart enough to know when to direct traffic along back roads and shortcuts. While bridges know the addresses of all computers on each side of the network, routers know the addresses of computers, bridges, and other routers on the network. Routers can even "listen" to the entire network to determine which sections are busiest -- they can then redirect data around those sections until they clear up. If you have a LAN that you want to connect to the Internet, you will need to purchase a router. In this case, the router serves as the translator between the information on your LAN and the Internet. It also the best route to send the data over the Internet. Routers can: • Direct signal traffic efficiently • Route messages between any two protocols • Route messages between linear bus, star, and star-wired ring topologies • Route messages across fiber optic, coaxial, and twisted-pair cabling

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 4.9

78

CONCLUSION

The frequent technological development and new innovations have a greater impact in network architecture. It is essential to upgrade knowledge on these concepts frequently becomes mandatory.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

79

UNIT V INTERNET TECHNOLOGY 5.1

Objectives

5.2

INTERNET – introductory concept

5.3

Historical Development

5.4

Type of Connections

5.5

Web Resources

5.6

Web Portal

5.7

Browsers

5.8

Search Engines

5.9

Internet Tools

5.10

References

5.1 OBJECTIVES

After studying this lesson, you should be able to 

Understanding the overview of internet technology

Different types of internet connectivity

Describe various types of Web resources

Different types Browsers, search engines

Identify the different types of Internet Tools

5.2 INTERNET Infusion of technologies into creative process leads to new technology, which enters into creative spheres at varying speed over different routes. To day it seems that each new advance in technology centres around new ways to store, retrieve and transmit information. The PC can now deliver all types of information i.e. text, still images, graphics, audio etc.. More importantly the Personal computers has the ability to present all type of

information in

two different ways i.e. in an integrated way and in an interactive way. It is quite clear that qualitative change in the nature of information storage and retrieval has taken place. Internet has come up in a big way for retrieval of enormous output of

information combining the

concepts of time, space and precision.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

80

5.2.1 WHAT IS INTERNET? The Internet is a system that lets computers all over the world to communicate with each other. The internet is a network of networks that connects computers all over the world

Internet is the largest worldwide network linking 140 countries with 3 million host computers and an estimated 40 million users. The Internet grows at the rate of 2,00,000 users per month. a) It’s a Network The computers on the Internet can talk to one another because they are networked; they are connected in some way so that they can exchange information with one another electronically. On the Internet, the connections take many different forms. Some computers are directly connected to others with wire or fiber-optic cables. Some are connected through local

and

long-distance

telephone

lines,

and

some

even

use

wireless

satellite

communications. b) It’s a loose organization

Although most people think or talk about the Internet as if it were some giant company or club, it really isn’t. No single entity or organization controls it. The computers on it are controlled by their owners.

Nobody controls the Internet.

People simply join up and

participate. It’s like a neighborhood where rules, and leaders. Just as each computer on the Internet is under its owner’s control, some networks that make up a large part of the Internet are controlled by their owners. c) It’s a relaxing place

Internet resources enable users to exchange information in an open, public way.

These

resources provide a forum where users can write and post messages for other users and where they can read messages posted by others.

These resources play the open-air-

exchange-site role played by public meeting place. There are thousands of resources, but the following list may give you a feel for the range of topics like Ceramics, Computers, Disabilities, Film and TV, Holistic Medicine, Nutrition, Law, Mystery Fiction, Astrology, Politics, Employment, Religion, Games, Mail. d) It’s a Business Tool The increasingly global business climate and the great extent to which big companies relay on computers, the Internet looks like a great vehicle for national and international business communication. It is certainly cheaper and more flexible than building a private,

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

81

global computer networks from scratch. Now a days, several organizations are running their business through Internet for various purposes like document exchange, Internet banking, Payment etc. e) It’s a Mailbox The most-used Internet facility is electronic mail, also known as e-mail. Everyone who lives in the Internet world has a unique Internet name, - email id. To send a message to an Internet user, anywhere in the world all the sender has to know the address of the recipient. The sender types up a message in his or her favourite word processing or e-mail software program, hooks on to the internet, types in the address and sends the message on its way. f) It’s an Information Pool

Internet is a pool of information. Whatever the information the users in need, it can be easily located and utilized from the Internet. Today Internet is the best utility that is available to all the users at cheaper prices to know about things. It’s an information pool that satisfies varied level of users from kids to old age, from students to business professions, from small and mid size organizations to Multi National companies, researchers and Government organizations. g) It’s a living thing

The Internet is a living thing, growing its own way, at its own pace, perhaps according to a divine design, but not according to any plan.

In the coming years, one can hear

increasing concern over the global economic, political, and cultural implications of the Internet.

5.3 HISTORICAL DEVELOPMENT OF INTERNET

The roots of internet, as in many cases, found in the military. computer scientists, in the year 1969, thought

A group of

of building a computer network that

would enable researchers around the USA to share ideas. This becomes the foundation of the Internet. The initial plan was to link four sites, the University of California (UCLA), Santa Barbara, the Standford Research Institute and the University of Utah. This project was called ARPANET, Advanced Research Project Agency NETwork, after the agency that initiated it.

The first official demonstration was held during 1969 by means of hooked up of computers between UCLA and Standford Research University which was separated by hundreds of kilometers away. In the year 1971 nearly 24 sites were connected. By the year

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 1981 there were more than 200 connections.

82

Scientists, Research Institutions and

Educational Organizations shown keen interest on connecting to the network, though their computers, could be of different size and speed.

As more and more computer connected, the ARPANET was replaced by the NSFNET, which was run by National Science Foundation. In late 1980’s the barrier of NSFNET for using Military and Research people has been broken away. By that it has reached public to use it. In 1989, the WWW has emerged for information services and 1990’s the combination of email, the web and online chat boosted the use of Internet Service across National and International prominence.

HARDWARE REQUIREMENTS FOR INTERNET BROWSING

The hardware requirements for having Internet facilities are - computer (reasonably fast – 386 and above) - Telephone Line - High speed Modem 14,400 bps ( rganizati 28,800 bps) - Simple communication software - An Internet account

5.4

TYPE OF CONNECTIONS

Type of connections can be categorized as follows

5.5

Dial-up connection

Leased Line connection

Dedicated connection

WEB RESOURCES Web resources are identified with a special name called “Uniform Resource Identifiers

(URIS)”. These identify objects that may be accessed on the web. These identify objects that may be accessed on the Web. Web pages are identified through its “Uniform Resource

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

83

Locators (URLs).URLs are simply, address for documents on the Web. The different parts of the URL are: 

Protocol (Eg. http – Hyper Text Transfer Protocol)

Hostname

Filename.

The syntax will be Protocol:://hostname/filename

Eg. (i) http://www.drtc.edu (ii) http://www.microsoft.com

The URL describes the protocol used to reach the target server, the host system on which the document resides, the directory path to the document, and the document file name. The uniform naming scheme for resources is makes the World Wide Web such a rich information environment.

5.5.1 INFORMATION SOURCES OVER THE WEB 

Electronic Journals

Electronic Discussion Lists/ Forums

Usenet News

Data and Software Archives

E-mail based Information Services

Campus Wide Information Systems

Library Catalogues – Web OPACs

Online Databases

Guides to Information Sources

Search Engines

Subject Gateways

Web Directories

Online Chatting

Commercial advertisings & Customer Service Information

Organisations’ Directories

Bulletin Board Services

Full text of documents

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

84

5.5.2 TYPES OF WEB RESOURCES 1. Open Web – Any thing online that can be found freely with a Search Engine 2. Gated Web- Online Resources accessible by Subscription E.g. OED, CA, LISA, BIOSIS, INSPEC, COMPENDIX etc. 3. Invisible Web – Databases that are not found by Search Engines and can only be accessible through a particular page or front end. E.g. LC’s American Web Site http://memory.loc.org

5.5.3 MEANS OF ACCESS TO WEB RESOURCES

1. Through Search Engines 2. Through Web OPACs 3. Through Specified URLs/ Web sites

5.5.3.1 Through Search Engines 

Yahoo http://www.yahoo.com

Altavista http://www.altavista.com

Lycos http://www.lycos.com

Google http://www.google.com

Excite http://www.excite.com

Hotbot http://www.hotbot.com

5.5.3.2 WEB RESOURCES: Vendor wise

IEL Online (http:\\Ieeexplore.lee.org) IEEE/IEE Electronic Library (IEL) provides a single source to almost of the world’s current electrical engineering and computer science literature.

Grants

unparalleled access to publications from the Institute of Electrical and

Electronics (IEEE) and the Institution of Electrical Engineers (IEE). 

Cover more than 780,000 documents from over 12,000 publications, including, journals conference proceedings, and IEEE standards.

Provides access to more than two million full-page PDF images.

Resources 110 Journals, transactions, magazines, conference proceedings, standards.

Back-files1988 onwards

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

85

Archival Access on DVD at 5% of prevailing subscription rates

Elsevier’s Science Direct (http://www.sciencedirect.com) 

Science Direct is the web-based interface to the full-text database of Elsevier Science journals

One of the world’s largest providers of scientific, technical and medical literature.

Offers a rich electronic environment for research journals, bibliographic databases and reference works.

Offers more than 1500 scientific, technical, medical peer reviewed journals, over 59 million abstracts, over two million full- text scientific journals articles, an expanding suite of bibliographic databases.

Linking to another one million full-text articles via cross reference to other publisher’s platforms.

Resources 1500 Journals published by Elsevier Science and Academic Press

Participants are required to maintain their print Subscription

Back-files1995 onwards

Archival Access offered on the cost of preparing set

Springer Verlag’s Link (http://link.springe.de) Springer Verlag’s Link provides Web-based full-text access to the scientific journals published by the Springer Verlag.

Incorporates full text of more than 450 journals, several thousand books and other serial publications.

Offers full- text access to complete collection of their electronic journals (approximately 400) excluding journals in medical science with restrictions in number of downloads limited to maximum of 2,000.

Well known series of titles like Lecture Notes in Computer Sciences, Physics Mathematics, etc., in the e-book collection.

Famous series of e-reference books like Advances in Polymer Science, LandoltBornstein Series are available.

Institutions are required to maintain their print subscription.

Deletion of subscribed titles not allowed

Back-files1980 onwards

Archival Access offered on one time fee of Euro 15,000

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

86

ACM Digital Library (http://portal.acm.org/portal.cfm) 

ACM digital library incorporates digital versions of works published by ACM since its inception.

Nearly half a century of pioneering concepts and fundamental research have been digitized and indexed in a variety of ways in this resource.

Major components of the resources are an enhanced version of the ACM digital library plus an extended bibliographic database consisting initially of more than a quartermillion citations of crore works in computing.

Covers works are of all types (journal, proceedings, books, technical reports, theses, among others), and from all the major publishers in the discipline.

Resources would be accessible through the Web site of ACM digital library.

Resources 30 full-text Journals, conference proceedings and others.

No Print-base.

Web media with CD ROM backup.

Back-files since inception.

Archival Access on CD ROM.

Ei Compendex plus and INSPEC (http://www.engineeringvillage2.org) 

Ei compendex provides summaries of technical reports, journals articles, and conference papers and proceedings.

It is the world’s only fully interdisciplinary engineering indexing and abstracting service. It covers over 2,600 international engineering journals, conference proceedings and technical reports.

Each year, 200,000 new abstracts are added with in the broad applied engineering areas of mechanical, civil, environmental, electrical, structural, process, material science, solid state and super conductivity, bioengineering, energy, chemical, optics, air and water pollution, solid waste management, and road transportation.

Knit-Rider Information Services Inc., (DIALOG) http://www.dialog.com 

Serving since 1972

Covers about 400 databases

One stop service for all the information needs.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

87

Areas covered: Agriculture; Food and Nutrition; Chemistry; Biosciences and Technology; Engineering; Business and Information; Company Information and Financial

Data;

Computers

and

Software;

Physical

Sciences;

Energy

and

Environment; Industry Analysis; Government and Public Affairs; Travel; Medicine, Health Care ad Drug Information; Patents, Trademarks and Copyrights; People, Books and Consumer News; Social Sciences and Humanities. 

Products: DIALOG Business Connection (DBC); DAILMAIL; DIALOG Alert; DIAL Order; DIALINDEX; One Search; DIALOG on Disc; DIALOG Link.

Silver Platter http://www.silverplater.com 

Covers about 180 databases.

Areas covered: Education; Food and Agriculture; Social sciences; Science and Technology; Health Sciences; Business; Humanities; Environment; Ref. Sources.

Provides world wide access to electronic information sources.

Proquest Databases (UMI) URL: http://www.umi.com 

1938 – Universal Microfilm International.

Areas covered: Business; scientific; Technical; humanities; General reference.

Products: Abstract and Index databases; Full Text Databases; Full Image Databases.

UMI Document Delivery Services: Supply of articles reprints; Supply of reprints of theses

ADONIS (Advanced Document Over Network Information Services) 

Covers about 650 journals from 40 publishers.

Covers Biomedicine,Bioengineering,Biochemistry,Biotechnology.

Supplies weekly new CDRom to the subscribers of this service, which covers all articles in the fields covered.

EEVL - Edinburgh Engineering Virtual Library 

EEVL provides a central access point to networked engineering information for the UK higher education and research community.

It is a free service, created and run by a team of information specialists from HeriotWatt University, with input from many other UK universities.

EEVL covers a Catalogue of selected engineering resources, targeted engineering search engines -

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

88

The CORE Project 

Chemical Online Retrieval Experiment [CORE] at Cornell university Mannis library.

Started by American Chemical Society with OCLC.

Provide access via electronically to all the journals of ACS.

IEEE/IEE Electronic Library 

Joint venture by Institute of Electrical and Electronics Engineers (USA) and Institute of Electrical Engineers (UK).

Covers records from INSPEC database.

Covers IEEE/IEE Journals, Conference Proceedings standards etc.

Adds 25,000 (approx.) records per year.

Fields covered: Electrical Engineering;Electronics;IT;Computer science;applied Physics and related areas.

Subscribers will get monthly updates.

American Chemical Society 

First professional association to bring electronic form of its 28 periodicals in full text over Bibliographical Retrieval Service (BRS) in 1983.

By 1993, there were 6998 online ND cd Rom databases

Institute of Scientific Information (ISI)

http://www.isinetcom is the site for the Institute for Scientific Information, Philadelphia that has fully integrated e-information solutions. Following details can be obtained while accessing this site: About ISI Company Information Journal Lists News ISI Staff Articles Search Employment Training & Support ISI Links, etc

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

89

ISI Chemistry is a web-based source of information on new synthetic methods and novel organic compounds. ISI Chemistry delivers the same content publishing in Index Chemicus (IC) and Current Chemical Reactions (CCR) in an easy to read format with advanced searching capabilities.

CCR contains approximately 6,24,000 reactions abstracted from journal articles since 1985 onwards. CCR is updated by 3,000 reactions each month. IC contains approximately 1.4 million compounds abstracted from journal articles from 1996 onwards. 3,500 compounds update it each week.

J-Gate http://www.informindia.co.in 

India’s first global e-journal portal.

J-Gate offers around 3 million articles since 2001

No. of Journals covered is about 10,000

No. of articles indexed is about 28 lakhs

No. of articles added each week is about 20,000

No. of free full text access journals covered is about 1,600

No. of free full text articles indexed and linked is about 4 lakhs

No. of articles with author e-mail address is about 9 lakhs

5.5.3.3 WEB RESOURCES: SUBJECT WISE The few subject wise web resources are discussed below. Engineering Sciences

In the field of Engineering Sciences the following URLs can be accessed for web based resources:

www.library.ucsb.edu/subj/enqineer.html By this web site databases like Compendex Plus, Computer Article Database, Current Contents, INSPEC, Magazine and Journal Articles, etc are accessibile. Also accessibility to Newsgroups, Organisations are possible..

http://bubl.ac.ukllink/enqineerinqlinks.html By this one can access the BUBL link with other accessibility like Edinburg Engineering Virtual Library, and the Databases on Engineering of different disciplines.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

90

http://www2.widener.eduIW0Ifqram-M...ary/su bject quides/enqineerinq .htm where one can get the selected resources for Engineering Research which is more useful for doing research activity. In the field of Chemical Sciences the following URLs can be accessed for web based resources: -

http://www.cas.orq/ This web site is from Chemical Abstracts Service provider. CAS is the producer of the world's largest and most comprehensive databases of chemical information. This covers Chemical Abstracts and Registry. CAS also produces databases of chemical reactions, commercially available chemicals, listed regulated chemicals and compounds claimed in patents. http://pubs.acs.orq/ This site is from the American Chemical Society (ACS) who is the largest producer of Chemical information in the world. One can see thE3 Jist of journals published by the ACS and can search them. Some are freely available with contents.

Medical Sciences

In the field of Medical Sciences the following URLs can be accessed for web based resources:

http://www.nih.qov/ This site is from the U.S. Department of Health and Human Services. One can get information about publications, fact sheets, clinical trials, grants and funding opportunities, sciertrific resources, etc. by accessing this site. http://www.nlm.nih.gov This site is from the U.S. National Library of Medicine, wherein one can get information related to' MEDLlNE, accessing could download MEDLINEplus, Library Services like catalog, databases, publications, etc. and other information. http://www.ncbi.nlm.nih.gov/ This site is from the National Centre for Biotechnology Information. It acts as a national resource for molecular biology information. Creates databases, conducts research in computational technology, develops software,etc. it related areas. http://www.healthseek.com/ This site is popular for healthcare community and used by hundreds of care giving professionals, medical patients, consumers and ordinary people. Many other web sites can also reached thru' this site, as it has linkages to them. http://avurvedaindia.orq/ This is launched recently by the Capital based NGO Ashtvaidyam Ayurveda Foundation in New Delhi, which explains the fundamental of Ayurveda to the layman in plain and simple language. It is to spread the knowledge of our ancient sciences among the masses.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

91

Mathematical Sciences

In the field of Mathematical Sciences the following URL can be accessed for web based resources: http://www.emis.de/ This is a- site for accessing the European Mathematical Information Service offered by European Mathematical Society. One can access the European countries as well as other countries. http://www.emis.de/journals This is a site for Mathematicians, wherein they get the list of journals in Mathematics. They will be able to see the contents pages of e-journals among them. In the field of Social Sciences the following URLs can be accessed for web based resources: http://www.ssm.com/ This is a site for Social Science Research Network, devoted to the worldwide dissemination of social science research and is composed of a number of specialized research networks in each of the social sciences.

5.6

WEB PORTAL

It is commonly referred to as simply a portal, a Web site or service that offers a broad array of resources and services, such as e-mail, forums, search engines, and on-line repositories. Traditionally, a portal denotes a gate, a door, or entrance. In the context of the World Wide Web, it is the next logical step in the evolution to a digital culture. Web pages are not completely self-referential anymore, but allow for personalization, workflow, notification, knowledge management and groupware, infrastructure functionality, and integration of information and applications. The idea of a portal is to collect information from different sources and create a single point of access to information - a library of categorized and personalized content. It is very much the idea of a personalized filter into the web. Portals are often the first page the web browser loads when users get connected to the Web or that users tend to visit as an anchor site. But now most of the traditional search engines and web sites have transformed themselves into Web portals to attract and keep a larger audience. A web portal is a collection of all pages under one domain. For example www.myuniversity.com, the online portal for collection and dissemination of information resources. So this is our web portal. No matter how small or large your institute is, members can profit enormously from a web portal. The reduced publishing costs alone are worth establishing a web portal for your institute. Imagine your all member institutes resources being collected and organized in such a way that any member can get up to date information from it. It may be documents, pictures,

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

92

videos, lecture notes, exam results, live class room videos etc. Whenever you offer a new course or organizing program, you simply update your web portal any time of day and it will reach the members as early as possible. A web portal is a special website designed to act as a gateway to give convenient access to users.

5.6.1

WHAT A WEB PORTAL DOES?

Enables universal login

Handles both structured and unstructured data

Facilitates multi-channel consistency

Facilitates messaging and notification

Automated tuning: pervasive content can be tuned based on personalization, location, browser, etc.

 5.6.2

Integration to other systems KEY FEATURES OF WEB PORTALS

Security

Access different data

Transactions

Search

Publish Content

Personal Content

5.6.3

WHAT A WEB PORTAL IS NOT?

It is not just a Website (which is usually characterized by static information)

It is not just a personalized intranet

It is not just a personalized extranet

It is not just a personalized front end for business applications

It is not just groupware

It is not just a personalized knowledge management solution

It is not just a sophisticated search engine Instead, a portal is nothing less than just one personalizable, browser based user

interface to all the components mentioned above. 5.6.4

MAJOR FUNCTIONS OF WEB PORTALS According to the analyst and consulting company Ovum - as described in their study

"Enterprise Portals: New Strategies for Information Delivery", 2000 - the ideal portal is based on eight functionality areas: 

Search and navigation

Information integration (content management)

Personalization

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

Notification (push technology)

Task management and workflow

Collaboration and groupware

Integration of applications and business intelligence

Infrastructure functionality

93

Although most of the functionality is not new, what is new is the idea that the business value of the whole is considerably more than the sum of its parts. Thus, a successful portal does not only consist of either a good collaboration support or a good integration of the information sources. Rather it consists of - just like a successful cooking recipe - a wellintegrated mixture of the basic portal functionalities. The first three important functions are explained below.

5.6.5

SEARCH AND NAVIGATION

This functionality forms the basis for most of the successful public web portals meaning that a successful portal should support its users in an efficient search for contents. A Web portal should 

Automatically present its users with the information appropriate to the user’s role.

Suggest additional information to the user, and/or allow the user to voluntarily personalize the information presented by the portal.

Allow the user to search for information that was not previously known to be relevant to the user’s role, but which may be available through the portal.

5.7

BROWSERS Web browser, also called a “browser”, to access content published on a web server.

Web browsers are software programs that allow accessing the graphical portion of the Internet. Browsers allow the users to access various web sites and view the web pages. They provide the option of entering the URL of the site to be visited. Browser software can be divided into the following two categories: 

Text based browsers - Lynx

GUI based browsers – NCSA Mosaic, Netscape Navigator, Internet Explore etc.

A browser is an application program that provides a way to look at and interact with all the information on the World Wide Web. The word "browser" seems to have originated prior to

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

94

the Web as a generic term for user interfaces that let you browse (navigate through and read) text files online. By the time the first Web browser with a graphical user interface was generally available (Mosaic, in 1993), the term seemed to apply to Web content, too. Technically, a Web browser is a client program that uses the Hypertext Transfer Protocol (HTTP) to make requests of Web servers throughout the Internet on behalf of the browser user.

5.7.1 FUNCTIONS OF BROWSERS

While some browsers also support e-mail (indirectly through e-mail Web sites) and the File Transfer Protocol (FTP), a Web browser is not required for those Internet protocols and more specialized client programs are more popular.

Short for Web browser, a software application used to locate and display Web pages. The two most popular browsers are Netscape Navigator and Microsoft Internet Explorer. Both of these are graphical browsers, which means that they can display graphics as well as text. In addition, most modern browsers can present multimedia information, including sound and video, though they require plug-ins for some formats

5.7.2 TYPES OF BROWSERS

A commercial version of the original browser, Mosaic, is in use. Many of the user interface features in Mosaic, however, went into the first widely-used browser, Netscape Navigator. Microsoft followed with its Microsoft Internet Explorer. Today, these two browsers are the only two browsers that the vast majority of Internet users are aware of. Although the online services, such as America Online, originally had their own browsers, virtually all now offer the Netscape or Microsoft browser. Lynx is a text-only browser for UNIX shell and VMS users. Another recently offered and well-regarded browser is Opera.

5.7.2.1 NETSCAPE

Netscape, now part of America Online (AOL), is one of the two most popular Web browsers. Currently, almost all Internet users use either Microsoft's Internet Explorer (MSIE) browser or Netscape, and many users use both. Although Netscape was initially the predominant product in terms of usability and number of users, Microsoft's browser is generally considered superior by many users (although many other users see them as roughly equivalent) and has taken a significant lead in usage.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

95

Netscape's browser, called "Navigator," was developed in 1995 by a team led by Marc Andreessen, who created Mosaic, the first Web browser that had a graphical user interface, at the University of Illinois' National Center for Supercomputing Applications (NCSA) in 1993.

The latest version of the Netscape browser can be downloaded from Netscape's Web site at no charge. CD-ROM versions can also be purchased in computer stores and are sometimes distributed freely as promotions

AOL envisions the Netscape Web site, now transformed into a leading Web portal, as a leading source of revenue through advertising and e-commerce.

5.7.2.2 MOSAIC

Mosaic was the first widely-distributed graphical browser or viewer for the World Wide Web. It is usually considered to have been the software that introduced the World Wide Web (and the Internet) to a wide general audience. Once Mosaic was available, the Web virtually exploded in numbers of users and content sites. (Of course, the software depended on the recent invention of the Hypertext Transfer Protocol by Tim Berners-Lee.)

Mosaic arrived in 1993. Marc Andreessen, then in his early 20s, is credited with inventing or leading the development of Mosaic. He developed it at the National Center for Supercomputing Applications (NCSA) at the University of Illinois in Urbana, Illinois. Andreessen and others went on to become part of Netscape Communications, originally called Mosaic Communications, that developed one of today's most popular browsers, Netscape (its full name is Netscape Navigator). The original Mosaic, now in a later version, has since been licensed for commercial use and is provided to users by several Internet access providers.

5.7.2.3 NETSCAPE COMMUNICATOR

Officially called Netscape Communications Corporation, Netscape was founded by James H. Clark and Marc Andreessen in 1994 and was acquired by AOL in 1999. It revolutionized the computer software market by giving away for free its popular Navigator Web browser until it had acquired an overwhelming market share for this category of software. This strategy is now used by many other software companies, including Microsoft, which also

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

96

distributes its Web browser, Internet Explorer, for free. The term Netscape is often used as the name of the company's browser, not the company itself.

5.7.2.4 INTERNET EXPLORER 6

Internet Explorer 6 is a set of core technologies in Microsoft Windows XP Home Edition and Windows XP Professional operating systems that provides enhanced privacy features and a flexible and reliable browsing experience for users of Windows XP, Windows Millennium Edition (Windows Me), Windows 2000, Windows 98, and Windows NT速 4.0 with Service Pack 6a or later. Whether you are a home user browsing content or getting e-mail on the Web, an IT administrator deploying and maintaining a rich set of Windows Internet technologies, or a Web developer creating Web content, Internet Explorer 6 gives you the freedom to experience the best of the Internet.

This overview describes some of the major features and technologies of Internet Explorer, provides information on how to get the latest version, and offers links to more information so you can start getting more from the Web the way you want. FEATURES AND TECHNOLOGIES OF IE 6

Internet Explorer 6 includes many new and enhanced features that can simplify the daily tasks that you perform, while helping you to maintain the privacy of your personal information on the Web. Here is a quick look at some of the major features of Internet Explorer 6 that help to provide a flexible and reliable browsing experience on the Web.

Flexibility With new, innovative browser capabilities and features such as Auto Image Resizing, Image Toolbar, Media Bar, and Print Preview, it's easy to manage, save, and print your pictures and other media from Web pages. Features such as Favorites, Auto Complete, History, and the Search Companion help you quickly find what you need online. And the customizable browsing layout makes it easy to change your layout so you can experience the Web the way you want.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

97

Web Privacy Internet Explorer 6 helps you manage your security and privacy preferences while on the Internet with tools that help you safeguard your family's browsing experience. Manage cookies to help control the personal information that Web sites collect about you, set different levels of security for different sites on the Web with Security Zones, and use Content Advisor to help block access to objectionable content. These tools support the Platform for Privacy Preferences (P3P), a technology under development by the World Wide Web Consortium (W3C).

Reliability Internet Explorer 6 helps deliver a more stable and more reliable web browsing experience. New fault collection services help to identify potential problems that need to be fixed in future updates to Windows Internet technologies. Learn more about these and other Internet Explorer features—including the features that help developers build rich 5.7.2.5 OPERA BROWSER

The Opera browser started out in 1994 as a research project in Norway's telecom company, Telenor. Independent development was continued by Opera Software ASA in 1995. The first public release of the Opera Browser was version 2.12 although earlier demo versions have been found and screenshots of the 1.0 version are available on the web.

Opera's co-founder Jon von Tetzchner made the first public announcement of Opera on usenet on July 14th 1996. He used the following introduction, which after many years of development still capture the core qualities of Opera

Series 1 Though not publicly released there are screenshots of the then-called MultiTorg Opera. It's fun to recognise the features that are still present in Opera's current form. In weblogs across the web evidence of a Multitorg Opera 1.0b4 can be found.

Series 2 The first public versions of Opera was the 2-series. They are of course extremely outdated but test-driving them you can witness the birth of the legend that is called Opera. The

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

98

oldest version found is a Norwegian demo version of Opera 2.0 which was included with a PC Magazine. It will only load local pages but you can already see a lot of key features that have made Opera famous!

Series 3 The Opera 3 series saw Opera evolve from a geek's tool to a powerful browsing machine with a climax in features, stability and speed with version 3.62. This version is often taken as a the standard to which future version of Opera are compared. It was far ahead of its time in CSS support and this browser can still view the web in a surprisingly good way, considering its respectable age. . Series 4

Opera 4 was long-awaited the first browser based on a new cross-platform core which facilitated the release of Opera for different Operating Systems and thus speeding up Project Magic. The core supported more standards such as CSS1, CSS2, HTML4, XML and WML and a new integrated e-mail client was included. The O4 browser was meant as the leap towards the larger public. Unfortunately the earlier versions were very unstable and buggy and didn't do Opera's reputation much good, though the later maintenance release 4.02 was very usable.

Series 5: "The fastest browser on earth" The 5 series really made the jump to the large public due to the new ad-sponsored version instead of the 30-day trial period. Furthermore Opera 5 was stable and during following releases it gained new features such as the integrated Instant Messaging, the fantastic mouse-gestures, hotlist panels and the integrated search. The 5 series ended with the 5.12 release which is still used by many today.

Series 6: "Simply the best Internet Experience" The Opera 6 series introduced the long-awaited unicode support. Also a new SDI/MDI interface was introduced, facilitating the transition from the SDI-browsers to Opera's unfulpraised MDI-interface. During the later bugfixreleases the kioskmode was enhanced, the integrated searches became editable and a lot of printing problems were solved. The 6 series has become stable and feature rich and now really has become a serious competitor to NN and Internet Explorer.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

99

Series 7: "Hey Presto!" Opera 7 has been released in early 2003. It features a brand new rendering engine under the name Presto, which has enhanced and expanded its support for standards and now includes W3C DOM and the Small Screen Rendering technique for handheld devices. The entire interface was redone, making use of a custom cross-platform skinning system which significantly reduced resource usage, and the entire UI is now configurable: keyboard shortcuts, mouse gestures, menus and toolbars! With the new combined SDI/MDI interface the user has even more power at his command and new innovative features such a FastForward, Notes and Slideshow make the user experience even more enjoyable. Opera 7 is definitely the best browser available today!

An especially noteworthy change in Opera 7 is the new mail and news client, called M2. This e-mail client is based on a powerful filtering system and offers revolutionizing mail organizing abilities, which will change the way you handle your e-mail.

5.8 SEARCH ENGINES

A search engine is a program that searches through the Internet data. The search engines are primarily for locating the information in the web. A search engine is most often used in association with searching through databases of HTML documents. The components of a search engine are: 

a robot

a database

an agent

5.8.1.1 The Robot

Robots are programs that traverse the WWW looking for the information specified. Robots move from one web document to the other by referring to the hyperlinks that are embedded in the web pages. Robots are also called as “Web wanderers”, “Web Crawlers” or “Spiders”.

5.8.1.2 The Database

The search engine database is that component which records all the indexed information.

It includes web addresses, titles, headers, words, first lines, abstracts and

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

100

sometime even full text in its lists. Databases can store anywhere from a thousand to millions of web pages. There are some search engines like “Lycos” which have more than one database.

5.8.1.3 The Agent

The agent is the interface between the user and the database. It is that program which represents the user to search database and displays a sorted list of “hits” after a user makes a search request. Generally, the basis of sorting is relevance to the search request.

5.8.2. TYPES OF SEARCH ENGINES

Search Engines can be categorized into three main types viz. 

Individual Search engine

Directory type search engine

Meta Search engines.

5.8.2.1 Individual Search Engine

The individual search engines can be categorized as full test and non-full text. It can also be divided on the basis of the procedure that their robots use to collect information from the database. Automated robots scan a large part of the web while designated robots re programmed to scan only specific sites. Some of the search engines give preference only to top level resources. Depth-oriented robots search deep into a document to pull out individual items and their respective links to other servers. Example for these type of search engines are www.google.com

5.8.2.2 Directory type search engine

Directories are hierarchical indexes.

They focus by subject matter for providing

information that is most commonly used access point by users. For example the Search engines www.yahoo.com and www.infoseek.com provides directories of major topics. The advantages of subject directories are very useful in browsing subject information.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

101

5.8.2.3 Meta-Search Engines

It behaves as search engines for search engines. combination of a number of search engines.

Meta search engines are a

They are also called “Combined” or

“Simultaneous” search engine. Eg. www.vivisimo.com

Further the Search engines can also be classified as follows: Free text search engines – eg. Alta Vista, Lycos, etc.

Index-or directory-based search engines – eg. Yahoo

Multi-or meta-search engines – eg. Search.com, Vivisimo.com

Natural language search engines – eg. Aj.com, ask.co.uk

Resource- or site specific search engines

Another type of search engines classifications are as follows: 

Major search engines – Google, Yahoo

News search engines – NewsIndex, InfoGrid

Specialty search engines – Ask Jeeves, Web Help

Kids search engines – AOL Kids only, KidsClick, Yahooligans

Metacrawlers – Dogpile, Metacrawler, Cnet Search

Multimedia search engines – MP3.com, Audiogalaxy

Regional search engine – Mosaique, Indiainfo.com, Japanese search engines

Search utilities – Copernic, InfoSeek Express, Lexibot.

5.8.3. USES OF SEARCH ENGINES

The display of search engine results comprises of 

Number of documents retrieved

Hyperlinked URL

First few lines of the document or a brief summary

Size of the document

Document type such as html, pdf, etc.

Language and Date

Percentage of relevance of each document, etc.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

102

5.8.4. LIMITATIONS OF SEARCH ENGINES

The limitations are 

Too many results

Duplicate in nature

Out-dated information

URL not found

Lack of consistency

Search instructions are insufficient

General help menus are not sufficient

5.9 INTERNET TOOLS The Internet offers a number of services to its user. They are 

E-Mail – Electronic Mail

FTP – File Transfer Protocol

Usenet News

Telnet – Remote login feature

5.9.1 E_MAIL – ELECTRONIC MAIL

E_Mail allows sending of information from one computer to another. In other words it allows transmission of text in machine- readable form from one computer to another. The different elements of E_mail are * the address of the both recipient/sender * a subject line and * the message 5.9.1.1 Email addresses: E-mail address contains two parts. They are USERID, DOMAIN. The domain can be classified in two types. They are Organizational domain and Geographic domain. The USERID and DOMAIN is separated by `@’ symbol. For example the E_mail address of MIT and Anna University library are: e.g.: 1. siemit@giasmd01.vsnl.net.in 2. annalib@sirnetm.ernet.in 5.9.2 WHAT IS FTP

FTP, File Transfer Protocol, connects to remote sites and to exchange data between two computers. The FTP allows computer users to download files and store these

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

103

files on their own hard disk. The files may be any type of data, i.e. programs, text, graphis, photographs. It also allows limited directory-related operations on that site.

5.9.3 TELENET

Telenet connects to remote computer locations as if you are a terminal for that location. Using Telnet one must know the name of the host ie. Either domain name or IP address and login name. For example if any one needs details about INFORMATION ON TECHNOLOGY the domain name and login name is eg. telnet debra.dgbt.doc.ca login name: chat Similarly to connect libraries the domain name and login name is eg. telnet nessie.cc.wwu.edu login name: libs 5.9.4 USENET NEWS

It is the bulletin board service of Internet. It is read and contributed to on a daily basis. Vast amount of communication and interaction can take place over a short period. Mainly it is used for propagation of news.

There are different News group, organized according to topic. They are

alt.

alternative topics

clair.

Businesses, products

comp.

computer

talk.

Talk and discussion

rec.

recreation

5.9.5 NETWORK NAVIGATION TOOLS:

The different internet navigational tools are 

Archie

Gopher

Veronica

Jughead

WWW – World Wide Web –

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

104

WAIS – Wide Area Information Server

5.9.5.1 ARCHIE Archie is a program that maintains a list of available files

at FTP sites

around the internet. The contents of information are

- Filename - File size - Type of file - File description

5.9.5.2 GOPHER

It is really guide on the internet. Developed in University of Minnesota. It allows to access databases from all around the internet through menu structure. As name implies it will “go for” the data or topic that is specified. Gopher server can be accessed by typing ID.

Eg. Gopher.msu.edu [Michigan University, USA]

5.9.5.3 VERONICA Very

Easy

Rodent

Oriented

Netwi6de

Index

to

Computerised Archive

(VERONICA) is used as a tool in conjunction with gopher. The folks at the University of Nevada develop it. It is

basically an extension to gopher (index)

5.9.5.4 JUGHEAD It is another add-on service for gopher. It is very similar to Veronica but narrow your search

5.9.5.5 WORLD WIDE WEB

Wide area hypermedia information retrieval initiative aiming to give universal access to a large universe of documents. The idea was explored in 1960’s, but began to use began in 1989.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

105

The web started as a small hypertext-based network of documents, where the document is distributed over several machines on the internet. At present, the web is truly world wide with web documents literally spanning the globe.

5.9.5.6 INFORMATION SERVICES The other information services that can be used in internet are: 

Electronic Discussion Lists and Forums

Electronic journals

Library catalogues

Universities

Computer Wide Information Systems (CWIS)

Database Access on Internet

Data and Software Archives

Companies and

Multiuser Dimensional Games (MUDS)

rganization

CONCLUSION

The use of Internet provides a much-enhanced interface between the user and the information. By use of fixed or moving images, combined with text and voice, information can be provided in forms, which are more easily interpretable, by the recipient. Some of the applications listed above may appear frivolous but the impact on may aspects of business and social life will be significant.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

106

UNIT-VI 6.0 Principles of Object_ Oriented programming 6.1 Software crisis 6.2 Software Evolution 6.3 A Look at Procedure-Oriented Programming 6.4 Object-Oriented Programming Paradigm 6.5 Basic Concept of Object-Oriented Programming 6.5.1 Objects 6.5.2 Classes 6.5.3 Data abstraction and encapsulation 6.5.4 Inheritance 6.5.5 Polymorphism 6.5.6 Dynamic binding 6.5.7 Message passing 6.6 Benefits of OOP 6.7 Object-Oriented Languages 6.8 Applications of OOP

6.0 Principles of Object Oriented Programming 6.1 Software Crisis Developments in software technology continue to be dynamic. New tools and techniques are being used. The software engineers and industry continuously look for new approaches to software design and development. These rapid advances appear to have created a situation of crisis within the industry. The following issues need to be addressed to face this crisis: 

How to represent real-life entities of problems in system design?

How to design systems with open interfaces?

How to ensure reusability and extensibility of modules?

How to develop modules that are to learnt to any changes in future?

How to improve software productivity and decrease software cost?

How to improve the quality of software?

How to manage time schedules?

How to industrialize the software development process? Many software products are either not finished, or not used, or else are delivered with

major errors.

Changes in user requirements have always been a major problem. In a

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

107

changing world with a dynamic business environment, requests for change are unavoidable and therefore systems must be adaptable and tolerant to changes. Software products should be evaluated carefully for their quality before they are delivered and implemented. Some of the quality issues that must be considered for critical evaluation are: 1. Correctness 2. Maintainability 3. Reusability 4. Openness and interoperability 5. Portability 6. Security 7. Integrity 8. User-friendliness 6.2 Software Evolution The evolution of software technology to the growth seems to be a tree. Like a tree, the software evolution has had distinct phases or “layers” of growth. These layers were built up one by one over the last five decades, with each layer representing an improvement over the previous one. In software systems, each of the layers continues to be functional, whereas only the uppermost layer is functional. To build today’s complex software it is just not enough to put together a sequence of programming statements and sets of procedures and modules; we need to incorporate sound construction techniques and program structures that are easy to comprehend, implement and modify. Since the invention of the computer, many programming approaches have been tried. These include techniques such as modular programming, top-down programming, bottom up programming and structured programming. The primary concern is to handle the increasing complexity of programs that are reliable and maintainable. With the advent of languages such as C, structured programming became very popular and was the main technique of the 6980s. Structured programming was a powerful tool that enabled programmers to write moderately complex programs fairly easily. However, as the programs grew larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-maintain, and reusable programs.

Object-Oriented Programming (OOP) is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several powerful new concepts. It is a new way of organizing and developing programs and has nothing to do

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

108

with any particular language. However, not all languages are suitable to implement the OOP concepts easily. 6.3 A Look at Procedure-Oriented Programming

Conventional programming, using high level languages such as COBOL, FORTRAN and C, is commonly known as procedure-oriented programming

Main Program

Function

Function

Function

-2

-1

-3

Function

Function

–4

-5

Function

Function

Function

-6

-7

-8

Figure. Typical structure of procedure-oriented programs. A number of functions are written to accomplish these tasks. The primary focus is on functions. The technique of hierarchical decomposition has been used to specify the tasks to be completed for solving a problem. Procedure-oriented programming basically consists of writing a list of instructions (or actions) for the computer to follow, and organizing these instructions into groups known as functions. We normally use a flowchart to organize these actions and represent the flow of control from one action to another. While we concentrate on the development of functions, very little attention is given to the data that are being used by various functions. What happens to the data? How are they affected by the functions that work on them? In a multi-function program, many important data items are placed as global so that they may be accessed by all the functions. Each function may have its own local data.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

109

In a large program it is very difficult to identify what data is used by which function. Another serious drawback with the procedural approach is that it does not model real world problems very well.

Global Data

Global Data

Function-1

Function-2

Function-3

Local Data

Local Data

Local Data

Figure. Relationship of data and functions in procedural programming

Some characteristics exhibited by procedure-oriented programming are: 

Emphasis is on doing things (algorithms).

Large programs are divided into smaller programs known as functions.

Most of the functions share global data.

Data move openly around the system from function to function.

Functions transform data from one form to another.

Employs top-down approach in program design.

6.4 Object-Oriented Programming Paradigm

The major motivating factor in the invention of object-oriented approach is to remove some of the flaws encountered in the procedural approach. OOP treats data as a critical element in the program development and does not allow it, and protects it from accidental modification from outside functions. OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects. The organization of data and functions in object-oriented programs is shown in Fig. 6.6. The data of an object can be accessed only by the functions associated with that object. However, functions of one object can access the functions of their objects. Some of the features of object-oriented programming are: 

Emphasis is on data rather than procedure

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

110

Programs are divided into what are known as objects

Data structure are designed such that they characterize the objects

Data is hidden and cannot be accessed by the external functions

Objects may communicate with each other through functions

New data and functions can be easily added whenever necessary.

Functions that operate on the data of the object are tied together in the data structure.

Follows bottom-up approach in program design.

Object A

Object B

Data

Data Communication

Functions

Functions

Object C

Functions

Data

Figure. Organization of data and functions in OOP We define “object-oriented programming as an approach that provides a way of modularizing programs by creating copies of such modules on demand.” Thus, an object is considered to be a partitioned area of computer memory that stores data and set of operations

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

111

that can access that data. Since the memory partitions are independent, the objects can be used in a variety of different programs without modifications.

6.5 Basic concepts of Object-Oriented Programming It is necessary to understand some of the concepts used extensively in objectoriented programming. These include: 

Objects

Classes

Data abstraction and encapsulation

Inheritance

Polymorphism

Dynamic binding

Message passing

6.5.1 Objects Objects are the basic run-time entities in an object-oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle.

STUDENT

Object : STUDENT

Total DATA Name Date-of-birth Marks ……….

FUNCTIONS Total Average Display …………

Average

Display

Figure. Two ways of representing an object

In OOP, a problem is considered as a collection of a number of entities called objects. Objects are instances of classes.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

112

Bird Attributes Feathers Lay eggs 6.5.2 Classes Objects contain data, and code to manipulate that data. The entire set of data of an object can be made a user defined data type with the help of a class. Once a class has been defined, we can create any number of objects belonging to that class. A class is a collection of objects of similar type. For example mango, apple and orange are members of the class fruit. Classes are user-defined data types and behave like the built-in types of a programming language. If fruit has been defined as a class, then the statement fruit mango; Will create an object mango belonging to the class fruit. 6.5.3 Data Abstraction and Encapsulation The wrapping up of data and functions into a single unit (called class) is known as encapsulation. The data is not accessible to the outside world, and only those functions which are wrapped in the class can access it. These functions provide the interface between the object’s data and the program. This insulation of the data from direct access by the program is called data hiding. Abstraction refers to the act of representing essential features without including the background details.

Classes use the concept of abstraction and are defined as a list of

abstract attributes and functions to operate on these attributes. They encapsulate all the essential properties of the objects that are to be created. The attributes are called data members because they hold information. The functions that operate on these data are called methods or member functions.

6.5.4 Inheritance Inheritance is the process by which objects of one class acquire the properties of objects of another class. In OOP, the concept of inheritance provides the idea of reusability.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

Flying Bird

113

Nonflying Bird

Attributes

Attributes

…………

………..

…………

………..

………….

……….. Figure. Property inheritance

Robin

Swallow

Attributes

Attributes

………….

…………

………….

…………

………….

…………

Penguin

Kiwi

Attributes

Attributes

………….

………….

………….

………….

………….

………….

This means that we can add additional features to an existing class without modifying it. This is possible by deriving a new class from the existing one. The new class will have the combined features of both classes.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

114

6.5.5 Polymorphism Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends upon the types of data used in the operation. For example, consider the operation of addition.

Shape Draw ()

Box object

Circle object Draw (circle)

Draw (box)

Triangle object

Draw (triangle)

Figure. Polymorphism

The process of making an operator to exhibit different behaviors in different instances is known as operator over loading. Figure shows that a single function name can be used to handle different number and different types of arguments. Using a single function name to perform different types of tasks is known as function over loading. Polymorphism is used in implementing inheritance.

6.5.6 Dynamic binding Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run time. It is associated with polymorphism and inheritance. A function call associated with a polymorphic reference depends on the dynamic type of that reference. 6.5.7 Message passing An object-oriented program consists of a set of objects that communicate with each other. The process of programming in an object-oriented language involves the following basic steps: 1. Creating classes that define objects and their behavior 2. Creating objects from class definitions

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

115

3. Establishing communications among objects Objects communicate with one another by sending and receiving information much the same way as people pass messages to one another. The concept of message passing makes it easier to talk about building systems that directly model or simulate their real-world counterparts. A message for an object is a request for execution of a procedure, and therefore will invoke a function (procedure) in the receiving object that generates the desired result. Message passing involves specifying the name of the object, the name of the function (message) and the information to be sent. Example, Employee. salary (name)

Object

information Message

6.6 Benefits of OOP OOP offers several benefits to both the program designer and the user. Objectorientation contributes to the solution of many problems associated with the development and quality of software products. The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost. The principal advantages are: 

Through inheritance, we can eliminate redundant code and extend the use of existing classes.

We can build programs from the standard working modules that communicate with one another, rather than having to start writing the code from scratch. This leads to saving of development time and higher productivity.

The principle of data hiding helps the programmer to build secure programs that cannot be invaded by code in other parts of the program.

It is possible to have multiple instances of an object to co-exist without any interference.

It is possible to map objects in the problem domain to those in the program.

It is easy to partition the work in a project based on objects.

The data-centered design approach enables us to capture more details of a model in implementable form.

Object oriented programming can be easily upgraded from small to large systems.

Software complexity can be easily managed.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

116

While it is possible to incorporate all these features in an object-oriented system, their importance depends on the type of the project and the preference of the programmer. Developing software that is easy to use makes it hard to build. It is hoped that the objectoriented programming tools would help manage this problem.

6.7 Object Oriented Languages OOP concepts can be implemented using languages such as C and Pascal. A language that is specially designed to support the OOP’s concept makes it easier to implement them. The languages should support several of the OOP concepts to claim that they are object-oriented. Depending upon the features they support, they can be classified into the following two categories: 1. Object based programming languages, and 2. Object oriented programming languages Major features that are required for object-based programming are: 

Data

Data hiding and access mechanisms

Automatic initialization and clear-up of objects

Operator overloading

Languages that support programming with objects are said to be object-based programming languages. They do not support inheritance and dynamic binding. Object-oriented programming incorporates all of object-based programming features along with two additional features such as inheritance and dynamic binding. Object-oriented programming can be characterized by Object–based

features + inheritance +

dynamic binding

Languages that support these features include C++, Smalltalk, Object Pascal and java. There are a large number of object-based and object-oriented programming languages. Some popular general purpose OOP languages are Simula, Smalltalk, Objective C, C++, Ada, Object Pascal, Turbo Pascal, Eiffel & Java. All languages provide for polymorphism and data hiding. However, many of them do not provide facilities for concurrency, persistence ad genericity. Eiffel, Ada and C++ provide generic facility which is an important construct for supporting reuse. C++ has now become the most successful, practical, general purpose OOP language and is widely used in industry today.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

117

6.8 Applications of OOP Applications of OOP are beginning to gain importance in many areas. The most popular application of object-oriented programming has been in the area of user interface design such as windows. Real-business systems are often much more complex and contain many more objects with complicated attributes and methods. OOP is useful in these types of applications because it can simplify a complex problem. The promising areas for application of OOP include: 

Real time systems

Simulation and modeling

Object oriented databases

Hypertext, hypermedia and expertext

AI and expert systems

NEURAL networks and parallel programming

Decision support and office automation system

CIM/CAM/CAD Systems

The OOP environment has enabled the software industry to improve not only the quality of software systems but also its productivity. Object-oriented technology is certainly changing the way the software engineers think, analyze, design and implement systems.

State whether the following statements are TRUE or FALSE: (a) In procedure-oriented programming, all data are shared by all functions. (b) The main emphasis of procedure-oriented programming is on algorithms rather than on data. (c) One of the features of OOP is the division of programs into objects that represent real-world entities. (d) Wrapping up of data of different types into a single unit is known as encapsulation. (e) One problem with OOP is that once a class is created it can never be changed. (f) Inheritance means the ability to reuse the data values of an one object by other objects. (g) Polymorphism is extensively used in implementing inheritance. (h) Object-oriented programs are executed much faster than conventional programs. (i) Object-oriented systems can scale up better from small to large. (j) Object-oriented approach cannot be used to create databases.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

118

UNIT-VII 7.1.0 Beginning with C++ 7.1.1 What is C++? 7.1.2 Applications of C++ 7.1.3 A Simple C++ Program 7.1.4 More C++ Statements with Class 7.1.5 An Example with Class 7.1.6 Structure of C++ Program 7.2 Tokens, Expressions and Control Structures 7.2.1 Introduction 7.2.2 Tokens 7.2.3 Keywords 7.2.4 Identifiers and Constants 7.2.5 Basic Data Types 7.2.6 User-Defined Data Types 7.2.7 Derived Data Types 7.2.8 Symbolic Constants 7.2.9 Type Compatibility 7.2.10 Declaration of Variables 7.2.11 Dynamic Initialization of Variables 7.2.12 Reference Variables 7.2.13 Operators in C++ 7.2.14 Scope Resolution Operators 7.2.15 Member Dereferencing Operators 7.2.16 Memory Management Operators 7.2.17 Manipulators 7.2.18 Type Caste Operator 7.2.19 Expressions and Implicit Conversations 7.2.20 Special Assignment Expressions 7.2.20.1 Chained Assignment 7.2.20.2 Compound Assignment 7.2.21 Operators Overloading 7.2.22 Operators Precedence 7 2.23 Control Structures 7.2.23.1 The if statement 7.2.23.2 The switch statement 7.2.23.3 The do-while statement

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

119

7.2.23.4 The while statement 7.2.23.5 The for statement 7.3 Functions in C++ 7.3.1 Introduction 2.3.2 Main function 7.3.3 Function Prototyping 7.3.4 Call by Reference 7.3.5 Return by Reference 7.3.6 Inline Functions 7.3.7 Default Arguments 7.3.8 Constant Arguments 7.3.9 Function Overloading 7.3.10 Friend and Virtual Functions

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

120

7.1.0 Beginning with C++ 7.1.1 What is C++? C++ is an object-oriented programming language. It was developed by Bjarne Stroustrup at AT&T Bell Laboratories in Murray Hill, New Jersey, USA in the early 1980s. Stroustrup wanted to combine the best features of Simula67 and C and create a more powerful language that could support object-oriented programming features. The result was C++. Therefore, C++ is an extension of C with a major addition of the class construct feature of simula67. Since the class was a major addition of the original C language. Stroustrup initially called the new language ‘C with classes’. In 1983 the name was changed to C++. C++ is an enhanced version of C. During the early 1990s, the language underwent a number of improvements and changes. In November 1997, the ANSI/ISO standards committee standardized these changes and added several new features to C++. C++ is a superset of C. Almost all C programs are also C++ programs. The most important facilities that C++ adds on to C are classes, inheritance, function overloading and operator overloading. These features enable creating abstract data types, inherit properties from existing data types and support polymorphism, thereby making C++ a truly objectoriented language. The object-oriented features in C++ allow programmers to build large programs with clarity, extensibility and ease of maintenance, incorporating the spirit and efficiency of C. 7.1.2 Applications of C++: C++ is a versatile language for handling very large programs. C++ programs are easily maintainable and expandable. When a feature needs to be implemented, it is very easy to add to the existing structure of an object. It is suitable for virtually any programming task including development of editors, communication systems and any complex real-life application systems. 

It is used in computer animation.

It is used to design compilers.

It is used to access relational databases.

It is used in simulation and modeling.

It is used to develop expert system.

It is used to develop computer games.

7.1.3 A SIMPLE C++ PROGRAM:

Consider an example of a C++ program that prints a string on the screen.

#include <iostream.h>

// include header file

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

121

main() { cout<<”C++ is better C.”; // C++ statement }

// End of example Program Features Like C, the C++ program is a collection of functions. The example contains only one function, main(). As usual, execution begins at main(). Every C++ program must have a main(). C++ is a free-form language. With a few exceptions, the compiler ignores carriage returns and white spaces. Like C, the C++ statements terminate with semicolons. Comments C++ introduces a new comment symbol // (double slash). Comments start with a double slash symbol and terminate at the end of the line. A comment may start anywhere in the line, and what ever follows till the end of the line is ignored. There is no closing symbol. Double slash comment is basically single line comment. Multiline comments can be written as follows: //This is an example of // C++ program to illustrate // some of its features The C comment symbols /*, */ are still valid and more suitable for multiline comments. The following comment is allowed: /* This is an example of C++ program to illustrate Some of its features */ For example, the double slash comment cannot be used in the manner as shown below: for (j=0; j<n; /* loops n times */ j++) Output operator The only statement in program is an output statement. The statement cout << ”C++ is better C.”;

causes the string in quotation marks to be displayed on the screen.

This statement

introduces two new C++ features, cout and <<. The identifier cout is a predefined object that represents the standard output stream in C++. The standard output stream represents the screen. It is also possible to redirect the output to other output devices.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

122

The operator << is called the insertion or put to operator. It inserts the contents of the variable on its right to the object on its left. The object cout has a simple interface. If string represents a string variable, then the following statement will display its contents: cout << string; Note that the operator << is the bit-wise left-shift operator and it can still be used for this purpose.

This is an example of how one operator can be used for different purposes,

depending on the context. This concept is known as operator overloading. The iostream.h File We have used the following #include directive in the program #include <iostream.h> This directive causes the preprocessor to add the contents of the iostream.h file to the program. It contains declarations for the identifier cout and the operator <<. The header file iostream.h should be included at the beginning of all programs that use input/output statements. Note that the naming conventions for header files may vary. Some implementations use iostream.hpp; yet others iostream.hxx. We must include appropriate header files depending on the contents of the program and implementation. For example, if we want to use the very familiar printf() and scanf() functions, the header file stdio.h must be included. The following table provides lists of C++ standard library header files that may be needed in C++ programs. Header file

Contents and Purpose

<assert.h>

Contains macros and information for adding diagnostics that

New Version <cassert>

aid program debugging. <ctype.h>

Contains

function

prototypes

for

functions

that

test

<cctype>

characters for certain properties, and function prototypes for functions that can be used to convert lowercase letters to uppercase letters and vice versa. <float.h>

Contains the floating-point size limits of the system.

<cfloat>

<limits.h>

Contains the integral size limits of the system.

<clmits>

<math.h>

Contains function prototypes for math library functions.

<cmath>

<stdio.h>

Contains function prototypes for the standard input/output

<cstdio>

library functions and information used by them. <stdlib.h>

Contains function prototypes for conversion of numbers to

<cstdlib>

text, text to numbers, memory allocation, random numbers, and various other utility functions. <string.h>

Contains function prototypes for C-style string processing

<cstring>

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

123

function. <time.h>

Contains function prototypes and types for manipulation the time and date.

<iostream.h>

Contains function prototypes for the standard input and

<iostream>

standard output functions. <iomanip.h>

Contains function prototypes for the stream manipulators

<iomanip>

that enable formatting of streams of data. <fstream.h>

Contains function prototypes for functions that perform input

<fstream>

from files on disk and output to files on disk. Table. Commonly used old-style header files Namespace Namespace is a new concept introduced by the ANSI C++ standards committee. This defines a scope for the identifiers that are used in a program. For using the identifiers defined in the namespace scope we must include the using directive, like Using namespace std; Return Statement

In C++, main() returns an integer type value to the operating system. Therefore, every main() in C++ should end with a return(0) statement; otherwise a warning or an error might occur. Since main() returns an integer type value, return type for main() is explicitly specified as int. The default return type for all functions in C++ is int. 7.1.4 More C++ Statements Let us consider another C++ program.

Program to read two numbers form the

keyboard and display their average on the screen. C++ statements to accomplish this are shown in Program. #include <iostream.h> using namespace std; int main() { float number1, number2, sum, average; cout << �Enter two numbers: �; //prompt cin >> number1;

// Reads numbers

cin >> number2;

//from keyboard

sum = number1 + number2; average = sum/2;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

124

cout<< ” Sum= “ <<sum<< ”/n”; cout<< ” Average=” <<average<< ”\n”; return 0; } The output of program is:

Enter two numbers: 6.5 7.5 Sum = 14 Average = 7 Variables The program uses four variables number1, number2, sum, and average. They are declared as type float by the statement. float number1, number2, sum, average; All variables must be declared before they are used in the program.

Input operator The statement cin >> number1; is an input statement and causes the program to wait for the user to type in a number. The number keyed in is placed in the variable number1. The identifier cin is a predefined object in C++ that corresponds to the standard input stream. Here, this stream represents the keyboard. The operator >> is known as extraction or get from operator. It takes the value from the keyboard and assigns it to the variable on its right. Object

Extraction operator

cin

Keyboard

>>

Variable

45.5

Figure. Input using extraction operator

Cascading of I/O operators We have used the extraction operator << repeatedly in the last two statements for printing results. The statement cout<< “Sum= “ << sum << “\n”;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

125

first sends the string “Sum=” to cout and then sends the value of sum. Finally, it sends the newline character so that the next output will be in the new line. The multiple use of << in one statement is called cascading. When cascading an output operator, we should ensure necessary blank spaces between different items. Using the cascading technique, the last two statements can be combined as follows: cout << “Sum = “ << sum << “\n” << “Average = “ <<average << “\n”; This is one statement but provides two lines of output. If you want only one line of output, the statement will be: cout << “Sum = “<< sum << “,” << “Average = “<< average<< “\n”;

The output will be: Sum = 14, Average = 7 We can also cascade input operator >> as shown below: cin>> number1 >> number2; The values are assigned from left to right. If we key in two values such as 10 and 20, then 10 will be assigned to number1 and 20 to number2. 7.1.5 An Example with Class One major features of C++ is classes. They provide a method of binding together data and functions which operate on them. Like structures in C, classes are user-defined data types. Program shows the use of class in C++ program #include <iostream.h> using namespace STD; class person

// NEW DATA TYPE

{ char name[30]; int age; public: void getdata(void); void display(void); }; void person :: getdata(void)// MEMBER FUNCTION { cout<< “Enter name: ”; cin>> name; cout<< “Enter age: ”;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

126

cin>>age; } void person :: display(void)// MEMBER FUNCTION { cout<<”\nName: ”<<name; cout<<”\nAge: ”<<age; } int main() { person p;

// OBJECT OF TYPE person

p.getdata(); p.display(): return 0; } The output of program is: Enter Name: Ravinder Enter Age: 30 Name: Ravinder Age: 30 The program defines person as a new data of type class. The class person includes two basic data type items and two functions to operate on that data. These functions are called member functions. The main program uses person to declare variables of its type. Class variables are known as objects. Here, p is an object of type person. Class objects are used to invoke the functions defined in that class.

7.1.6 Structure of C++ Program A typical C++ program would contain four sections as shown in figure. These sections may be placed in separate code files and then compiled independently or jointly.

Include files Class declaration Member functions Definitions Main function program

Figure. Structure of a C++ program

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

It is a common practice to organize a program into three separate files.

127

The class

declarations are placed in a header file and the definitions of member functions go into another file. Finally, the main program that uses the class is placed in a third file which “includes” the previous two files as well as any other files required. This approach is based on the concept of client-server model. 7.2 Tokens, Expressions and Control Structures 7.2.1 Introduction C++ is a superset of C and therefore most constructs of C are legal in C++ with their meaning unchanged. However, there are some exceptions and additions. 7.2.2 Tokens The smallest individual units in a program are known as tokens. More than one token can appear in a single line separated by white spaces. White space may be blank, carriage return or tab. C++ has the following tokens. 

Keywords

Identifiers

Constants

Strings

Operators

A C++ program is written using these tokens, white spaces, and the syntax of the language. 7.2.3 Keywords Keywords are reserved words which belong to C++ language. They cannot be used as variable names or other user-defined program elements. They have standard predefined meaning. Keywords should be written in lowercase. Example asm auto

char

delete extern if

class

break const

do

double for

continue else default

float

operator

inline private int

friend long

enum goto

return struct

new

short

try switch

void typedef volatile

protected signed template union while case public register

sizeof static

this

throw

unsigned catch virtual

7.2.4 Identifiers and Constants Identifiers refer to the names of variables, functions, arrays, classes, etc. created by the programmer. They are fundamental requirement of any language. Each language has its own rules for naming these identifiers. The following are rules are common to both C and C++:

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

Only alphabetic characters, digits and underscores are permitted

The name cannot start with a digit.

Uppercase and lowercase letters are distinct.

A declared keyword cannot be used as a variable name.

128

A major difference between C and C++ is the limit on the length of a name. C recognizes only the first 32 characters in a name; rather ANSI C++ has no limit. Constants refer to fixed values that do not change during the execution of a program. There are several kinds of literal constants.

Example 123

// decimal integer

12.34

// floating point integer

‘C’

//character constant

“C++” // string constant 37

// octal integer

7.2.5 Basic Data Types Each variable in C++ has a data type. Data types specify the size and type of values that can be stored. The C++ language offers a set of data types. They can be classified into the following three categories: i.

User-defined type

ii.

Built-in type

iii.

Derived type

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

129

C++ Data Types

User-defined type

Derived type

Built-in type

structure union class enumeration

array function pointer

Integral type

int

Void

Floating type

float

char

double

Figure. Hierarchy of C++ data types Both C and C++ compilers support all the built-in data types. Table lists all combinations of the basic data types and modifiers along with their size and range. Type

Bytes

Range

char

1

-128 to 127

unsigned char

1

0 to 255

signed char

1

-128 to 127

int

2

-32768 to 32767

unsigned int

2

0 to 65535

signed int

2

-32768 to 32767

short int

2

-32768 to 32767

unsigned short int

2

0 to 65535

signed short int

2

-32768 to 32767

long int

4

-2147483648 to 2147483647

signed long int

4

-2147483648 to 2147483647

unsigned long int

4

0 to 4294967295

float

4

3.4E-38 to 3.4E+38

double

8

1.7E-308 to 1.7E+308

Long double

10

3.4E-4932 to 1.1E+4932

The type void was introduced in ANSI C. Two normal uses of void are (1)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

130

to specify the return type of a function when it is not returning any value, and (2) to indicate an empty argument list to a function. Example: void funct1(void); Another interesting use of void is in the declaration of generic pointers. Example: void *gp;

//gp becomes generic pointer

A void pointer cannot be directly assigned to other type pointers in C++.

We need to use a

cast operator as shown below: ptr2 = (char *) ptr1;

7.2.6 User-Defined Data Types Structures and Classes

We have used user-defined data types such as struct and union in C. While these data types are legal in C++, some more features have been added to make them suitable for object-oriented programming. C++ also permits us to define another user-defined data type known as class which can be used, just like any other basic data type, to declare variables. The class variables are known as objects, which are the central focus of objectoriented programming. Enumerated Data Type

An enumerated data type is another user-defined type which provides a way for attaching names to numbers, thereby increasing comprehensibility of the code.

The

enum keyword automatically enumerates a list of words by assigning them values 0,1,2, and so on. This facility provides an alternative means for creating symbolic constants. The syntax of an enum statement is similar to that of the struct statement. Examples:

enum shape {circle, square, triangle}; enum colour {red, blue, green, yellow}; enum position {off, on};

The enumerated data types differ slightly in C++. In C++, the tag names shape, colour, and position become new type names. That means we can declare new variables using these tag names. Examples:

shape ellipse;

//ellipse is of type shape

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY colour background;

131

// background is of type colour

In C++, each enumerated data type retains its own separate type. This means that C++ does not permit an int value to be automatically converted to an enum value. Examples: colour background = blue; colour background = 7;

//allowed //Error in C++

colour background = (colour) 7;

//OK

However, an enumerated value can be used in place of an int value.

int c=red;

//valid, colour type promoted to int

By default, enumerators are assigned integer values starting with 0 for the first enumerator, 1 for the second and so on. For example, enum colour {red, blue=4, green=8}; enum colour{red=5, blue, green}; are valid definitions. In the first case, red is 0 by default. In the second case, blue is 6 and green is 7. C++ also permits the creation of anonymous enums (i.e., enums without tag names). Example: enum {off, on}; In C++, an enum defined within a class is local to that class only. 7.2.7 Derived Data Types Arrays The application of arrays in C++ is similar to that in C. The only exception is the way character arrays are initialized. When initializing a character array in ANSI C, the compiler will allow us to declare the array size as the exact length of the string constant. For instance, char string[3] = “xyz” is valid in ANSI C. But in C++ the size should be one larger than the number of characters in the string char string[4]= “xyz”; // O.K. . for C++ Functions A function is a part of a program that can be invoked from other parts of the program as often needed. Functions have undergone major changes in C++. While some of these changes are simple, others require a new way of thinking when organizing our programs.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

132

Pointers Pointers are variables that contain the addresses of other variables. Pointers are declared and initialized as in C. Examples:

int *ip; //int pointer ip =&x; //address of x assigned to ip *ip = 10;

//50 assigned to x through indirection

C++ adds the concept of constant pointer and pointer to a constant. .

char * const ptr1 = “GOOD�;

//constant pointer

We can modify the address that ptr1 is initialized to int const * ptr2 = &m;

//pointer to a constant

ptr2 is declared as pointer to a constant. It can point to any variable of correct type, but the contents of what it points to cannot be changed Pointers are extensively used in C++ for memory management and achieving polymorphism.

7.2.8 Symbolic Constants

There are two ways to create symbolic constants in C++: 1. Using the qualifier constant and 2. Defining a set of integer constants using enum keyword.

In both C and C++, any value declared as const cannot be modified by the program in anyway. However, there are some differences in implementation. In C++, we can use const in a constant expression, such as

const int size =10; char name [size];

It is illegal in C. As with long and short, if we use the const modifier alone, it defaults to int. For example, const size =10; means

const int size =10;

The named constants are just like variables except their values cannot be changed. C++ requires a const to be initialized. In ANSI C, const values are global in nature. They are visible outside the file in which they are declared. However, they can be made local by declaring them as static.

To give a const value as external linkage so that it can be

referenced from another file, we must explicitly define it as an extern in C++. Example:

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

133

extern const total =100; Another method of naming integer constants is as follows: enum { X,Y,Z}; This defines X, Y and Z as integer constants with values 0,1 and 2 respectively. This is equivalent to: const X=0; const Y=1; const Z=2; We can also assign values to X, Y and Z explicitly. enum{X=100, Y=50, Z=200}; such values can be any integer values.

7.2.9 Type Compatibility C++ is very strict with regard to type compatibility as compared to C. For instance, C+ defines int, short int, and long int as three different types. They must be cast when their values are assigned to one another. Similarly, unsigned char, char, and signed char are considered as different types, although each of these has a size of one byte. In C++, the types of values must be the same for complete compatibility. otherwise, a cast must be applied. These restrictions are necessary in order to support function overloading where two functions with the same name are distinguished using the type of function arguments.

Another notable difference is the way char constants are stored. In C, they are stored as ints. Therefore, sizeof (‘x’) is equivalent to sizeof (int) in C. In C++, however char is not promoted to the size of int and therefore, sizeof (‘x’) equals sizeof (char)

7.2.10 Declaration of Variables C++ allows the declaration of a variable anywhere in the scope. This means that a variable can be declared right at the place of its first use. This makes the program much easier to write and reduce the errors. Example: int main() {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

134

float x; float sum = 0;

//declaration

for(int i=1; i<5; i++)

//declaration

{ cin>>x; sum = sum + x; } float average; average= sum/i;

//declaration

cout<<average; return 0; }

7.2.11 Dynamic Initialization of Variables Initialization of variables during the run time is called dynamic initialization of variables. In C++, a variable can be initialized at run time using expressions at the place of declaration. For example, the following are valid initialization statements. int i; cin>>i; float avg=i/10; The variable avg is initialized only during run time, because the value of i is available during run time only.

Thus both the declaration and initialization of a variable can be done

simultaneously at the place where the variable is used for the first time. The following two statements in the example float average; average = sum/i;

//declare where it is necessary

can be combined into a single statement: float average = sum / i;

// initialize dynamically at run time

dynamic initialization is extensively used in object-oriented programming. 7.2.12 Reference Variables A reference variable is a name that acts as an alternative name for a previously defined variable. A reference variable is created as follows:

Data-type & reference-name = variable-name Example: float total = 100;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

135

float & sum = total;

total is a float type variable that has already been declared; sum is the alternative name declared to represent the variable total. Both the variables refer to the same data object in memory. Now, the statements cout << total; and cout<< sum; Both variables will print the same value and if we change values, it will reflect in both the variables. A reference variable must be initialized the time of declaration. C++ also assigns additional meaning to the symbol &. Here, & is not an address operator. The notation float & means reference to float. Other examples are int n[10]; int & x = n[10]; // x is alias for n[10] char & a =’\n’;

// initialize reference to a literal.

The variable x is an alternative to the array element n[10]. The variable a is initialized to the new-line constant.

7.7.13 Operators In C++ An operator is a symbol which represents some operations that can be performed on data. The different types of operators are: 1. Arithmetic operators

+ - * / % ++ --

2. Relational operators

> < >= <= = = !=

3. Logical operators

&& || !

4. Assignment operators

+= -= *= /= %=

5. Conditional operators

?:

6. Bitwise operators

& | ^ << >> ~

7. Scope resolution operator

::

8. Pointer-to-pointer declarator

::*

9. Pointer-to-member operator

->*

10. Pointer-to-member operator

.*

11. Memory release operator

delete

12. Line feed operator

endl

13. Memory allocation operator 14. Field width operator

new setw

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

136

7.2.14 Scope Resolution Operator C++ is a block structured language. Blocks and scopes can be used in constructing programs. The same variable name can be used to have different meanings in different blocks. A variable declared inside a block is said to be local to that block. The scope resolution operator is denoted by a pair of colon (::). This is used: (1) to define a member function outside the class, (2) to refer global variable. It takes the following form: :: variable-name This operator allows access to the global version of a variable. For Example int a=50;

// global a

void main() { int a=30;

// a redeclared, local to main

cout<< ” a = ”<<a<<”\n”; cout<< ” ::a = ”<<::a<<’\n”; return 0; } The output is: a = 30; ::a = 50; Note that ::a will always refer to the global a.

7.2.15 Member Dereferencing Operators Member dereferencing operators are operators which are used to access the member functions in a class through pointer. They are: ::* * ->*

To declare a pointer to a member of a class. To access a member using object name and a pointer to that member. To access a member using a pointer to the object and a pointer to that member.

7.2.16 Memory Management Operators Memory management operators are used to manage the available memory in an efficient manner. There are two memory management operators. They are (i) new, and (ii) delete. An object can be created by using new, and destroyed by using delete as and when required. The new operator can be used to create objects of any type. It takes the following form: Pointer-variable = new data-type;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

137

The new operator allocates sufficient memory to hold a data object of type data-type and returns the address of the object. The data-type may be any valid data type. The pointervariable holds the address of the memory space allocated. Examples: p = new int; q = new float; where p is a pointer of type int and q is a pointer of type float alternatively, we can combine the declaration of pointers and their assignments as follows: int *p = new int; float *q = new float; subsequently, the statements *p = 25; *q = 7.5; assign 25 to the newly created int object and 7.5 to the float object. We can also initialize the memory using the new operator. This is done as follows: pointer-variable = new data-type(value); Here, value specifies the initial value. Examples: int *p = new int(25); float *q = new float(7.5); new can be used to create a memory space for any data type including user-defined types such as arrays, structures and classes. The general form for a one-dimensional array is: pointer-variable = new data-type [size]; Here, size specifies the number of elements in the array. For example, the statement int p* = new int[10]; When a data object is no longer needed, it is destroyed to release the memory space for reuse. The general form for the delete operator is delete pointer-variable; The pointer variable is the pointer that points to a data object created with new. Examples:

delete p; delete q;

if we want to free a dynamically allocated array, we must use the following form of delete: delete [size] pointer-variable; Here, the size specifies the number of elements in the array. In C++, you need not specify the size. For example, delete [ ] p; will delete the entire array pointed to by p.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

138

7.2.17 Manipulators Manipulators are operators that are used to format the data to be displayed, with the insertion operator (<<). The most commonly used manipulators are endl and setw. The endl manipulator is used to transfer the control to a new line while printing. It has the same effect as using the newline character “\n”. For example, the statement .... .... cout<< “m =“<< m <<endl << “n =“<< n <<endl << “p =“<< p <<endl; .... .... If we assume the values of the variables as 2597, 14 and 175 respectively, the output will appear as shown below: m = 2597 n = 14 p = 175 Here, the numbers are right-justified. This form of output is possible only if we can specify the common field width for all the numbers and force them to be printed right-justified. The setw manipulator does this job. It is used as follows: cout<<setw(5)<<sum<<endl; This manipulator setw(5) specifies a field width 5 for printing the value of the variable sum. This value is right-justified within the field as shown below: 3

4

5

The symbol is the new manipulator which represents Rs. The identifier symbol can be used wherever we need to display the string Rs.

7.2.18 Type Cast Operator Type cast operator is a operator which is used to convert the predefined data type into a new data type. There are two types of data type conversion. They are (i)

Explicit conversion

(ii)

Implicit conversion

C++ permits explicit type conversion of variables or expressions using the type-cast operator. The following two versions of equivalent: (type-name) expression

// C notation

type-name (expression)

// C++ notation

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

139

examples: average =sum / (float)i; //C notation average =sum / float(i); // C++ notation Alternatively, we can use typedef to create an identifier of the required type and use it in the functional notation. typedef int * int _pt; p = int_pt(q); 7.2.19 Expressions and Implicit Conversations An expression is a combination of operators, constants and variables arranged as per the rules of the language.

It may also include function calls which return values.

An

expression may consist of one or more operands and zero or more operators to produce a value. Expressions may be of seven types, namely, constant expressions, integral expressions,

float

expressions,

pointer

expressions,

relational

expressions,

logical

expressions and bitwise expressions.. Constant expressions consist of only constant values. Examples: 15 20 + 5 / 2.0 ‘x’ Integral expressions are those which produce integer results after implementing all the automatic and explicit type conversions. Examples: m m*n–5 m - ‘x’ 5 + int(2.0) Where m and n are floating-point variables Float expressions are those which, after all conversions, produce floating-point results, Examples: x+y x * y /10 5 + float(10) Where x and y are floating-point variables. Pointer expressions produce address values. Examples: &m ptr ptr + 1 “xyz” Where m is variable and ptr is a pointer.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

140

Relational expressions yield results of type bool which take a value true or false. Examples: x <= y a + b == c + d Logical expressions combine two or more relational expressions and produces boolean type results. Examples: a>b && x = =1 x ==10 || y == 5 Bitwise expressions are used to manipulate data at bit level. Examples: x<<3 // Shift three bit position to left y>>1 // Shift one bit position to right 7.2.20 Special Assignment Expressions 7.2.20.1 Chained assignment x = ( y = 10) or x = y = 10; First 10 is assigned to y and then to x. A chained statement cannot be used to initialize variables at the time of declaration. Example: float a = b = 12.34 is illegal. This may be written as, float a=12.34, b=12.34 Embedded Assignment x = ( y = 50 ) + 10; (y = 50) is an assignment expression, known as embedded assignment. First , 50 is assigned to y and 60 is assigned to x. 7.2.20.2 Compound Assignment Like C, C++ supports a compound operator which is a combination of assignment operator with a binary arithmetic operator. For example, x = x + 10; This may be written as x +=10; The operator += known as compound assignment operator.

We can mix data types in expressions. For example,

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

141

float m; m = 5 + 7.5; is a valid statement. The operands 5 and 7.5 in the expression are different data types. But while execution the integer data 5 is automatically converted into float type and the operation is performed. So the result is 12.5. Wherever data types are mixed in an expression, C++ performs the conversion automatically.

This process is known as implicit or automatic

conversion.

7.2.21 operator overloading Overloading means assigning different meanings to an operation, depending on the context. C++ permits overloading of operators, thus allowing us to assign multiple meanings to operators.

For example, the input/output operators << and >> are good examples of

operator overloading. The << operator is used for shifting of bits as well as displaying the values of various data types. This has been made possible by the header file iostream.h where a number of overloading definitions for << are included. Thus, the statement cout<<75.86; invokes the definition for displaying a double type value, and cout<<�well done�; invokes the definition for displaying a char value. meanings to other C++ operators.

Similarly, we can define additional

For example, we can define + operator to add two

structures or objects. 7.2.22 Operator Precedence Although C++ enables us to add multiple meanings to the operators, their association and precedence remain the same.

For example, the multiplication operator will continue

having higher precedence than the add operator. The operators present in an expression are evaluated based on the priority or precedence of operators. Associativity means how an operator associates with its operands.

Associativity of an operator is either left to right

operation or right to left operation. For example, the associativity of = is from right to left. i.e., the right hand side value is assigned to left hand side variable.

Operator :: -> . ( ) [ ] postfix++ postfix--

associativity left to right left to right

Prefix++ prefix-- ~ ! unary + unaryUnary* unary &(type) size of new delete -> * *

right to left left to right

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY */%

left to right

+-

left to right

<< >>

left to right

<< = >>=

left to right

== ! =

left to right

&

left to right

^

left to right

|

left to right

&&

left to right

||

left to right

?:

left to right

142

=*=/=%=+=-= << = >> = & = ^ = | =

right to left

,

left to right

7.2.23 CONTROL STRUCTURES One method of achieving the objective of an accurate, error-resistant and maintainable code is to use one r any combination of the following three control structures : 1.

Sequence structure(Straight line)

2.

Selection structure(branching)

3.

Loop structure(iteration or repetition)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

143

Basic Control Structures

It is important to understand that all program processing can be coded by using only the three logic structures.

The approach of using one or more of these basic control

constructs in programming is known as structured programming.

7.2.23.1 The if statement The if statement is implemented in two forms:  Simple if statement  if….else statement

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

a)First level of Abstraction

144

b)Second level of Abstraction

Different level of Abstraction

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

145

Examples: Form 1

if(expression is true) { action1; } action2; action3; Example if (age<18) { cout<<“The person is not eligible for vote”; } Form 2

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

146

If(expression is true) { action1; } else { action2; } action3; Example if (age<18) { cout<<“The person is not eligible for vote”; } else { cout<<“The person is eligible for vote”; } 7.2.23.2 The switch statement This is a multiple-branching statement where, based on a condition, the control is transferred to one of the many possible points. This is implemented as follows: switch(expression) { case1: { action1; } case2: { action2; } case3: { action3; default: { action4;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

147

} } action5; Example index=marks/10; switch(index) { case 10: case 9: case 8: Grade=”Honours”; break; case 7: case 6: Grade=”first class”; break; case 5: Grade=”second class”; break; case 4: Grade=”third class”; break default: Grade=”fail”; break; } 7.2.23.3 The do-while statement The do-while is an exit-controlled loop. Based on a condition, the control is transferred back to a particular point in the program. The syntax is as follows: do { action1; } while(condition is true); action2; Example class total

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

148

{ public: public void sum( ) { int sum,n; sum=0; n=1; do { sum=sum+n; n++; } while(n<=5); cout<<"sum="<<sum; } }; int main( ) { total t; t.sum( ); } O/P is:sum= 15 7.2.23.4 The while statement This is also a loop structure, but is an entry-controlled one. The syntax is as follows: while(condition is true) { action1; } action2; Example class total { public: public void sum( ) { int sum,n; sum=0; n=1;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

149

while (n<=5) { sum=sum+n; n++; } cout<<"sum="<<sum; } }; int main( ) { total t; t.sum( ); } O/P is:sum= 15

7.2.23.5 The for statement The for is an entry-controlled loop and is used when an action is to be repeated for a predetermined number of times. The syntax is as follows: for(initial value; test; increment) { action1; } action2; Example class total { public: public void sum( ) { int sum=0; for(int i=1;i<=5;i++) { sum=sum+i; } cout<<"sum="<<sum; } };

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

150

int main( ) { Total t; t.sum( ); } O/P is:sum= 15

7.3.1 FUNCTIONS IN C++ Dividing a program into functions is one of the major principles of top-down, structured programming. Another advantage of using functions is that it is possible to reduce the size of a program by calling and using them at different places in the program. When the function is called, control is transferred to the first statement in the function body. The other statements in the function body are then executed and control returns to the main program when the closing brace is encountered.

C++ is no exception.

Functions

continue to be the building blocks of C++ programs. In fact, C++ has added many new features to functions to make them more reliable and flexible.

7.3.2 THE MAIN FUNCTION C does not specify any return type for the main( ) function which is the starting point for the execution of a program. The definition of main( ) would look like this: main ( ) { //main program statements }

This is perfectly valid because the main ( ) in C does not return any value. In C++, the main ( ) returns a value of type int to the operating system. C++, therefore, explicitly defines matching one of the following prototypes: int

main ( ) ;

int

main ( int argc,

char

*

argv [] );

The functions that have a return value should use the return statement for termination. The main( ) function in C++ is , therefore , defined as follows: int

main ( )

{ ‌‌..

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

151

‌‌.. return 0 ; } Since the return type of functions is int by default, the keyword int in the main( ) header is optional. Most C++ Compilers will generate an error or warning if there is no return statement. Turbo C++ issues the warning Function should return a value And then proceeds to compile the program. It is good programming practice to actually return a value from main( ). 7.3.3 FUNTION PROTOTYPING Function prototyping is one of the major improvements added to C++ functions. The prototype describes the function interface to the compiler by giving details such as the number and type of arguments and the type of return value. With function prototyping, a template is always used when declaring and defining a function. When a function is called, the compiler uses the template to ensure that proper arguments are passed, and the return value is treated correctly. Any violation in matching the arguments or the return types will be caught by the compiler at the time of compilation itself. These checks and controls did not exist in the conventional C functions. There is a major difference between C and C++. Function prototype is a declaration statement in the calling program and is of the following form: type function-name (argument-list); The argument-list contains the types and names of arguments that must be passed to the function

Example float volume( int x, float y, float z);

Note that each argument variable must be declared independently inside the parentheses. That is, a combined declaration like float volume( int x, float y, z); is illegal. We can either include or exclude the variable names in the argument list of prototypes. In function definition, names are required because the arguments must be referenced inside the function. Example: float volume( int a, float b, float c);

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

152

{ float v= a*b*c; …… …… } The function volume() can be invoked in a program as follows: float cube1= volume(b1,w1,h1); //function call The variable b1,w1, and h1 are known as the actual parameters which specify the dimensions of cube1. We can also declare a function with an empty argument list, as in the following example: void display( );

In C++, this means that the function does not pass any parameters. It is identical to statement void display(void); 7.3.4 CALL BY REFERENCE Provision of the reference variables in C++ permits us to pass parameters to functions by reference. When we pass arguments by reference, the formal arguments in the called function become aliases to the actual arguments in the calling function. This means that when the function is working with its own arguments, it is actually working on the original data. Consider the following function.

void swap(int a, int b)

//a and b are reference variables

{ int t = a;

//dynamic initialization

a = b; b = t; }

Now, if m and n are two integer variables, then the function call

swap(m, n); will exchange the values of m and n using their aliases(reference variables) a and b. 7.3.5 RETURN BY REFERENCE A function can also return a reference. Consider the following: int & max(int &x, int &y) {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

153

if(x>y) return x; else return y; } Since the return type of max() is int &, the function returns reference to x or y. Then the function call such as max(a,b) will yield a reference to either a or b depending on their values. This means that this function call can appear on the left-hand side of an assignment statement. That is, the statement

max(a,b) = -1;

is legal and assigns -1 to a if it is larger, otherwise -1 to b

7.3.6 INLINE FUNCTIONS To eliminate the cost of calls to small functions C++ proposes a new feature called inline function. A inline function is a function that is expanded in line when it is invoked. That is, the compiler replaces the function call with the corresponding function code. The inline funct6ions are defined as follows: inline function-header { function body } Example

inline double cube(double a) { return(a*a*a); }

The above inline function can be invoked by statements like c = cube(3.0); d = cube(2.5+1.5); 7.3.7 DEFAULT ARGUMENTS C++ allows us to call a function without specifying all its arguments. In such case, the function assigns a default value of the parameter which does not have a matching argument in the function call. Default values are specified when the function is declared. The

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

154

compiler looks at the prototype to see how many arguments a function uses and alerts the program for possible default values. Here is an example of a prototype with default values: float amount(float principal, int period, float rate=0.15); The default value is specified in a manner syntactically similar to a variable initialization. The above prototype declares a default value of 0.15 to the argument rate. A subsequent function call like value = amount(5000,7);

//one argument missing

passes the vale of 5000 to principal and 7 to period and then lets the function use default value of 0.15 for rate. The call value = amount(5000,5,0.12); passes an explicit value of 0.12 to rate.

7.3.8 Const ARGUMENTS In C++ argument to a function can be declared as const as shown below. int strlen(const char *p); int length(const string &s); The qualifier const tells the compiler that the function should not modify the argument. The compiler will generate an error when this condition is violated. This type of declaration is significant only when we pass arguments by reference or pointers.

7.3.9 FUNCTION OVERLOADING

Function overloading refers to use the same function name to create different functions that perform a variety of tasks. This is known as function polymorphism in OOP. Using this concept of function overloading to design a family of functions with one function name but with different argument lists.

The function would perform different

operations depending on the argument list in the function call. The correct function to be invoked is determined by checking the number and type of the arguments but not on the function type. Examples: //Declarations

int add(int a, int b);

//prototype1

int add(int a, int b, int c);

//prototype2

double add(double x, double y);

//prototype3

double add(double p, int q);

//prototype4

//Function calls

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY cout<<int add(5,10);

155

//prototype1

cout<<int add(5,10,15);

//prototype2

cout<<double add(12.5,7.5);

//prototype3

cout<<double add(15, 10.5);

//prototype4

A function call first matches the prototype having the same number and type of arguments and then calls the appropriate function for execution.

7.3.10 FRIEND AND VIRTUAL FUNCTIONS C++ introduces two new types of functions, namely, friend function and virtual function. They are basically introduced to handle some specific tasks related to class objects. We will discuss them later.

State whether the following statements are TRUE or FALSE:

a) In C++, a function contained within a class is called a member function. b) In C++, it is very easy to add new features to the existing structure of an object. c) The concept of using one operator for different purposes is known as Operator Overloading. d) The output function printf() cannot be used in C++ programs. e) A function argument is a value returned by the function to the calling program. f) A function can return a value by reference.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

156

UNIT-VIII 8.1.0 Classes and Objects 8.1.1 Introduction 8.1.2 C Structures Revisited 8.1.3 Specifying a Class 8.1.4 Defining Member Functions 8.1.5 A C++ Program with Class 8.1.6 Making an Outside Function Inline 8.1.7 Nesting of Member Functions 8.1.8 Arrays within a Class 8.1.9 Memory Allocation for Objects 8.1.10 Static Data Members 8.1.11 Static Members Function 8.1.12 Arrays of Objects 8.1.13 Objects as Function Arguments 8.1.14 Friendly Functions 8.1.15 Returning Objects 8.1.16 const Member Functions 8.1.17 Pointers to Members 8.1.18 Local Classes 8.2. CONSTRUCTORS AND DESTRUCTORS 8.2.1 Introduction 8.2.2 Constructors 8.2.3 Parameterized Constructors 8.2.4 Multiple Constructors in a Class 8.2.5 Constructors with Default Arguments 8.2.6 Dynamic Initialization of Objects 8.2.7 Copy Constructor 8.2.8 Dynamic Constructors 8.2.9 Constructing two- Dimensional Arrays 8.2.10 const objects 8.2.11 Destructors

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

157

8.1.0 CLASSES AND OBJECTS 8.1.1 INTRODUCTION: The most important feature of c++ is a “class”. Its significance is highlighted by the facts that Stroustrup initially gave the name “c with classes” to his new language. A class is an extension of the idea of structure used in c. It is a new way of creating and implementing a user-defined data type. we shall discuss, in this. 8.1.2.C STRUCTURES REVISITED: They provide a method for packing together data of different types. A structure is a convenient tool for handling a group of logically related items. It is a user –definied data type with a template that servers to define its data properties. struct student { Char name[20]; Int roll_number; Float total_marks; };

8.1.3 SPECIFYING THE CLASS:

A class is a way to bind the data and its associated functions together. it allows the data to be hidden, if necessary, from external use. when defining a class, we are creating a new abstract data type that can be treated Like any other built-in data type. Generally, a class specification has two types: 

Class declaration

Class function definitions

The class declaration describe the type and scope of its members. The class functions definitiomns describe how the class functions are implemented. General form: class class-name { private: variable declarations; function declarations; public:

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

158

variable declarations; function declarations; }; 

The variables declared inside the class are know as data members and the functions are know as member functions.

The binding up of data and functions together into a single class-type variable is referred to as encapsulation.

A simple example: class item { int number; float cost; public: void getdata(int a, int b); void putdata(void); }; Creating Objects: Remember that the declaration of class defined any objects of class-name. Once a class has been declared, we can create variable of that type by using the class name. Example classname object1,object2,….. ACCESSING CLASS MEMBERS: The private data of a class can be accessed only through the member function of that class. The following is the format for calling a member functions: Object-name. function-name(actual-arguments); Example: x. getdata (100,7.5); similarly x. putdata (); both can implement in the class. Sample program: class xyz { int x; int y: public:

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

159

int z; }; …… …… xyz p; p.x=0;

// error,x is private

p.z=10;

// ok,z is public

……. ……. 8.1.4 DEFINING MEMBER FUNCTIONS Member functions can be defined in two places: 

Outside the class definition.

Inside the class definition.

It is obvious that, irrespective of the place of definition, the function should perform the same task .therefore, the code for the function body would be identical in the both the classes. However, there is a suitable difference in this section. OUTSIDE THE CLASS DEFINITION: Member functions that are declared inside a class have to be defined separately outside the class. Their definitions are very much like the normal function definition, the ANSI prototype must be used for defining the function header. return-type class-name : : function-name (argument declaration) { function body }

The membership label class-name :: tells the compiler that the function function-name belongs to the class class-name, that is, the scope resolution operator. Example:

void item ::getdata(int a,float b) { number = a; cost =b; } void item :: putdata (void)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

160

{ cout<< “number”<<”\n”; cout<<”cost”<<”\n”; } Since these functions do not return any value, their return type is void. Functions arguments are declared using the ANSI prototype.

SPECIAL CHARACTERISTICS: The member functions have some special characteristics that are often used in the program development, these characteristics are: 

Several different classes can use the same function name. The ‘membership label’ will resolve their scope.

Member functions can access the private data of the class. a non-member function cannot do so.

A member function can call another member function directly, without using the dot operator.

INSIDE THE CLASS DEFINITION: Another method of defining a member function declaration by the actual function definition inside the class. For example, we could define the item class as follows: class item { int number; float cost; public: void getdata(int a,float b); void putdata(void) { cout<<number<<”\n”; cout<<cost<<”\n”; } }; Whenever the function defined inside the class, it is treated as an inline function.

8.1.5 A C++ PROGRAM WITH CLASS: // CLASS IMPLEMENTATION #include <io.stream>

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY class item

161

//class declaration

{ int number; float cost; public; void getdata (int a, float b); void putdata(void) { cout << “number :” <<number <<”\n”; cout << “cost :”

<< cost

<<”\n”;

} }; //member function definition…………… void item: : get data ( int a, float b)//use membership label { number=a; cost=b; } // main program……………// main () { item x; cout<<”\n objects x” << “\n”; x . getdata (100,299.95); x . putdata ( ); item y; cout<<”\n objects y “ << “\n”; y. getdata(200,175.50); y . putdata( ); } Output: Object x number:100 cost : 299.950012 Object y number : 200 cost : 175.5

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

162

8.1.6MAKING AN OUTSIDE FUNCTION INLINE: One of the objectives of oops is to separate the details of implementation from the class definition. We can define a member function outside the class definition and still make it inline by just using the qualifier inline in the header line of function definition. EXAMPLE: class item { …….. ……. public: void getdata(int a,int b); }; inline void item :: getdata(int a,float b)//definition { number=a; cost=b; }

8.1.7 NESTING OF MEMBER FUNCTIONS: A member function can be called by using its name inside another member function of the same class this is know as nesting of membership functions. EXAMPLE: #include<iostream> Class nest { Int m=2, n=3,a=0; Public: Void input(void); Void display(void); }; Int nest : : input(void) { A = M+N; Display(); }

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

163

Int nest :: display(void) { Cout<<”the sum =”<<a; } Int main() { Nest n; n.input(); return 0; }

8.1.8 PRIVATE MEMBER FUNCTIONS:

Although it is normal practice to place all the data item in a private section and all the functions in public, some situations may require certain functions to be hidden from the outside calls. A private member function can only called by another function that is a member of its class. Even an object cannot invoke a private function using the dot operator. Consider a class as defined below: class sample { int m; void read(void); public; void update(void); void write(void); }; If s1 is an object of sample, then s1.read(); is illegal. However, the function read() can be called by the function update()to update the value of m. void sample :: update(void) { read(); }

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

164

8.5.9 ARRAY WITHIN A CLASS: The arrays can be used as member variable in a class. the following class definition is valid. const int size=10; class array { int a[size]; public: void setval(void); void display(void); }; The array variable a[] declared as a private member of the class array can be used in the member functions, like any other array variable. we can perform any operations on it.

8.1.10 MEMORY ALLOCATION FOR OBJECTS: The member functions are created and placed in the memory space only once when they are defined as a part of a class specification. since all the objects belonging to that class use the same member functions, no separate space is allocated for member function when the objects are created. only space for member variables is allocated separately for each object. Separate memory locations for the objects re essential, because the member variable will hold different data value for different objects.

8.1.11 STATIC DATA MEMBERS: A data member of a class can be qualified as static. The

properties of a static

member variable are similar to that of a ‘C ‘static variable. CHARACTERISTICS: 

it is initialized to zero when the first object if its class is created. No other initialization is permitted.

Only one copy of that member is created for the entire class and is shared by all the objects of that class, no matter how objects are crated.

It is visible only within the class, but its lifetime is the entire program.

Static variables are normally used to maintain values common to the entire class.

8.1.12 STATIC MEMBER FUNCTION: Like static member variable, we can also have static member functions. a member function that is declared static has the following properties: 

A static function can have access to only other static members(functions or

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

165

variables)declared in the same class. 

A static member function can be called using the class name(instead of its objects)as follows: class-name : : function-name;

8.1.13 ARRAY OF OBJECTS: We know that an array can be of any data type including struct. Similarly, we can also have array of variable that are of the type class. such variable are called array of objects. Consider the following definition: class employee { char name[30]; float age; public: void getdata(void); void putdata(void); }; The identifier employee is a user-defined data type and can be used to create objects that relate to different categories of the employees. EXAMPLE employee manager [3]; The

array

manager

contains

three

objects

(manager)

namely,

manager[0],manager[1],manager[2] of type employee class. Since an array of objects behave like any other array, we can use the usual array accessing methods to access individual elements, and the dot member operator to access the member functions. Example: manager[i].putdata(); Will display the data of the ith element of the array manager . That is, this statement request the object manager[i] to invoke the member function putdata(). Note that only the space for data items of the objects is created. Member functions are stored separately and will be used by all the objects.

8.1.14 OBJECTS AS FUNCTIONS ARGUMENTS: Like any other data type, an object may be used as a function argument, this can be done in two ways: 

a copy of the entire objects is passed to the function.

Only the address of the object is transferred to the function.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

166

The first method is called pass-by-value. Since a copy of the objects is passed to the function, any changes made to the object inside the function do not affect the object used to call the function. the second method is called pass-by-reference. when an address of the object is passed, the called function works directly on the actual object used in the call. this means that any changes made to the object used in the call. this means that any changes made to the objects inside the function will reflect in the actual objects. the pass-by-reference Method is more efficient since it requires to pr\as only the address of the object and not the entire objects.

8.1.15 FRIENDLY FUNCTION: We have been emphasizing this chapter that the private members cannot accessed from outside the class. that is a non-member function cannot have an access to the private data of a class. however, there could be a situation where we would like two classes to share a particular function. We would like to use a function income tax to operate on the objects of both these classes. In such situations++ allows the common function to be made friendly with both the classes, thereby allowing the function to have access to the private data of these. classes. such a function need not be a member any of these classes. To make an outside function “friendly” to a class, we have to simply declare this function as a friend of the class as shown below: class ABC { …….. …….. public: …….. …….

friend void xyz(void); }; The function declaration should be preceded by the keyword friend. The function is defined elsewhere in the program like a normal c++ function definition does not use either the keyword friend or the scope operator ::. SPECIAL CHARACTERISTICS: 

It is not in the scope of the class to which it has been declared as friend.

Since it is not in the scope of the class, it cannot be called using the object of that class.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

167

It can be invoked like a normal functions, it cannot access the member names directly and has to use an object name and dot membership operator with each member name(e.g.A.x)

It can be declared either in the public or the private part of a class without affecting its meaning.

Usually, it has the objects as arguments. The friend function often used in the operator overloading which will be discussed here.

8.1.17 CONST MEMBER FUNCTION: If a member function does not alter any data in the class, then we may declare it as a const member function as follows: void mul(int,int) const; double get-balance()const; The qualifier const is appended to the function prototypes. The compiler will generated will generate an error message if such functions try to alter the data values.

8.1.18 POINTERS TO MEMBERS: It is possible to take the address of a member of a class and assign it to a pointer. The address of a member can be a member can be obtained by applying the operator & to a “fully qualified” class member name. a class member pointer can be declared using the operator ::* with the class name. EXAMPLE class a { private: int m; public: void show(); };

8.1.19 LOCAL CLASSES: Classes can be defined and used inside a function or a block. Such classes are called local classes. EXAMPLE: void test(int a) {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

168

…… ……. class student { ….. ….. }; … student s1(a); … } Local classes can use global variables and static variables declared inside the function but cannot use automatically local variables the globel variables should be used with the scope operator (::). 8.2 CONSTRUCTORS AND DESTRUCTORS 8.2.1 INTRODUCTION C++ provides a special member function called the constructor which enables an object to initialize itself when it is created. This is known as automatic initialization of objects. It also provides another member function called the destructor that destroys the objects when they are no longer required.

8.2.2CONSTRUCTORS It is special because its name is the same as the class name the constructor is invoked whenever an object of its associated class is created. It is called constructor because it constructs the values of data members of the class. example class integer { int m,n; public: integer(void); …….. ……… }; integer::integer(void) { m=0,n=0;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

169

} when a class contains a constructor like the one defined above, it is guaranteed that an object created by the class will be initialized automatically. CHARACTERISTICS 

They should be declared in the public section.

They are invoked automatically when the objects are created.

They do not have return type, not even void and therefore, and they cannot return values.

They cannot be inherited, through a derived class can call the base class constructor.

Like other c++ functions, they can have default arguments.

Constructors cannot be virtual.

We cannot refer to their addresses. An object with a constructor cannot be used as a member of a union.

They make ‘implicit calls’ to the operators new and delete when memory allocation is required.

8.2.3 PARAMETERIZED CONSTRUCTORS C++ permits us to achieve This objective by passing arguments to the constructs function when the object are created. The constructors that can take arguments to the constructor function when the objects are created. The constructors that can take arguments are called parameterized constructors. The constructors integer() may be modified to take arguments as shown below: class integer { int m,n; public: integer (int x, int y) …… …….. }; integer ::integer(int x,int y) { m=x: n=y; } When a constructor has been parameterized, the object declaration statement such as integer int1;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

170

INITIALISATION OF VALUES We must pass the initial values as arguments to the constructor function when an object is declared. This can done in two ways: 

By calling the constructor explicitly.

By calling the constructor implicitly.

The following declaration illustrates the first method: integer int1= integer (0,100); This statement creates an integer object int1 and passes the value 0 and 100 to it.The second is implemented as follows: integer int1(0,100); This method, sometimes called the shorthand method, is used very often as it is shorter,looks better and is easy to implement. Remember, when the constructor is parameterized, we must provide appropriate arguments for the constructor. The constructor functions can also be defined as inline functions. EXAMPLE class integer { int m,n; public: Integer(int x, int y) { m=x;y=n; } … …. }; However, a constructor can accept a reference to iits own class as a parameter. Thus , the statement class a { … …. public: a(a&); };

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

171

Is valid. In such cases, the constructor is called the copy constructor.

3.2.4 MULTIPLE CONSTRUCTORS IN A CLASS So far we have used two kinds of constructors.they are integer(); integer(int,int); In the first case, the constructor itself supplies the data values and no values are passed by the calling program. In the second case, the function call passes the appropriate values from main().C++ permits to use both these constructors in the same class. example class integer { int m,n; public: integer() { m=0; n=0; } integer(int a, int b) { m=a; n=b; } integer (integer &i) { m=i.m; n=i.n; } }; This declares three constructors for an integer object.the first constructor receives no arguments, the second receives two integer arguments and the third receives one integer object as an argument.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

172

8.2.5 CONSTRUCTORS WITH DEFAULT ARGUMENTS It is possible to define constructors with default arguments. For example, the constructor complex() can be declared as follows: complex(float real, float image=0.0); The default value of the argument image is zero then, the statement complex c(5.0); Assign the value 5.0 to the real variable and 0.0 to image (by default). However, the statement complex c(2.0,3.0); Assign 2.0 to real variable and 3.0 to image. The actual parameter, when specified, overrides the default value as pointed out earlier, the missing arguments must be the trailing ones.

8.2.6 DYNAMIC INITIALIZATION OF OBJECTS Class objects can be initialized dynamically too that is to say, the initial value of an object may be provided during run time. One advantage of dynamic initialization is that we can provide various initialization formats, using overloaded constructors this provides the flexibility of using different format of data at run time depending upon the situation.

8.2.6 CONSTRUCTING TWO-DIMENTIONAL ARRAYS We can construct matrix variables using the class type objects. EXAMPLE #include<iostream> class matrix { int **p; int d1,d2; public: matrix(int x,int y); void get-element(int i,int j,int value) { p[i][j]=value; } int & put-element(int I,int j) {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

173

return p[i][j]; } }; matrix :: matrix(int x, int y) { d1 =x; d2 = y; p= new int *[d1]; for(int i=0; i< d1 ;i++) p[i]= new int[d2]; } int main() { int m,n; cout <<”ENTER SIZE OF MATRIX:”; cin>>m>>n; matrix a(m,n); cout<<”ENTER MATRIX ELEMENTS ROW BY ROW; int i,j,value; for(i=0;i<m;i++) for(j=0;j<n;j++) { cin>> value; a.get-element(i,j,value); } cout<<”\n”; cout<<a.get-element(1,2); return 0; }; OUTPUT: ENTER SIZE OF MATRIX: 3 4 ENTER MATRIX ELEMENTS ROW BY ROW 11 12 13 14 15 16 17 18 19 20 21 22 Output 17

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

174

The constructor first creates a vector pointer to an int of size d1. then, it allocates, interactively an int type vector of size d2 pointed at by each element p[i]. Thus, space for the elements of a d1* d2 matrix is allocated from free store as show above.

8.2.7 COPY CONSTRUCTOR A copy constructor is used to declare and initialize an object from another object. EXAMPLE: integer i2(i1); Would define the object i2 and the same time initialize it to the values of i1. A copy constructor takes a reference to an object of the same class as itself as an argument.

8.2.8 DYNAMIC CONSTRUCTORS The constructors can also be used to allocate memory while creating objects. This will enable the system to allocate the right amount of memory for each object when the objects are not of the same size, thus resulting in the saving of memory. Allocation of memory to objects at the time of their construction is known as dynamic construction of objects. 8.2.9 CONSTRUCTING TWO-DIMENSIONAL ARRAYS: We can construct matrix variables using the class type objects. The example will explain in detail about constructors. EXAMPLE: #incluude<iostream> Clas matrix { Int **p; Int d1,d2; Public; Matrix (int x, int y); Void get_element(int I, int j, int value); { P[i][j]=value;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

175

} Int & put_element(int I,int j); { Return p[i][j]; } }; Matrix :: matrix (int x ,int j) { Di=x; D2=y; P=new int *[d1]; For(int I =0 ; i<d 1; i++) P[i]= new int[d2]; } Int main() { Int m,n; Cout<< “ENTER SIZE OF MATRIX”; Cin>>m>>n; Matrix A(m,n); Cout>> “ENTER MATRIX ELEMENTS ROW BY ROW \n”; Int I,j,value;

For(i=0 ; i<m ;i++) For(j=0 ; j<n ;j++) { Cin>>value; A.get_element(I,j,value);

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

176

} Cout<<”\n”; Cout<<A.put_element(1,2); Return 0; }; OUTPUT: ENTER SIZE OF MATRIX: 3 4 ENTER MATRIX ELEMENTS ROW BY ROW: 11 12 13 14 15 16 17 18 19 20 21 22

8.2.10 const OBJECTS We may create and use constant objects using const keyword before object declaration. const matrix x(m,n); Any attempt to modify the values of m and n will generate compile-time error. Further, a constant object can call only const member functions. As we know, a const member is a function Prototype or function definition where the keyword const appears after the function’s signature. Whenever const objects try to invoke non-const member functions, the compiler generates error.

8.2.11DESTRUCTORS A destructor, as the name implies, is used to destroy the objects that have been created by a constructor. like a constructor, the destructor is a member function whose name is the same as the class name but is preceded by a title. EXAMPLE ~integer() { } A destructor never takes any argument nor does it return any value it will be invoked implicitly by the compiler upon exit from the program to clean up storage that is no longer

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

177

accessible. It is a good practice to declare destructors in a program since it releases memory space for future use. Whenever new is used to allocate memory in the constructors, we should use delete to free that memory. example matrix :: ~matrix() { for(int i=0; i<d1 ;i++) delete p[i]; delete p; } This is required because when the pointers to objects go out of scope, a destructor is not called implicitly.

State whether the following statements are TRUE or FALSE: 1) Data item in a class must always be private. 2) A function designed as private is accessible only to member functions of that class. 3) A function designed as public can be accessed like any other ordinary functions. 4) Member functions defined inside a class specifier become inline functions by default. 5) Friend functions have access to only public members of a class. 6) Constructors, like other member functions, can be declared anywhere in the class. 7) Constructors do not return any values. 8) A constructor that accepts no parameter is known as the default constructor. 9) A class should have at least one constructor 10) Destructors never take any argument.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

178

UNIT-IX 9.1.0 Operator Overloading and Type Conversions

9.1.1 Introduction 9.1.2 Defining Operator Overloading 9.1.3 Overloading Unary Operators 9.1.4 Overloading Binary Operators 9.1.5 Overloading Binary Operators Using Friends 9.1.6 Manipulation of Strings Using Operators 9.1.7 Rules for Overloading Operators 9.1.8 Type Conversions

9.2.0 Inheritance 9.2.1. Introduction 9.2.2. Defining Derived Classes 9.2.3. Single Inheritance 9.2.4. Making a Private Member Inheritable 9.2.5. Multilevel Inheritance 9.2.6. Multiple Inheritance 9.2.7. Hierarchical Inheritance 9.2.8. Hybrid Inheritance 9.2.9. Virtual Base Classes 9.2.10. Abstract classes 9.2.11. Constructors in Derived Classes 9.2.12. Member Classes: Nesting of Classes

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

179

9.3.0 Pointers, Virtual Functions and Polymorphism 9.3.1 Introduction 9.3.2 Pointers to Objects 9.3.3 this pointer 9.3.4 Pointers to Derived Classes 9.3.5 Virtual Functions 9.3.6 Pure Virtual Functions

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

180

9.1.0 Operator Overloading and Type Conversions 9.1.1 Introduction

Operator overloading is one of the many exciting features of C++ language. It is an important technique that has enhanced the power of extensibility of C++. C++ tries to make the user-defined data types behave in much the same way as the built-in types. C++ has the ability to provide the operators with a special meaning for a data type. The mechanism of giving such special meanings to an operator is known as operator overloading.

Operator overloading provides a flexible option for the creation of new definitions for most of the C++ operators. We can give additional meaning to all the C++ operators except Class member access operators (., .*), Scope resolution operator (::), Size operator (sizeof), and Conditional operator (?:).

9.1.2 Defining Operator Overloading

To define an additional task to an operator, we must specify what it means in relation to the class to which the operator is applied. This is done with the help of a special function, called operator function, which describes the task. The general form of an operator function is: returntype classname :: operator op (arg-list) { Function body

// task defined

} Where returntype is the type of value returned by the specified operation and op is the operator being overloaded. The op is preceded by the keyword operator. operator op is the function name.

Operator functions must be either member functions or friend functions.

A basic

difference between them is that a friend function will have only one argument for unary operators and two for binary operators, while a member function has no arguments for unary operators and only one for binary operators. Arguments may be passed either by value or by reference. Operator functions are declared in the class using prototypes. The process of overloading involves the following steps: 1. First, create a class that defines the data type that is to be used in the overloading operation.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

181

2. Declare the operator function operator op ( ) in the public part of the class. It may be either a member function or a friend function. 3. Define the operator function to implement the required operations. 9.1.3 Overloading Unary Operators Let us consider the unary minus operator. A minus operator, when used as a unary, takes just one operand. We know that this operator changes the sign of an operand when applied to a basic data item. We will see here how to overload this operator so that it can be applied to an object in much the same way as is applied to an int or float variable. The unary minus when applied to an object should change the sign of each of its data items. Program shows how the unary minus operator is overloaded. #include <iostream.h> class space { int x; int y; int z; public: void getdata (int a, int b, int c); void display (void); void operator-( );

// overload unary minus

}; void space :: getdata ( int a, int b, int c) { x=a; y=b; z=c; } void space :: display (void) { cout<< x << “ ”; cout<< y << “ ”; cout<< z << “\n”; } void space :: operator-( )

// Defining operator-( )

{ x=-x; y=-y;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

182

z=-z; } main ( ) { space S; S.getdata (10, -20, 30); cout<< “S : ”; S.display ( ); -S;

// activates operator-( )

cout<<”S : ”; S.display ( ); } The program produces the following output: S : 10 -20 30 S : -10 20 -30 Note that the function operator-( ) takes no argument. This operator function changes the sign of data members of the object S. Since this function is a member function of the same class, it can directly access the members of the object which activated it.

The function

operator-( ) does not return any value. It can work if the function is modified to return an object. Therefore, the changes made inside the operator function will not reflect in the called object.

9.1.4 Overloading Binary Operators

We have just seen how to overload a unary operator. The same mechanism can be used to overload a binary operator. Let us illustrate how to add two complex numbers using a friend function. A statement like C=sum(A, B);

//functional notation

was used. The functional notation can be replaced by an expression C=A+B;

//arithmetic notation

By overloading the + operator using an operator+( ) function. The program illustrates how this is accomplished.

#include<iostream.h>

class complex {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY float x;

//real part

float y;

//imaginary part

183

public: complex( ) { }

//constructor1

complex(float real, float imag)

//constructor2

{ x = real; y = imag; } complex operator+(complex); void display(void); }; complex complex :: operator+(complex c) { complex temp;

//temporary

temp.x = x + c.x;

//float addition

temp.y = y + c.y;

//float addition

return(temp); } void complex :: display(void) { cout<< x << “+ j” << y << “\n”; } main( ) { complex C1, C2, C3;

//invokes constructor1

C1=complex(2.5, 3.5); //invokes constructor2 C2=complex(1.6, 2.7); //invokes constructor3 C3=C1 + C2;

//invokes operator+( )

cout<< “C1 = “; C1.display( ); cout<< “C2 = “; C2.display( ); cout<< “C3 = “; C3.display( );

}

The output of program would be: C1 = 2.5 + j3.5 C2 = 1.6 + j2.7 C3 = 4.1 + j6.2

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

184

9.1.5 Overloading Binary Operators Using Friends

Friend functions may be used in the place of member functions for overloading a binary operator. The only difference being that a friend function requires two arguments to be explicitly passed to it while a member function requires only one. The complex number program can be modified using a friend operator function as follows: 1. Replace the member function declaration by the friend function declaration. friend complex operator+(complex, complex); 2. Redefine the operator function as follows: complex operator+(complex a, complex b) { return complex((a.x + b.x), (a.y + b.y)); } Program illustrates this using scalar multiplication of a vector. It also shows how to overload the input and output operators >> and <<. #include<iostream.h> const size = 3; class vector { int v[size]; public: vector( ); vector( int * x); friend vector operator * (int a, vector b); //friend 1 friend vector operator * (vector b, int a); //friend 2 friend istream & operator >> (istream &, vector &); friend ostream & operator >> (ostream &, vector &); }; vector :: vector( ) { for(int i=0; i<size; i++) v[i]=0; } vector :: vector(int * x ) { for(int i=0; i<size; i++) v[i]=x[i];

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

185

} vector operator *(int a, vector b) { vector c; for(int i=0; i<size; i++) c.v[i] = a * b.v[i]; return c; } vector operator *(vector b, int a) { vector c; for(int i=0; i<size; i++) c.v[i] = b.v[i] * a; return c; } istream & operator >> (istream & din, vector & b) { for(int i=0; i<size; i++) din >> b.v[i]; return(din); } ostream & operator << (ostream & dout, vector & b) { dout<<”{“<<b.v[0]; for(int i=0; i<size; i++) dout<<” , “<< b.v[i]; dout<< “)”; return(dout); } int x[size] = {2,4,6}; main( ) { vector m;

//invokes constructor 1

vector n = x;

//invokes constructor 2

cout<< “Enter elements of vector m”<<”\n”; cin>>m;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

186

cout<<”\n”; cout<<”m = “<<m<<”\n”;

vector p,q; p = 2 * m; q = n * 2; cout<<”\n”; cout<<”p = “<<p<<”\n”; cout<<”q = “<<q<<”\n”; }

Shown below is the output of program: Enter elements of vector m 5 10 15

m = (5, 10, 15)

p = (10, 20, 30) q = (4, 8, 12) 9.1.6 Manipulation of Strings Using Operators

ANSI C implements strings using character arrays, pointers and string functions. There are no operators for manipulating the strings. One of the main drawbacks of string manipulations in C is that whenever a string is to be copied, the programmer must first determine its length and allocate the required amount of memory.

Although these limitations exist in C++ as well, it permits us to create our own definitions of operators that can be used to manipulate the strings very much similar to the decimal numbers. For example, statements like string3 = string1 + string2; if(string1 >= string2) string = string1; Strings can be defined as class objects which can be manipulated like the built-in types. Since the strings vary greatly in size, we use new to allocate memory for each string and a pointer variable to point to the string array. Thus, we must create string objects that can hold information about length and location, which are necessary for string manipulations. class string

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

187

{ char *p;

//pointer to string

int len; //length of string public: …..

//member functions

…..

//to initialize and

…..

//manipulate strings

}; 9.1.7 Rules for Overloading Operators

Although it looks simple to redefine the operators, there are certain restrictions and limitations in overloading them. Some of them are listed below: 1. Only existing operators can be overloaded. New operators cannot be created. 2. The overloaded operator must have at least one operand that is of userdefined type. 3. We cannot change the basic meaning of an operator. That is, we cannot redefine the plus(+) operator to subtract one value from another. 4. Overloaded operators follow the syntax rules of the original operators. That cannot be overridden. 5. There are some operators that cannot be overloaded. 6. We cannot use friend functions to overload certain operators. However, member Functions can be used to overload them.

7. Unary operators, overloaded by means of a member function, take no explicit arguments and return no explicit values. But, those overloaded by means of a friend function take one reference argument. 8. Binary operators overloaded through a member function take one explicit Argument and those which are overloaded through a friend function take two explicit arguments. 9. When using binary operators overloaded through a member function, the left- hand operand must be an object of the relevant class. 10. Binary arithmetic operators such as +,-.*, and / must explicitly return a value. They must not attempt to change their own arguments.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

188

9.1.8 Type Conversions

We know that when constants and variables of different types are mixed in an expression, C applies automatic type conversion to the operands as per certain rules. Similarly, an assignment operation also causes the automatic type conversion. The type of data to the right of an assignment operator is automatically converted to the type of the variable to the left. For example, the statements int m; float x = 3.14159; m = x;

convert x to an integer before its value is assigned to m. Thus, the fractional part is truncated. The type conversions are automatic as long as the data types involved are built-in types. Consider the following statement that adds two objects and then assigns the result to a third object. V3 = V1 + V2; //V1, V2 and V3 are class type objects

When the objects are of the same class type, the operations of addition and assignment are carried out smoothly and the compiler does not make any complaints. Since the user-defined data types are designed by us to suit our requirements, the compiler does not support automatic type conversions for such data types. Therefore, we must design the conversion routines by ourselves, if such operations are required. Three types of situations might arise in the data conversion between uncompatible types: 1. Conversion from built-in type to class type. 2. Conversion from class type to built-in type. 3. Conversion from one class type to another class type.

Basic to Class Type The conversion from basic type to class type is east to accomplish. For example, a constructor was used to build a vector object from an int type array. Similarly, we used another constructor to build a string type object from a char* type variable. These are all examples where constructors perform a defacto type conversion from the argument’s type to the constructor’s class type. Let us consider an example of converting an int type to a class type. class time { int hrs;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

189

int mins; public: ….. ….. time(int t)

//constructor

{ hours = t / 60;

//t in minutes

mins = t % 60; } }; The following conversion statements can be used in a function: time = T1;

//object T1 created

int duration = 85; T1 = duration; //int to class type After this conversion, the hrs member of T1 will contain a value of 1 and mins member a value of 25, denoting 1 hour and 25 minutes. Note that the constructors used for the type conversion take a single argument whose type is to be converted.

Class to Basic Type

The constructor functions do not support this operation. C++ allows us to define an overloaded casting operator that could be used to convert a class type data to a basic type.The general form of an overloaded casting operator function, usually referred to as a conversion function, is: operator typename( ) { ….. ….. (Function statements) ….. } This function converts a class type data to typename.For example, the operator double() converts a class object to type double, the operator int( ) converts a class type object to type int, and so on. Consider the following conversion: Vector :: operator double( ) { double sum = 0; for(int i=0; i<size; i++)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

190

sum=sum+v[i] * v[i]; return sqrt(sum); } This function converts a vector to the corresponding scalar magnitude. The operator double( ) can be used as follows:

double length = double(V1); or double length = V1; where V1 is an object of type vector. Both the statements have exactly the same effect. The casting operator function should satisfy the following conditions: 

It must be a class member.

It must not specify a return type.

It must not have any arguments.

Since it is a member function, it is invoked by the object and the values used for conversion inside the function belong to the object that invoked the function. This means that the function does not need an argument.

One Class to Another Class Type

There are situations to convert one class type data to another class type. Example: objX = objY;

//objects of different types

objx is an object of class X and obj Y is an object of class Y. The class Y type data is converted to class X type data and the converted value is assigned to the objX. Since the conversion takes place from class Y to class X, Y is known as the source calss and X is known as the destination class. Such conversions between objects of different classes can be carried out by either a constructor or a conversion function. The compiler treats them the same way. Then, how do we decide which form to use? It depends upon where we want the type-conversion function to be located, in the source class or in the destination class. We know that the casting operator function Operator typename () Converts the class object of which it is a member to typename. The typename may be a builtin type or a user-defined one (another class type).

In the case of conversions between

objects, typename refers to the destination class. Therefore, when a class needs to be converted, a casting operator function can be used (i.e source class). The conversion takes place in the source class and the result is given to the destination class object.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

191

Now consider a single-argument constructor function which serves as an instruction for converting the argument’s type to the class type of which it is a member. This implies that the argument belongs to the source class and is passed to the destination class for conversion. This makes it necessary that the conversion constructor be placed in the destination class.

A Data Conversion Example

Let us consider an example of an inventory of products in a store. One way of recording the details of the products is to record their code number, total items in the stock and the cost of each item. Another approach is to just specify the item code and the value of the item in the stock. The example shown in program uses two classes and show how to convert data of one type to other.

#include <iostream.h> //class invent2 Class invent1 { Int code; Int items; Float price; Public: Invent1(int a, int b, float c) { Code = a; Items = b; Price = c; } Void putdata() { Cout << “code:” << code << “\n”; Cout << “items: “ << items << “\n”; Cout << “value: “ << price << “\n”; } Int getcode() (return code;) Int getitems() (return items;) Int getprice() (return price;)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

192

Operator float () (return (items * price) ;) /* operator invent2() // invent to invent2 { Invent2 temp; Temp.code = code; Temp.value = price * items; Return temp; } */ }; // end of source class

Class invent2 // destination class { Int code; Float value; Public: Invent2() { code = 0; value = 0; Invent 2(int x, float y) { code = x; value y; Void putdata() { Cout << “code : “<< code << “\n”; Cout << “value : “<< value << “\n\n”; } Invent2(invent1 p) { Code = p.getcode( ); Value = p.getitems( ) * p.getprice( ); } }; Main( ) { Invent1 s1(100,5, 140.0); Invent2 d1; Float total_value;

Total_value = s1;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

193

D1= s1; Cout << “product details – invent1 type” << “\n “; S1. putdata ( ); Cout << “\n stock value “ << “\n”; Cout << “value = “ << total_value << “\n\n”; Cout << “product details – invent2 type” << “\n”; D1.putdata ( ); }

Following is the output of program: Product details – invent type Code: 100 Items : 5 Value : 140 Stock value Value : 700 Product details – invent2 type Code : 100 Value: 700

It is important that we do not use both the constructor and the casting operator for the same type conversion, since this introduces an ambiguity as to how the conversion should be performed. 9.2.0 Inheritance: Extending Classes 9.2.1 Introduction Reusability is yet another important feature of OOP. It is always nice if we could reuse something that already exists rather than trying to create the same all over again. It would not only save time and money but also reduce frustration and increase reliability. For instance, the reuse of a class that has already been tested, debugged and used many times can save us the effort of developing and testing the same again. The mechanism of deriving a new class from an old one is called inheritance (or derivation). The old class is referred to as the bass class and the new one is called the derived class or subclass. The derived class inherits some or all of the traits form the bass class. A class can also inherit properties form more than one class or form more than one level. A derived class with only one base class, is called single inheritance and one with several base

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

194

classes is called multiple inheritance. On the other hand, the traits of one class may be inherited by more than one class. This process is known as hierarchical inheritance. The mechanism of deriving a class from another ‘derived class’ is known as multilevel inheritance. Figurer 8.1 shows various forms of inheritance that could be used for writing extensible programs. The direction of arrow indicates the direction of inheritance. (Some authors show the arrow in opposite direction meaning “inherited from”.

A

B

(a) Single inheritance

A

B

A

(b) Multiple inheritance C

(c) B Hierarchical inheritance C

A

A

B (d) Multilevel inheritance

C

D

B

C (e) Hybrid inheritance

B

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

195

9.2.2 Defining Derived Classes A derived class can be defined by specifying its relationship with the base class in addition to its own details. The general form of defining a derived class is : Class derived –class –name

: visibility – mode base – class – name

{ …..// …..// members of derived class …..// }; The colon indicates that the derived – class- name is derived from the base – class – name. The colon indicates that the derived – class – name is derived from the base – class – name. the visibility – mode is optional and, if present, may be either private or public. The default visibility – mode is private. Visibility mode specifies whether the features of the base class are privately derived or publicly derived. Example : class ABC: private XYZ

// private derivation

{ members of ABC }; class ABC: public XYZ

// public derivation

{ members of ABC };

Class ABC: XYZ

// private derivation by default

{ members of ABC }; 9.2.3 Single Inheritance A base class B and a derived class D.

The class B contains one private data

member, one public data member, and three public member functions. The class D contains one private data member and two public member functions. Single Inheritance: Public #include <iostream> using namespace std; class B {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY Int a;

//private; not inheritable

Int b;

// public; ready for inheritance

196

Public:

void get_ab(); int get_a(void); void show_a(void); }; Class D : public B

// public derivation

{ int c; public: void mul(void); void display (void); }; //----------------------------------------------------------------------Void B :: get_ab(void) { a = 5; b = 10; } int B :: get_a() { Return a; } Void B :: show_a() { Cout << ”a = ” << “\n”; } void D :: mul() { c = b * get_a(); } Void D :: display () { cout << “ a = “ << get_a() << “\n”; cout << “b = “ << b << “\n”; cout << “ c = “ << c << “\n\n”; }

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

197

//----------------------------------------------------------------int main () { D d; d.get_ ab(); d.mul(); d.show_a(); d.display();

d.b = 20; d.mul (); d.display (); return 0; } Given below is the output of program a=5 a=5 b = 10 c = 50 a=5 b = 20 c = 100 The class D is a public derivation of the base class B. Therefore, D inherits all the public members of B and retains their visibility. Thus a public member of the base class B is also a public member of the derived class D. The private members of B cannot be inherited by D.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

198

Class D Private Section C Public Section B

Inherite d from B

get_ab()

B

get_a() show_a()

mul() display ()

9.2.4 Making a Private Member Inheritable

What do we do if the private data needs to be inherited by a derived class? This can be accomplished by modifying the visibility limit of the private member by making it public. This would make it accessible to all the other functions of the program, thus taking away the advantage of data hiding. C++ provides a third visibility modifier, protected, which serve a limited purpose in inheritance. class alpha { private :

// optional

…..

// visible to member functions

…..

// within its class

protected: …..

// visible to member functions

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY …..

// of its own and derived class

…..

// visible to all functions

…..

// in the program

199

public:

};

When a protected member is inherited in public mode, it becomes protected in the derived class too and therefore is accessible by the member functions of the derived class. It is also ready for further inheritance. A protected member, inherited in the private mode derivation, becomes private in the derived class. The pictorial representation for two levels of derivation

Class B Not inheritable x

x Not inheritable

Privat e Protecte d Public

Class D2: private B

Class D1: public B Privat e Protecte d Public

Privat e Protecte d Public

Class X: publicD1: protected D2 Privat e Protecte d Public Effect of inheritance on the visibility of member The keywords private, protected, and public may appear in any order and any number of times in the declaration of a class. For example, class beta { Protected: …….

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

200

public: ……. private: ……. public: …….. }; is a valid class definition. However, the normal practice is to use them as follows: class beta { ……… // private by default ……… protected : ……… public: ……… } It is also possible to inherit a base class in protected mode (known as protected derivation). In protected derivation, both the public and protected members of the base class become protected members of the derived class.

9.2.5 Multilevel Inheritance The class A serves as a base class for the derived class B, which in turn serves as a base class for the derived class C. the class B is known as intermediate base class since it provides a link for the inheritance between A and C. The chain ABC is known as inheritance path.

All users

own member functions

derived class

and friendly functions

private

and classes

Member functions A simple view of access control to the members of a class

protected

A FOR MORE DETAILSBase VISITclass US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621 public Grand father


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

201

Multilevel inheritance A derived class with multilevel inheritance is declared as follows: Class A {……};

// base class

Class B: public A {……..};

// B derived from A

Class C: public B {……..};

// C derived from B

Let us consider a simple example. Assume that the test results of a batch of students are stored in three different classes. Class student stores the roll- number, class test stores the marks obtained in two subjects and class result contains the total marks obtained in the test. The class result can inherit the details of the marks obtained in the test and the rollnumber of students through multilevel inheritance. Example: Class student { Protected; Int roll_number; Public: Void get_number(int); Void put_number(void); }; Void student : : get_number(int a) { Roll_number = a; } Void student : : put_number() { Cout << “Roll Number : “ << roll_number << ”\n”; } Class test : public student

// first level derivation

{ Protected : Float sub1; Float sub2; Public : Void get_marks(float, float); Void put_marks(void); }; Void test : : get_marks(float x, float y) {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

202

Sub1 = x; Sub2 = y; } Void test : : put_marks () { Cout << “marks in SUB1 = “ << sub1 << “\n”; Cout << “marks in SUB2 = “ << sub2 << “\n”; } Class result : public test

// second level derivation

{ Float total;

// private by default

Public: Void display (void); }; Void result : : display (viod) { Total = sub1 + sub2; Put_number(); Put_marks (); Cout << “Total = “<< total << “\n”; } Int main () { Result student1 ;

// student1 created

Student1.get_number (111); Student1.get_marks (75.0, 59.5); Student1.display(); Return 0; } Display the following output: Roll Number : 111 Marks in SUB1 = 75 Marks in SUB2 = 59.5 Total = 134.5

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

203

9.2.6 Multiple inheritance A class can inherit the attributes of two or more classes. This is known as multiple inheritance. Multiple inheritance allows us to combine the features of several existing classes as a starting point for defining new classes. It is like a child inheriting the physical features of one parent and the intelligence of another.

B-1

B-2

…..

B-n

The syntax of a derived class with multiple base classes is as follows:

D

Class D: visibility B-1, visibility B-2 … { …… …… (Body of D) …… };

Where, visibility may be either public or private. The base classes are separated by commas.

Example : Class P: public M, public N { Public : Void display (void); }; Classes M and N have been specified as follows: Class M {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

204

Protected : int m; public : void M :; get_m(int); }; Void M : : get_m(int x) { m= x; } Class N { Protected: int n; public: void get_n(int); }; Void N : : get_n(int y) { n = y; } The derived class P, as declared above, would, in effect, contain all the members of M and N in addition to its own members as shown below: Class P { Protected : int m;

// from M

int n;

// form N

public: void get_m (int);

// form M

void get_n (int);

// from N

void display(void);

//own member

}; The member function display () can be defined as follows: Void P : : display (void) { Cout << “m = “ << m << “\n”; Cout << “n = “ << n << “\n”;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

205

Cout << “m*n = “ <<m*n << “\n”; }; The main () function which provides the user-interface may be written as follows: Main() MULTIPLE INHERITNACE # include <iostream> Using namespace std; Class M { protected : int n; public : void get_m(int); }; Class N { Protected: Int n; Public : Void get_jn(int); }; Class P : public M, public N { public: void display (void); }; void M :: get_m(int x) { m=x; } void N :: get_n(int y) { n=y; } void P :: display (void) { cout <<” m=”<< m<<”\n”; cout <<” n=” << m << ”\n”; cout <<”m* n=” << m *n << ”\n”; } int main ( ) { Pp; p.get_m(10); p.get_n(20); p.display(); return 0; }

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

206

The output of Program 8.4 would be; m = 10 n = 20 m*n = 200 9.2.7 HIERARCHICAL INHERITANCE The other application of inheritance is to use as a support to the hierarchical design of a program. Many programming problems can be cast into a hierarchy where certain features of one level are shared by many others below that level. The below figure a hierarchical classification of students in a university. Students

Arts

Engineering

Mech.

Elec.

Medical

Civil

9.2.8 HYBRID INHERITANCE Assume that we have to give weight age for sports before finalizing the results. The weight age for sports is stored in a separate class called sports. The new inheritance relationship between the various classes would be as shown in Fig. student

test

sports

result

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

207

The sports class might look like : class sports { protected: float score; public : void get_score(float); void put_score(void); }; The result will have both the multilevel and multiple inheritance and its declaration would be as follows:

class result

:

public test, public sports

{ …………… …………… }; Where test itself is a derived class from student. That is class test

:

public student

{ …………. …………. }

Program 8.5 illustrates the implementation of both multilevel and multiple inheritance.

HYBRID INHERITANCE

# include <iostream> Using namespace std; class student { protected: int roll_number ; public: void get_number ( int a) {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

208

Roll_number = a; } void put_number(void) { cout<<”Roll No: <<roll_number <<”\n”: } }; Class test

:

public student

{ protected : float part1, part2; public ; void get_marks(float x, float y) { part1 = x; part2 -= y; } void put_marks(void) { cout << “ Marks obtained:”<<”\n” << “part1 = “<< part1 << “\n” << “part2 =”<<part2<<”\n”; } } class sports { protected: float score; public: void get_score(float s) { score = s; } void put_score (void) { cout<< “Sports wt: “ <<scire <<”\n\n”; } };

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY Class result

:

209

public test, public sports

{ float total; public void display (void); }; void result

:: display (void)

{ total = part1 + part2 = score ; put _number ( ); put_marks ( ); put_score ( ); cout << ”Total Score :”<< total << “\n”; } int main ( ) { result student_1; student_1.get_number(1234); student_1.get_marks(27.5, 33.0); student_1.get_score(6.0); student_1.display( ); return 0; } Here is the output of Program 8.5 Roll No: 1234 Marks Obtained : Part1 = 27.5 Part2 = 33 Sports wt :6 Total Score : 66.5

9.2.9 VIRTUAL BASE CLASSES Consider a situation where all the three kinds of inheritance, namely, multilevel, multiple and hierarchical inheritance, are involved. This is illustrated the child has two direct base classes ‘parent1’

and ‘ parent 2’ which themselves hava a common base class ‘

grandparent’. The child inherits the traits of ‘grandparent ‘ vin two separate paths. It can also Inherit directly as shown by the broken line. The grandparent is sometimes referred to as indirect base class.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

210

Grandparent

Parent 1

Parent 2

Child

The duplication of inherited members due to these multiple paths can be avoided by making the common base class (ancestor class ) as virtual base class while declaring the direct or intermediate base classes as shown below :

Class A

// grandparent

{ ……….. ………. }; Class B1

: virtual public A

// parent 1

{ ………… ………... }; Class B2 : public virtual A

// parent 2

{ ……….. ………. }; class C : public B1, public B2

// child

{ ……..

// only one copy of A

…….

// will be inherited

};

When a class is made a Virtual base class, C++ takes necessary care to see that only see copy of that class is inherited, regardless of how many inheritance paths exist between the virtual base class and a derived class.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

211

student

As virtual base class

As virtual base class

test

sports

result

A program to implement the concept of virtual base class is illustrated in program Virtual Base Class # include <iostream> using namespace std; class student { protected; int roll_number; public : void get_number ( int a) { roll_number = a; } void put_number(void) { cout << “Roll No : << roll_number <<”/n”; } }; class test : virtual public student { protected : float part, part2; Public : void get_marks (float x, float y) { part1 = x; part2=y; }

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

212

void put_marks(void) { cout<<”Marks obtained :”<<”\n”” << “part1=”<<part1<<”\n” <<”part2=”<<oart2<<”\n”; } }; class sports : public virtual student { protected: float score : public : void get_score (float s) { Score = s; } void put_score(void) { cout<< “Sports wt: “<score<<”\n\n”; } }; class result :public test, public sports { float total; public : void display (void); }; void result ::display (void) { total = part1 + part2 +score; put_number (); put_marks(); put_score(); cout<< “total score : “ << total <<”\n” } int main ()

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

213

{ result student _1; student_1.get_number(678); student_1.get_marks(30.5, 25.5); student_1.get_score (7.0); student_1 .display (); return 0: } The output of Program 8.6 would be Roll No : 678 Marks obtained : Part1 = 30.5 Part2 = 25.5 Sport wt: 7 Total Score : 63 9.2.10 ABSTRACT CLASSES An abstract class is one that is not used to create objects. An abstract class is designed only to act as a base class ( to be inherited by other classes). It is a design concept in program development and provides a base upon which other classes may be built. In the previous example, the student class is an abstract class since it was not used to create any objects.

9.2.11 CONSTRUCTOS IN DERIVED CLASSES The Constructors play an important role in initializing objects. We did not use them earlier in the derived classes for the sake of simplicity. One important thing to note here is that, as long as no base class constructor take any arguments , the derived class need not have a constructor function. In case of multiple inheritance, the base classes are constructed in the order in which they appear in the declaration of the derived class. Similarly, in a multilevel inheritance, the constructors will be executed in the order of inheritance. The constructor of the derived class received the entire list of values as its arguments and passes them on to the base constructors in the order in which they are declared in the derived class. The base constructors are called and executed before executing the statements in the body of the derived constructor. The general form of defining a derived constructor is :

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

Derived –constructor

(Arglist1,

Arglist2,…. ArglistN,

214

Arglist(D)

base1(arglist1), base2(arglist2), …………. …………. baseN (arglistN),

arguments for base (N)

{ Body of derived constructor }

The header line of derived constructor function contains two parts separated by a colon(;). The first part provides the declaration of the arguments that are passed to the derived – constructor and the second part lists the function calls to the base constructors.

CONSTRUCTORS IN DERIVED CLASS # include <iostream> using namespace std; class alpha { int x; public : alpha ( int i) { x = i; cout << “alpha initialized \n” } void show x(void) { cout <<”x=”<<x<<”\n”; } }; Class beta { float y; public ;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

215

beta (float j) { y = j; cout << ”beta initialized \n”; } void show_y (void) { cout << “y=”<<y<<”\n”;} }; Class gamma : public beta, public alpha { int m, n; public ; gama ( int a, float b, int c, int d); alpha (a), beta(b); { m = c; n = d; cout<< “gamma initialized \n “; } void show_mn(void) { cout << “m=<<m<<”\n” <<”n=”<<n<<”\n”; } }; int main() { gamma g(5,10.75, 20, 30); cout <<”\n” g.show_x(); g.show_y(); g.show_mn(); return(); }

The output of Program 8.7 would be beta initialized

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

216

alpha initialized gamma initialized x=5 y = 10.75 m = 20 n = 30

Program8.8 illustrates the use of initialization lists in the base and derived constructors.

INITIALIZATION LIST IN CONSTRUCTORS # include ( iostream> using namespace std; class alpha { int x; public : alpha ( int i) { x = i; cout << “\n alpha constructor”; } void show_alpha(void) { cout<<”x”<<x<<”\n”: } }; class beta { float p,q; public : beta (float a, float b ) : p(a), q(b+b) { cout <<”\n beta constructed ‘; } void show _beta(void) { Cout <<”p=”<<p<<”\n”;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

217

Cout <<”q=”<<q<<”\n”; } };

Class gamma : public beta, public alpha { int u,v; public: gamma ( int a, int b, float c); alpha (a*2), beta (c,c) u(a) { v=b; cout <<”\n gamma constructed”;} void show_gamma(void) { cout<<”u=”<<u<<”\n”; cout<<”v=”<<v<<”\n”;

} }; int main () { gamma g( 2,4, 2.5); cout <<”\n\n Display member values “<<”\n\n”; g.show_alpha (); g.show_beta (); g.show_gamma (); return 0; };

The output of Program 8.8 would be: beta constructed alpha constructed gamma constructed Display member values x=4 p = 2.5 q=5 u=2

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

218

v=4

9.2.12 MEMBER CLASSES : NESTING OF CLASSES

C++ supports yet another way of inheriting properties of one class into another. This approach takes a view that an object can be a collection of many other objects. That is, a class can contain objects of other classes as its members as shown below : class alpha ( ……); class beta (…….); class gamma { alpha a;

// a is an object of alpha class

beta b;

// b is an object of beta class

……… }; All objects of Gamma class will contain the objects a and b. This kind of relationship a called containership or nesting. Example : Class gamma { …….. alpha a:

// a is object of alpha

beta b;

// b is object of beta

public : gamma(arglist); a(arglist1), b(arglist2) { // constructor body } }; arglist is the first of arguments that is to be supplied when a gamma object is defined. These parameters are used for initializing the members of gamma. arglist 1 is the argument list for the constructor of a and arglist2 is the argument list for the constructor if b. arglist1 and agrlist2 may or may not use the arguments from arglist remember, a(arglist 1 ) and b(arglist 2) are function calls and therefore the arguments do not contain the date types. They are simply variables or constants.

Exmaple :

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

219

gamma ( int x, int y, float z) : a(x), b(x,z) { Assignment section ( for ordinary other members) }

9.3.0 POINTERS, VIRTUAL FUNCTIONS AND POLYMORPHISM 9.3.1 Introduction Polymorphism is one of the crucial features of OOP. It simply means ‘one name, multiple forms’. We have already seen how the concept of polymorphism is implemented using the overloaded member functions are ‘selected’ for invoking be matching arguments, both type and number.

9.3.2 Pointers Pointers is one of the key aspects of C++ language similar to that of C. As we know, Pointers offer a unique approach to handle data in C and C++. We know that a pointer is a derived data type that refers to another data variable by storing the variable’s memory address rather than data. A pointer variable defined where to get the value of a specific data variable instead of defining actual data.

9.3.3 Pointers and Objects We are already seen how to use pointers to access the class members. As stated earlier, a pointer can point to an object created by a class. Consider the following statement: item x; Where item is a class and x is an object defined to be of type item. Similarly we can define a pointer it_ptr of type item as follow: Item * it_ptr; Object pointers are useful in creating objects at run time, We can also use an object pointer to access the public members of an object. Consider a class item defined as follows :

class item { int code; float price; public: void getdata (int a, float b) {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

220

code = a; price = b; } void show (void) { cout<<”Code:”<<code<<”\n”; <<”price:”<<price<<”\n\n”; } };

Let us declare an item variable x and a pointer ptr to x as follows: item x; item *ptr=&x; The Pointer ptr is initialized with the address of x. We can refer to the member functions of item in two ways, one by using the dot operator and the object, and another by using the arrow operator and the object pointer. The statements x.getdata ( 100,75.50); x.show(); are equivalent to ptr -> getdata (100, 75.50); ptr -> show (); Since “ ptr is an alias of x, we can also use the following method; ( *ptr.show(); The parentheses are necessary because the dot operator has higher procedure than the indirection operator “.

POINTERS TO OBJECTS # include <iostream> using namespace std; class item { int code; float price; public : void getdata (int a, float b) {

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

221

code = a; price = b; } void show ( void ) { cout<<”Code:”<<code<<”\n”; cout<<”Price:”<<Price<<”\n”; } }; const int size = 2; int main () { item *p=new item (size}; item *d = p; int x; i; float y; for ( i=0; i<size; i++) { cout << “Input code and price for item” << i+1; cin >> x >> y; p-> getdata (x,y); p++; } for (i=0; i<size; i++) { cout<< “Item:”<< i+1 << “\n”; d-> show (); d++; } return 0 ; } The output of Program 9.8 will be Input code and price for item1 40 500 Input code and price for item2 50 600 Item:1 Code : 40 Price : 500 Item : 2 Code : 50 Price : 600

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

222

ARRAY OF POINTERS TO OBJECTS # include <iostream.h> #include <cstring> using namespace std; class city; { protected: char *name; int len; public : city () { len = 0; name = new char {len+1}; } Void getname(void) { char *s; s = new char (30); cout<<”Enter city name :”; cin>>s; len = strlen(s); name = new char (len +1); strcpy (name, s); } void printname (void) { cout<< name<<”\n”; } }; int main () { city *cptr [10];

// array of 10 pointers to cities

int n=1; int option; do { cptr[n] = new city; // create new city cptr[n]->getname(); n++; cout<<”Do you want to enter one more name?\n”; cout<<”(Enter 1 for yes 0 for no):”; cin>> option; } while (option); cout<<”\n\n”; for(int i = 1; i <=n; i++) { cptr[i] -> printname ();

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

223

} return 0; }; The output of program 9.9 would be: Enter city name : Hyderabad Do you want to enter one more name ? (Enter 1 for yes 0 for no);1 Enter city name : Secunderabad Do you want to enter one more name ? (Enter 1 for yes 0 for no);1 Enter city name : Malkajgiri Do you want to enter one more name ? (Enter 1 for yes 0 for no);0 Hyderabad Secunderabad Malkajgiri

9.3.4 This Pointer C++ uses a unique keyword called this to represent an object that invokes a member function, this is a pointer that points to the object for which this function was called. For example, the function call A.max() will set the pointer this to the address of the object.A. The starting address is the same as the address of the first variable in the class structure. This unique pointer is automatically passed to the member function when it is called. The pointer this acts as an implicit

argument to all the member functions. Consider the

following simple example:

class ABC { int a; ……. ……. }; The private variable ‘a’ can be used directly inside a member function, like a=123 ; We can also use the following statement to do the sane job: This->a 123; Since C++ permits the use of shorthand form a=123, we have not been using the pointer this explicitly so far. However, we have been implicitly using the pointer this when overloading the operators using member function.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

224

Recall that, when a binary operator is overloaded using a member function, we pass only one argument to the function. The other argument is implicitly passed using the pointer this. One important application of the pointer this is to return the object it points to. For example, the statement

return * this; inside a member function will return the object that invoked the function. This statement assumes importance when we want to compare two or more objects inside a a member function and return the invoking as a result. This Pointer # include <iostream> # include <cstring> using namespace std; class person { char name [20]; float age ; public : person (char *s, float a) { Strcpy(name, s); age= a; } person & person ::greater (person & x) { If(x.age>=age) return x; else return *this; } void display(void) { cout << “Name:”<<name<< “\n” <<Age :”<<age<<”\n”; } }; int main () { person P1(“John”, 37;.50), P2(:Ahmed:”, 29.0), P3(“Hebber”,40.25); person P = P1.greater (P3); cout<<”Elder person is :\n”; p.dispaly();

// P3.greater (P1)

return 0; }

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

225

The output of Program 9.10 would be: Elder person is: Name : Hebber Age : 40.25 Elder person is: Name : John Age : 37.5

9.3.5 POINTERS TO DERIVED CLASSES We can use pointers not only to the base objects but also to the objects of derived classes. Pointers to objects of a base class are type-compatible with pointers to objects of a derived class. Therefore, a single pointer variable ca be made to point to objects belonging to different classes. For Example, if B is a base class and D is a Derived class from B, then a pointer declared as a pointer to B can also be a pointer to D. Consider the following declarations: B * cptr; B b; D d; Cptr = &b;

// pointer to class B type variable // base object // derived object // cptr points to object b

We can make cptr to point to the object d as follows: Cptr = &d; // cptr points to object d This is perfectly valid with C++ because d is an object derived from the class B. However, there is problem in using cptr to access the public members of ther derived class D. Using cptr, we can access only those members which are inherited from b and not the members that originally belong to D. In case a member of D has the same name as one of the members of B, then any reference to that member by cptr will always access the base class member.

POINTERS TO DERIVED OBJECTS #include <iostream> using namespace std; class BC { public int b; void show ()

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

226

{ cout <<” b = << b << “\n”; } }; Class DC : public BC { public : ind d; void show () { cout << “b=”<<b<<”\n” <<”d=”<<d<<”\n”; } }; int main ( ) { BC * bptr ;

// base pointer

BC base; bptr = & base; bptr->b=100;

// access BC via base pointer

cout<<”bptr points to base object \n”; bptr ->show (); // derived class DC derived; Bptr = & derived

// address of derived object

bptr-> b=200;

// access DC via base pointer

/* bptr ->d = 300;*/

// won’t work

cout<< “bptr now pointers to derived object \n”; bptr ->show();

// bptr now points to derived object

/* accessing a using a pointer of type derived class DC */ DC *dptr; dptr =&derived dptr->d=300; cout <<”dptr is derived type pointer\n”; dptr ->show(); (( DC *)bptr)->d=400; ((DC*)bptr ->show (); return 0;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

227

} Program 9.11 produces the following output : bptr pointers base object b=100 bptr now points to derived object b=200 bptr is derived type pointer b=200 d=300 using ((DC*)bptr) b=200 d=400 9.3.6 VIRTUAL FUNCTIONS When we use the same function name in both the base and derived classes, the function in base class is declared as virtual using the keyword virtual preceding its normal declaration. When a function is made virtual, C++ determines which function to use at run time based on the type of object to be the base pointer, rather than the type of the pointer. Thus, by making the base pointer to point to different objects, we can execute different versions of the virtual function. Program 9.12 illustrates this point.

# include <iostrean> using namespace std; class Base { public : void display () { cout <<”\n Display base “; } virtual void show () {cout <<”\n show base “; } }; Class Derived : public Base { public : void display () { cout <<”\n Display base “; } virtual void show () {cout <<”\n show base “; } }; int main () { base B;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

228

Derived D; Base * bptr; cout <<”\n bptr points to base \n”; bptr =&B; bptr-> display (); // calls Base version bptr-> show (); // calls Base version cout <<”\n bptr points to Derived \n”; bptr =&D; bptr-> display (); // calls Base version bptr-> show (); // calls Derived version return 0; } The output of Program 9.12 would be: bptr points to Base Display base Show base bptr points to Derived Display base Show derived

RUNTIME POLYMOTPHISM # include <iostream> #include <cstring> using namespace std; class meida { protected : char title [50]; float price; public : media (char*s, float a) { Strcpy (title,s); price = a; } virtual void display() { } // empty virtual function }: class book; public meida { int pages; public : book (char*s, float a, int p) :meida (s,a) { pages = p;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

229

} void display (); };

class tape : public media { float time ; public : tape(char*s, float a, float t):media (s,a) { time = t; } void display(); }; void book ::display () { cout<< “\n Title :”<< title; cout<< “\n Pages :”<< pages; cout<< “\n Price :”<< price; }

void tape ::display () { cout<< “\n Title :”<<title; cout<< “\n Play time :”<<title << “mins”; cout<< “\n Price :”<< price; } int main () { char * title = new char [30]; float price, time; int pages; // Book details cout <<”\n Enter book details \n” cout<< “\n Title :”<< title; cin>>title; cout<< “\n Pages :”<< pages; cin>> pages; cout<< “\n Price :”<< price; cin >> price ; book book1 (title, price, pages ); // Tape details cout <<”\n Enter Tape details \n” cout<< “\n Title :”<< title; cin>>title; cout<< “\n Price :”<< price; cin >> price ; cout<< “\n Play time (mins)::”; cin >> time ; tape tape1(title, price, time); media * list [ 2]; list [0] =&book1; list [1] =&tape1;

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

cout << “\n MEDIA DETAILS “; cout <<”\n ………Book ……..”; list[0] -> display ( );

// display book details

cout <<”\n ………Tabe ……..”; list[1] -> display ( );

// display tape details

230

result 0; } The output of Program 9.13 would be ENTER BOOK DETAILS Title : Programming _in_basic Price : 88 Pages : 400 ENTER BOOK DETAILS Title : Computing_Concepts Price : 90 Play time (mins):55 MEDIA DETAILS ……. BOOK ………. ENTER BOOK DETAILS Title : Programming _in_ANSI_C Pages : 400 Price : 88 ……… TAPE…….. Title : Computing_Concepts Play time : 55mins Price : 90

RULES FOR VIRTUAL FUNCTION When virtual functions are created for implementing late binding. We should observe some basic rules that satisfy the compiler requirements. 1. 2. 3. 4. 5. 6.

7. 8.

9.

The virtual functions must be members of some class. They cannot be static members. They are accessed by using object pointers. A virtual function can be a friend of another class. A virtual function in a base class must be defined, even though it may not be used. The prototypes of the base class version of a virtual function and all the derived class versions must be identical. If two functions with the same name have different prototypes, C++ considers them as overloaded functions, and the virtual function mechanism is ignored. We cannot have virtual constructors, but we can have virtual destructors. While a base pointer can point to any type of the derived object, the reverse is not true. That is to say, we cannot use a pointer to a derived class to access an object of the base type. When a base pointer to a derived class, incrementing or decrementing it will not make it to point to the next object of the derived class. It is incremented or

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

231

decremented only relative to its base type. Therefore, we should not use this method to move the pointer to the next object. If a virtual function is defined in the base class, it need not be necessarily redefined in the derived class. In such cases, calls will invoke the base function.

10.

9.3.7 PURE VIRTUAL FUNCTIONS It is normal practice to declare a function virtual inside the base class and redefine it in the derived classes. The function inside the base class in seldom used for performing any task. It only serves as a placeholder.

State whether the following statements are TRUE or FALSE:

a) Using the operator overloading concept, we can change the meaning of an operator. b) Operator overloading works when applied to class objects only. c) Friend functions cannot be used to overload operators. d) The overloaded operator must have at least one operand that is user-defined type. e) Through operator overloading, a class type data can be converted to a basic type data. e) A constructor can be used to convert a basic type to a class type data.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

232

UNIT-V 10. 1.0 Managing Console I/O Operations 10.1.1 Introduction 10.1.2 C++ streams 10.1.3C++ stream classes 10.1.4Unformatted i/o operations 10.1.5Managing output with manipulators

10.2.0 WORKING WITH FILES 10.2.1Introduction 10.2.2Classes for file stream operations 10.2.3Opening and closing a file 10.2.4 Detecting end-of-file 10.2.5.More about open():file modes 10.2.6 File pointers and their manipulations 10.2.7 Sequential input and output operations 10.2.8Updating a file: random access 10.2.9Error handling during file operations 10.2.10 command-line arguments

10.3.0 TEMPLATES 10.3.1Introduction 10.3.2 Class templates 10.3.3 Class templates with multiple parameters 10.3.4 Function templates 10.3.5Function templates with multiple parameters 10.3.6Overloading of template functions 10.3.7Member function templates 10.3.8Non-type template arguments

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

233

10.4.0 EXCEPTION HANDLING 10.4.1Introduction 10.4.2Basics of exception handling 10.4.3Exception handling mechanism 10.4.4Throwing mechanism 10.4.5Catching mechanism 10.4.6Rethrowing an exception 10.4.7Specifying exceptions

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

234

10.1.0 MANAGING CONSOLE I/O OPERATION 10.1.1 INTRODUCTION: C++ uses the concept of stream and stream classes to implement i/o operations with console and disk files. We will discus in this chapter how stream classes support the console oriented i/o operations. 10.1.2 C++ STREAMS: A stream is a sequence of bytes. It acts either as a source from which the input data can be obtained or as a destination to which the output data can be sent. the source stream that provides data to the program is called the input stream and the destination stream that receives output from the program is called the output stream in other words a program extracts the bytes from an input stream and inserts bytes into an output stream.

Input stream Input device

extraction from input stream Program Output

Insertion

Stream

into output stream

Output device

10.1.3 C++ STREAM CLASSES: The c++ i/o system contains a hierarchy of a classes that are used to define various streams to deal with both the console and disk files, these classes are called stream classes. ios

istream

pointer streambuf

Input

ostream Output

iostream

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

Istream_withassign

iostream_withassign

235

ostream_withassign

The class ios provides the basic support for formatted and unformatted i/o operations the class istream provides the facilities for formatted and unformatted input while the class ostream(through inheritance)provides the facilities for formatted output. The class iostream provides the facilities for handling both input and output streams three classes, namely, isstream_withassign,

ostream_withassign,

and

iostream_withassign

add

assignment

operators to these classes. 10.1.4 UNFORMATTED I/O OPERATIONS: Overloaded operators << and >>: We have used the objects cin and cout for the input and output of data of various types. This has been made possible by overloading the operators >> and << to recognize all the basic c++ types. The >> operators is overloaded in the istream class and << is overloaded in the ostream class. The following is the general format for reading data from the keyboard: Syntax: Cin >> variable > variable2 >>…..>>variableN variable1,variable2,….. are valid c++ variable names that have been declared already this statement will cause the computer to stop the execution and look for input data from the keyboard. The input data for this statement would be.. data1 data2 ……dataN The input data are separated by white spaces and should match the type of variable in the cin list spaces, new lines and tabs will be skipped. PUT() AND GET() FUNCTIONS: The classes istream and ostream define two member function get() and put() respectively to handle the single character i/o operations. There are 2 types of get functions. We can use both get(char*) and get(void) prototypes to fetch a character including the blank space, tab and the new line character. The get(char*) version assigns the input character to its argument and the get(void) version returns the input character .since these functions are members of the i/o stream classes , we must invoke them using an appropriate object EXAMPLE: char c; cin.get(c); while(c!= ‘\n’) { cout<<c; cin.get(c);

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

236

} This code reads and displays the line of text remember, the operator >> can also be used to read a character but it will skip the white spaces and newline character. GETLINE() AND WRITE(): We can read and display a line of text more efficiently using the line oriented i/o function getline() and write(). The getline() function reads a whole line of text that end with a newline character. This function can be invoked by using the objects cin as follows: cin.getline(line, size); This function call invokes the function getline() which reads character inputs into the variable line. The reading is terminated as soon as either the new line character ‘\n’ is encountered or size-1 character is read. The new line character is read but not saved. Instead it is replaced by the null character. EXAMPLE: char name[20]; cin.getline( name , 20); 10.1.5 FORMATTED CONSOLE I/O OPERATIONS C++ supports a number of features that could be used for formatting the output., these features include: 

ios class functions and flags.

Manipulators.

User_defined output functions.

The ios class contains a large number of member functions that would help us to format the output in a number of ways, the most important ones among them are listed in the table.

FUNCTION

TASK

width()

To specify the required size for displaying an output vale.

precision()

To specify the number of the number of digits to be displayed after the decimal point of a float value.

fill()

To specify a character that is used to fill the unused portion of a field.

setf()

To specify format flags that can control the form of output display.

unsetf()

To clear the flags specified

Manipulators are special functions that can be included in the i/o statements to alter the format parameters of a stream.the table below show some important manipulator functions

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

237

that are frequently used to access these manipulators, the file iomanip should be included in the program. Manipulator

Equivalent ios function

setw()

width()

Setprecision()

precision()

setfill()

fill()

setiosflags()

setf()

Resetiosflag()

unsetf()

In addition to these functions supported by the c++ library, we can create our own manipulator functions to provide any special output formats. DEFINING FIELD WIDTH: Width () We can use the width() function to define the width of a field necessary for the output of a item. Since, it is a member function, we have used an object to invoke it, as shown below: cout.width(w); Where w is the field width. The output will be printed in a field of a character wide at the right end of the field. The width() function can specify the field width for only one item. After printing one item it will revert back to the default. EXAMPLE: cout. width(5); cout << 543 << 12 <<’\n’; Will produce the output: 5

4

3

1

2

SETTING PRECISION:PRECISION() By default, the floating numbers are printed with six digits after the decimal point. However we can specify the number of digits to be displayed after the decimal point while printing the floating-point numbers. This can be done by using the precision() member function as follows: cout.precision(3); Where d is the number of digits to the right of the decimal point , for example the statements cout.precision(3); cout << sqrt(2) << ”\n”; cout << 3.14159 << ”\n”; cout <<2.50032 << “\n”; will produce the following output: 1.141 (truncated)

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

238

3.142 (rounded to the nearest cent) 2.5

(no training zeros)

Not that, unlike the function width(), precision() retains the setting in effect until it is reset. That is why we have declared only one statement for the precision setting which is used by all the three outputs.

FILLLING AND PADDING: fill() We have been printing the values using much larger field widths than required by the values. The unused positions of the fields are filled with white spaces, by default. However, we can use the fill() function to fill the unused positions by any desired character. It is used in the following form: cout. fill (ch); where ch represents the character which is used for filling the unused positions. EXAMPLE: cout.fill(‘*’); cout.width(10); cout<< 5250 << “\n”; The output: *

*

*

*

*

*

5

2

5

0

Financial institutions and banks use this kind of padding while printing cheques so that no one can change the amount easily like precision(), fill() stay in effect till we change it. FORMATTING FLAGS, BIT-FIELDS AND SETF() We have seen that when the function width() is used, the value is printed right-justified in the field width created. But it is a useful practice to print the text left-justified. The setf(), a member function of the ios class, can provide answers to these and many other formatting questions. The setf() function can be used as follows: Syntax: cout.setf (arg1, arg2) The arg1 is one of the formatting flags defined in the class ios. the formatting flags specifies the format action required for the output. Another ios constant, arg2, know as bit field specifies the group to which the formatting flag belongs.

10.1.6 MANAGING OUTPUT WITH MANIPULATORS: The header file iomanip provides the set of functions called manipulators which can be used to manipulate the output formats. They provide the same features as that of the ios member functions and flags. Some manipulators are more convenient to use then their

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

239

counter parts in the ios. For example two or more manipulators can be used as a chain in one statement as shown below EXAMPLE: cout<<manip1<<manip2<<manip3<<item; cout<<manip1<<item1<<manip2<<item2; This kind of concatenation is useful when we born to display several column of output. The tables also give their meaning and equivalents. To access these manipulators, we must include the file iomanip in the program.

Manipulator

Meaning

setw(int w) Setprecision(int d)

Set the field width to w. Set the floating point precision to d

setfill(int c)

Set the fill character to c

setiosflag(long f)

Set the format flag f.

Resetiosflag(long f)

Clear the flag specified by f.

DESIGNING OUR OWN MANIPULATORS: We can design our manipulators for certain special purposes. The general form for creating a manipulator without any arguments is: ostream & manipulator(ostream & output) { ….. ……(code) ….. return output; } Here, the manipulator is the name of the manipulator under creation the following function defines a manipulator called unit that display “inches”: ostream & unit (ostream & output) { output<< “inches”; return output; } The statement cout<<36<<unit; will produce the following output

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

240

36 inches We can also create manipulators that could represent a sequence of operations.

10.2.0 WORKING WITH FILES 10.2.1 INTRODUCTION: We need to use some devices such as floppy disk or hard disk to store the data. The data is stored in these devices using the concept of file. A file is a collection of related data stored in a particular area on the disk program can be designed to perform the read and write operations on these files.

10.2.2 Classes for File Stream Operations: The I/O system of C++ contains a set of classes that define the file handling methods. These include ifstream, ofstream and fstream. These classes are derived from fstreambase and from the corresponding iostream class. These classes, designed to manage the disk files, are declared in fstream and therefore we must include this file in any program that uses files. 10.2.3OPENING AND CLOSING A FILE: If we want to use a disk file, we need to decide the following things about the file and its intended use: 

Suitable name for the file.

Data type and structure.

Purpose

Opening method.

Class

Content

Filebuf

Its purpose is to set the file buffers to read and write.

Fstreambase

Provides operations common to the file streams.

Ifstream

Provide input operations

Ofstream

Provide output operations

Fstream

Provide support for simultaneous input and output operations.

OPENING FILES USING CONSTRUCTORS: We know that a constructor is used to initialize an object while it is being created. Here a filename is used to initialize the file stream object. This involves the following steps: create a file stream object to manage the stream using the appropriate class. That is to say, the class ofstream is used to create the output stream and the class. 

Initialize the file object with the desired filename.

Example: ofstream outfile(“results”);

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

241

OPENING FILES USING OPEN() As stated earlier, the function open() can be used to open multiple files that use the same stream object. SYNTAX: File-stream-class stream-object; stream-object.open (“filename”); EXAMPLE: ostream outfile; outfile.open(“data1”); …… …… outfile.close(); outfile.open(“data2”); ….. …… outfile.close(); … ….. The previous program segment opens two files in sequence for writing the data. Note that the first file is closed before opening the second one. This is necessary because a stream can be connected to only one file at a time.

10.2.4 DETECTING END-OF-FILE: Detecting of the end-of-file condition is necessary for preventing any further attempt to read data from the file. Example: while (fin) An ifstream object, such as fin, returns a value of 0 if any error occurs in the file operations including the end-of-file condition. Thus, the while loop terminates when file returns a value of zero on reaching the end of-file condition. There is another approach to detect the end-of-file condition. Note that we have used the following statement: if(fin1.eof() != 0) { exit; } eof() is a number function of ios class.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

242

10.2.5 MORE ABOUT OPEN():FILEMODES We have used ifstream and ofstream constructors and the function open() to create new files as well as to open the existing files. Remember, in both these methods, we used only one argument that was the filename, however, these functions can take two arguments, the second one for specifying the file mode. The general form of the function open() with two arguments is: stream-object.open(“filename”,mode); The second argument mode specifies the purpose for which the file is opened.

10.2.6 FILL POINTERS AND THEIR MANIPULATION: Each file has associated pointer known as the file pointers. One of them is called the input pointer and the other is called the output pointer.we can use these pointers to move through the files while reading or writing. The inout pointer is used for reading the contents of a given file location and the output pointer is used for writing to a given file location. Each time an input or output pointer is used for writing to given file location. Each time an input or output operation take place, the appropriate pointer is automatically advanced. DEFAULT ACTIONS: When we open a file in write-only mode, the existing contents are deleted and the output pointer is set at the beginning. This enables us to write to the file from the start. In case, we want to open an existing file to the end of the file.

H

E

L

L

O

H

A

I

FUNCTIONS FOR MANIPULATION OF FILE POINTERS: All the actions on the file pointers take place automatically by default.we can control of the movement of the file pointers ourselves. The file stream classes support the following functions to manage such situations. 

seekg() moves get pointer to a specified location .

seekp() moves put pointer to a specified location.

tellg() give the current position of the get pointer.

tellp() give the current position of the put pointer.

example: infile.seekg(10); It moves the file pointer to the byte number 10.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

243

10.2.7 SPECIFYING THE OFFSET: We have just now seen how to move a file pointer to a desired location using the seek functions. ‘seek’ functions seekg() and seekp() can also be used with two arguments as follows: seekg (offset, reposition); seekp (offset, reposition); The parameter offset represents the number of bytes the file pointer is to be moved from the location specified by the parameter reposition. The reposition takes one of the following three constants defined in the ios class: * ios::beg

start of the file

* ios::cur

current position of the pointer

* ios::end

end of the file.

The seek function moves the associated file’s ‘get’ pointer while the seekp() function moves the associated file’s put pointer. SEQUENTIAL INPUT AND OUTPUT OPERATIONS: The file stream classes supports a number of member functions for performing the input and output operations on the files. One pair of functions write() and read are designed to write and read blocks of binary data. put() and get() Functions: The function put() writes a single character to the associated stream. Similarly, the functions get() read a single character from the associated stream. WRITE() AND READ() FUNCTIONS: The functions write() and read(), unlike the functions put() and get(), handle the data in binary form. This means that the values are stored in the disk file in the same format in which they are stored in the internal memory.

READING AND WRITING A CLASS OBJECT: The binary input and output functions read() and write() are designed to do exactly those job. These functions handle the entire structure of an object as a single unit, using the computer’s internal representation of data. The function write() copies a class object from memory byte by byte with no conversion. One important point to remember is that only data members are written to the disk file and the member functions are not. 10.2.8UPDATING A FILE: RANDOM ACCESS: Updating is a routine task in the maintenance of any data file. The updating would include one or more of the following tasks: 

displaying the contents of a file.

modifying an existing item.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY 

adding a new item.

deleting an existing item.

244

These actions require the file pointers to particular location that corresponds to the item/objects of equal lengths, in such a case, the size of each object can be obtained using the statement. Example: in object_length = sizeof(object); That it receive the integer value of the given object. Remember, we are opening an existing file for reading and updating the values. It is, therefore, essentially that the data members are of the same type and declared in the same order as in the existing file. Since, the member functions are not stored, they can be different.

10.2.9 ERROR HANDLING DURING FILE OPERATIONS: So, far we have been opening and using the files for reading and writing on the assumption that every thing is fine with the files. This may not be true always for instance, one o the following things may happen when dealing with the files: 

a file which we are attempting to open for reading does not exist.

The file name used for a new file may already exit.

We may attempt an invalid operation such as reading past the end-of-file.

There may not be any space in the disk for storing more data.

We may use invalid file name.

We may attempt to perform an operations when the file is not for that purpose. The class ios supports several member functions that can be used to read the status

recorded in a file stream. These functions that can be read the status recorded in a file stream. These functions along with their meanings are listed in table below: FUNCTION

RETURN VALUE&MEANING

eof()

Returns true if end-of-file encountered while reading.

fail()

Returns true when an input or output operations has failed.

Good()

Returns true if any error is found

bad()

Returns true if an invalid operation is attempted

These functions may be used in the appropriate places in a program to locate the status of the file stream .

10.2.10 COMMAND-LINE ARGUMENTS: The command-line arguments are typed by the user and delimited by a space. The first argument is always the filename and contains the program to be executed.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

245

c> exam data results here, exam is the name of the file containing the program to be executed and the data results are the filenames passed to the program as command-line arguments. The main() functions which we have been using upto now without any arguments can take two arguments.

example: main(int argc, char * argv[]) The first argument argc represent the number of arguments in the command line, .the second argument argc represents an array of char type pointers that points to the command line arguments.

State whether the following statements are TRUE or FALSE:

1) A C++ stream is a file. 2) C++ never truncates data. 3) The main advantage of width() function is that we can use one width specification for more than one item. 4) The get(void) function provides a single-character input that does not skip over the white spaces. 5) A programmer can define a manipulator that could represent a set of format functions. 6) The header file iomanip.h can be used in place of iostream.h 7) A stream may be connected to more than one file at a time. 8) A file pointer always contains the address of the file. 9) The ios::ate mode allows us to write data anywhere in the file. 10) We can add data to an existing file by opening in write mode. 11) The parameter ios::app can be used only with the files capable of output. 12) The data written to a file with write() function can be read with the get() function. 13) We can use the functions tellp() and tellg() interchangeably for any file.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

246

UNIT QUESTIONS UNIT-I QUESTIONS Answer the following questions 1. What is information 2. “Whether the information Science is a discipline?” Discuss. 3. Discuss the impact of Information Technology in LIS What are the branches of Information Technology

UNIT-2 QUESTIONS 1. 2. 3. 4. 5. 6. 7. 8.

Discuss on different generations of Computers Write different Input and Output devices used in computers What is software and discuss various types of software What are the functions of operating system and the types of OS Briefly discuss MS DOS Discuss Unix operating system What are the advantages of Windows over other OS Describe Linux OS

UNIT-3 QUESTIONS 1. 2. 3. 4. 5.

What is Network? Discuss the purpose of Networking. Give the different types of networking topologies Briefly Discuss on Bus, Ring and Star Topologies with their merits and demerits Give the basic elements in Networking and explain the use of it.

UNIT-4 QUESTIONS

1. What is network protocol 2. Discuss briefly about Hyper Text 3. Distinguish between Hyper Text and Hyper Media 4. Write notes on Multi media 5. Explain the concept ISDN 6. Write elaborately on OSI Protocol 7. Discuss different types of Network Accessories.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

247

UNIT-5 QUESTIONS 1. What is Internet 2. Discuss briefly the web resources 3. Explain Web Portal 4. Describe different search engines 5. What are the Internet tools available to-day 6. Write briefly about browsers

UNIT-6 Questions: 1. List the principles of object-oriented programming. 2. What are the major issues facing the software industry today? 3. Briefly discuss the software evolution? 4. What is procedure-oriented programming? What are its main characteristics? 5. What is object-oriented programming? How it differs from procedure-oriented programming? 6. What are the unique advantages of an object-oriented paradigm? 7. Distinguish between the following terms: (a) Objects and classes (b) Data abstraction and data encapsulation (c) Inheritance and polymorphism (d) Dynamic binding and message passing 8. Explain the basic concepts of object-oriented programming in detail. 9. What are the benefits of OOP? 10. Write short notes on Object Oriented Languages. 11. List a few areas of application of OOP.

UNIT-7 Questions:

1) What do we need the preprocessor directive #include<iostream.h>? 2) Describe the structure of a C++ Program? 3) What are the applications of C++?

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

248

4) Describe with examples the uses of enumeration data types. 5) Why is an array called a derived data type? 6) What is a reference variable? What is the major use of this variable? 7) List at least four new operators added by C++? 8) What is the application of the scope resolution operator :: in C++? 9) What are the advantages of function prototypes in C++? 10) What is the main advantage of passing arguments by reference? 11) When will you make a function inline? Why?

UNIT-8 Questions: 1) What is a class? 2) What are objects? How they are created? 3) How is a member function of a class defined? 4) When do we declare a member of a class static? 5) What is a friend function? What are the merits and demerits of using friend function? 6) What is a constructor? Is it required to use constructors in a class? 7) How do we invoke a constructor function? 8) List some of the special properties of the constructor functions. 9) What is a parameterized constructor? 10) What is meant by dynamic initialization of objects? 11) Describe the importance of destructors?

UNIT-9 Questions:

1. What is operator overloading? 2. Why is it necessary to overload an operator? 3. What is an operator function? Describe the syntax of an operator function. 4. What is a conversion function? How is it created? Explain its syntax. 5. How many arguments are required in the definition of an overload unary operator?

UNIT-10 Questions: 1) What is a stream? 2) Describe briefly the features of I/O system supported by C++.

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


COMPUTER PROGRAMMING & INFORMATION TECHNOLOGY

249

3) Why it is necessary to include the file iostream.h in all our programs? 4) Discuss the various forms of get() function supported by the input stream. How are they used? 5) What is the role of file() function? When do we use this function? 6) Discuss the syntax of set() function?

----------------------------------------------THE END----------------------------------------

FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621


Comput erPr ogr ammi ng andI nf or mat i onTechnol ogy

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


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.