0% found this document useful (0 votes)
23 views122 pages

Eduniv 2

The document provides an introduction to computers, covering topics such as computer components, memory types, and the generations of computers. It includes definitions, distinctions between data and information, characteristics of computers, and applications in various fields. Additionally, it discusses input/output devices, printing technologies, and number systems, along with their encoding methods.

Uploaded by

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

Eduniv 2

The document provides an introduction to computers, covering topics such as computer components, memory types, and the generations of computers. It includes definitions, distinctions between data and information, characteristics of computers, and applications in various fields. Additionally, it discusses input/output devices, printing technologies, and number systems, along with their encoding methods.

Uploaded by

thalapathy666333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 122

Lesson 1- Introduction to Computers

Study Material
Book Back One words
1. First generation computers used Vacuum tubes
2. Name the volatile memory RAM
3. Identify the output device Monitor
4. Identify the input device Mouse
5. … Plotter … Output device is used for printing building plan, flex board, etc.
6. In ATM machines, which one of the following is used to Touch Screen
7. When a system restarts which type of booting is used. Warm booting
8. Expand POST Power on Self Test
9. Which one of the following is the main memory? RAM
10. Which generation of computer used IC’s? Third

Question and Answers ( 2 Marks)

1. What is a Computer?
A computer is an electronic device that manipulates information, or data. It
has the ability to store, retrieve, and process data. Computer works faster than
human being and given the values more accuracy and reliable.

2. Distinguish between Data and Information.


Data:
Data is defined as an unprocessed collection of raw facts, suitable for
communication, interpretation or processing. For example: 134, 16, ‘Kavitha’,
‘C’ is data. This will not give any meaningful message.
Information:
Information is a collection of facts from which conclusions may be
drawn. In simple words we can say that data is the raw facts that are processed
to give meaningful, ordered or structured information.
For Example: Kavitha is 16 years old. This information is about Kavitha and
conveys some meaning. This conversion of data into information is called data
processing.

3. Write the Components of a Computer.


1. Input Unit 2.Central Processing Unit (Control Unit, Arithmetic Logic
Unit, Memory Unit) 3.Output Unit
4. Write about Arithmetic and Logic Unit.
The ALU is a part of the CPU where various computing functions are
performed on data. The ALU performs arithmetic operations such as addition,
subtraction, multiplication, division and logical operations. The result of an
operation is stored in internal memory of CPU.The logical operations of ALU
promote the decision-making ability of a computer.

5. Write about Control Unit.


The control unit controls the flow of data between the CPU, memory and
I/O devices. It also controls the entire operation of a computer.

6. Write about Memory Unit / Storage Unit.


The Memory Unit is of two types which are primary memory and
secondary memory. The primary memory is used to temporarily
store the programs and data when the instructions are ready to execute.
The secondary memory is used to store the data permanently

7. Differentiate Input/ output unit.


Input Unit
Input unit is used to feed any form of data to the computer, which can be stored
in the memory unit for further processing. Example: Keyboard, mouse, etc.
Output Unit
An Output Unit is any hardware component that conveys information to users in
an understandable form. Example: Monitor, Printer etc.

8. Differentiate Primary and secondary memory.


• The Primary Memory is volatile, that is, the content is lost when the
power supply is switched off.
• The Random Access Memory (RAM) is an example of a main memory.
• The Secondary memory is non volatile, that is, the content
is available even after the power supply is switched off.
• Hard disk, CD-ROM and DVD ROM are examples of secondary memory.

Question and Answers( 3 Mark)


1. What are the Characteristics of Computer?
Computer is the powerful machine. It can perform large number of tasks. The
main capacities of computer are work length, speed accuracy, diligence,
versatility memory and automation and lots of more tasks.

2. Write the Applications of computer.


▪ Business
▪ Education
▪ Marketing
▪ Banking
▪ Insurance
▪ Communication
▪ Health care
3. What is an input device? Give two examples
Input device is used to feed any form of data to the computer, which can be stored
in the memory unit for further processing.
Example: Keyboard, Mouse, Scanner, Fingerprint scanner, Track Ball, Retinal
Scanner, Light pen etc.

4. Name any three Output Devices.


Monitors, Printers, Speakers.

5. Difference between Optical and Laser Mouse

Optical Mouse Laser Mouse


Measures the motion and acceleration of Measures the motion and acceleration of
pointer. pointer.
It uses light source instead of ball to judge Laser Mouse uses Laser Light.
the motion of the pointer.

Optical mouse is less sensitive towards Laser Mouse is highly sensitive and able
surface. to work on any hard surface.

6. Write a short note on impact printers


Impact printers :
• These printers print with striking of hammers or pins on ribbon. These printers can
print on multi- part (using carbon papers) by using mechanical pressure. For
example, Dot Matrix printers and Line matrix printers are impact printers.
• A Dot matrix printer that prints using a fixed number of pins or wires.
• Line matrix printers use a fixed print head for printing.

7. Write the characteristics of sixth generation


• In the Sixth Generation, computers could be defined as the era of intelligent
computers based on Artificial Neural Networks.
• One of the most dramatic changes in the sixth generation will be the explosive
growth of Wide Area Networking.
• Natural Language Processing (NLP) is a component of Artificial Intelligence
(AI).
• It provides the ability to develop the computer program to understand human
language.

8. Write the significant features of monitor.


Monitor:
• Monitor is the most commonly used output device to display the information. It
looks like a TV.
• Pictures on a monitor are formed with picture elements called PIXELS.
• Monitors may either be Monochrome which display text or images in Black and
White or can be color, which display results in multiple colors.
• There are many types of monitors available such as CRT (Cathode Ray Tube),
LCD (Liquid Crystal Display) and LED (Light Emitting Diodes).
• The video graphics card helps the keyboard to communicate with the screen.
• It acts as an interface between the computer and display monitor.

Question and Answers( 5 Mark)

1. Explain the basic components of a computer with a neat diagram.

• Input unit : Input unit is used to feed any form of data to the computer,
which can be stored in the memory unit for further processing.
• Central Processing Unit : CPU is the major component which interprets
and executes soft- ware instructions. It also control the operation of all
other components such as memory, input and output units.
• Arithmetic and Logic Unit : The ALU is a part of the CPU where
various computing functions are performed on data. The ALU performs
arithmetic operations such as addition, subtraction, multiplication, division
and logical operations.

• Control Unit : The control unit controls the flow of data between the CPU,
memory and I/o devices. It also controls the entire operation of a computer.
• Output Unit : An output unit is any hardware component that conveys
information to users in an understandable form. Example : Monitor, Printer
etc.
• Memory Unit : The Memory Unit is of two types which are primary
memory and secondary memory. The primary memory is used to temporarily
store the programs and data when the instructions are ready to execute. The
secondary memory is used to store the data permanently. The Primary
Memory is volatile, that is, the content is lost when the power supply is
switched off. The Random Access Memory (RAM) is an example of a main
memory. The Secondary memory is non volatile, that is, the content is
available even after the power supply is switched off. Hard disk, CD-ROM
and DVD ROM are examples of secondary memory.

2. Discuss the various generations of computers.


Main Component
S.N Generation Period Merits/ Demerits
used
1 First Generation 1942-1955 Vaccum tubes • Big in size
• Consumed more power
• Malfunction due to overheat
• Machine Language was used

First Generation Computer - ENIAC, EDVAC, UNIVAC 1


ENIAC weighed about 27 tons, size 8 feet × 100 feet × 3 feet and consumed around 150 watts of power

2. Second Generation 1955-1964 Transistors • Smaller compared to First Generation


• Generated Less Heat
• Consumed less power compared to first
• generation
• Punched cards were used
• First operating system was developed -Batch
Processing and Multiprogramming
Operating System
• Machine language as well as Assembly
language was used.
Second Generation Computers - IBM 1401, IBM 1620, UNIVAC 1108
3. Third 1964-1975 Integrated Circuits • Computers were smaller, faster and more
Generation (IC) reliable
• Consumed less power.
• High Level Languages were used
Third Generation Computers - IBM 360 series, Honeywell 6000 series
4. Fourth 1975-1980 Microprocessor • Smaller and Faster.
Generation Very Large Scale • Microcomputer series such as IBM and
Integrated Circuits APPLE were developed.
(VLSI) • Portable Computers were introduced.
5. Fifth 1980-till Ultra Large Scale • Parallel Processing
Generation date Integration (ULSI) • Super conductors
• Computers size was drastically reduced.
• Can recognize Images and Graphics
• Introduction of Artificial Intelligence and
• Expert Systems
• Able to solve high complex problems
including decision making and logical
reasoning
6. Sixth In future • Parallel and Distributed computing
Generation • Computers have become smarter, fasterand
smaller
• Development of robotics
• Natural Language Processing
• Development of Voice
Recognition Software

3 .Explain the following : a. Inkjet Printer b. Multi media projector c. Bar code /
QR code Reader
Ans.
Inkjet Printers:
• Inkjet Printers use colour cartridges which combined Magenta, Yellow and
Cyan inks to create color tones. A black cartridge is also used for monochrome output.
Inkjet printers work by spraying ionised ink at a sheet of paper.
• They use the technology of firing ink by heating it so that it explodes
towards the paper in bubbles or by using piezoelectricity in which tiny electric currents
controlled by electronic circuits are used inside the printer to spread ink in jet speed.
• An Inkjet printer can spread millions of dots of ink at the paper every single
second.
Multimedia Projectors:
• Multimedia projectors are used to produce computer output on a big screen.
• These are used to display presentations in meeting halls or in classrooms.
Bar Code / QR Code Reader:
• A Bar code is a pattern printed in lines of different thickness. The Bar code
reader scans the information on the bar codes transmits to the Computer for
further processing.
• The system gives fast and error free entry of information into the computer.
QR (Quick response) Code:
The QR code is the two dimension bar code which can be read by a
camera and processed to interpret the image.

***************************
MAHATMA
Computer Science / computer Application
Class XI Chapter 2- Number System

One Word

1. Which refers to the number of bits processed by a computer’s CPU?


Word length
2. How many bytes does 1 KiloByte contain?
1024
3. Expansion for ASCII
American Standard Code for Information Interchange
4. 2^50 is referred as
Peta
5. How many characters can be handled in Binary Coded Decimal System?
64
6. For 11012 what is the Hexadecimal equivalent?
D
7. What is the 1’s complement of 00100110?
11011001
8. Which amongst this is not an Octal number?
876

BCD – Binary Coded Decimal.


EBCDIC – Extended Binary Coded
ASCII – American Standard Code for Information Interchange
ISCII - Indian Standard Code for Information Interchange
TSCII – Tamil Standard Code for Information Interchange.
MSB- Most Significant Bit.
LSB- Least Significant Bit
IBM- International Business machine
2marks:

1. Define data
➢ The term data comes from the word datum, which means a raw fact.
➢ The data is a fact about people, places or some objects.
➢ Data is defined as an un- processed collection of raw facts,
➢ suitable for communication, interpretation or processing.
➢ It is an input of the computer.
➢ It will not giving any meaningful message. Ex. 134, 16 „Kavitha‟, „C‟

2. Write the 1’s complement procedure.


This is for negative numbers only i.e. the number whose MSB is 1
Step 1: Convert given Decimal number into Binary
Step 2: Check if the binary number contains 8 bits, if less add 0 at the left most
bit, to make it as 8 bits.
Step 3: Invert all bits (i.e. Change 1 as 0 and 0 as 1) Example:
Find 1‟s complement for (-24)10

3. Convert (46)10 into Binary number


4. We cannot find 1’s complement for (28)10. State reason.
(28)10 is a positive number.1‟s Complement method is for Negative numbers only. Hence we
cannot find 1‟s complement for 28.

5. List the encoding systems for characters in memory.


1. BCD – Binary Coded Decimal
2. EBCDIC – Extended Binary Coded Decimal Interchange Code
3. ASCII – American Standard Code for Information Interchange
4. Unicode
5. ISCII - Indian Standard Code for Information Interchange

3marks:

1. What is radix of a number system? Give example

➢ Radix or base is number of digits in each number system.


➢ Each number system is uniquely identified by its base value or radix.
➢ Radix or base is the general idea behind positional numbering system.
➢ A numbering system is a way of representing numbers Example:
Decimal number system( Base Value 10 )
0,1,2,3,4,5,6,7,8,9
Binary number system( Base Value 2 )0,1
Octal number system( Base Value 8 ) 0,1,2,3,4,5,6,7
Hexadecimal number system( Base Value 16)
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

2. Write note on binary number system.


.
➢ There are only TWO DIGITS in the Binary system, namely, 0 and 1.
➢ The numbers in the binary system are represented to the base 2 and the positional
multipliers are the powers of 2.
➢ The left most bit in the binary number is called as the Most Significant Bit (MSB) and
it has the largest positional weight.
➢ The right most bit is the Least Significant Bit (LSB) and has the smallest positional
weight.

4. Write a short note on ISCII

➢ ISCII is the system of handling the character of Indian local languages.


➢ This is a 8-bit coding system.
➢ Therefore it can handle 256 (28) characters.
➢ This system is formulated by the department of Electronics in India in the year 1986-
88 and recognized by Bureau of Indian Standards (BIS).
3. Convert (150)10 into Binary, then convert that Binary number to Octal.

5. Add a) -2210+1510 a) 2010+2510


5marks:

1. a) Write the procedure to convert fractional Decimal to Binary


The method of repeated multiplication by 2 has to be used to convert such
kind of decimal fractions.
The steps involved in the method of repeated multiplication by 2:

Step 1: Multiply the decimal fraction by 2 and note the integer part. The integer part is
either 0 or 1.

Step 2: Discard the integer part of the previous product. Multiply the fractional part of
the previous product by 2. Repeat Step 1 until the same fraction repeats or terminates (0).

Step 3: The resulting integer part forms a sequence of 0s and 1s that become the
binary equivalent of decimal fraction.

Step 4: The final answer is to be written from first integer part obtained till the last integer
part obtained.

Write the integer parts from top to bottom to obtain the equivalent fractional binary number

b) Convert (98.46)10 to Binary


2. Find 1’s Complement and 2’s Complement for the following Decimal number a) -98 b) -135
3. a) Add 11010102+1011012
b) Subtract 11010112 - 1110102
Extra 1 mark questions

1. The term data comes from the word datum which means a raw fact
2. The data is a fact about people, places or some objects.
3. Computer handles data in the form of „0‟(Zero) and „1‟ (One).
4. A bit is the short form of Binary digit which can be „0‟ or „1‟.
5.Bit is the basic unit of data in computers.
6. A nibble is a collection of 4 bits
7. A collection of 8 bits is called Byte
8. A byte is considered as the basic unit of measuring the memory size in the
Computer
9. Word length refers to the number of bits processed by a Computer‟s CPU
10. Computer memory (Main Memory and Secondary Storage)is normally
represented in terms of KiloByte (KB) or MegaByte (MB). 11.In decimal system,
1 Kilo represents 1000
12.In binary system, 1 KiloByte represents 1024 bytes
13.Yotta =2^80,Zetta=2^70, Exa=2^60, Peta=2^50,Tera=2^40,Giga=2^30
Mega=2^20,Kilo=2^10
14. Bytes are used to represent characters in a text
15. ASCII stands for American Standard Code for Information Interchange
16. The ASCII value for (blank space) is 32
17.ASCII value of numeric 0 is 48
18.ASCII values for lower case alphabets is from 97 to 122 19.ASCII
values for the upper case alphabets is 65 to 90
20. A numbering system is a way of representing numbers 21.The most
commonly used numbering system in real life is Decimal number system
22. Each number system is uniquely identified by its base value or radix
23. Radix or base is thecount of number of digits in each number system
24. In the positional number system, each decimal digit is weighted relative to its
position in the number
25. The numbers in the binary system are represented to the base 2
26. The left most bit in the binary number is called as the Most Significant Bit
27. The right most bit is the Least Significant Bit
28. Octal number system uses 8 digits
29. A hexadecimal number is represented using base 16
30. Which number system is used to represent data in a more compact
manner – Hexadecimal Number system
31. To convert Decimal to Binary “Repeated Division by 2” method can be used.
32. To convert Decimal to Octal, “Repeated Division by 8” method can be used.
33. To convert Decimal to Hexadecimal, “Repeated division by 16” method can
be used
34. The method of repeated multiplication by 2 has to be used to convert
Decimal Fraction to Binary Fraction
35. Computers can handle both positive (unsigned) and negative (signed) numbers.
36. The simplest method to represent negative binary numbers is called
Signed Magnitude
37. In signed magnitude method, the left most bit is Most Significant Bit
(MSB), is called sign bit or parity bit
38. In signed binary representation, the left most bit is considered as sign bit
39. 1‟s Complement representation is an easier approach to represent
signed numbers
40. BCD – Binary Coded Decimal
41. EBCDIC – Extended Binary Coded Decimal Interchange Code
42. ASCII – American Standard Code for Information Interchange
43. ISCII - Indian Standard Code for Information
Interchange 44.BCD can handle 64 characters.
45. Most popular encoding system recognized by United States - ASCII
46. ASCII can handle 128 characters.
47. The new edition (version) ASCII -8 can handle 256 characters
48. The ASCII code equivalent to the uppercase letter „A‟ is 65
49.EBCDIC coding system is formulated by International Business
Machine(IBM)
50. EBCDIC can handle 256 characters.
51. Indian Standard Code for Information Interchange is a 8-bit coding system
52.ISCII was formulated in the year 1986-88 and recognized by Bureau of
Indian Standards (BIS)
53. English and European Languages alone can be handled by ASCII
54. Unicode was generated to handle all the coding system of Universal
languages
55. Unicode is a 16 bit code and can handle 65536 characters
56. Unicode scheme is denoted by hexadecimal number

***********************************************
LESSON 3 Computer Organization
Study Material’s
Oneword:
1. Which of the following is sadi to be the brain of a computer? Microprocessor
2. Which of the following is not the part of a microprocessor unit? Cache memory
3. How many bits constitute a word? determined by the processor used.
4. Which of the following device identifies the location when address is placed in the
memory address register? decoder
5. Which of the following is a CISC processor? Pentium III
6. Which is the fastest memory? Cache memory
7. How many memory locations are identified by a processor with 8 bits address bus at a
time? 256
8.What is the capacity of 12cm diameter DVD with single sided and single layer? 4.7 GB
9.What is the smallest size of data represented in a CD? pits
10. Display devices are connected to the computer through. VGA connector

Question and Answers (2 Mark):

1. What are the parameters which influence the characteristics of microprocessor?


A microprocessor’s performance depends on the following characteristics:
a. Clock speed b. Instruction set c. Word size

2. What is an instruction?
A command which is given to a computer to perform an operation on data is called
an instruction.

3. What is a program counter?


The program counter (PC) is a special register in the CPU which always keeps the
address of the next instruction to be executed.

4. What is HDMI?
High-Definition Multimedia Interface is an audio/video interface which transfers the
compressed video and audio data from video controller, to a compatible computer monitor,
LCD projector, digital television etc..

5. Which source is used to erase the content of a EPROM?


Ultra-violet-rays is used erase the content of a EPROM.

Question and Answer(3 mark)


1. Differentiate Computer Organization from Computer Architecture.
Computer architecture deals with the engineering considerations involved in
designing a computer. Computer Organization deals with hardware
components that are transparent to the programmer.
2. Classify the microprocessor based on the size of the data.
Microprocessors can process instructions. The microprocessor can be
classified as follows based on the size of the data.
i.8-bit microprocessor.
ii. 16-bit microprocessor.
iii. 32-bit microprocessor.
iv. 64-bit microprocessor.
3. Write down the classifications of microprocessors based on the instruction set.
The two types of microprocessors which are based on their instruction sets.
i. Reduced Instruction Set Computers (RISC)
ii. Complex Instruction Set Computers (CISC)

4. Differentiate PROM and EPROM.


PROM can be written only and cannot be erased. EPROMS are used widely
in personal computers because they enable the manufacturer to change the
contents of the PROM to replace with updated versions or erase the contents
before the computer is delivered.

5. Write down the interface and ports available in a computer.


The various types of ports are given below:
Serial Port: To connect the external devices, found in old computer.
Parallel Port: To connect the printers found in old computer.
USB Port: To connect external devices like camera, scanners,
mobile phones external hard disks and printers to the computer.

6. Differentiate CD and DVD.

CD DVD
▪ Expansion is Compact-Disc. ▪ Expansion is Digital
▪ A standard CD can store about Versatile Disc.
700 MB of Data. ▪ A standard DVD can hold
▪ CD players cannot play DVDs. 4.7 GB of Data.
▪ It stores up to 80 min of audio. ▪ DVD players can play
CDs.
▪ It can range from 4.7 GB to
17.08
GB.

7. How will you differentiate a flash memory and an EEPROM?

Flash EEPROM
Memory
▪ Faster in performance. ▪ Slower in performance.
▪ Flash uses the slower NAND ▪ EEPROM uses the faster NOR
gate. gate.
▪ |Using flash, access and erase ▪ Using EEPROM, access and
data in block-wise. erase data only byte-wise or
▪ Storage capacity can range byte at a time.
from a GB to hundred of GB. ▪ Storage capacity can range
from a kilobytes to couple of
megabytes.

Question and Answer(5 mark)

1. Explain the characteristics of a microprocessor.

A Microprocessor’s performance depends on the following


characteristics:
a) Clock speed
b) Instruction set
c) Word size

a) Clock Speed
Every microprocessor has an internal clock that regulates the speed at
which it executes instructions. The speed at which the microprocessor executes
instructions is called the clock speed. Clock speed is measured in MHz (Mega
Hertz) or in GHz (Giga Hertz).

b) Instruction Set
A command which is given to a computer to perform an
operation on data is called an instruction. Basic set of machine level
instructions that a microprocessor is designed to execute is called as an
instruction set. This instruction set carries out the following types of
operations:
• Data transfer
• Arithmetic operations
• Logical operations
• Control flow
• Input/output

c) Word Size
The number of bits that can be processed by a processor in a single
instruction is called its word size.
Word size determines the amount of RAM that can be accessed by a
microprocessor at one time and the total number of pins on the microprocessor.
Total number of input and output pins in turn determines the architecture
of the microprocessor.

2. How the read and write operations are performed by a processor? Explain.
i. The Central Processing Unit (CPU) has a Memory Data Register (MDR)
and a Memory Address Register (MAR).
ii. The Memory Data Register (MDR) keeps the data which is transferred
between the Memory and the CPU. The Program Counter (PC) is a special
register in the CPU which always keeps the address of the next instruction to
be executed.
iii. The Arithmetic and Logic unit of CPU places the address of the memory
to be fetched,
into the Memory Address Register.
iv. A bus is a collection of wires used for communication between the
internal components of a computer.
v. The address bus is used to point a memory location. A decoder, a digital
circuit is used to point to the specific memory location where the word can be
located.
vi. The address register is connected with the address bus, which provides
the address of the instruction. A data bus is used to transfer data between
the memory and the CPU.
vii. The data bus is bidirectional and the address bus is unidirectional. The
control bus controls both read and write operations.
Viii The read operation fetches data from memory and transfer to MDR. A
single control line performs two operations like Read/Write using 1 or 0.
IX. Also , the write operation transfers data from the MDR to memory.
3. Arrange the memory devices in ascending order based on the access time. –
Explain (or) Explain the types of Secondary Storage devices.

• CD / DVD Blu-Ray
• Flash Drives
• Cache Memory
Compact Disc (CD)
A CD or CD-ROM is made from 1.2 millimeters thick, polycarbonate
plastic material. A thin layer of aluminum or gold is applied to the surface. CD
data is represented as tiny indentations known as "pits", encoded in a spiral
track molded into the top of the polycarbonate layer. The areas between pits
are known as "lands". A motor within the CD player rotates the disk. The
capacity of an ordinary CDROM is 700MB.
DVD (Digital Versatile Disc or Digital Video Disc)
A DVD is an optical disc capable of storing up to 4.7 GB of data, more
than six times what a CD can hold. DVDs are often used to store movies at a
better quality. Like CDs, DVDs are read with a laser.
The disc can have one or two sides, and one or two layers of data per side; the
number of sides and layers determines how much it can hold. A 12 cm diameter
disc with single sided, single layer has 4.7 GB capacity, whereas the single sided,
double layer has 8.5 GB capacity. The 8 cm DVD has 1.5 GB capacity. The
capacity of a DVD-ROM can be visually determined by noting the number of
data sides of the disc. Double-layered sides are usually gold-colored, while
single-layered sides are usually silver-colored, like a CD.
Blu-Ray Disc
Blu-Ray Disc is a high-density optical disc similar to DVD. Blu-ray is the
type of disc used for PlayStation games and for playing High-Definition (HD)
movies. A double layer Blu-Ray disc can store up to 50GB (gigabytes) of data.
This is more than 5 times the capacity of a DVD, and above 70 times of a CD.
The format was developed to enable recording, rewriting and playback of high-
definition video, as well as storing large amount of data. DVD uses a red laser to
read and write data. But, Blu-ray uses a blue-violet laser to write. Hence, it is
called as Blu-Ray.
Hard Disk
Hard disk is a magnetic disk on which you can store data. The hard disk
has the stacked arrangement of disks accessed by a pair of heads for each of the
disks. The hard disks come with a single or double sided disk.
Flash Memory
Flash memory is an electronic (solid-state) non-volatile computer storage
medium that can be electrically erased and reprogrammed. They are either
EEPROM or EPROM. Examples for Flash memories are pen-drives, memory
cards etc. Flash memories can be used in personal computers, Personal Digital
Assistants (PDA), digital audio players, digital cameras and mobile phones.
Flash memory offers fast access times. The time taken to read or write a
character in memory is called access time. The capacity of the flash memories
vary from 1 Gigabytes (GB) to 2 Terabytes (TB).
Cache Memory
The cache memory is a very high speed and expensive memory, which is
used to speed up the memory retrieval process. Due to its higher cost, the CPU
comes with a smaller size of cache memory compared with the size of the main
memory. Without cache memory, every time the CPU requests the data, it has to
be fetched from the main memory which will consume more time. The idea of
introducing a cache is that, this extremely fast memory would store data that is
frequently accessed and if possible, the data that is closer to it. This helps to
achieve the fast response time. Where response Time, (Access Time) refers to
how quickly the memory can respond to a read / write request.

4. Explain the Types ROMs.


a.Read-only Memory (ROM)
b.Programmable Read-only Memory (PROM)
c.Erasable Programmable Read-only Memory (EPROM)
d.Electrically Erasable Read-only Memory (EEPROM)

Read-only Memory (ROM)


✓ Read Only Memory refers to special memory in a computer with pre-
recorded data at manufacturing time which cannot be modified. The stored
programs that start the computer and perform diagnostics are available in
ROMs.
✓ ROM stores critical programs such as the program that boots the computer.
Once the data has been written onto a ROM chip, it cannot be modified or
removed and can only be read.
✓ ROM retains its contents even when the computer is turned off. So, ROM is
called as a non-volatile memory.

Programmable Read-only Memory (PROM)


✓ Programmable read only memory is also a non-volatile memory on which
data can be written only once. Once a program has been written onto a
PROM, it remains there forever.
✓ Unlike the main memory, PROMs retain their contents even when the
computer is turned off.
✓ The PROM differs from ROM. PROM is manufactured as a blank
memory, whereas a ROM is programmed during the manufacturing process
itself.
✓ PROM programmer or a PROM burner is used to write data to a PROM chip.
The process of programming a PROM is called burning the PROM.

Erasable Programmable Read Only Memory (EPROM)


✓ Erasable Programmable Read Only Memory is a special type of memory
which serves as a PROM, but the content can be erased using ultraviolet rays.
EPROM retains its contents until it is exposed to ultraviolet light. The
ultraviolet light clears its contents, making it possible to reprogram the
memory.
✓ An EPROM differs from a PROM, PROM can be written only once and cannot
be erased. EPROMs are used widely in personal computers because they
enable the manufacturer to change the contents of the PROM to replace
with updated versions or erase the contents before the computer is
delivered.

Electrically Erasable Programmable Read Only Memory (EEPROM)


✓ Electrically Erasable Programmable Read Only Memory is a special type of
PROM that can be erased by exposing it to an electrical charge.
✓ Like other types of PROM, EEPROM retains its contents even when the
power is turned off. Comparing with all other types of ROM, EEPROM is
slower in performance.

****************************
MAHATMA
CHAPTER - 4
THEORETICAL CONCEPTS OF OPERATING SYSTEM
Class XI Computer Science
_______________________________________________________________________________________
Part I
1) Operating system is a
A) Application Software B) Hardware C) System Software D) Component
2) Identify the usage of Operating Systems
A) Easy interaction between the human and computer
B) Controlling input & output Devices
C) Managing use of main memory
D) All the above
3) Which of the following is not a function of an Operating System?
A) Process Management B) Memory Management
C) Security management D) Compiler Environment
4) Which of the following OS is a commercially licensed Operating system?
A) Windows B) UBUNTU C) FEDORA D) REDHAT
5) Which of the following Operating systems support Mobile Devices?
A) Windows 7 B) Linux C) BOSS D) iOS
6) File Management manages
A) Files B) Folders C) Directory systems D) All the Above
7) Interactive Operating System provides
A) Graphics User Interface (GUI) B) Data Distribution
C) Security Management D) Real Time Processing
8) An Example for Single task Operating System
A) Linux B) Windows
C) MS-DOS D) UNIX
9) The File Management system used by Linux is
A) Ext2 B) NTFS C) FAT D) NFTS
Part II
1) List any two uses of Operating System?
 to ensure that a computer can be used
 to extract what the user wants it do.
 Easy interaction between the users and computers.
 Starting computer operation automatically when power is turned on (Booting).
 Controlling Input and Output Devices
 Manage the utilization of main memory.
 Providing security to user programs.
2) What is the multi-user Operating system?
 It is used in computers and laptops that allow same data and applications
to be accessed by multiple users at the same time.
 The users can also communicate with each other. Windows, Linux and
UNIX are examples for multi-user Operating System
3) What is a GUI?
 GUI stands for Graphical User Interface
 The GUI is a window based system with a pointing device to direct I/O,
choose from menus, and make selections and a keyboard to enter text.
 Its vibrant color’s attract the user very easily.
4) What are the security management features available in Operating System?
The Operating System provides three levels of securities to the user end. They are
(1) File access level
(2) System level
(3) Network level

 In order to access the files created by other people, you should have the
Access permission. Permissions can either be granted by the creator of the file
or by the administrator of the system.
 System level security is offered by the password in a multi-user environment.
Both windows and Linux offer the password facility.
 Network security is an indefinable one. So people from all over the world try
to provide such a security.

5) What is multi-processing?
 This is a one of the features of Operating System.
 It has two or more processors for a single running process (job).
 Processing takes place in parallel is known a parallel processing.
 Since the execution takes place in parallel, this feature is used for high
speed execution which increases the power of computing.

6) What are the different Operating Systems used in computer?


 Single User Operating Systems
 Multi-user Operating Systems
 Multi-Processing Operating Systems
 Distributed Operating Systems
 Prominent Operating Systems

PART III

1) What are the advantages and disadvantages of Time-sharing features?

Time-Sharing Operating
System
Advantages Disadvantages
It allows execution of multiple tasks or
Problem of Reliability
processes concurrently
Questions of security and integrity of
Quick Response
uses programs and data
Avoids duplication of software Problem of data communication
Reduces CPU idle time Various processes after a time is elapsed.

2) List Out the Key features of Operating System

The Key features of Operating System are


 User Interface
 Memory Management
 File management
 Fault Tolerance
 Security Management
 Process Management
3) Write a note on multi-processing
 This is a one of the features of Operating System.
 It has two or more processors for a single running process (job).
 Processing takes place in parallel is known a parallel processing.
 Since the execution takes place in parallel, this feature is used for high
speed execution which increases the power of computing.
Part IV
1) Explain the concept of a Distributed Operating System.
This feature takes care of the data and application that are stored and
processed on multiple physical locations across the world over the digital network
(internet/intranet).

The Distributed Operating System is used to access shared data and files that
reside in any machine around the world. The user can handle the data from different
locations.
The users can access as if it is available on their own computer.

The advantages of distributed Operating System are as follows:


 A user at one location can make use of all the resources available at another
location over the network.
 Many computer resources can be added easily in the network
 Improves the interaction with the customers and clients.
 Reduces the load on the host computer.

2) List out the points to be noted while creating a user interface for an
Operating System
User interface is one of the significant features in Operating System. The only way
that user can make interaction with a computer. This is a main reason for key
success of GUI (Graphical User Interface) based Operating System. The GUI is a
window based system with a pointing device to direct I/O, choose from menus,
make selections and a keyboard to enter text. Its vibrant colours attract the user
very easily.
Now Linux distribution is also available as GUI based Operating System. The
following points are considered when User Interface is designed for an application.
1. The user interface should enable the user to retain this expertise for a longer
time.
2. The user interface should also satisfy the customer based on their needs.
3. The user interface should save user’s precious time.
4. The ultimate aim of any product is to satisfy the customer. The User Interface is
also to satisfy the customer.
5. The user interface should reduce number of errors committed by the user
3) Explain the Process Management Algorithms in Operating System
Process management is function that includes creating and deleting processes
(program) and providing mechanisms for processes to communicate and
synchronize with each other.
The following algorithms are mainly used to allocate the job (process) to the
processor.
1. FIFO
2. SJF
3. Round Robin
4. Based on Priority

FIFO (First In First Out) Scheduling:


This algorithm is based on queuing technique. Assume that a student is
standing in a queue (Row) to get grade sheet from his/her teacher. The other student
who stands first in the queue gets his/her grade sheet first and leaves from the queue
(Row). Followed by the next student in the queue gets it corrected and so on. This is the
basic logic of the FIFO algorithm.

Technically, the process that enters the queue first is executed first by the CPU, followed
by the next and so on. The processes are executed in the order of the queue (row).

SJF (Shortest Job First) Scheduling:


This algorithm works based on the size of the job being executed by the CPU.
Consider two jobs A and B.
1) A = 6 kilo bytes 2) B = 9 kilo bytes
First the job “A” will be assigned and then job “B” gets its turn.

Round Robin Scheduling


The Round Robin (RR) scheduling algorithm is designed especially for time sharing
systems. Jobs (processes) are assigned and processor time in a circular method. For
example take three jobs A, B, C. First the job A is assigned to CPU then job B and job C
and then again A, B and C and so on.

Based On Priority
The given job (process) is assigned based on a Priority. The job which has higher
priority is more important than other jobs. Take two jobs A and B. Let the priority of A
be 5 and priority B be 7.
Job B is assigned to the processor before job A.
MAHATMA
Computer Science

Class XI
___________________________________________________________________________

Home Work (13.10.2020 –Tuesday)

2marks:
1. What are the different Operating Systems used in computer?
2. What is a GUI?
3. List any two uses of Operating System?
4. What is the multi-user Operating system?
5. What is multi-processing?

3marks:
1. List Out the Key features of Operating System

5marks:
1. List out the points to be noted while creating a user interface for an Operating
System
MAHATMA
Computer Science

Class XI
___________________________________________________________________________

Home Work (15.10.2020 –Thursday)

2marks:
1. What are the security management features available in Operating System?

3marks:
1. Write a note on multi-processing
2. What are the advantages and disadvantages of Time-sharing features?

5marks:
1. Explain the Process Management Algorithms in Operating System
2. Explain the concept of a Distributed Operating System.

6
Lesson 5 –Working with typical Operating System
Book Back Question and Answers
One Word
1. From the options given below, choose the operations managed by the operating
system.
a. Memory b. Processes c. Disks and I/O devices d. All of these
2. Which is the default folder for many Windows Application to save your file?
a. My Document b. My Picture c. Documents and Settings d. My Computer
3. Under which of the following OS the option Shift+Delete – permanently deletes a file or
folder?
a. Windows 7 b. Windows 8 c. Windows 10 d. All of the OS
4. What the meaning of “Hibernate” in Windows XP/ Windows7?
a. Restart the Computer in safe mode
b. Restart the Computer in Hibernate mode
c. Shutdown the Computer terminating all the running applications.
d. Shutdown the Computer without closing the running application.
5. The shortcut key used to rename a file in windows
a. F2 b.F4 c.F5 d. F6
Answer the following( 2 mark)
1. what is known as Multitasking?

Every computer needs an Operating System to function. Microsoft Windows is


one of the most popular Graphical User Interface (GUI). Multiple applications
can execute simultaneously in Windows, and this is known as “Multitasking

2. What are called standard icons


The icons which are available on desktop by default while installing Windows
OS are called standard icons. The standard icons available in all Windows OS
are My Computer, Documents and Recycle Bin.

3. Differentiate Files and Folders.


File is the collection of records. Folder is a collections of files

4. Differentiate Save and Save As option.


“Save” option save a document with a name “Save As” option save an
already saved the document with a new name and also create a copy of
already saved document with new name obviously.
5. How will you Rename a File
1. Select the File or Folder you wish to Rename.
2. Click File→ Rename.
3. Type in the new name.
4. To finalise the renaming operation, press Enter

SECTION-C
Short Answers

1. What are the functions of Windows Operating system.


• Memory Management
• Process Management
• Device Management
• File Management
• Security Management
• Control overall system performance

2. Write a note on Recycle bin.


Recycle bin is a special folder to keep the files or folders deleted by the user,
which means you still have an opportunity to recover them. The user cannot
access the files or folders available in the Recycle bin without restoring it.

3. Write a note on the elements of a window.


Title Bar, Menu Bar, The Workspace, Scroll bars, Corners and borders

4. Write the two ways to create a new folder.


Method I:
Step 1: Open Computer Icon.
Step 2: Open any drive where you want to create a new folder. (For example
select D:)
Step 3: Click on File → New → Folder.
Step 4: A new folder is created with the default name “New folder”.
Step 5: Type in the folder name and press Enter key.
Method II:
In order to create a folder in the desktop:
Step 1: In the Desktop, right click → New → Folder
Step 2: A Folder appears with the default name “New folder”.
Step 3: Type the name you want and press Enter Key.
Step 4: The name of the folder will change.

5. Differentiate copy and move

Copying means creating copy of data at another location and it remains


intact at its previous location, while moving data means copying same data
into another location and removing from original location

SECTION – D
Explain in detail
1. Explain the versions of Windows Operating System.
2. Explain the different ways of finding a file or Folder
To find a file or folder:
1. Click the Start button, the search box appears at the bottom of the start
menu.
2. Type the name of the file or the folder you want to search. Even if you give
the part of the file or folder name, it will display the list of files or folders
starting with the specified name.
3. The files or the folders with the specified names will appear, if you click
that file, it will directly open that file or the folder.
4. There is another option called “See more results” which appears above the
search box.
5. If you click it, it will lead you to a Search Results dialog box where you can
click and open that file or the folder

Searching Files or folders using Computer icon

1. Click Computer Icon from desktop or from Start menu.


2. The Computer disk drive screen will appear and at the top right corner of
that screen, there is a search box option.
3. Type the name of the file or the folder you want to search. Even if you give
the part of the file or folder name, it will display the list of files or folders
starting with the specified name.. Finding a File/Folder using Start button
4. Just click and open that file or the folder.

3. Write the procedure to create shortcut in Windows OS.


• Select the file or folder that you wish to have as a shortcut on the Desktop.
• Right click on the file or folder.
• Select Send to from the shortcut menu, then select Desktop (create
shortcut) from the sub-menu.
• A shortcut for the file or folder will now appear on your desktop and you
can open it from the desktop in the same way as any other icon.

**********************************************************************
UNIT II ALGORITHMIC PROBLEM SOLVING

CHAPTER 6
SPECIFICATION AND ABSTRACTION
PART I Choose the Best Answer
1. Which of the following activities is algorithmic in nature?
(a) Assemble a bicycle. (b) Describe a bicycle.
(c) Label the parts of a bicycle. (d) Explain how a bicycle works.
2. Which of the following activities is not algorithmic in nature?
a)Multiply two numbers. (b) Draw a kolam.
(c) Walk in the park. (d) Braid the hair

3. Omitting details inessential to the task and representing only the essential
features of the task is known as
a. specification (b) abstraction (c) composition (d) decomposition
4. Stating the input property and the as :-output relation a problem is known
a. specification (b) statement (c) algorithm (d) definition
5. Ensuring the input-output relation is
a. the responsibility of the algorithm and the right of the user.
b. the responsibility of the user and the right of the algorithm.
c. the responsibility of the algorithm but not the right of the user.
d. the responsibility of both the user and the algorithm.
6. If i = 5 before the assignment i := i-1 after the assignment, the
value of i is (a) 5 (b) 4 (c) 3 (d)
2
7. If 0 < i before the assignment i := i-1 after the assignment, we can
conclude that
(a) 0 < i (b) 0 ≤ i (c) i = 0 (d) 0 ≥ i

PART II Very Short Answers


1. Define an algorithm.
➢ An algorithm is a step-by-step sequence of statements to solve a problem.
➢ As an algorithm is executed, a process evolves which solves the problem.
`
2. Distinguish between an algorithm and a process.

ALGORITHM PROCES
S
An algorithm is a step-by-step sequence
An instruction describes an action
of statements to solve a problem
When the instructions are executed, a
As an algorithm is executed, a process
process
evolves which solves the problem. evolves, which accomplishes the
intended task or solves the given
problem
3. Specify a function to find the minimum of two numbers.
Minimum(A,B)
- - inputs: A an B are integers (or) Real numbers
- - Outputs: A is minimum such that (A<B)
(or) B is minimum such that (B<A)

4. If √2 = 1.414, and the square root() function returns -1.414, does


it violate the following specification?
-- square_root (x)
-- inputs: x is a real number , x ≥ 0
-- outputs: y is a real number such that y2=x
Yes, it violates the specification. For a Positive input (x>=0), the output square
root value should also be positive.

PART III Short Answers


1. When do you say that a problem is algorithmic in nature?
We usually say that a problem is algorithmic in nature when its solution
involves the construction of an algorithm. Some types of problems can be
immediately recognized as algorithmic.

2. What is the format of the specification of an algorithm?


Let P be the required property of the inputs and Q the property of the
desired outputs. Then the algorithm S is specified as
1. algorithm_name (inputs)
2. --inputs : P
3. --outputs: Q

3. What is abstraction?
A problem can involve a lot of details. Several of these details are
unnecessary for solving the problem. Only a few details are essential.
Abstraction is the process of hiding or ignoring the details irrelevant to the
task so as to model a problem only by its essential features.

4. How is state represented in algorithms?


State is a basic and important abstraction.
Computational processes have state. A computational process starts with
an initial state. As actions are performed, its state changes. It ends with a
final state.
State of a process is abstracted by a set of variables in the algorithm. The
state at any point of execution is simply the values of the variables at that
point.

5. What is the form and meaning of


assignment statement? Assignment
statement
➢ Variables are named boxes to store values. Assignment statement is
used to store a value in a variable.
➢ It is written with the variable on the left side of the assignment
operator and a value on the right side.
Format / Form:
Variable := value
Example:
m := 2
6. What is the difference between assignment operator and equality
operator?

ASSIGNMENT OPERATOR EQUALITY OPERATOR


Assignment operator is used to Equality operator is used to the values
assign the of both
right hand side value into left hand right hand side variable and left hand
side variable. side variable and results in either true
or false.
Example: Example:
A=5 A==B (a=5, b=5) True
B=10 A≠B (a=5, b=10) True
Mahatma
Computer Science
Class: XI
Date : 29.10.2020

Home Work

3marks:

1. When do you say that a problem is algorithmic in nature?


2. What is the format of the specification of an algorithm?
3. What is Abstraction?
4. How is state represented in algorithms?

5Marks:

Write the specification for multiplying 2 numbers


Write the algorithm specification for subtracting 2 numbers
MAHATMA
Computer Science
Chapter 7
COMPOSITION AND DECOMPOSITION

1. Suppose u, v = 10, 5 before the assignment. What are the values of u and v after the sequenceof
assignments?
1 u := v
2 v := u
(a) u, v = 5 ,5 (b) u, v = 5 ,10 (c) u, v = 10 ,5 (d) u, v = 10 ,10

2. Which of the following properties is true after the assignment (at line 3?
1 – i,j= 0,0
2 i, j := i+1, j-1
3 -- ?
(a) i+j >0 (b) i+j < 0 (c) i+j =0 (d) i = j

3. If C1 is false and C2 is true, the compound statement


1 if C1
2 S1
3 else
4 if C2
5 S2
6 else
7 S3

a) S1 (b) S2 (c) S3 (d) none


4. If C is false just before the loop, the control flows through
1 S1
2 while C
3 S2
4 S3
(a) S1 ; S3 (b) S1 ; S2 ; S3 (c)S1 ; S2 ; S2 ; S3 (d) S1 ; S2 ; S2 ; S2 ; S3
5. If C is true, S1 is executed in both the flowcharts, but S2 is executed in

(a) (1) only (b) (2) only (c) both (1) and (2) (d) neither (1) nor (2)
6. How many times the loop is iterated?
i := 0
while i ≠ 5
i := i + 1
(a) 4 (b) 5 (c) 6 (d) 0
Part II
1. Distinguish between a condition and a statement.

CONDITION STATEMENT
Condition is the Checking process of either True
Processing the condition
/ False.
A condition is contained in a diamond shaped A statement is contained in a rectangular box
box with two outgoing arrows, labeled true and with a single outgoing arrow, which points to the
false. box to be executed next.
EX: a>b EX: Print a (a-is a Biggest value)

2. Draw a flowchart for conditional statement.

Start

Stop

3. Both conditional statement and iterative statement have a condition and a statement. How
do they differ?

 Conditional statement is executed only if the condition is true. Otherwise nothing is done.

 Iterative statement repeatedly evaluates a condition and executes a statement as long as


the condition is true.
4. What is the difference between an algorithm and a program?
ALGORITHM PROGRAM
A Computer program is a sequence of
An algorithm is a self-contained step-by-step set
instructions that complete the rules of a specific
of operations to be performed to solve specific
programming language, written to perform a
problems.
specified task with a computer.
Method / Procedure of a program Computer Coding / Program

5. Why is function an abstraction?


 The parts of an algorithm are known as functions. A function is like a sub algorithm.
 It takes an input, and produces an output, satisfying a desired input output relation.

6. How do we refine a statement?

In refinement, starting at a high level, each statement is repeatedly expanded into more detailed
statements in the subsequent levels
Part III

1. For the given two flowcharts write the pseudo code.

Pseudo code :
1. If C
2. S1
3. ELSE
4. S2

2. If C is false in line 2, trace the control flow in this algorithm.


1. S1
2. - - C is false
3. if C
4. S2
5. else
6. S3
7. S4
i) Test the condition
ii) If C is false the statement S1 ,S3 and S4 is executed
Answer: S1; S3; S4

3. What is case analysis?


Case analysis statement generalizes it to multiple cases.
Case analysis splits the problem into an exhaustive set of disjoint cases. For each case, the problem
is solved independently. If C1, C2, and C3 are conditions, and S1,
S2, S3 and S4 are statements, a 4-case
analysis statement has the form,
1. case C1
2. S1
3. case C2
4. S2
5. case C3
6. S3
7. else
8. S4
The conditions C1, C2, and C3 are evaluated in turn. For the first condition that evaluates to
true, the corresponding statement is executed, and the case analysis statement ends. If none of
the conditions
evaluates to true, then the default case S4 is executed.
4. Draw a flowchart for -3case analysis using alternative statements.
5. Define a function to double a number in two different ways: (1) n + n, (2) 2 x n
Evaluate code

Default statement

(1) n + n

double(n)
- - Input: n is a real number or an integer, n>0
- - Output: y is a real number or an integer such that y = n + n

(2) 2 x n

Double(n)

- - Input: n is a real number or an integer, n>0


- - Output: y is a real number or an integer such that y = 2 x n

Part IV
1. Exchange the contents: Given two glasses marked A and B. Glass A is full of apple drink and glass B is
full of grape drink. Write the specification for exchanging the contents of glasses A and B, and write a
sequence of assignments to satisfy the specification.

Solution:
drink( A, B )
-- inputs : A, B where A is Apple drink, B is grape drink
-- outputs : A (grape Drink), B ( apple drink)
t :=A;
A:=B;
B:=t.

2. Circulate the contents: Write the specification and construct an algorithm to circulate the contents of the
variables A, B and C as shown below: The arrows indicate that B gets the value of A, C gets the value of B
and A gets the value of C.

Solution:
Circulate ( A, B, C )
--Inputs : A, B, C are real numbers or an integers, A≠0, B≠0, C≠0
--Outputs :
B:=A

C:=B

A:=C
Pseudo code:
1. Start
2. Read A,B,C
3. B=A
4. C=B
5. A=C
6. Print A,B,C
7. End
3. Decanting problem. You are given three bottles of capacities 5, 8, and 3 litres. The 8L
bottle is filled with oil, while the other two are empty. Divide the oil in 8L bottle into
two equal quantities. Represent the state of the process by appropriate variables.
What are the initial and final states of the process? Model the decanting of oil from
one bottle to another by assignment. Write a sequence of assignments to achieve the
final state.
Answer:
(a)
Let a, b, c be the variables whose maximum value are 8L, 5L and 3L respectively.
Initial State:

a, b, c: = 8, 0, 0

Final State:

a, b, c: = 4, 4, 0
Specifications:

1. decant
2. – – inputs: a, b, c : = 8, 0, 0
3. – – outputs: a, b, c : = 4, 4, 0
Algorithm:
Let us assume that a: = b denote oil in b is poured into a bottle until either “a” is
full or “b” becomes empty.

1. decant (a, b, c)
2. – – a, b, c : = 8, 0, 0
3. b : = a
4. – – a, b, c : = 3, 5, 0
5. c : = b
6. – – a, b, c : = 3, 2, 3
7. a : = c
8. – – a, b, c : = 6, 2, 0
9. c : = b
10. – – a, b, c : = 6, 0, 2
11. b : = a
12. – – a, b, c : = 1, 5, 2
13. c : = b
14. – – a, b, c : = 1, 4, 3
15. a : = c
16. – – a, b, c: = 4, 4, 0

4. Trace the step – by – step execution of the algorithm for factorial(4).


factorial(n)
– – inputs : n is an integer , n ≥ 0
– – outputs : f = n!
f, i : = 1,1
while i ≤ n
f, i : = f x i, i + 1
Answer:
Answer:
CS-Lesson 8
Iteration and recursion

1. A loop invariant need not be true


(a) at the start of the loop. (b) at the start of each iteration
(c) at the end of each iteration (d) at the start of the algorithm
2. We wish to cover a chessboard with dominoes, the number of black squares and the number
of white squares covered by dominoes, respectively, placing a domino can be modeled by
(a) b := b + 2 (b) w := w + 2 (c) b, w := b+1, w+1 (d) b := w
3. If m x a + n x b is an invariant for the assignment a, b : = a + 8, b + 7, the values of m and n are
(a) m = 8, n = 7 (b) m = 7, n = -8 (c) m = 7, n = 8 (d) m = 8, n = -7
4. Which of the following is not an invariant of the assignment?
m, n := m+2, n+3
(a) m mod 2 (b) n mod 3 (c) 3 X m - 2 X n (d) 2 X m - 3 X n
5. If Fibonacci number is defined recursively as F(n)=
0
1
F(n-1)+F(n-2) otherwise

to evaluate F(4), how many times F() is applied?


(a) 3 (b) 4 (c) 8 (d) 9
6. Using this recursive definition an=
1 if n=0
a*an-1 otherwise

how many multiplications are needed to calculate a10?


(a) 11 (b) 10 (c) 9 d) 8

SECTION-B

Very Short Answers

1. What is an invariant?
a. An expression involving variables, which remains
unchanged by an assignment.

b. These variables are called an invariant of the assignment


2. Define a loop invariant.
An invariant for the loop body is known as a loop invariant

3. Does testing the loop condition affect the loop invariant? Why?

No. It does not affect the loop invariant. Because a loop invariant is true
• at the start of the loop
• at the start of each iteration
• at the end of each iteration
• at the end of the loop .
4. What is the relationship between loop invariant, loop condition and the input- output recursively
a. Establish the loop invariant at the start of the loop.
b. The loop body should be update the variables and maintain the loop invariant, at the same time.
c. When the loop ends, the termination condition and the loop invariant should establish the input-output
relation.
5. What is recursive problem solving?

To solve a problem recursively,


• Each solver receives an input and reduces the problem to sub-problems,
• and calls another instance of the solver, known as sub-solver, to solve the sub-problem is known as
recursive call.
• The input size to a sub-problem is smaller than the input size to the original problem.
From the solution to the sub-problem, the solver constructs the solution
Base case: The problem size is small enough to be solved directly.
Recursion step: The problem size is not small enough. Deconstruct the problem into a sub-
problem, strictly smaller in size than the given problem.

6. Define factorial of a natural number recursively.


Factorial(n)
--input :n
--output: factorial of n get n
f=1
i=1 -- base case loop(i<n) true
f=f*I – recursion
step False: factorial
SECTION-C
Short Answers

1. There are 7 tumblers on a table, all standing upside down. You are allowed to turn any 2 tumblers
simultaneously in one move. Is it possible to reach a situation when all the tumblers are right side up? (Hint: The
parity of the number of upside down tumblers is invariant.)

Output : To turn all tumblers up The number of tumblers up is u; Model


Step 1.

Two tumblers upside up u increments by 2 u:=u+2

Step 2.

Two tumblers upside down


u decrements by 2
u:=u – 2

Step 3.

One tumbler is upside down and another is proper u is not changed


u is either incremented or decremented So we can ignore of u not being
changed. Now Invariants are u + 2 , u – 2
2. A knockout tournament is a series of games. Two players compete in each game; the loser is knocked out (i.e.
does not play any more), the winner carries on. The winner of the tournament is the player that is left after all
other players have been knocked out. Suppose there are 1234 players in a tournament. How many games are
played before the tournament winner is decided?

No. of Players : p No. of Games : g


Initially : p=1234 , g = 0 p, g := p – 1 , g + 1 Invariant is p + g

Finally Winner player is 1 , p = 1

p + g : = 1234 g =1234 – 1

g = 1233 ( No.of games played = 1233)

3. King Vikramaditya has two magic swords. With one, he can cut off 19 heads of a dragon, but after that the
dragon grows 13 heads. With the other sword, he can cut off 7 heads, but 22 new heads grow. If all heads are cut
off, the dragon dies. If the dragon has originally 1000 heads, can it ever die? (Hint:The number of heads mod 3 is
invariant.)

If the dragon has 1000 heads we start at 1000=1(mod 3) we cannot get to 0 .so the dragon lives.

SECTION – D
Explain in detail
1. Assume an 8 × 8 chessboard with the usual coloring. "Recoloring" operation changes the color of all squares
of a row or a column. You can recolor re-peatedly. The goal is to attain just one black square. Show that you
cannot achieve the goal. (Hint: If a row or column has b black squares, it changes by (|8 - b) - b|).

White squares W = 32 Black squares B = 32

W+ B = 64 , W – B = 0 = 0 mod 4

But the required

state has 63 W 1 B

So W – B = 63 – 1= 62 = 2 mod 4

Which is impossible.

2. Power can also be defined recursively as { a n = 1 if n = 0 a × an -1 if n is odd a n/2 × a n/2 if n is even Construct
a recursive algorithm using this definition. How many multiplications are needed to calculate a10?

Power (a,n)

--inputs : n integer

--output : a n

If( n=0 ) --base case 1

else if (n is odd)
a x power (a , a n-1) -- recursion step

else (n is even)

a x power (a n/2 x a n/2) -- recursion step


3. A single-square-covered board is a board of 2n x 2n squares in which one square is covered with a single
square tile. Show that it is possible to cover the this board with triominoes without overlap.
MAHATMA
Computer Science
Chapter 9 –Introduction to C++
Class XI
Choose the correct answer.

1. Who developed C++?


(a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai
2. What was the original name given to C++?
(a) CPP (b) Advanced C (c) C with Classes (d) Class with C
3. Who coined C++?
(a) Rick Mascitti (b) Rick Bjarne (c) Bill Gates (d) Dennis Ritchie
4. The smallest individual unit in a program is:
(a) Program (b) Algorithm (c) Flowchart (d) Tokens
5. Which of the following operator is extraction operator of C++?
(a) >> (b) << (c) <> (d) ^^
6. Which of the following statements is not true?
(a) Keywords are the reserved words convey specific meaning to the C++ compiler.
(b) Reserved words or keywords can be used as an identifier name.
(c) An integer constant must have at least one digit without a decimal point.
(d) Exponent form of real constants consists of two parts
7. Which of the following is a valid string literal?
(a) „A‟ (b) „Welcome‟ (c) 1232 (d) “1232”
8. A program written in high level language is called as
(a) Object code (b) Source code (c) Executable code (d) All the above
9. Assume a= 5, b=6; what will be result of a&b?
(a) 4 (b) 5 (c) 1 (d) 0
10. Which of the following is called as compile time operators?
(a) sizeof (b) pointer (c) virtual (d) this

Part – II
Answer to all the questions
1. What is meant by a token? Name the token available in C++.

The smallest individual unit in a program is known as a “Token” or “Lexical unit.”


C++ has the following tokens:

 Keywords
 Identifiers
 Constants
 Operators
 Punctuator

2. What are keywords? Can keywords be used as identifiers?


 Keywords are the reserved words which convey specific meaning to the C++ compiler.
 Keywords are Essential elements of C++ programs.
 C++ is a case sensitive programming language so, all the keywords must be in lowercase.

 Reserved words or keywords cannot be used as an identifier name.


Example: auto, break, case, if, else, short, int, char, float etc.

3. The following constants are of which type?


(i) 39 - Decimal (Integer)
(ii) 032 - Octal (Integer)
(iii) 0XCAFE - Hexadecimal (Integer)
(iv) 04.1 4 - Real constant (Floating Point)

4. Write the following real constants into the exponent form:


(i) 23.197 - 0.23197 X 102 0.23197E02
(ii) 7.214 - 0.7214 X 101 0.7214E01
-4
(iii) 0.00005 - 0.5 X 10 0.5E-04
1
(iv) 0.319 - 0.0319 X 10 0.0319E01

5. Assume n=10; what will be result n++ and - - n?


N++ = 11 ,- -N = 9

6. Match the following

Part – III
Answer to all the questions
1. Describe the differences between keywords and identifiers?

KEYWORDS IDENTIFIERS
Keywords are the reserved words which Identifiers are the user-defined names
convey specific meaning to the C++ given to different parts of the C++
compiler. program
Keywords are the essential elements to These are the fundamental building
construct C++ programs. blocks of a program.
EX: int , void , break , do , if etc.. EX: variable_name, function_name,
array_name, classe_name etc..

2. Is C++ case sensitive? What is meant by the term “case sensitive”?

 C++ is a case sensitive programming language.


 C++ is case sensitive as it treats upper and lower-case characters differently.
 Capital Letters ≠ Small Letters

3. Differentiate “=” and “==”.

= ==
It is an assignment statement It is relational Operator

It is used to assign a value to a variable which is It is used to compare 2 values and the result will
on the left hand side of an assignment statement be either true or false
EX: EX:
a=b a == b
(b value is assigned to a) (a value will be compared with b value)

4. What is the use of a header file?

 Usually all C++ programs begin with include statements starting with a #
(hash /pound).
 The symbol # is a directive for the preprocessor. That means, these
statements are processed before the compilation process begins.
 #include <iostream> statement tells the compiler‟s preprocessor to include
the header file “iostream” in the program. The header file iostream should
included in every C++ program to implement input /output functionalities.
 iostream header file contains the definition of its member objects cin and
cout.
 If you fail to include iostream in your program, an error message will
occur on cin and cout; and we will not be able to get any input or send any
output.

5. Why is main function special?


 C++ program is a collection of functions. Every C++ program must have a
main function.
 The main( ) function is the starting point where all C++ programs begin their
execution.
 Therefore, the executable statements should be inside the main( ) function.
i.e The main function always special.
Part – IV

1. Write about Binary operators used in C++.

Binary Operators - Require two operands

C++ Operators are classified as:


(1) Arithmetic Operators
(2) Relational Operators
(3) Logical Operators
(4) Assignment Operators
(5) Conditional Operator

(1) Arithmetic Operators


Arithmetic operators to perform simple arithmetic operations like addition, subtraction,
multiplication, division etc.,

2. Relational Operators

Relational operators are used to determine the relationship between its operands. When the relational
operators are applied on two operands, the result will be a Boolean value i.e 1 or 0 to represents
True or False respectively.

C++ provides six relational operators. They are,

3. Logical Operators
A logical operator is used to evaluate logical and relational expressions. The logical
operators act upon the operands that are themselves called as logical expressions.
C++ provides three logical operators

4. Assignment Operator:

Assignment operator is used to assign a value to a variable which


is on the left hand side of an assignment statement.

= (equal) is commonly used as the assignment operator in all


computer programming languages.

This operator copies the value at the right side of the operator to
the left side variable. It is also a binary operator.
5. Conditional Operator:

 In C++, there is only one conditional operator is used. ?: is a conditional Operator.


 This is a Ternary Operator.
 This operator is used as an alternate to if … else control statement.
2. What are the types of Errors?

Some common types of errors are given below


Lesson 9 Part 2
PART – 1
I. Choose the correct answer
1.How many categories of data types available in C++?
(a) 5 (b) 4 (c) 3 (d) 2

2.Which of the following data types is not a fundamental type?


(a) signed (b) int (c) float (d) char

3.What will be the result of following statement?


char ch= ‘B’;
cout<< (int) ch;
(a) B (b) b (c) 65 (d) 66

4.Which of the character is used as suffix to indicate a floating point value?


(a) F (b) C (c) L (d) D

5.How many bytes of memory allocates for the following variable declaration if
you are using
Dev C++? short int x;
(a) 2 (b) 4 (c) 6 (d) 8

6.What is the output of the following snippet?


charch =‘A’;
ch = ch + 1;
(a) B (b) A1 (c) F (d) 1A

7.Which of the following is not a data type modifier?


(a) signed (b) int (c) long (d) short

8.Which of the following operator returns the size of the data type?
(a) sizeof() (b) int () (c) long () (d) double ()

9.Which operator is used to access reference of a variable?


(a) $ (b) # (c) & (d) !
10.This can be used as alternate to endl command:
(a) \t (b) \b (a) \0 (d) \n

PART – 2
II. Answer to all the questions

1.Write a short note const keyword with an example.


const is the keyword used to declare a constant, const keyword modifies
/ restricts the accessibility of a variable. So, it is known as Access modifier.
2.What is the use of setw( ) format manipulator?
setw manipulator sets the width of the field assigned for the output. The
field width determines the minimum number of characters to be written in
output.
Syntax:
setw(number of characters)

3.Why is char often treated as integer data type?


Character data type accepts and returns all valid ASCII characters.
Character data type is often said to be an integer type, since all the characters
are represented in memory by their associated ASCII Codes. If a variable is
declared as char, C++ allows storing either a character or an integer value.

4.What is a reference variable? What is its use?


Reference variable in C++ is alias for existing variable. They store nothing
but the address of the variable used at the time of its declaration. It is
important to assign the reference variable at the time of declaration, else it will
show an error.

5.Consider the following C++ statement. Are they equivalent?


char ch = 67;
charch = ‘C’;
Both the statements are equivalent as they declare ‘ch’ to be char and
initialize it with the value of 67. Since this is the ASCII code for ‘C’, the
character constant also can be used to initialize ‘ch’ to 67.

6.What is the difference between 56L and 56?


56L – The suffix L forces the constant to be represented as long, which
occupies 4 bytes.

56 – This will be represented as int type constant which occupies 2 bytes as


per Turbo C++.

7.Determine which of the following are valid constant? And specify their
type.

1. 0.5 – is a valid constant. It is a decimal.


2. ‘Name’ – Invalid constant as single quote is not allowed.
3. ‘\t’ – Escape sequence (or) non – graphical character (horizontal tab).
4. 27,822 – Invalid constant. Comma is not allowed.
8.Suppose x and y are two double type variable that you want add as
integer and assign to an integer variable. Construct a C++ statement for
the doing so.
double x = 10.5, y = 4.5; int a;
a = int (x) + int (y);

9.What will be the result of following if num=6 initially.


(a) cout << num;
(b) cout << (num==5);
Answer:
(a) 6 (b) False

10.Which of the following two statements are valid? Why? Also write their
result, int a; a = 3,014; a=(3,014);
It is invalid as comma is not allowed in an integer constant. It is valid.
Comma in bracket is allowed.

PART – 3
III. Answer to all the questions

1. 1.What are arithmetic operators in C++? Differentiate unary and


binary arithmetic operators. Give example for each of them.
Arithmetic operators : perform simple arithmetic operations like
addition, subtraction, multiplication, division etc.
Unary Operators : Require only one operand :
Example: ++ (Plus, Plus) Increment operator, – – (Minus, Minus)
Decrement operator, NOT, ~,
Binary Operators: Require only one operand :
Example:+, -, *, /, %, >, <, <=, AND, OR ,NOT (Explain
Each)
2. How relational operators and logical operators are related to one
another?
Relational operators are used to determine the relationship between its
operands. When the relational operators are applied on two operands, the
result will be a Boolean value 1 or 0 which represents True or False
respectively which represents logical operator.

3.Evaluate the following C++ expressions where x, y, z are integers and m,


n are floating point numbers. The value of x = 5, y = 4 and m = 2.5;
Answer:

1. n = x + y / x;
2. z = m * x + y;
3. z = (x++) * m + x;

Answer:
1. n = x + y / x;
= 5 + 4/5
= 5 + 0 (both x and y are int type. Therefore only integer part of quotient is
considered)
=5

2. z = m * x + y;
= 2.5 * 5 + 4 (m is float type, so x value is promoted to float [implicit
conversion])
= 12.5 + 4 ‘
= 16 (2 is int type. So ‘.2’, the fractional part is discarded)

3. z = (x++) * m + x;
= 5*2.5 + x
= 12.5 + 5
= 18 (z is int type, therefore the fractional part is removed, x is
incremented after the addition)

*******************************
Computer Science

CHAPTER – 10- Flow of Control

PART – I

Choose the correct answer.

1. What is the alternate name of null statement?

(A) No statement (B) Empty statement (C) Void statement

(D) Zero statement

2. In C++, the group of statements should enclosed within:

(A) { } (B) [ ] (C) ( ) (D) < >

3. The set of statements that are executed again and again in iteration is
called as:

(A) condition (B) loop (C) statement (D) body of loop

4. The multi way branching statement:

(A) if (B) if … else (C) switch (D) for

5. How many types of iteration statements?

(A) 2 (B) 3 (C) 4 (D) 5

6. How many times the following loop will execute? for (int i=0; i<10; i++)

(A) 0 (B) 10 (C) 9 (D) 11

7. Which of the following is the exit control loop?

(A) for (B) while (C) do…while (D) if…else

8. Identify the odd one from the keywords of jump statements:

(A) break B) switch (C) goto (D) continue

9. Which of the following is the entry control loop?

(A) do-while (B) for (C) while (D) if-else

10. A loop that contains another loop inside its body:


(A) Nested loop (B) Inner loop (C) Inline loop (D) Nesting of loop

Part – II

Answers to all the questions (2 Marks):

1. What is a null statement and compound statement?

• The "null or empty statement" is a statement containing only a semicolon


(;)
• C++ allows a group of statements enclosed by pair of braces {}. This
group of statements is
called as a compound statement or a block.

2. What is selection statement? Write it's types?

• The selection statement means the statement (s) are executed depends
upon a condition.
• If a condition is true, a true block (a set of statements) is executed
otherwise a false block is
executed. This statement is also called decision statement or selection
statement
Types:

If, if else, Nest if, if -else-if ladder, The ?: Alternative to if- else, Switch
statement

3. Correct the following code segment:

if (x=1)

p = 100;

else

p = 10;

Answer:

if (x= =1)

p = 100;

else
p = 10;

4. What will be the output of the following code:

int year;

cin >> year;

if (year % 100 == 0)

if ( year % 400 == 0)

cout << "Leap";

else

cout << "Not Leap year";

If the input given is

(i) 2000 - Leap

(ii) 2003 - Not Leap year

(iii) 2010 - Not Leap year

5. What is the output of the following code?

for (int i=2; i<=10 ; i+=2)

cout << “\n” <<i;

output:

10
6. Write a for loop that displays the number from 21 to 30.

#include <iostream>

using namespace std;

int main()

int i;

for (i=21; i<=30 ; i++)

cout << “\n” <<i;

return 0;

7. Write a while loop that displays numbers 2, 4, 6, 8. 20.

#include <iostream>

using namespace std;

int main()

int i;

while (i=2; i<=20 ; i+=2)

cout << “\n” <<i;

return 0;

8. Compare an if and a ? : operator.

If else ? : conditional operator


if the condition is true then a true- The conditional operator (or) Ternary
block operator
executed, otherwise the true-block is is an alternative for „if else statement‟.
skipped

Syntax: Syntax:
if (expression) expression 1? expression 2 :
true-block; expression 3
statement-x;

Part – III

Answers to all the questions (3 Marks):

1. Convert the following if-else to a single conditional statement:

if (x >= 10)

a = m + 5;

else

a = m;

Answer:

a= (x >= 10) ? m + 5 : m ;

2. Rewrite the following code so that it is functional:

v = 5;

do;

total += v;

cout << total;

}while v <= 10

Answer:

int v = 5;
do
{
cout << v;
total += v;
}while (v <= 10);

3. Write a C++ program to print multiplication table of a given number.

#include<iostream>

using namespace std;

int main()

int num;

cout<<"Enter Number To Find Multiplication table ";

cin>>num;

for(int a=1;a<=10;a++)

cout<<num<<" * "<<a<<" = "<<num*a<<endl;

return 0;

Output:
4. Write the syntax and purpose of switch statement.

Syntax of switch

switch(expression)

case constant 1:

statement(s);

break;

case constant 2:

statement(s);

break;

default:

statement(s);

purpose of switch statement

• The switch statement is a multi-way branch statement.


• A switch statement can only work for quality of comparisons.
• No two case labels in the same switch can have identical values.

5. Write a short program to print following series: (a) 1 4 7 10. .......... 40

#include<iostream>

using namespace std;

int main()

int i;
for(i=1;i<=40;i+=3)

cout<<”\t<<i;

return 0;

Part – IV

Answers to all the questions (5 Marks):

1. Explain control statement with suitable example.

Control statements are statements that alter the sequence of flow of


instructions.
In a program, statements may be executed sequentially, selectively or
iteratively. Every programming languages provide statements to support
sequence, selection (branching) and iteration.
If the statements are executed sequentially, the flow is called as sequential
flow. In some situations, if the statements alter the flow of execution like
branching, iteration, jumping and function calls, this flow is called as
control flow.
2. What entry control loop? Explain any one of the entry control loop with
suitable example.

Loop body will be executed first, and then condition is checked. ......... If Test
condition is false, loop

body will be executed once.

Examples of Entry Controlled Loop:

• for loop
• while loop

for loop:

The for-loop is the easiest looping statement which allows code to


be executed repeatedly.

The general syntax is: Flowchart:

for (initialization(s); test-expression; update expression(s))

Statement 1;

Statement 2;

………….

Statement-x;

Example Program:

#include <iostream>

using namespace std;

int main ()

int i;
for(i = 0; i< 5; i ++ )
cout<< "value of i : " <<i<<endl;
return 0;
}
Output

value of i : 0
value of i : 1
value of i : 2
value of i : 3
value of i : 4

3. C++ program to find the LCM and GCD of a number

#include <iostream>
int main() {
int a, b, x, y, t, gcd, lcm;

cout<<"Enter two integers\n";


cin>>x>>y;

a = x;
b = y;

while (b != 0) {
t = b;
b = a % b;
a = t;
}
gcd = a;
lcm = (x*y)/gcd;
cout<<"Greatest common divisor of "<<x<<" and "<<y<<"="<<gcd;
cout<<"Least common multiple of "<<x<<" and "<<y<<"="<<lcm;
return 0;
}

Output:
Output:
#include <iostream>
using namespace std;
int main()
{
clrscr();
int i,n;
float x,sum=0;
cout<<“x+x^2/2+x^3/3+…..+x^n/n”;
cout<<“\n Enter value of x and n:”;
cin>>x>>n;
for(i=1;i<=n;++i)
sum+=pow(x,i)/i;
cout<<“\n sum=”<<sum;
return 0;
}

5. Write a program to find sum of the series

#include <iostream>
using namespace std;
int main()
{
clrscr();
long i,n,x,sum=1;
cout<<“1+x+x^2+……+x^n”;
cout<<“\n Enter the value of x and n:”;
cin>>x>>n;
for(i=1;i<=n;++i)
sum+=pow(x,i);
cout<<“\n Sum=”<<sum;
getch();
}
Output:
Chapter 11 Functions

PART–1
I. Choose The Correct Answer
Question1.
Which of the following header file defines the standard I/O predefined functions?
(a) stdio.h (b) math.h (c) string.h (d) ctype.h
Answer:
(a) stdio.h

Question2.
Which function is used to check whether a character is alphanumeric or not?
(a) isalpha() (b) isdigit() (c) isalnum() (d) islower()
Answer:
(c) isalnum()

Question3.
Which function begins the program execution?
(a) isalpha() (b) isdigit() (c) main() (d) islower()
Answer:
(c) main()
Question4.
Which of the following function is with a return value and without any argument?
(a) x = display(int, int) (b) x = display() (c) y = display(float) (d) display(int)
Answer:
(b) x = display()

Question5.
Which is return data type of the function prototype of add(int, int);?
(a) int (b) float (c) char (d) double
Answer:
(a) int

Question6.
Which of the following is the scope operator?
(a) > (b) & (c) % (d) ::
Answer:
(d) ::
PART–2
II. Answer to all the questions
Question1.
DefineFunctions.
Answer:
A large program can typically be split into small sub – programs (blocks) called as
functions where each sub-program can perform some specific functionality. Functions
reduce the size and complexity of a program, makes it easier to understand, test and check
for errors.
Question2.
Write about strlen() function.
Answer:
The strlen() takes a null terminated byte string source as its argument and returns its
length. The length does not include the null(\0) character.

Question 3.
What are importance of void data type? void type has two important purposes:
Answer:
1. To indicate the function does not return a value.
2. To declare a generic pointer.

Question 4.
What is Parameter and list its types?
Answer:
Arguments or parameters are the means to pass values from the calling function to the
called function. The variables used in the function definition as parameters are known as
formal parameters. The constants, variables or expressions used in the function call are
known as actual parameters. Types : Default arguments and Constant Arguments.

Question 5.
Write a note on Local Scope.
Answer:

1. A local variable is defined within a block. A block of code begins and ends with
curly braces { }.
2. The scope of a local variable is the block in which it is defined.
3. A local variable cannot be accessed from outside the block of its declaration.
4. A local variable is created upon entry into its block and destroyed upon exit.

PART – 3
III. Answer to all the questions
Question 1.
What is Built – in functions?
Answer:
C++ provides a rich collection of functions ready to be used for various tasks. The tasks
to be performed by each of these are already written, debugged and compiled, their
definitions alone are grouped and stored in files called header files. Such ready – to – use
sub programs are called pre – defined functions or built – in functions.

Question 2.
What is the difference between isupper() and toupper() functions?
Answer:
isupper():

 This function is used to check the given character is uppercase.


 This function will return 1 if true otherwise 0.
toupper():

 This function is used to convert the given character into its uppercase.
 This function will return the upper case equivalent of the given character. If the
given character itself is in upper case, the output will be the same.
Question 3.
Write about strcmp() function.
Answer:
The strcmp() function takes two arguments: string1 and string2. It compares the
contents of string1 and string2 lexicographically.
The strcmp() function returns a:

1. Positive value if the first differing character in string1 is greater than the
corresponding character in string2. (ASCII values are compared)
2. Negative value if the first differing character in string1 is less than the
corresponding character in string2.
3. 0 if string1 and string2 are equal.

Question 4.
Write short note on pow() function in C++.
Answer:
The pow() function returns base raised to the power of exponent. If any argument passed
to pow() is long double, the return type is promoted to long double. If not, the return type
is double. The pow() function takes two arguments:

1. base – the base value


2. exponent – exponent of the base
Example:
cout << pow(5, 2);

Output:
25

Question 5.
What are the information the prototype provides to the compiler?
Answer:
The prototype above provides the following information to the compiler:
1. The return value of the function is of type long.
2. Fact is the name of the function.
3. The function is called with two arguments:
 The first argument is of int data type.
 The second argument is of double data type, int display(int, int) // function
prototype//.
 The above function prototype provides details about the return data type, name of
the function and a list of formal parameters or arguments.

Question 6.
What is default arguments? Give example.
Answer:
In C++, one can assign default values to the formal parameters of a function prototype.
The Default arguments allows to omit some arguments when calling the function.
1. For any missing arguments, complier uses the values in default arguments for the
called function.

2. The default value is given in the form of variable initialization.


Example : void defaultvalue(int n1 = 10, n2 = 100);
3. The default arguments facilitate the function call statement with partial or no
arguments.
Example :
1. defaultvalue (x, y);
2. defaultvalue (200, 150);
3. defaultvalue (150);
4. defaultvalue (x, 150);
4. The default values can be included in the function prototype from right to left, i.e., we
cannot have a default value for an argument in between the argument list.
Example:
1. void defaultvalue (int n1=10, n2);//invalid prototype.
2. void defaultvalue (int n1, n2 = 10);//valid prototype.

PART – 4
IV. Answers to all the questions
Question 1.
Explain Call by value method with suitable example.
Answer:
This method copies the value of an actual parameter into the formal parameter of the
function. In this case, changes made to formal parameter within the function will have
no effect on the actual parameter.
Question 2.
What is Recursion? Write a program to find GCD using recursion.
Answer:
A function that calls itself is known as recursive function. And, this technique is known
as recursion.

Question 3.
What are the different forms of function return? Explain with example.
Answer:
The return statement:
Returning from the function is done by using the return statement. The return statement
stops execution and returns to the calling function. When a return statement is
executed, the function is terminated immediately at that point. The return statement is
used to return from a function. It is categorized as a jump statement because it
terminates the execution of the function and transfer the control to the called statement.
Syntax:
return expression/variable;
Example : retun(a + b); retun(a);
return; // to terminate the function

The Returning values:


The functions that return no value is declared as void. The data type of a function is
treated as int, if no data type is explicitly mentioned. For example,
For Example:
int add (int, int);
add (int, int);
In both prototypes, the return value is int, because by default the return value of a
function in C++ is of type int.

Returning Non – integer values:


A string can also be returned to a calling statement.

The Returning by reference:


#include
using namespace std;
int main( )
{

int n 1 = 150;
int &n 1 ref = n1;
cout << “\nThe Value of N1 = “<< n1 << “and n 1 Reference =”<< n 1 ref;
n 1 ref++;
cout << “\n After nl increased the Value of N1 =”<< n1;
cout << “and n 1 Reference = ”<< n 1 ref;
retum(0);

}
Output:
The Value of N1 = 150 and nl Reference =150
After n1 increased the Value of N1 = 151 and n1 Reference =151

Question 4.
Explain scope of variable with example.
Answer:
Scope refers to the accessibility of a variable.
There are four types of scopes in C++

1. Local Scope
2. Function Scope
3. File Scope
4. Class Scope
1. Local Scope:

 A local variable is defined within a block. A block of code begins and ends with
curly braces {}.
 The scope of a local variable is the block in which it is defined.
 A local variable cannot be accessed from outside the block of its declaration.
 A local variable is created upon entry into its block and destroyed upon exit;
Example:
int main( )
{
int a,b; //Local variable
}
2. Function Scope:

 The scope of variable within a function is extended to the function block and all
sub-blocks therein.
 The lifetime of a function scope variable is the lifetime of the function block.
Example:
int. sum(intx, int y); //x and y has function scope.
3. File Scope:

 A variable declared above all blocks and functions (including main()) has the scope
of a file.
 The lifetime of a file scope variable is the lifetime of a program.
 The file scope variable is also called as global variable.
Example:
#include
using namespace std;
int x,y; //x and y are global variable
void main()
{
……..
}
4. Class Scope:
Data members declared in a class has the class scope.
Data members declared in a class can be accessed by all member functions of the
class.
Example:
Class example
{
int x,y; //x and y can be accessed by print() and void():
void print();
Void total();

};

Question 5.
Write a program to accept any integer number and reverse it.
Answer:
Chapter 12 Arrays and Structures

PART – 1
I. Choose The Correct Answer
1. Which of the following is the collection of variables of the same type that an referenced
by a common name?
(a) int (b) float (c) Array (d) class Answer:(c)Array
2.int age[ ]={6, 90, 20, 18, 2}; How many elements are there in this array?
(a) 2 (b) 5 (c) 6 (d) 4 Answer:(b) 5

3. cin >> n[3]; To which element does this statement accepts the value?
(a) 2 (b) 3 (c) 4 (d) 5 Answer:(c) 4

4. By default, a string ends with which character?


(a) \o (b) \t (c) \n (d) \b Answer:(a) \o
5. Structure definition is terminated by
(a) : (b) } (c) ; (d) ::

6. What will happen when the structure is declared?


(a) it will not allocate any memory (b) it will allocate the memory
(c) it will be declared and initialized (d) it will be only declared

7.A structure declaration is given below,


struct Time
{
int hours; int
minutes;int
seconds;
} t;
Using above declaration which of the following refers to seconds.
a.Time.seconds (b) Time::seconds (c) seconds (d) t. seconds

8.Which of the following is a properly defined structure?


a.struct {int num;} (b) struct sum {int num;}
(c) struct sum int sum; (d) struct sum {int num;};

9.A structure declaration is given below,


struct employee
{
int empno; char ename[10]; } e[5];
Using above declaration which of the following statement is correct?
(a)cout << e[0].empno << e[0].ename;
(b) cout << e[0].empno << ename;
(c) cout << e[0]->empno << e[0] → ename;
(d) cout << e.empno << e.ename;

10.When accessing a structure member, the identifier to the left of thedot operator is
the name of …………………
a.structure variable (b) structure tag
(c) structure member (d) structure function
PART – 2
II. Answers to all the questions
Question 1.
What is Traversal in an Array? Answer:
Accessing each element of an array at least once to perform any operation is known as
“Traversal”. Displaying all the elements in an array is an example of “traversal”.

Question 2.
Whatis Strings?
Answer:
A string is defined as a sequence of characters where each character may be a letter,
number or a symbol. Each element occupies one byte of memory. Every string is
terminated by a null (‘\0’, ASCII code 0) character which must be appended at the end of
the string.

Question 3.
What is the syntax to declare two – dimensional array.
Answer:
The declaration of a 2 – D array is
data – type array_name[row – size] [col – size];
In the above declaration, data-type refers to any valid C++ data – type, array _ name
refers to the name of the 2 – D array, row – size refers to the number of rows and col-
size refers to the number of columns in the 2 – D array.

4. Define structure. What is its use?


Structure is a user – defined which has the combination of data items with
different data types. This allows to group of variables of mixed data typestogether into a
single unit. The structure provides a facility to store different data types as a part of the
same logical element in one memory chunk adjacent to each other.
5. What is the error in the following structure definition?
struct employee {inteno ;chamame [20] ;char dept;}
Employee e1,e2;
Errors:
1. ‘i’ is missing.
2. Spaces are missing at two places
3. Structure name given wrongly.
Corrected structure:
struct employee {
int eno;
char ename [20];
char dept;
} e1, e2;
PART – 3
III. Answers to all the questions

Question 1.
Define an Array. What are the types?
Answer:
“An array is a collection of variables of the same type that are referenced by a common
name”. An array is also a derived datatype in C++.
There are different types of arrays used in C++. They are:

1. One – dimensional arrays


2. Two – dimensional arrays
3. Multi – dimensional arrays

Question 2.
Write a note on Array of strings.
Answer:
An array of strings is a two – dimensional character array. The size of the first Index
(rows) denotes the number of strings and the size of the second index (columns)
denotes the maximum length of each string. Usually, array of strings are declared in
such a way to accommodate the null character at the end of each string. For example,
the 2 – D array has the declaration:
char name [7][10];
In the above declaration,
No. of rows = 7;
No. of columns =10;
We can store 7 strings each of maximum length 10 characters.

3. The following code sums up the total of all students name starting
with ‘S’ and display it. Fill in the blanks with required statements.
4. How to access members of a structure? Give example.
Once objects of a structure type are declared, their members can beaccessed
directly. The syntax for that is using a dot(.) between the object name and the
member name.
Example:
struct
{
long rollno;
int age;
float weight;
}student;

The student can be referred as reference name to the above structure and theelements
can be accessed like student.roll no, student.age, and student.weight.

5. What is called anonymous structure? Give an example.


A structure without a name/tag is called anonymous structure.Example:
struct
{
long rollno;
int age;
float weight;
};
The student can be referred as reference name to the above structure and the elements
can be accessed like student.rollno, student.age and student.weight.

PART – 4
I. Answers to all the questions
Question 1.
Write a C++ program to find the difference between two matrix.
Answer:
2. Write a C++ program to add two distances using the following
structure definition

Answer:
int main()
{
cout << “Enter 1st distance:” << end1;
cout << “Enter feet:”; cin >> d1.feet;
cout << “Enter inch:”; cin >> d1.inch;
cout << “\n information for 2nd distance:” << end1;
cout << “Enter feet:”; cin >> d2.feet;
cout << “Enter inch:”; cin >> d2.inch;
sum.feet = d1 . feet + d2.feet;
sum.inch = d1.inch + d2.inch;
if (sum.inch > 12)
{
++ sum.feet;
sum.inch = 12;
}
cout << end1; “Sum of distance =” << sum.feet << “feet” << sum.inch <<“inches”;
return 0;
}
Output:
Enter 1 st distance
Enter feet: 6
Enter inch: 3.4
Enter 2nd distance
Enter feet: 5
Enter inch: 10.2
Sum of distances = 12 feet 1.6 inches
3. Write the output of the following C++ programOutput
Details of Book No. 1
………………………………….
Book name : Programming
Book author : Dromy
…………………………………..
Details of Book No. 2
Book Name : C++ Programming
Book Author : Bjame Stroustrup
………………………………..
………………………………..
I |programming | Dromy
…………………………………
…………………………………
2| C++ Programming | Bjame Stroustrup
……………………………….
………………………………
4. Write the output of the following C++ program
Output
First student
roll no : 1
name : Brown
Phone no. : 123443
Second Student roll
no : 2
name : Sam
Phone no. : 1234567822
5. Debug the error in the following program

Corrected Program:
Chapter 13

Introduction to Object-Oriented Programming Techniques

PART – 1
I. Choose The Correct Answer
Question 1.
The term is used to describe a programming approach based on classes and objects
(a) OOP (b) POP (c) ADT (d) SOP Answer: (a) OOP
Question 2.
The paradigm which aims more at procedures ……………….
(a) Object Oriented Programming (b) Procedural programming
(c) Modular programming (d) Structural programming
Answer: (b) Procedural
programming
Question 3.
Which of the following is a user defined data type?
(a) class (b) float (c) int (d) object Answer: (a) class

Question 4.
The identifiable entity with some characteristics and behaviour is ……………….
(a) class (b) object (c) structure (d) member Answer: (b) object

Question 5.
The mechanism by which the data and functions are bound together into a single unit is
known as ……………….
(a) Inheritance (b) Encapsulation (c) Polymorphism (d) Abstraction
Answer:(b) Encapsulation

Question 6.
Insulation of the data from direct access by the program is called as ……………….
(a) Data hiding (b) Encapsulation (c) Polymorphism (d) Abstraction
Answer:(a) Data hiding

Question 7.
Which of the following concept encapsulate all the essential properties of the object that
are to be created?
(a) Class (b) Encapsulation (c) Polymorphism (d) Abstraction
Answer:(d) Abstraction

Question 8.
Which of the following is the most important advantage of inheritance?
(a) data hiding (b) code reusability (c) code modification (d) accessibility
Answer:(b) code reusability

Question 9.
“Write once and use it multiple time” can be achieved by ……………….
(a) redundancy (b) reusability (c) modification (d) composition
Answer:(b) reusability

Question 10.
Which of the following supports the transitive nature of data?
(a) Inheritance (b) Encapsulation (c) Polymorphism (d) Abstraction
Answer:(a) Inheritance
PART – 2
II. Answers to all the questions
Question 1.
How is modular programming different from procedural programming paradigm?
Answer:
Modular programming:

 Emphasis on algorithm rather than data.


 Programs are divided into individual modules.
 Each modules are independent of each other and have their own local data.
 Modules can work with its own data as well as with the data passed to it.
Procedural programming:

 Programs are organized in the form of subroutines or sub programs.


 All data items are global.
 Suitable for small sized software application.
 Difficult to maintain and enhance the program code as any change in data type
needs to be propagated to all subroutines that use the same data type.

Question 2.
Differentiate classes and objects.
Answer:
Class:
 Class is a blue print or template from which objects are created.
 Class doesn’t allocate memory when it is created.
 Class is a logical entity.
Object:
 Object is an instance of a class.
 Objects allocate memory when it is created.
 Object is a physical entity.

Question 3.
What is polymorphism?
Answer:
Polymorphism is the ability of a message or function to be displayed in more than one
form.

Question 4.
How is encapsulation and abstraction are interrelated?
Answer:
Abstraction means giving only essential things and hiding unnecessary details.
Encapsulation is the binding of data members and methods together in a capsule to avoid
accidental changes to data from external users, i.e., encapsulation is the bundling of
related algorithms and data.

Question 5.
Write the disadvantages of OOP.
Answer:

1. Size: Object Oriented Programs are much larger than other programs.
2. Effort: Object Oriented Programs require a lot of work to create.
3. Speed: Object Oriented Programs are slower than other programs, because of their
size.
PART – 3
III. Answers to all the questions

Question 1.
What is paradigm? Mention the different types of paradigm.
Answer:
Paradigm means organizing principle of a program. It is an approach to programming.
There are different approaches available for problem solving using computer. They are
Procedural programming, Modular Programming and Object Oriented Programming.

Question 2.
Write a note on the features of procedural programming.
Answer:
Important features of procedural programming

1. Programs are organized in the form of subroutines or sub programs


2. All data items are global
3. Suitable for small sized software application
4. Difficult to maintain and enhance the program code as any change in data type
needs to be propagated to all subroutines that use the same data type. This is time
consuming.
5. Example: FORTRAN and COBOL.

Question 3.
List some of the features of modular programming.
Answer:
Important features of Modular programming:

1. Emphasis on algorithm rather than data


2. Programs are divided into individual modules
3. Each modules are independent of each other and have their own local data
4. Modules can work with its own data as well as with the data passed to it.
5. Example: Pascal and C.

Question 4.
What do you mean by modularization and software reuse?
Answer:

1. Modularization : where the program can be decomposed into modules.


2. Software re – use : where a program can be composed from existing and new
modules.

Question 5.
Define information hiding.
Answer:
Encapsulation is the most striking feature of a class. The data is not accessible to the
outside world, and only those functions which are wrapped in the class can access it. This
encapsulation of data from direct access by the program is called data hiding or
information hiding.
PART – 4
IV. Answers to all the questions
Question 1.
Write the differences between Object Oriented Programming and Procedural Programming
Answer:
Object Oriented Programming:

 Emphasizes on data rather than algorithm.


 Data abstraction is introduced in addition to procedural abstraction.
 Data and its associated operations are grouped in to single unit.
 Programs are designed around the data being operated.
 Example: C++, Java, VB.Net, Python
Procedural Programming:

 Programs are organized in the form of subroutines or sub programs.


 All data items are global.
 Suitable for small sized software application.
 Difficult to maintain and enhance the program code as any change in data type
needs to be propagated to all subroutines that use the same data type.
 Example: FORTRAN and COBOL

Question 2.
What are the advantages of OOPs?
Answer:
Re – usability : “Write once and use it multiple times” you can achieve this by using class.
Redundancy: Inheritance is the good feature for data redundancy. If you need a same
functionality in multiple class you can write a common class for the same functionality
and inherit that class to sub class.

Easy Maintenance : It is easy to maintain and modify existing code as new objects can be
created with small differences to existing ones.

Security : Using data hiding and abstraction only necessary data will be provided thus
maintains the security of data.

Question 3.
Write a note on the basic concepts that supports OOPs?
Answer:
The Object Oriented Programming has been developed to overcome the drawbacks of
procedural and modular programming. It is widely accepted that object – oriented
programming is the most important and powerful way of creating software.

The Object – Oriented Programming approach mainly encourages:

1. Modularization: where the program can be decomposed into modules.


2. Software re – use: where a program can be composed from existing and new
modules.
Main Features of Object Oriented Programming:

1. Data Abstraction.
2. Encapsulation.
3. Modularity.
4. Inheritance.
5. Polymorphism.
Encapsulation:
The mechanism by which the data and functions are bound together into a single unit is
known as Encapsulation. It implements abstraction. Encapsulation is about binding the
data variables and functions together in class. It can also be called data binding.
Encapsulation is the most striking feature of a class.

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 encapsulation of data from direct access by the
program is called data hiding or information hiding.

Data Abstraction:
Abstraction refers to showing only the essential features without revealing background
details. Classes use the concept of abstraction to define a list of abstract attributes and
function which operate on these attributes. They encapsulate all the essential properties
of the object 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
function.

Modularity:
Modularity is designing a system that is divided into a set of functional units (named
modules) that can be composed into a larger application.

Inheritance:
Inheritance is the technique of building new classes (derived class) from an existing Class
(base class). The most important advantage of inheritance is code reusability.

Polymorphism:
Polymorphism is the ability of a message or function to be displayed in more than one
form.
Lesson 14 Classes and Objects
PART – 1
I. Choose The Correct Answer
1. The variables declared inside the class are known as ____________
(a) data (b) inline
(c) member functions (d) attributes

2. Which of the following statements about member functions are True or


False?
(i) A member function can call another member function directly with using
the dot operator.
(ii) Member function can access the private data of the class.
(a) (i) – True, (ii) – True (b) (i) – False, (ii)-True
(c) (i) – True, (ii) – False (d) (i) – False, (ii) – False

3. A member function can call another member function directly, without


using the dot operator called as ………………..
(a) sub function (b) sub member
(c) nesting of member function (d) sibling of member function

4. The member function defined within the class behave like ………………..
(a) inline function (b) Non – inline function
(c) Outline function (d) Data function

5. Which of the following access specifier protects data from inadvertent


modifications?
(a) Private (b) Protected (c) Public (d) Global

6. class x
{
int y; public:
x(int z){y=z;}
}x1[4];
int main()
{x x2(10);
return 0;}
How many objects are created for the above program?
(a) 10 (b) 14 (c) 5 (d) 2

7. State whether the following statements about the constructor are True or
False.
(i) constructors should be declared in the private section.
(ii) constructors are invoked automatically when the objects are created.
(a) True, True (b) True, False (c) False, True (d) False, False
8.Which of the following constructor is executed for the following prototype?
add display( add &); // add is a class name
(a) Default constructor (b) Parameterized constructor
(c) Copy constructor (d) Non-Parameterized constructor

PART – 2
II. Answers to all the questions
1. What are called members?
The class body contains the declaration of its members – Data member and
Member functions.

2. Differentiate structure and class though both are user-defined data types.
The only difference between structure and class is the members of the structure
are by default public whereas it is private in class.

3. What is the difference between the class and object in terms of OOP?
A class specification just defines the properties of a class. To make use of a class
specified, the variables of that class type have to be declared.
The class variables are called objects. Objects are also called an instance of the class.

4. Why it is considered as a good practice to define a constructor though a


compiler can automatically generate a constructor?
Declaring a constructor with arguments hides the compiler-generated
constructor. After this, we cannot invoke the compiler-generated constructor.

5. Write down the importance of the destructor.


The purpose of the destructor is to free the resources that the object may have
acquired during its lifetime. A destructor function removes the memory of an object
which was allocated by the constructor at the time of creating an object.
PART – 3
Answers to all the questions
1. Rewrite the following program after removing the syntax errors if any
and underline the errors:

2. Write with an example of how will you dynamically initialize objects?


When the initial values are provided during runtime then it is called
dynamic initialization.
Example to illustrate dynamic initialization
Output:
Enter the Roll Number 1201
Enter the Average 98.6
Roll number:- 1201
Average:- 98.6

3. What are the advantages of declaring constructors and destructors


under public accessibility?
A constructor can be defined either in private or public section of a class. If it
is defined in public section of a class, then its object can be created in any
function.
4. Given the following C++ code, answer the questions (i) & (ii).

1. Function 1 is the ‘destructor’.


It is executed automatically when an object of the class TestMeOut goes
out of scope.
2. Function 2 is called the default ‘constructor’.
It is executed automatically when an instance of the class TestMeOut
comes into the scope or when objects of the class TestMeOut are created.
PART – 4
III. Answers to all the questions

1. Mention the differences between constructor and destructor.

Constructor:

• The name of the constructor must be same as that of the class.


• No return type can be specified for constructor.
• A constructor can have parameter list.
• The constructor function can be overloaded.
• They cannot be inherited but a derived class can call the base class
constructor.
• The compiler generates a constructor, in the absence of a user defined
constructor.
Destructor:

• The destructor has the same name as that of the class prefixed by the
tilde character
• It has no return type.
• The destructor cannot have arguments
• Destructors cannot be overloaded i.e., there can be only one destructor
in a class.
• They cannot be inherited.
• In the absence of user defined destructor, it is generated by the
compiler.

2. Define a class RESORT with the following description in C++ :

Class RESORT
{
Private:
int Rno;
char name [20];
float charges;
int days;
float compute( );
Public:
void getinf( );
void dispinfo( );
}
void RESORT: : getinfo()
{
cout << “Enter Registration number:”; cin >> Rno.;
cout << “\n Enter name:”;
gets(name);
cout << “\n Enter per day charges:”; cin >> charges;
cout << “\n Enter number of days:”; cin >> days;
}
void RESORT: : dispinfo()
{
cout << “\n 1. Registration number:” << Rno;
cout << “\n 2. Name:”;
puts(name);
cout << “\n 3. charges per day:” << charges ;
cout<< “\n 4. Number of days:” <<days;
cout<< “\n 5. Amount:” <<compute( );

int compute()
{
long float;
amount = charges*days;
if (amount> 11000)
amount = 1,02*days*charges;
return amount;
}
RESORT obj;
void main()
{
clrscr();
obj.getinfo();
obj.dispinfoQ;
getch();
}

3. Write the output of the following.

Constructor
Name : Bharathi
Roll no : 14
Marks: 100
Back to main
***************************
Chapter 15 Polymorphism
I. Choose The Correct Answer
Question 1.
Which of the following refers to a function having more than one distinct meaning?
(a) Function Overloading (b) Member overloading
(c) Operator overloading (d) Operations overloading
Answer: (a) Function Overloading

Question 2.
Which of the following reduces the number of comparisons in a program?
(a) Operator Overloadig (b) Operations overloading
(c) Function overloading (d) Member overloading
Answer: (c) Function overloading

Question 3.
void dispchar(char ch = ‘$\ int size=10)
{

for(int i = 1;i< = size;i ++)


cout << ch;

}
How will you invoke the function dispchar() for the following input?
To print $ for 10 times
(a) dispchar(); (b) dispchar(ch,size);
(c) dispchar($,10); (d) dispchar(T, 10 times);
Answer: (a) dispchar();

Question 4.
Which of the following is not true with respect to function overloading?
(a) The overloaded functions must differ in their signature.
(b) The return type is also considered for overloading a function.
(c) The default arguments of overloaded functions are not considered for overloading.
(d) Destructor function cannot be overloaded.
Answer:(b) The return type is also considered for overloading a function.

Question 5.
Which of the following is invalid prototype for function overloading
(a) void fun (intx); void fun (char ch);
(b) void fun (intx); void fun (inty);
(c) void fun (double d); void fun (char ch);
(d) void fun (double d); void fun (inty);
Answer:(b ) void fun (intx);void fun (inty);
PART – 2
II. Answers to all the questions
Question 1.
What is function overloading?
Answer:
• The ability of the function to process the message or data in more than one form is called
function overloading.
• In other words, function overloading means two or more functions in the same scope share
the same name but their parameters are different.

Question 2.
List the operators that cannot be overloaded.
Answer:
Operator that are not overloaded is as follows:

1. scope operator (::)


2. sizeof
3. member selector.
4. member pointer selector *
5. ternary operator ?:

Question 3.
class add{int x; public: add(int)}; Write an outline definition for the constructor.
Answer:
add (int temp)
{
x = temp;
}

Question 4.
Does the return type of function help in overloading a function?
Answer:
No. The return type of a function does not help in overloading a function. Only arguments are
considered.

Question 5.
What is the use of overloading a function?
Answer:
Function overloading is not only implementing polymorphism but also reduces the number of
comparisons in a program and makes the program execute faster. It also helps the programmer by
reducing the number of function names to be remembered.
PART – 3
III. Answers to all the questions
Question 1.
What are the rules for function overloading?
Answer:
Rules for function overloading:
• The overloaded function must differ in the number of its arguments or data types.
• The return type of overloaded functions is not considered for overloading the same data
type.
• The default arguments of overloaded functions are not considered as part of the parameter
list in function overloading.

Question 2.
How does a compiler decide as to which function should be invoked when there are many
functions? Give an example.
Answer:
When you call an overloaded function (when there are many functions with same name), the
compiler determines the most appropriate definition to use by comparing the argument types used
to call the function with the parameter types specified in the definitions. The process of selecting
the most appropriate overloaded function or operator is called overload resolution.
Example:
#include using namespace std; void print (int i)
{
cout<< “It is integer” <<i<< endl;
}
void print (string c)
{
cout<< “It is string”<< c << endl;
}
int main ()
{
print (10);
print (“Good”);
return 0;
}
Output:
It is integer 10
It is string Good

Question 3.
What is operator overloading? Give some example of operators which can be overloaded.
Answer:
The term operator overloading refers to giving additional functionality to the normal C++ operators
like It is also a type of polymorphism in which an operator is overloaded to give user-defined
meaning to it.
Integer, String (concatenation), etc.

Question 4.
Discuss the benefit of constructor overloading?
Answer:

• Function overloading can be applied for constructors, as constructors are special functions of
classes.
• A class can have more than one constructor with a different signature.
• Constructor overloading provides the flexibility of creating multiple type of objects for a class.

Question 5.
class sale ( int cost, discount; public: sale(sale &); Write a non-inline definition for constructor
specified;
Answer:
class sale
{
int cost, discount;
public:
sale (sale&);
};
// non inline constructor
sale: : sale(sale&s)
{
cost = s.cost;
discount = s.discount;
}

PART – 4
IV. Answers to all the questions
Question 1.
What are the rules for operator overloading?
Answer:
Rules for operator overloading:

• The precedence and associativity of an operator cannot be changed.


• No new operators can be created, only existing operators can be overloaded.
• Cannot redefine the meaning of an operator’s procedure, we cannot change how integers are
added. Only additional functions can be to an operator.
• Overloaded operators cannot have default arguments.
• When binary operators are overloaded, the left-hand object must be an object of the relevant
class.
2. Answer the question (i) to (v) after going through thefollowing
class.

1. Constructor overloading (function 1 and function 4 are constructors


with different signatures in the class book)
2. Function 3 is destructor of the class. Function 3 is executedwhen the
object of the class book goes out of scope.
3. Function 3 is destructor of the class.
• Destructor (function3) will free resources if any that theobject may
have acquired during its lifetime
• Destructor function removes the memory of an object whichwas
allocated by the constructor at the time of creating an object. Thus frees
the unused memory.
4. book b; b.display (4.5);
5. Book: :Book (int sc.char.s[], float, F) // Function 4
{
Book Code = SC
strcpy (Book name, S);
fees= F;
}

3. Write the output of the following program.

Output:
Seminar starts now Welcome to seminar
Recap of previous seminar contentLectures in the
seminar on
Vote of thanks Vote of thanks
Vote of thanks

4. Answer the questions based on the following program

1. Objects: ob and ob1 of main ()


2. Object ob of void operator = = (comp ob);
3. Overloaded operator: = =
Statement that invokes: ob = = ob1;
4. void operator = = (comp ob):
5. Operands used are the objects of the class comp
6. The default constructor generated by the compiler will be
executed.[comp();]
Output 1
Enter first string: hello Enter second string: hello String are equal
Output 2
Enter first string: hello Enter second string: fine String are notequal.
Chapter 16 Inheritance
PART – 1
I. Choose The Correct Answer
Question 1.
Which of the following is the process of creating new classes from an existing class?
(a) Polymorphism (b) Inheritance
(c) Encapsulation (d) super class
Answer: (b) Inheritance

Question 2.
Which of the following derives a class student from the base class Shool?
(a) school: student (b) class student: public school
(c) student: public school (d) class school : public student
Answer: (b) class student: public school

Question 3.
The type of inheritance that reflects the transitive nature is ………………
(a) Single Inheritance (b) Multiple Inheritance
(c) Multilevel Inheritance (d) Hybrid Inheritance
Answer: (c) Multilevel Inheritance

Question 4.
Which visibility mode should be used when you want the features of the base class to be
available to the derived class but not to the classes that are derived from the derived class?
(a) Private (b) Public
(c) Protected (d) All of these
Answer: (a) Private

Question 5.
Inheritance is process of creating new class from ………………
(a) Base class (b) abstract
(c) derived class (d) Function
Answer: (a) Base class

Question 6.
A class is derived from a class which is a derived class itself, then this is referred to as ……………….
(a) multiple inheritance (b) multilevel inheritance
(c) single inheritance (d) double inheritance
Answer: (b) multilevel inheritance

Question 7.
Which amongst the following is executed in the order of inheritance?
(a) Destructor (b) Member function
(c) Constructor (d) Object
Answer: (c) Constructor
Question 8.
Which of the following is true with respect to inheritance?
(a) Private members of base class are inherited to the derived class with private
(b) Private members of base class are not inherited to the derived class with private accessibility
(c) Public members of base class are inherited but not visible to the derived class
(d) Protected members of base class are inherited but not visible to the outside class
Answer:
(b) Private members of base class are not inherited to the derived class with private
accessibility

Question 9.
Based on the following class declaration answer the questions (from 9.1 to 9.4)
class vehicle
{ int wheels;
public:
void input_data(float,float);
void output_data();
protected:
int passenger;
};
class heavyvehicle : protected vehicle {
int diesel_petrol;
protected:
int load;
protected:
int load;
public:
voidread_data(float,float)
voidwrite_data(); };
class bus: private heavy vehicle {
charTicket[20];
public:
voidfetch_data(char); voiddisplay_data(); };
};

Question 9.1.
Which is the base class of the class heavy_vehicle?
(a) Bus (b) heavy_vehicle
(c) vehicle (d) both (a) and (c)
Answer: (c) vehicle

Question 9.2.
The data member that can be accessed from the function displaydata()
(a) passenger (b) load
(c) Ticket (d) All of these
Answer: (d) All of these
Question 9.3.
The member function that can be accessed by an objects of bus Class is
(a) input_data() (b) read_data(), output_data()write_data()
(c) fetch_data() (d) All of these display_data()
Answer: (d) All of these

Question 9.4.
The member function that is inherited as public by Class Bus
(a) input_data() (b) read_data(), output_data()write_data()
(c) fetch_data() (d)none of these
Answer: (d) none of these

PART – 2
II. Answers to all the questions
Question 1.
What is inheritance?
Answer:
It is a process of creating new classes called derived classes, from the existing or base classes.

Question 2.
What is a base class?
Answer:
A class that is used as the basis for inheritance is called a superclass or base class.

Question 3.
Why derived class is called a power-packed class?
Answer:
The derived class is a power-packed class, as it can add additional attributes and methods and
thus enhance its functionality.

Question 4.
In what multilevel and multiple inheritances differ though both contain many base class?
Answer:
The derived class is a power-packed class, as it can add additional attributes and methods and
thus enhance its functionality.
5.What is the difference between public and private visibility mode?
Private visibility mode:
When a base class is inherited with private visibility mode the public and
protected members of the base class become ‘private’ members of the derived
class.
Public visibility mode:
When a base class is inherited with public visibility mode, the protected members
of the base class will be inherited as protected members of the derived class
and the public members of the base class will be inherited aspublic members
of the derived class.
PART – 3
III. Answers to all the questions
Question 1.
What are the points to be noted while deriving a new class?
Answer:
The following points should be observed for defining the derived class.
• The keyword class has to be used.
• The name of the derived class is to be given after the keyword class.
• A single colon.
• The type of derivation (the visibility mode), namely private, public, or protected. If
no visibility mode is specified, then by default the visibility mode is considered
private.
• The names of all base classes(parent classes) separated by a comma.

2. What are the differences between the members present in the


privatevisibility mode and the members present in the public visibility
mode?
Members present in the private visibility mode:
• Can be accessed only by the class members.
• By default the members will be in private visibility mode.
• When classes are inherited, private members are not inherited.
Members present in the public visibility mode:
• Can be accessed by outside members also.
• Members, to be in public visibility mode has to be specified explicitly.
• When classes are inherited, the public members are inherited as
private,protected and public members of the derived class.

Question 3.
What is the difference between polymorphism and inheritance though both are used for the
reusability of code?
Answer:
Inheritance:
• Promotes code sharing and reduces development cost.
• Inheritance is implemented in classes.
• Inheritance type may be a single inheritance, multiple inheritances, multilevel
inheritance, hierarchical inheritance, and hybrid inheritance.
Polymorphism:
• Reduces the complexity of the program.
• Polymorphism is a common interface for multiple forms.
• Polymorphism is basically implemented on function.
• Polymorphism may be a compile Time polymorphism (overloading) or run-
time polymorphism (overriding).
4. What do you mean by overriding?
When a derived class member function has the same name as that of its base
class member function, the derived class member function shadows/hides the
base class’s inherited function. This situation is calledfunction overriding.

5. Write some facts about the execution of constructors and destructorsin


inheritance. Some Facts About the execution of constructor in
inheritance
Some facts about the execution of constructors in inheritance.
• Base class constructors are executed first, before the derived
classconstructors execution.
• A derived class can not inherit the base class constructor but it can
callthe base class constructor by using.
• If there are multiple base classes, then it starts executing from
theleftmost base class.
• In multilevel inheritance, the constructors will be executed in the order
ofinheritance.
Some facts about the execution of the destructor in inheritance.

• Own (Derived) class constructors are executed first, before the base
classdestructors execution.
• A derived class can not inherit the destructor.
• In multilevel inheritance, the destructors will be executed in the
reverseorder of inheritance.

PART – 4
IV. Answers to all the questions
Question 1.
Explain the different types of inheritance.
Answer:
Types of Inheritance: There are different types of inheritance viz., Single inheritance, Multiple
inheritance, Multilevel inheritance, hybrid inheritance, and hierarchical inheritance.

1. Single Inheritance: When a derived class inherits only from one base class, it is known
as single inheritance.
2. Multiple Inheritance: When a derived class inherits from multiple base classes it is known
as multiple inheritances.
3. Hierarchical inheritance: When more than one derived class is created from a single
base class, it is known as Hierarchical inheritance.
4. Multilevel Inheritance: The transitive nature of inheritance is itself reflected by this form
of inheritance. When a class is derived from a class which is a derived class then it is
referred to as multilevel inheritance.
5. Hybrid inheritance: When there is a combination of more than one type of inheritance,
it is known as hybrid inheritance.
6. Hence, it may be a combination of Multilevel and Multiple inheritances or Hierarchical
and Multilevel inheritance or Hierarchical, Multilevel and Multiple inheritances.

2. Explain the different visibility modes through pictorial representation.


An important feature of Inheritance is to know which member of the baseclass
will be acquired by the derived class. This is done by using visibility modes. The
accessibility of base class by the derived class is controlled by visibility modes. The
three visibility modes are private, protected, and public.

The default visibility mode is private. Though visibility modes and access
specifiers look similar, the main difference between them is Access specifierscontrol
the accessibility of the members within the class whereas visibility modes control
the access of inherited members within the class.

Private visibility mode:


When a base class is inherited with private visibility mode the public and
protected members of the base class become ‘private’ members of the derived
class

Protected visibility mode:


When a base class is inherited with protected visibility mode the
protected and public members of the base class become ‘protected members ‘
of the derived class.
When a base class is inherited with public visibility mode, the protected members of
the base class will be inherited as protected members of the derived class and the
public members of the base class will be inherited aspublic members of the
derived class.

3. Answer the following questions based on the above-given program:


3.1Multiple inheritances.
3.2 Private for the publisher.
Public for a branch.
3.3 branch(); // constructor of branch class
publisher (); // constructor of publisher class
author (); // constructor of author class
∼author (); // destructor of author class
∼publisher (); // destructor of publisher class
∼branch (); // destructor of branch class
3.4 Base class(/es): branch and publisherDerived class (/es): author
3.5.

3.6.The data members that can be accessed is bphone[2][10].

3.7 Member functions that can be accessed are:


1. public member functions of branch have_data();
give_data();

2. public member functions of author:


getdata();
putdata();

3.8.
4. Write the output of the following program

Output:
I am class A
I am class B
X = 30 Y = 20
Bye Bye
Bye

5. Debug the following program.


Program
Computer Application
17 COMPUTER ETHICS AND CYBER SECURITY

Part II
Answer to the following questions (2 Marks):
1. What is harvesting?
A person or program collects login and password information from a
legitimate user to illegally gain access to others’ account(s).
2. What are Warez?
Commercial programs that are made available to the public illegally are
often called warez.
3. Write a short note on cracking.
Cracking is where someone edits a program source so that the code can be exploited or
modified. A cracker (also called a black hat or dark side hacker) is a malicious or
criminal hacker.
4. Write two types of cyber attacks.
Malware is a type of software designed through which the criminals gain illegal access
to software and cause damage.
Types: 1. Virus, 2.Worms, 3.Spyware, 4. Ransomware
5. What is a Cookie? Part IV Answer
A cookie is a small piece of data sent from a website and stored on the user's to the following questions (5 Marks):
computer memory (Hard drive) by the user's web browser while the user is browsing 1. What are the various crimes happening using computer?
internet. Crime Function
Type of cookies: HTTP cookie, web cookie, Internet cookie, browser cookie, or Crime Hacking, threats, and blackmailing towards a
simply cookie Function business or a person.
Cyber stalking Harassing through online.
Part III Answer Malicious programs that can perform a variety
to the following questions (3 Marks): of functions including stealing, encrypting or
Malware
1. What is the role of firewalls?( layered security) deleting sensitive data, monitoring user’s
Firewalls also vary in type depending on where communication originates, computer activity without their permission.
where it is intercepted, and the state of communication being traced. Overloading a system with fake requests
Denial of
2. Write about encryption and decryption. so that it cannot serve normal legitimate
service attack
Encryption and decryption are processes that ensure confidentiality that requests.
only authorized persons can access the information.
Encryption is the process of translating the plain text data (plaintext) Manipulating data, for example changing the
into random and mangled data (called cipher-text). Fraud banking records to transfer money to an
Decryption reverse process of converting the cipher-text back to plaintext. unauthorized account.
Encryption and decryption are done by cryptography A person or program collects login and
3. What are the guidelines to be followed by any computer user? Harvesting password information from a legitimate user to
illegally gain access to others’ account(s).
 Honesty: Users should be truthful while using the internet.
It is a crime where the criminals impersonate
 Confidentiality: Users should not share any important information with Identity theft
individuals, usually for financial gain.
unauthorized people.
Intellectual Stealing practical or conceptual information
 Respect: Each user should respect the privacy of other users. property theft developed by another person or company.
 Professionalism: Each user should maintain professional conduct. Stealing tiny amounts of money from each
 Obey The Law: Users should strictly obey the cyber law in computer usage. Salami slicing
transaction.
 Responsibility: Each user should take ownership and responsibility for their Tricking people into believing something that
actions Scam
is not true.
4. What are ethical issues? Name some. Distribute unwanted e-mail to a large number
An Ethical issue is a problem or issue that requires a person or organization Spam
of internet users.
to choose between alternatives that must be evaluated as right (ethical) or wrong It is a malicious practice in which
(unethical). Spoofing communication is send from unknown source
These issues must be addressed and resolved to have a positive influence in disguised as a source known to the receiver.
society.
Some of the common ethical issues are listed below:
Cyber crime Use of computers to commit fraud
Software Piracy Sabotage in the form of viruses
Unauthorized Access Making false claims using computers
Hacking
.
3. Write the different types of cyber attacks
2. What is piracy? Mention the types of piracy How can S. Cyber
Function
it be prevented No Attack
Software Piracy is about the copyright violation of software created originally by A virus is a small piece of computer code that can repeat
an individual or an institution. itself and spreads from one computer to another by attaching
Software Piracy is “unauthorized copying of software” itself to another computer file.
S Type of Trojan: A Trojan virus is a program that appears to perform
Function 1. Virus
No Piracy one function (for example, virus removal) but actually
Unauthorized access is when someone gains performs malicious activity
Unauthoriz when executed.
1 ed access to a website, program, server, service,
access or other system by breaking into a legitimate
Worms are self- repeating and do not require a computer
user account. program to attach themselves. Worms continually look for
Hacking is gaining unauthorized access to s computer 2. Worms vulnerabilities and report back to the author of the worm when
2 Hacking system without the owner’s permission. weaknesses are
discovered.
Cracking is gaining unauthorized access to computer
systems to commit a crime, such as stealing the code to Spyware can be installed on the computer automatically
3 Cracking make a copy- when the attachments are open, by clicking on links or by
3. Spyware
protected program run thus denying service to downloading infected
software.
legitimate users.
Prevented Action: Ransomware is a type of malicious program that demands
To pretend being your friend and talk to you on Internet Relay Chat(IRC) or by payment after launching a cyber-attack on a computer
Ransom
Instant messenger. e-mail can also be a source for them. 4. system. This type of malware has
ware
They may send official e-mail requesting some sensitive information. become increasingly popular among criminals and costs the
organizations millions each year.
Computer Application- CHAPTER 18
Tamil Computing
1. List the search engines supported by Tamil language
Google and Bing provide searching facilities in Tamil,
which means you can search everything through Tamil. The
Google search engine gives you an inbuilt Tamil virtual
keyboard.
2. What are the keyboard layouts used in Android?
Sellinam and Ponmadal – are familiar Tamil keyboard
layouts that works on Android operating system in Smart
phone using phonetics.
3. Write a short note about Tamil Programming Language.
Programming languages to develop software in
computers and smart phones are available only in English.
Based on Python programming language, the first Tamil
programming language “Ezhil” (எழில் ) is designed.
4. What is TSCII?
TSCII (Tamil Script Code for Information Interchange) is
the first coding system to handle our Tamil language. This
encoding scheme was registered in IANA (Internet Assigned
Numbers Authority) a unit of ICANN.
5. Write a short note on Tamil Virtual Academy.
With the objectives of spreading Tamil to the entire
world through internet, Tamil Virtual University was
established on 17th February 2001 by the Govt. of
Tamilnadu. Now, this organisation functions with the name
of “Tamil Virtual Academy”. It offers different courses in Tamil
language, Culture, heritage etc., from kindergarten to under
graduation level.
Website: http://www.tamilvu.org/index.php

******************************

You might also like