Xi - CS em Minimum Study Material 2024-2025

Download as pdf or txt
Download as pdf or txt
You are on page 1of 133

J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

https://csknowledgeopener.com 1 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

PROVERB
As Nelson Mandela says,
“Education is the most powerful weapon which you can use to change the world.”
As Bill Gates says,
“Don’t compare yourself with anyone in this world… if you do so, you are insulting yourself.”

• “CS KNOWLEDGE OPENER” Computer Science for standard XI has been prepared in
accordance with the New Textbook released by the Government of Tamil Nadu.
• Each chapter consists of an Important Terms / Definition and Answers to the Textbook
Questions, which gives a summary of the concepts presented in the text in a simple and
lucid language.
• It is hoped that this book in the present form will satisfy all types of learners and help them
improve their learning potential, apart from mentally preparing them to face any type of
questions in the examinations.
• This Minimum Study Material is prepared from Re-Print Text Book 2024
• Our aim is to make all the students who study this study material to score high marks in
theory.
PUBLIC QUESTION PATTERN (THEORY)
PART – I Choose the Correct Answers MCQ 15x1=15

Out of 9
PART – II Answer any Six Questions. Question No.24 Compulsory 6x2=12
Questions
Out of 9
PART – III Answer any Six Questions. Question No.33 Compulsory 6x3=18
Questions
OR Type
PART – IV Answer all the Questions 5x5=25
Questions
TOTAL 70

PUBLIC PRACTICAL PATTERN


Internal Marks 15
External Marks 15
TOTAL 30

https://csknowledgeopener.com 2 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

TABLE OF CONTENTS
COMPUTER SCIENCE – I YEAR

CHAPTER NO CHAPTER TITLE


UNIT I – FUNDAMENTALS OF COMPUTER AND WORKING WITH A TYPICAL
OPERATING SYSTEMS (WINDOWS)
1 INTORDUCTION TO COMPUTERS

2 NUMBERS SYSTEMS

3 COMPUTER ORGANISATION

4 THEORETICAL CONCEPTS OF OPERATING SYSTEM

5 WORKING WITH WINDOWS OPERATING SYSTEM

UNIT II – ALGORITHMIC PROBLEM SOLVING

6 SPECIFICATION AND ABSTRACTION

7 COMPOSITION AND DECOMPOSITION

8 ITERATION AND RECURSION

UNIT III – INTRODUCTION TO C++

9 INTRODUCTION TO C++

10 FLOW OF CONTROL

11 FUNCTIONS

12 ARRAYS AND STRUCTURES

UNIT IV – OBJECT ORIENTED PROGRAMMING WITH C++


INTRODUCTION TO OBJECT ORIENTED PROGRAMMING
13
TECHNIQUES
14 CLASSES AND OBJECTS

15 POLYMORPHISM

16 INHERITANCE

17 COMPUTER ETHICS AND CYBER SECURITY

18 TAMIL COMPUTING

https://csknowledgeopener.com 3 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

1. INTRODUCTION TO COMPUTERS
Choose the correct answer: (1 mark)
1. First generation computers used
(a)Vacuum tubes (b) Transistors (c) Integrated circuits (d) Microprocessors
2. Name the volatile memory
(a) ROM (b) PROM (c) RAM (d) EPROM
3. Identify the output device
(a) Keyboard (b) Memory (c) Monitor (d) Mouse
4. Identify the input device
(a) Printer (b) Mouse (c) Plotter (d) Projector
5. …………… Output device is used for printing building plan, flex board, etc.
(a) Thermal printer (b) Plotter (c) Dot matrix (d) inkjet printer
6. In ATM machines, which one of the following is used to
(a) Touch Screen (b) speaker (c) Monitor (d) Printer
7. When a system restarts ……………….. Which type of booting is used?
(a) Warm booting (b) Cold booting (c) Touch boot (d) Real boot.
8. Expand POST
(a) Post on self Test (b) Power on Software Test
c) Power on Self Test (d) Power on Self Text
9. Which one of the following is the main memory?
(a) ROM (b) RAM (c) Flash drive (d) Hard disk
10. Which generation of computer used IC’s?
(a) First (b) Second (c) Third (d) Fourth
Very Short Answers (2 mark)
1. What is a computer?
• A computer is an electronic device that processes the input according to the set of instructions provided
to it and gives the desired output at a very fast rate.
2. Distinguish between data and information.
Data Information
Data is defined as an unprocessed collection Information is a collection of facts from which
of raw facts, suitable for communication, conclusions may be drawn.
interpretation or processing.
Example: 134, 16 ‘Kavitha’, ‘C’are data. Example: Kavitha is 16 years old.
3. What are the components of a CPU?
The CPU has three components, they are Control unit, Arithmetic and logic unit (ALU) and Memory unit.
4. What is the function of an ALU?
• 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.
5. Write the functions of control unit.
• The control unit controls the flow of data between the CPU, memory and I/O devices.

https://csknowledgeopener.com 4 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• It also controls the entire operation of a computer.


6. What is the function of memory?
• 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
• The secondary memory is used to store the data permanently.
7. Differentiate Input and output unit.
Input Unit Output Unit
An Input unit is used to feed any form of data An Output Unit is any hardware component that
to the computer, which can be stored in the conveys information to users in an
memory unit for further processing. understandable form
Example: Keyboard, mouse Example: Monitor, Printer
8. Distinguish Primary and Secondary memory.
Primary Memory Secondary memory
The Primary Memory is volatile, that is, the The Secondary memory is non-volatile, that is,
content is lost when the power supply is the content is available even after the power
switched off. supply is switched off.
Example: Random Access Memory (RAM). Example: Hard disk, DVD ROM.
Short Answers (3 mark)
1. What are the characteristics of a computer?
Computers have revolutionized our lives with their speed, accuracy, storage, reliability, versatility and
diligence performing a job, it is truly remarkable.
2. Write the applications of computer.
Computers are seen everywhere around us, in all spheres of life, in the field of education, research, travel
and tourism, weather forecasting, social networking, e-commerce, Robotics , Nanotechnology,
Bioengineering etc.
3. What is an input device? Give two examples.
• An input device is a hardware or peripheral device used to send data to a computer.
• An input device allows users to communicate and feed instructions and data to computers for
processing, display, storage and/or transmission.
• Example: Keyboard, mouse, Scanner, Track Ball, Light Pen.
4. Name any three output devices.
Monitor: Monitor is the most commonly used output device to display the information. It looks like a
TV.
Plotter: Plotter is an output device that is used to produce graphical output on papers.
Printers: Printers are used to print the information on papers.
5. Differentiate Optical mouse and Laser mouse (Out of Portion)
6. Write short note on impact printer
• An impact printer is a type of printer that works by direct contact 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.

https://csknowledgeopener.com 5 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

7. Write the characteristics of sixth generation.


• Sixth Generation, computers could be defined as the era of intelligent computers, based on Artificial
Neural Networks.
• 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).
8. Write the significant features of 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.
• There are many types of monitors available such as CRT (Cathode Ray Tube), LCD (Liquid Crystal
Display) and LED (Light Emitting Diodes).
• Monochrome which display text or images in Black and White or can be color, which display results
in multiple colors.
Explain in detail (5 mark)
• The computer is the combination of hardware and software.
• It needs certain input, processes that input and produces the desired output

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.
Central Processing Unit
• CPU is the major component which interprets and executes software instructions. It also control the
operation of all other components such as memory, input and output units.
Arithmetic and Logic Unit
• 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.

https://csknowledgeopener.com 6 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• The Primary Memory is volatile, that is, the content is lost when the power supply is switched off.
• The secondary memory is used to store the data permanently.
2. Discuss the various generations of computers.
SN Generation Period Main Component Merits/Demerits
used
• Big in size
1 First 1940-1956 Vacuum tubes • Consumed more power
Generation • Malfunction due to overheat
• Smaller compared to First Generation
Second 1956-1964 Transistors • Generated Less Heat
2 Generation • Punched cards were used
• Computers were smaller, faster and more
3 Third Integrated Circuits reliable
Generation 1964-1971 (IC) • Consumed less power
• High Level Languages were used
• Smaller and Faster
4 Fourth • Microcomputer series such as IBM and
Generation 1971-1980 Microprocessor APPLE were developed
• Portable Computers were introduced.
• Parallel Processing
5 Fifth 1980 – till Ultra Large Scale • Super conductors
Generation date Integration (ULSI) • Introduction of Artificial Intelligence
• Parallel and Distributed computing
Sixth • Development of robotics
6 Generation In future • Natural Language Processing

3. Explain the following


a. Inkjet Printer
• Inkjet Printers use color cartridges which combined Magenta, Yellow and Cyan inks to create color
tones.
• A tiny electric currents controlled by electronic circuits are used inside the printer to spread ink in jet
speed.
b. Multimedia projector
• Multimedia projectors are used to produce computer output on a big screen. These are used to
display presentations in meeting halls or in classrooms.
c. Bar code
• 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.
d. QR code Reader
• The QR code is the two-dimension bar code which can be read by a camera and processed to
interpret the image.

https://csknowledgeopener.com 7 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. NUMBER SYSTEMS
Choose the correct answer: (1 mark)
1. Which refers to the number of bits processed by a computer’s CPU?
A) Byte B) Nibble C) Word length D) Bit
2. How many bytes does 1 Kilobyte contain?
A) 1000 B) 8 C) 4 D) 1024
3. Expansion for ASCII
A) American School Code for Information Interchange
B) American Standard Code for Information Interchange
C) All Standard Code for Information Interchange
D) American Society Code for Information Interchange
4. 2^50 is referred as
A) Kilo B) Tera C) Peta D) Zetta
5. How many characters can be handled in Binary Coded Decimal System?
A) 64 B) 255 C) 256 D) 128
6. For 11012 what is the Hexadecimal equivalent?
A) F B) E C) D D) B
7. What is the 1’s complement of 00100110?
A) 00100110 B) 11011001 C) 11010001 D) 00101001
8. Which amongst this is not an Octal number?
A) 645 B) 234 C) 876 D) 123

Very Short Answers (2 mark)


1. What is 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.
2. Write the 1’s complement procedure.
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)
3. Convert (46)10 into Binary number
2 46 LSB
2 23 -0
2 11 -1
2 5 -1
2 2 -1
MSB 1 -0

(46)10 = (101110)2
4. We cannot find 1’s complement for (28)10. State reason.
Reason: We cannot find 1’s complement for (28)10. Because it is a positive number. 1’s complement
apply only with negative number.

https://csknowledgeopener.com 8 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

5. List the encoding systems for characters in memory.


There are several encoding systems used for computer.
BCD – Binary Coded Decimal
EBCDIC – Extended Binary Coded Decimal Interchange Code
ASCII – American Standard Code for Information Interchange Unicode
ISCII – Indian Standard Code for Information Interchange
Short Answers (3 mark)
1. What is radix of a number system? Give example
• Each number system is uniquely identified by its base value or radix.
• Radix or base is the count of number of digits in each number system.
• Radix or base is the general idea behind positional numbering system.
Example:
Binary Number System - Radix 2  (1010)2
Octal Number System - Radix 8  (457)8
Decimal Number System - Radix 10  (312)10
Hexadecimal Number System - Radix 16  (25F)16
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.
3. Convert (150)10 into Binary, then convert that Binary number to Octal
2 150 LSB
2 75 -0
2 37 -1
2 18 -1
2 9 -0
2 4 -1
2 2 -0
MSB 1 -0

(150)10 = (10010110)2

Binary Number to Octal


10010110 = ?
010 010 110
2 2 6
(10010110)2 = (226)8

https://csknowledgeopener.com 9 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

4. Write short note on ISCII


• ISCII means Indian Standard Code for Information Interchange. Itis the system of handling the
character of Indian local languages.
• This as a 8-bit coding system. Therefore, it can handle 256 (28) characters.
• The department of Electronics in India in the year 1986- 88 and recognized by Bureau of Indian
Standards (BIS).
5. Add a) -2210+1510
2 22 LSB
2 11 -0
2 5 -1
2 2 -1
MSB 1 -0 The Binary equivalent of 2210 = (10110)2

Binary equivalent of +22 = 10110


8 bit format = 00010110
1’s complement = 11101001
Add 1 bit = +1
2’s complement −22 = 11101010

2 15 LSB
2 7 -1
2 3 -1
MSB 1 -1 The Binary equivalent of 1510 = (1111)2

The binary addition of −22 and 15


−2210 = 11101010
+1510 = 00001111
−710 = 11111001

−710 = (11111001)2

b) 2010+2510
2 20
2 10 - 0 LSB
2 5 -0
2 2 -1
MSB 1 -0 The Binary equivalent of 2010 = (10100)2

https://csknowledgeopener.com 10 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2 25 LSB
2 12 -1
2 6 -0
2 3 -0
MSB 1 -1 The Binary equivalent of 2510 = (11001) 2

8 bit format of 2010 = 00010100


8 bit format of 2510 = 00011001
4510 = 00101101

4510 = (00101101)2
Explain in detail (3 mark)
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.
b) Convert (98.46)10 to Binary
i) Integer Part
2 98 LSB
2 49 -0
2 24 -1
2 12 -0
2 6 -0
2 3 -0
MSB 1 -1

9810 = (1100010)2
ii) Fraction Part
0.46 × 2 = 0.92 = 0
0.92 × 2 = 1.84 = 1
0.84 × 2 = 1.68 = 1
0.68 × 2 = 1.36 = 1
0.36 × 2 = 0.72 = 0
0.72 × 2 = 1.44 = 1
0.44 × 2 = 0.88 = 0
4610 = (0111010)2
(98.46)10 = (1100010. 0111010….)2

https://csknowledgeopener.com 11 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. Find 1’s Complement and 2’s Complement for the following Decimal number
a) -98
2 98 LSB
2 49 -0
2 24 -1
2 12 -0
2 6 -0
2 3 -0
MSB 1 -1 The Binary equivalent of 9810 = (1100010)2

Binary equivalent of +98 = 1100010


8 bit format = 01100010
1’s complement = 10011101
Add 1 bit = +1
2’s complement −98 = 10011110
−98 = (10011110)2
b) -135
2 135 LSB
2 67 -1
2 33 -1
2 16 -1
2 8 -0
2 4 -0
2 2 -0
MSB 1 -0 The Binary equivalent of 13510 = (1000111)2

Binary equivalent of +135 = 10000111


8 bit format = 10000111
1’s complement = 01111000
Add 1 bit = +1
2’s complement −135 = 01111001
−135 = (01111001)2
3. a) Add 11010102+1011012

1 1 0 1 0 1 0
+ 1 0 1 1 0 1

1 0 0 1 0 1 1 1
0+1=1
11010102 + 1011012 = 100101112 1+0=1
1 + 1 =10 = (1) Carry
1 + 1 + 1 = 11

https://csknowledgeopener.com 12 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

b) Subtract 11010112 − 1110102

1 1 0 1 0 1 1
− 1 1 1 0 1 0

0 1 1 0 0 0 1
0–0=0
1–0=1
1–1=0
0 – 1= 1 (1) Borrow
10 – 1= 1
11010112 − 1110102 = 01100012

PART - II - BOOLEAN ALGEBRA


Choose the correct answer: (1 mark)
1. Which is a basic electronic circuit which operates on one or more signals?
(A) Boolean algebra (B) Gate (C) Fundamental gates (D) Derived gates
2. Which gate is called as the logical inverter?
(A) AND (B) OR (C) NOT (D) XNOR
3. A + A = ?
(A) A (B) O (C) 1 (D) A

4. NOR is a combination of ?
(A) NOT(OR) (B)NOT(AND) (C ) NOT(NOT) (D) NOT(NOR)
5. NAND is called as …… Gate
(A) Fundamental Gate (B) Derived Gate (C) Logical Gate (D) Universal gate
Very Short Answers (2 mark)
1. What is Boolean algebra?
• Boolean algebra is used for designing digital circuits in a digital computer.
• It describes the relation between inputs and outputs of a digital circuit.
2. Write a short note on NAND Gate.
• The NAND gate operates an AND gate followed by a NOT gate.
• The output is "false" / “0” if both inputs are "true"/ “1”, otherwise, the output is "true" / “1”.
3. Draw the truth table for XOR gate.
The truth table for XOR gate is
Input Output
A B C
0 0 0
0 1 1
1 0 1
1 1 0

https://csknowledgeopener.com 13 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

4. Write the associative laws?


Associative,
A + (B + C) = (A + B) + C
A . (B . C) = (A . B) . C
5. What are derived gates?
• The logic gates like NAND, NOR, XOR and XNOR are derived gates which are derived from the
fundamental gates.
SECTION – C (3 mark)
Short Answers
1. Write the truth table of fundamental gates.
The truth table for AND gate is
Input Output
A B C
0 0 0
0 1 0
1 0 0
1 1 1
The truth table for OR gate is
Input Output
A B C
0 0 0
0 1 1
1 0 1
1 1 1
The truth table for NOT gate is
Input Output
A C
1 0
0 1
2. Write a short note on XNOR gate.
• The XNOR (exclusive - NOR) gate is a combination XOR gate followed by an inverter.
• Its output is "true" / “1” if the inputs are the same, and "false" / “0” if the inputs are different.
XNOR Operation
• C=A⊙B
The logical symbol is

3. Reason out why the NAND an NOR are called universal gates?
• NAND and NOR gates are called Universal gates, because the fundamental logic gates can be
realized through them.
https://csknowledgeopener.com 14 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

4. Give the truth table of XOR gate.


The truth table for XOR gate is
Input Output
A B C
0 0 0
0 1 1
1 0 1
1 1 0

5. Write the De Morgan’s law.


�������
A+B= A �. B

��������
(A. �+B
B) = A �
Explain in detail (5 mark)
1. Explain the fundamental gates with expression and truth table.
• A gate is a basic electronic circuit which operates on one or more signals to produce an output signal.
• There are three fundamental gates namely AND, OR and NOT.
i) AND Gate
• The AND gate can have two or more input signals and produce an output signal.
• The output is "true" / “1” only when both inputs are "true" / “1”, otherwise, the output is "false" / “0”.
• The output of the AND gate is represented by C, where A and B are two Boolean variables.
• A variable can take either of the values '0' or '1'.
The logical symbol of the AND gate is

AND gate
C = A AND B
AND Operation
zC = A . B or C = AB
Example
For instance if both inputs are 0,
C=A.B
=0.0
=0
Truth Table for AND Gate
Input Output
A B C
0 0 0
0 1 0
1 0 0
1 1 1
https://csknowledgeopener.com 15 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

ii) OR Gate
• The OR gate gets its name from its behaviour like the logical inclusive "OR".
• The output is "true" / “1” if either or both of the inputs are "true" / “1”.
• If both inputs are "false" / “0” then the output is "false" / “0”.
The logical symbol of the OR gate is

OR gate
C = A OR B
OR Operation
C=A+B
Example
For instance, if both the inputs are 1
C=A+B=1+1=1
Truth Table for OR gate
Input Output
A B C
0 0 0
0 1 1
1 0 1
1 1 1
iii) NOT Gate
• The NOT gate, called a logical inverter, has only one input.
• It reverses the logical state.
• In other words the output C is always the complement of the input.
The logical symbol of the NOT gate is

NOT gate
C = NOT A
NOT operation

C=A
Example
If A is 0,
C = 0� = 1
On the other hand, if A is 1,
C = 1� = 0
https://csknowledgeopener.com 16 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

The Truth Table for NOT gate


Input Output
A C
1 0
0 1

2. How AND and OR can be realized using NAND and NOR gate.
(i) Realized AND Gate using NAND Gate:

(ii) Realized OR Gate using NAND Gate:

(iii) Realized AND Gate using NOR Gate:

(iv) Realized OR Gate using NOR Gate:

https://csknowledgeopener.com 17 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

3. Explain the Derived gates with expression and truth table.


• The logic gates like NAND, NOR, XOR and XNOR are derived gates which are derived from the
fundamental gates.
i) NAND gate
• The NAND gate operates an AND gate followed by a NOT gate.
• The output is "false" / “0” if both inputs are "true"/ “1”, otherwise, the output is "true" / “1”.
The logical symbol of NAND gate is

NAND gate Expression


C = ��������
(A. B)

For example if both the inputs are 1

������� = 1� = 0
C = (1.1)

The truth table for NAND gate is


Input Output
A B ��������
C= (𝐀𝐀. 𝐁𝐁)
0 0 1
0 1 1
1 0 1
1 1 0
ii) NOR gate
• The NOR gate circuit is an OR gate followed by an inverter.
• Its output is "true" if both inputs are "false" / “0” Otherwise, the output is "false" / “0”.
The Logic symbol of NOR Gate is

NOR gate Expression


C = �������
A+B
For example if both the inputs are 0,
�������
C=0 + 0 = 0� = 1
The truth table for NOR gate is
Input Output
A B 𝐂𝐂 = ��������
𝐀𝐀 + 𝐁𝐁
0 0 1
0 1 0
1 0 0
1 1 0

https://csknowledgeopener.com 18 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

iii) XOR gate


• The XOR (exclusive - OR) gate acts in the same way as the logical "either/or."
• The output is "true" / “0” if either, but not both, of the inputs are "true" / “1”.
• The output is "false" / “0” if both inputs are "false" / “0” or if both inputs are "true" / “1”
• In Boolean algebra. exclusive - OR operator ⊕ or "encircled plus".
The logical symbol of XOR gate is

XOR Gate Expression


C = A ⊕B
The truth table for XOR gate is
Input Output
A B C
0 0 0
0 1 1
1 0 1
1 1 0
iv) XNOR gate
• The XNOR (exclusive - NOR) gate is a combination XOR gate followed by an inverter.
• Its output is "true" / “1” if the inputs are the same, and "false" / “0” if the inputs are different.
XNOR gate Expression
(Using De Morgan's Theorem)
In boolean algebra, ⊙ or "included dot" stands for the XNOR.
C=A⊙B
The logical symbol is

The truth table for XNOR Gate is


Input Output
A B C
0 0 1
0 1 0
1 0 0
1 1 1
3. COMPUTER ORGANISATION
Choose the correct answer: (1 mark)
1. Which of the following is said to be the brain of a computer?
(a) Input devices (b) Output devices (c) Memory device (d) Microprocessor
2. Which of the following is not the part of a microprocessor unit?
(a) ALU (b) Control unit (c) Cache memory (d) register

https://csknowledgeopener.com 19 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

3. How many bits constitute a word?


(a) 8 (b) 16 (c) 32 (d) Determined by the processor used.
4. Which of the following device identifies the location when address is placed in the memory address
register?
(a) Locator (b) Encoder (c) Decoder (d) Multiplexer
5. Which of the following is a CISC processor?
(a) Intel P6 (b) AMD K6 (c) Pentium III (d) Pentium IV
6. Which is the fastest memory?
(a) Hard disk (b) Main memory (c) Cache memory (d) Blue-Ray disk
7. How many memory locations are identified by a processor with 8 bits address bus at a time?
(a) 28 (b) 1024 (c) 256 (d) 8000
8. What is the capacity of 12cm diameter DVD with single sided and single layer?
(a) 4.7 GB (b) 5.5 GB (c) 7.8GB (d) 2.2 GB
9. What is the smallest size of data represented in a CD?
(a) Blocks (b) Sectors (c) Pits (d) Tracks
10. Display devices are connected to the computer through.
(a) USB port (b) Ps/2 port (c) SCSI port (d) VGA connector
Very Short Answers (2 mark)
1. What are the parameters which influence the characteristics of a microprocessor?
A Microprocessor’s performance depends on the following characteristics:
• Clock speed
• Instruction set
• 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 uncompressed
video and audio data from a video controller, to a compatible computer monitor, LCD projector,
digital television etc.
5. Which source is used to erase the content of a EPROM?
• Ultraviolet rays are used to erase the content of a EPROM.

Short Answers (3 mark)


1. Differentiate Computer Organization from Computer Architecture.
Computer organization Computer Architecture
Computer organization deals with the hardware Computer Architecture also deals with how they
components of a computer system such as Input / are interconnected to implement an architectural
Output devices, the CPU, Storage Devices and specification.
Primary Memory.
https://csknowledgeopener.com 20 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

It deals with the hardware components that are It deals with the engineering considerations
transparent to the programmer. involved in designing a computer.
2. Classify the microprocessor based on the size of the data.
• 8-bit microprocessor
• 16-bit microprocessor
• 32-bit microprocessor
• 64-bit microprocessor
3. Write down the classifications of microprocessors based on the instruction set.
• Two types of Microprocessors based on their instruction sets:
 Reduced Instruction Set Computers (RISC): Pentium IV, Intel P6, AMD K6 and K7.
 Complex Instruction Set Computers (CISC): Intel 386 & 486, Pentium, Pentium II and III, etc.
4. Differentiate PROM and EPROM.
PROM EPROM
Programmable read only memory is a non- Erasable Programmable Read Only Memory is
volatile memory a special type of memory.
PROMs retain their contents even when the EPROM retains its contents until it is exposed
computer is turned off. to ultraviolet light.
PROM can be written only once and Ultraviolet rays is used to erase the content of a
cannot be erased. EPROM
5. Write down the interfaces and ports available in a computer.
• Serial Port: To connect the external devices, found in old computers.
• Parallel Port: To connect the printers, found in old computers.
• VGA Connector: To connect a monitor or any display device like LCD projector.
• Audio Plugs: To connect sound speakers, microphone and headphones.
6. Differentiate CD and DVD
CD DVD
CD stands for Compact Disk DVD stands for Digital Versatile Disc
CD data is represented as tiny indentations DVD-ROM can be visually determined by
known as "pits" noting the number of data sides of the disc
Capacity: CD-ROM is 700MB. Capacity: 4.7 GB
A thin layer of aluminum or gold is applied to Double-layered sides are usually gold-coloured.
the surface.
7. How will you differentiate a flash memory and an EEPROM?
Flash Memory EEPROM
Flash memory is an electronic (solid-state) Electrically Erasable Programmable Read Only
non- volatile computer storage Memory is a special type of PROM
Flash memory offers fast access times. EEPROM is slower in performance.
It can be erased by exposing it to an electrical It can be electrically erased and reprogrammed.
charge.

https://csknowledgeopener.com 21 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Explain in detail (5 mark)


1. Explain the characteristics of a microprocessor.
• Clock speed
• Instruction set
• Word size
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).
Instruction Set
• 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
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
2. How the read and write operations are performed by a processor? Explain.
• The read operation transfers the data(bits) from word to Memory Data Register.
• The read operation fetches data from memory and transfers to MDR.
• A single control line performs two operations like Read/Write using 1or 0.
• The write operation transfers the data(bits) from Memory Data Register to word.
• Also, the write operation transfers data from the MDR to memory.
• If the size of the MDR is 8 bits, which can be connected with a word in the memory which is also 8
bits size.
• The data bus has eight parallel wires to transfer data either from MDR to word or word to MDR
based on the control(Read or write).
• This control line is labeled as R/W , which becomes 1 means READ operation and 0 means WRITE
operation.
3. Arrange the memory devices in ascending order based on the access time.
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 HD movies.
• A double-layer Blu-Ray disc can store up to 50GB of data.
Hard Disks
• 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.

https://csknowledgeopener.com 22 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• The hard disks come with a single or double sided disk.


Random-Access Memory (RAM)
• The main memory or Random Access Memory is available in computers in the form of Integrated
Circuits (ICs).
• The smallest unit of information that can be stored as a bit.
• The memory can be accessed as a byte.
• RAM is a volatile memory.
Cache Memory
• The cache memory is a very high speed and expensive memory 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.
4. Explain the types of ROM.
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.
Programmable Read Only Memory (PROM)
• Programmable read only memory is also a non-volatile memory on which data can be written only
once.
• 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.
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.
• EEPROM retains its contents even when the power is turned off.
• EEPROM is slower in performance.
4. THEORETICAL CONCEPTS OF OPERATING SYSTEM
Choose the correct answer: (1 mark)
1. Operating system is a
a) Application Software b) Hardware c) System Software d) Component

https://csknowledgeopener.com 23 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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) Complier 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 is
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
Very Short Answers (2 mark)
1. List out 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.
• Controlling Input and Output Devices
2. What is the multi-user Operating system?
• Multi-user Operating system 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.
Example: Windows, Linux and UNIX
3. What is a GUI?
• 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
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 File access level, System level, Network level
5. What is multi-processing?
• Multi-processing 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 as parallel processing.
• This feature is used for high-speed execution which increases the power of computing.
https://csknowledgeopener.com 24 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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


• Operating Systems used in personal computers and laptops are Windows, UNIX and Linux.
• The different Operating Systems used in computers are:
 Single User Operating Systems
 Multi-user Operating Systems
 Distributed Operating Systems
Short Answers (3 mark)
1. What are the advantages and disadvantages of Time-sharing features?
Advantages:
• All the tasks are given specific time and task switching time is very less so applications don’t get
interrupted by it.
• Many applications can run at the same time.
• Time sharing in batch systems increases performance.
• Provides quick response, Avoids duplication of software, Reduces CPU idle time.
Disadvantages:
• It consumes much resource.
• Switching between tasks between lots of users may hang up the system.
• Problem of reliability, Question of security and integrity, Problem of data communication.
2. List out the key features of Operating system
The various key features are given below,
 User Interface (UI)
 File Management
 Memory Management
 Fault Tolerance
 Process management
 Security Management
3. Write a note on Multiprocessing
• Multi-processing 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 as parallel processing.
• The execution takes place in parallel, this feature is used for high speed execution which increases the
power of computing.
Explain in Detail (5 mark)
1. Explain the concept of a Distributed Operating System along with its advantages.
• 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

https://csknowledgeopener.com 25 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• 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.
• The user interface should enable the user to retain this expertise for a longer time.
• The user interface should also satisfy the customer based on their needs.
• The user interface should save user’s precious time.
• The ultimate aim of any product is to satisfy the customer. The User Interface is also to satisfy the
customer.
• The user interface should reduce number of errors committed by the user
3. Explain the process management algorithms in Operating System.
The Process Management 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:
• FIFO algorithm is based on queuing technique.
• 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.
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.
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.
5. WORKING WITH WINDOWS OPERATING SYSTEM
Choose the correct answer: (1 mark)
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 the above
2. Which is the default folder for many Windows Applications to save your file?
a. My Document b. My Pictures 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. MS-DOS c. Linux d. Android OS
4. What is the meaning of "Hibernate" in Windows XP/Windows 7?
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 applications
5. The shortcut key used to rename a file in windows
a. F2 b.F4 c.F5 d. F6

https://csknowledgeopener.com 26 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Very Short Answers (2 mark)


1. What is known as Multitasking?
• Multiple applications can execute simultaneously in Windows, and this is known as “Multitasking”.
2. What are called standard icons?
• 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
3. Differentiate Files and Folders.
Files Folders
A file consists of a collection of data. A folder stores files and folders. It is also called a
directory.
Each file has its own extension. A folder does not have any extension
Folder and sub folder cannot be created in a file Folder and sub folder can be created in a folder
4. Differentiate Save and Save As option.
Save Save As
“Save” command is used to save a document “Save As” command can save a file by two or
by only one name more than two names.
Shortcut Keys : Ctrl + S Shortcut Keys : Ctrl+Shift+S
5. How will you Rename a File?
• Rename files or folders can be done in number of ways such as using the File menu, left mouse button
or right mouse button.
1. Select the File
2. Click File→ Rename.
3. Type in the new name.
4. To finalise the renaming operation
Short Answers (3 mark)
1. What are the functions of Windows Operating system?
• Access applications on the computer.
• Load any new program on the computer.
• Manage hardware.
• File management activities.
• Change computer settings.
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.
• Restore option is used to restore file or folder from the Recycle Bin
• To delete all files in the Recycle bin, select Empty the Recycle Bin.
3. Write a note on the elements of a window.
Title Bar
• The title bar will display the name of the application and the name of the document opened.

https://csknowledgeopener.com 27 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Menu Bar
• Menus in the menu bar can be accessed by pressing Alt key and the letter that appears underlined in
the menu title.
The Workspace
• The workspace area is used to enter or type the text of your document.
Scroll bars
• The scroll bars are used to scroll the workspace horizontally or vertically.
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.
Step 3: Click on File → New → Folder.
Step 4: Type in the folder name and press Enter key.
Method II:
Step 1: In the Desktop, right click → New → Folder
Step 2: A Folder appears with the default name “New folder” and it will be highlighted.
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.
Copy Move
Copy option is used to copy a file or folder, Cut option is used to move a selected file or
and paste in a specified location. folder from one place to another.
Edit → Copy or Ctrl + C or Right click→ Edit → Cut or Ctrl + X or Right click → Cut
Copy
Explain in Detail (5 mark)
1. Explain the versions of Windows Operating System.
VERSIONS YEAR SPECIFIC FEATURES
WINDOWS 1.X 1985 • Introduction of GUI in 16 - bit processor.
WINDOWS 2.X 1987 • Supports to minimize or maximize windows.
WINDOWS 3.X 1992 • Introduced the concept of multitasking.
WINDOWS NT 1993 • Designed to act as servers in network.
• Introduced Start button, the taskbar, Windows Explorer and
WINDOWS 95 1995
Start menu.
• Integration of the Web browser (Internet Explorer) with the
WINDOWS 98 1998
Operating System.
WINDOWS Me 2000 • It introduced automated system diagnostics and recovery tools.
• Served as an Operating System for business desktop and laptop
WINDOWS 2000 2000
systems.
WINDOWS XP 2001 • Introduced 64-bit Processor.

https://csknowledgeopener.com 28 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• Updated the look and feel of Windows.


WINDOWS Vista 2006

• Introduced new user interfaces like Aero Peek, pinning


WINDOWS 7 2009
programs to taskbar, handwriting recognition etc.
• Start button was removed.
WINDOWS 8 2012 • Windows 8 takes better advantage of multi-core processing,
solid state drives (SSD),
• Start Button was added again.
WINDOWS 10 2015
• Multiple desktops.
2. Explain the different ways of finding a file or Folder.
To find a file or folder:
• Click the Start button, the search box appears at the bottom of the start menu.
• Type the name of the file or the folder you want to search.
• 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.
Searching Files or folders using Computer icon:
• Click Computer Icon from desktop or from Start menu.
• The computer disk drive screen will appear and at the top right corner of that screen, there is a search
box option.
• Type the name of the file or the folder you want to search.
• Just click and open that file or the folder.
3. Write the procedure to create shortcut in Windows OS.
• Shortcuts to your most often used folders and files may be created and placed on the Desktop to help
automate your work.
• 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
6. SPECIFICATION AND ABSTRACTION
Choose the correct answer: (1 mark)
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) Swapping of two numbers.

https://csknowledgeopener.com 29 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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 input-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
Very Short Answers (2 mark)
1. Define an algorithm.
• An algorithm is a sequence of instructions to accomplish a task or solve a problem.
2. Distinguish between an algorithm and a process.
ALGORITHM PROCESS
• An algorithm is a sequence of • When the algorithms are executed, a process
instructions to accomplish a task or evolves which accomplishes the intended
solve a problem. task or solves the given problem.
3. Initially,
farmer, goat, grass, wolf = L, L, L, L
and the farmer crosses the river with goat.
Model the action with an assignment statement.
SPECIFICATION:
1. – – farmer, goat, grass, wolf = L, L, L, L
2. farmer, goat := R, R
3. – – farmer , goat , grass , wolf = R, R, L, L
4. farmer := L
5. – – farmer, goat, grass, wolf = L, R, L, L
6. farmer, grass := R, R
7. – – farmer , goat , grass , wolf = R, R, R, L
8. farmer, goat := L, L
9. – – farmer, goat, grass, wolf = L, L, R, L

https://csknowledgeopener.com 30 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

10. farmer, wolf := R, R


11. – – farmer , goat , grass , wolf = R, L, R, R
12. farmer : = L
13. – – farmer , goat , grass , wolf = L, L, R, R
14. farmer , goat : = R, R
15. – – farmer , goat , grass , wolf = R, R, R, R
4. Specify a function to find the minimum of two numbers.
ANSWER:
Minimum (A,B,C)
– – Inputs: A, B and C are integers (or) Real numbers
– – Outputs: A is minimum (A<B) and (A<C)
B is minimum (B<A) and B<C)
C is minimum (C<A) and (C<B)
5. 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
ANSWER:
• Yes, It violates the specification. The given input (x>=0) and square_root (x) is also a positive
number. Hence the output will not be negative.
Short Answers (3 mark)
1. When do you say that a problem is algorithmic in nature?
• 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 using input and output data.
2. What is the format of the specification of an algorithm?
Specification format: We can write the specification in a standard three part format:
1. The name of the algorithm and the inputs.
algorithm_name (inputs)
2. Input: the property of the inputs.
– – inputs : P
3. Output: the desired input-output relation.
– – outputs: Q
3. What is abstraction?
• Ignoring or hiding unnecessary details and modeling an entity only by its essential properties is known
as abstraction.

https://csknowledgeopener.com 31 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Example:
• The map-maker picks out the details that we need to know.
4. How is state represented in algorithms?
• The state of a process can be represented by a set of variables in an algorithm.
• The state at any point of execution is simply the values of the variables at that point.
• As the values of the variables are changed, the state changes.
5. What is the form and meaning of assignment statement?
• 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.
• Assignment statement : variable := value
Example:
m := 2
It stores value 2 in variable m.

6. What is the difference between assignment operator and equality operator?


ASSIGNMENT OPERATOR EQUALITY OPERATOR
Assignment Operator: := Equality Operator: =
Assignment operator is used to assign the right Equality operator is used to compare the values of
hand side value into left hand side variable. both right hand side variable and left hand side
variable and results in either true or false.
Example: u:=5 Example: u=v
Explain in Detail (5 mark)
1. Write the specification of an algorithm hypotenuse whose inputs are the lengths of the two
shorter sides of a right angled triangle, and the output is the length of the third side.
1. hypotenuse (a, b)
2. – – inputs: a, b are real numbers, a > 0, b > 0
3. – – outputs: c2 = a2 + b2 where c is real number, c > 0
INPUT: a,b
OUTPUT: c [c2 = a2 + b2]
2. Suppose you want to solve the quadratic equation ax2 + bx + c = 0 by an algorithm.
quadratic_solve (a, b, c)
– – inputs : ?
– – outputs: ?
You intend to use the formula and you are prepared to handle only real number roots. Write a
suitable Specification.

−𝒃𝒃 ± √𝒃𝒃𝟐𝟐 − 𝟒𝟒𝟒𝟒𝟒𝟒


𝑿𝑿 =
𝟐𝟐𝟐𝟐

https://csknowledgeopener.com 32 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

ANSWER:
SPECIFICATION:
Quadratic – solve (a, b, c)
– – inputs: where a, b, c are real numbers, a >= 0
– – outputs: x is real numbers and b2-4ac >0
−𝒃𝒃 ± √𝒃𝒃𝟐𝟐 − 𝟒𝟒𝟒𝟒𝟒𝟒
𝒙𝒙 =
𝟐𝟐𝟐𝟐
3. 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. For exchanging the contents of glasses A and B, represent the state by
suitable variables, and write the specification of the algorithm.
ANSWER:

• Let the variables A,B,C represent the glass A, glass B and Glass C respectively.
• Variables A, B, C can store values APPLE, GRAPE or EMPTY.
Initial State: 1. – –A, B, C := Apple, Grape, Empty
2. C : =B
3. – –A, B, C := Apple, Empty, Grape
4. B :=A
5. – –A, B, C := Empty, Apple, Grape
6. A :=C
Final State 7. – –A, B, C := Grape, Apple, Empty
SPECIFICATION:
1. Exchange ( )
2. – – inputs: A, B, C:= Apple, Grape, Empty
3. – – outputs: A, B, C: = Grape, Apple, Empty
7. COMPOSITION AND DECOMPOSITION
Choose the correct answer: (1 mark)
1. Suppose u, v = 10 ,5 before the assignment. What are the values of u and v after the sequence of
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 -- ?

https://csknowledgeopener.com 33 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

(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
executes
(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
SECTION-B (2 mark)
Very Short Answers
1. Distinguish between a condition and a statement.
CONDITION STATEMENT

• A condition is contained in a diamond-shaped • A statement is contained in a rectangular


box with two outgoing arrows, labeled true box with a single outgoing arrow, which
and false. points to the box to be executed next.

https://csknowledgeopener.com 34 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. Draw a flowchart for conditional statement.

3. Both conditional statement and iterative statement have a condition and a statement. How do
they differ?
CONDITION STATEMENT ITERATIVE STATEMENT
• Iterative statement repeatedly evaluates a
• Conditional statement is executed only if the
condition and executes a statement as long
condition is true. Otherwise, nothing is done.
as the condition is true.
• If, If Else are the examples of Conditional • While, Do While are the examples of
Statements Iterative Statements
4. What is the difference between an algorithm and a program?
ALGORITHM PROGRAM

• An algorithm is a sequence of instructions to • An algorithm expressed in a programming


accomplish a task or solve a problem. language is called a program.
5. Why is function an abstraction?
• After an algorithmic problem is decomposed into sub problems, we can abstract the sub problems as
functions.
• A function can also be specified by its input property, and its input-output relation.
6. How do we refine a statement?
• Each sub problem can be expanded into more detailed steps.
• Each step can be further expanded to still finer steps, and so on.
• This is known as refinement.

https://csknowledgeopener.com 35 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Short Answers (3 mark)


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

PSEUDO CODE:
1. If ( C is True)
2. Prints “S1”
3. Print “S2”

PSEUDO CODE:
1. If ( C is True)
2. Prints “S1”
3. else
4. Print “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
ANSWER:
S1
S3
S4
3. What is case analysis?
• Case analysis statement generalizes it to multiple cases.
https://csknowledgeopener.com 36 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• Case analysis splits the problem into an exhaustive set of disjoint cases.
• For each case, the problem is solved independently.
EXAMPLE:
1. case C1
2. S1
3. case C2
4. S2
5. else
6. S3
4. Draw a flowchart for -3case analysis using alternative statements.

ENTER

IF (C1) S1

IF (C2) S2

IF (C3)
S3

S4

EXIT
5. Define a function to double a number in two different ways: (1) n + n, (2) 2 × n
(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

https://csknowledgeopener.com 37 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

(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 ×n
Example: Double a Value can be done in 2 Methods
n=2 (assume)
1. n+n= 2+2= 4
2. 2×n=2×2= 4
Explain in Detail (5 mark)
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.
ANSWER:
Let the variables a, b, c represent Glass A, Glass B and Glass C and a, b, c can store values APPLE,
GRAPE or EMPTY.
SPECIFICATION:
1. Exchange (a, b)
2. – – inputs: a, b : = APPLE, GRAPE
3. – – outputs: a, b : = GRAPE, APPLE
ALGORITHM:
Initial State: 1. – –a, b, c := Apple, Grape, Empty
2. c :=b
3. – –a, b, c := Apple, Empty, Grape
4. b :=a
5. – –a, b, c := Empty, Apple, Grape
6. a :=c
Final State 7. – –a, b, c := Grape, Apple, Empty
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.

SPECIFICATIONS:
1. circulate
2. – – inputs: a, b, c: = A, B, C
3. – – outputs: a, b, c: = C, A, B
ALGORITHM:
1. circulate (a, b, c)
https://csknowledgeopener.com 38 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. – – a, b, c: = A, B, C
3. temp : = c
4. c : = b
5. b : = a
6. a : = temp
7. – – a, b, c: = C, A, B
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.
(a) MODEL:
Let a, b, c be the variables whose maximum values are 8L, 5L and 3L respectively.
Initial State: a, b, c := 8, 0, 0
Bottel 1 = 8 L Bottel 2 = 5 L Bottel 3 = 3 L
a b c

Final State: a, b, c := 4, 4, 0
Bottel 1 = 8 L Bottel 2 = 5 L Bottel 3 = 3 L
a b c

(b) SPECIFICATION:
decant
– – inputs: a, b, c : = 8, 0, 0
– – outputs: a, b, c : = 4, 4, 0

https://csknowledgeopener.com 39 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

(c) ALGORITHM:
Let us assume that a: = b denotes oil in b is poured into a bottle until either “a” is full or “b” becomes
empty.
decant (a, b, c)
– – a, b, c : = 8, 0, 0
b:=a
– – a, b, c : = 3, 5, 0
c:=b
– – a, b, c : = 3, 2, 3
a:=c
– – a, b, c : = 6, 2, 0
c:=b
– – a, b, c : = 6, 0, 2
b:=a
– – a, b, c : = 1, 5, 2
c:=b
– – a, b, c : = 1, 4, 3
a:=c
– – 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 × i , i + 1
ALGORITHM TRACE:
ITERATION CONDITION n=4 f=f*i (f=1) i = i +1 (i=1)

1 1<=4 (T) f=1x1=1 i=1+1=2


2 2<=4 (T) f=1x2=2 i=2+1=3
3 3<=4 (T) f=2x3=6 i=3+1=4
4 4<=4 (T) f = 6 x 4 = 24 i=4+1=5
5 5<=4 (F)
The value of factorial(4) is 24 LOOP ENDS

8. ITREATION AND RECURSION


Choose the correct answer: (1 mark)
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

https://csknowledgeopener.com 40 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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

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


(a) 3 (b) 4 (c) 8 (d) 9
6. Using this recursive definition

How many multiplications are needed to calculate a10?


(a) 11 (b) 10 (c) 9 (d) 8
Very Short Answers (2 mark)
1. What is an invariant?
• An expression involving variables, which remains unchanged by an assignment to one of these
variables, is called an invariant of the assignment.
2. Define a loop invariant.
• An invariant for the loop body is known as a loop invariant.
• An unchanging property of the variables during loop execution is also called the loop invariant.
3. Does testing the loop condition affect the loop invariant? Why?
• No, the loop conditions do not affect the loop invariant.
• Because each time the loop body is executed repeatedly, the variables are updated. However, there is
also a property of the variables which remains unchanged by the execution of the loop body.
4. What is the relationship between loop invariant, loop condition and the input- output
recursively?
• The loop invariant is true before the loop body and after the loop body, each time.
• When the loop ends, the termination condition and the loop invariant should establish the input-output
relation.
5. What is recursive problem solving?
• Recursion step breaks the problem into sub-problems of smaller size, assumes solutions for sub-
problems are given by recursive calls, and constructs solution to the given problem.
• The input size of a sub-problem is smaller than the input size of the original problem.

https://csknowledgeopener.com 41 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

6. Define factorial of a natural number recursively.

RECURSIVE ALGORITHM:
fact (n)
– – inputs : n
– – outputs : fact = n!
if (n = 0) – – base case
1
else
n * fact (n – 1) – – recursive step
Short Answers (3 mark)
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.)
ANSWER:
Let’s assume,
u – No. of tumblers right side up
v – No. of tumblers upside down
INITIAL STAGE : u = 0, v = 7 (All tumblers upside down)
FINAL STAGE OUTPUT: u = 7, v = 0 (All tumblers right side up)
POSSIBLE ITERATIONS:
(i) Turning both upside down tumblers to right side up
u = u + 2, v = v – 2 [u is even]
(ii) Turning both right side up tumblers to upside down.
u = u – 2, v = v + 2 [u is even]
(iii) Turning one right side up tumblers to upside down and other tumbler from upside down to right side
up.
u = u + 1 – 1 = u, v = v + 1 – 1 = v [u is even]
• Initially u = 0 and continuous to be even in all the three cases.
• Therefore u is always even in all stages.
• Therefore it is not possible to reach a situation where all the tumblers are right side up.
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?
ANSWER:
No. of Players(r) 2 3 4 5 n 1234
No. of games(n) 1 2 3 4 n-1 1234−1=1233

https://csknowledgeopener.com 42 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

EXPLANATION:
• After every game, r will be reduced by 1.
• If r = 2 then n = 1
• As n increases, r decreases. So, n, r : = n + 1, r – 1
n + r = (n + 1) + (r – 1)
=n+1+r–1
=n+r
• Therefore n + r is invariant.
• n + r = 1234 (No. of players initially)
• The winner (only one player) of the tournament that is left after all other players have been
knocked out.
• i. e. n = 1
• n + r = 1234
• 1 + r = 1234
• r = 1234 – 1 = 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.)
ANSWER:
No. of heads of dragon = 1000
Sword 1 = cuts 19 heads but 13 heads grow back.
Sword 2 = cuts 7 heads but 22 heads grow back.
n = number of heads of the dragon at initial state.
Case 1: King uses Sword 1
n : = n – 19 + 13
=n–6
No. of heads are reduced by 6.
Case 2: King uses Sword 2
n : = n – 7 + 22
= n + 15
No. of heads are increased by 15.
NOTE:
• In the above two cases either 6 heads are removed or 15 heads added.
• Both 6 and 15 are multiples of 3.
• Therefore repeating case 1 and case 2 recursively will either reduce or increase dragon heads in
multiples of 3.
• That is the invariant is n mod 3.
• If n mod 3 = 0 then there is a possibility that the dragon dies.
• But 1000 is not a multiple of 3, 1000 mod 3 = 1
• i.e 1 ≠ 0
• So, It is not possible to kill the dragon.

https://csknowledgeopener.com 43 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• The dragon never dies.


Explain in Detail (5 mark)
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|).
ANSWER:
The letter B is used for black square and W is used for white square.
• Consider the chessboard as starting with a white square.
• The first row will have 4 white and 4 black squares. (B = 4 & W = 4)
1) If we coloring the first square (white) to black square then B = 5 & W = 3
2) If we coloring the second square (black) to white square then B = 4 & W = 4
• If we repeat 1 & 2, we will have the value B=4 & W=4 at the end of the first row.
• The above result applies to all the rows. Therefore, it is not possible to coloring all the squares on the
chessboard to one black color.
2. Power can also be defined recursively as

Construct a recursive algorithm using this definition. How many multiplications are needed to
calculate a10?
ANSWER:
power (5, 2) = 5 x 5 = 25
power (a, n) raise a to the power n
ALGORITHM:
power(a,n)
if n=0 --base case
1
else --recursion step
if n is odd
a * power(a,n-1)
else
p = power(a, n/2)
p*p

https://csknowledgeopener.com 44 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

TO FIND a10 :

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.
ANSWER:
This problem can be solved using recursion.
• A corner-covered board is a board of 2n x 2n squares in which the square at one corner is covered with
a single square tile.

• In the recursion step, divide the corner-covered board of size 2n x 2n into 4 sub-boards, by drawing
horizontal and vertical lines through the centre of the board.

https://csknowledgeopener.com 45 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• Place a triominoe (L-shaped tile) at the center of the entire board so as to not cover the corner-covered
sub-board.

• Now, we have four corner-covered boards, each of size 2n-1 x 2n-1


Recursive process of covering a corner-covered board of size 2 x 23

• When place a triominoe (L-shaped tile)


• 23x23corner-covered board is covered with triominoes without overlap by recursion.
9. INTRODUCTION TO C++
Choose the correct answer (1 mark)
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

https://csknowledgeopener.com 46 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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 in C++?
(a) >> (b) << (c) <> (d) ^^
6. Which of the following statements is not true?
(a) Keywords are the reserved words which 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 consist 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
Very Short Answers (2 mark)
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 a Lexical unit
• C++ has the following tokens:
 Keyword
 Identifiers
 Literals
 Operators
 Punctuators
2. What are keywords? Can keywords be used as identifiers?
• Keywords are the reserved words which convey specific meaning to the C++ compiler.
• Reserved words or keywords cannot be used as an identifier name.
3. The following constants are of which type?
(i) 39 (ii) 032 (iii) 0XCAFE (iv) 04.14
i) 39 – Integer
ii) 032 – Octal
iii) OXCAFE – Hexadecimal
iv) 04.14 – Floating Point
4. Write the following real constants into the exponent form:
(i) 23.197 (ii) 7.214 (iii) 0.00005 (iv) 0.319
i) 23.197 = 0.23197 x 10 2
=> 0.23197E02
ii) 7.214 = 0.7214 x 101 => 0.7214E01
iii) 0.00005 = 0.5 x 10 -4
=> 0.5E – 04

https://csknowledgeopener.com 47 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

iv) 0.319 = 3.19 x 10-1 => 0.0319E-01


5. Assume n=10; what will be result of n++ and --n?
Result:
n++  n=10+111
--n  n-1=10-1 9
6. Match the following
A B
a) Modulus 1) Tokens
b) Separators 2) Remainder of a division
c) Stream extraction 3) Punctuators
d) Lexical Units 4) get from
Answer: a-2; b-3; c-4, d-1
A B
a) Modulus 2) Remainder of a division
b) Separators 3) Punctuators
c) Stream extraction 4) get from
d) Lexical Units 1) Tokens
Short Answers (3 mark)
1. Describe the differences between keywords and identifiers?
Keywords Identifiers
• Keywords are the reserved words which • Identifiers are the user-defined names given
convey specific meaning to the C++ to the variables, functions, arrays, classes
compiler. etc.
• They are the essential elements to construct • These are the fundamental building blocks
C++ programs. of a program.
• Example: Switch, for, if, etc., • Example: name, age, class, etc.,
2. Is C++ case sensitive? What is meant by the term “case sensitive”?
• Yes, C++ is case sensitive as it treats upper and lower-case characters differently.
• All the keywords must be in lowercase
3. Differentiate “=” and “==”.
“=” “= =”
• ‘= =’ is an equal to operator and it is a
• ‘=’ is an assignment operator
relational operator.
• It is used to assign the value of variable or • It is used for compare two values and the
expression result will be either true or false
• Example: x==y (x value will be compared
• Example: x=y (y value is assigned to x)
with y value)

https://csknowledgeopener.com 48 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

4. What is the use of a header file?


• #include<iostream> statement tells the compiler’s preprocessor to include the header file “iostream”
in the program.
• The header file “iostream” should be included to implement input/output functionalities.
• In simple words, “iostream” header file contains the definition of its member objects cin and cout.
5. Why is main function special?
• The main( ) function in the C++ program is the starting point.
• All the programs begin their execution in main().
• Therefore, the executable statements should be inside the main( ) function.
Explain in Detail (5 mark)
1. Write about Binary operators used in C++.
Binary Operators - Require two operands and one operator
C++ Binary Operators are classified as:
(1) Arithmetic Operators
(2) Relational Operators
(3) Logical Operators
(4) Assignment Operators
(5) Conditional Operator
(1) Arithmetic Operators
• Arithmetic operators perform simple arithmetic operations like addition, subtraction,
multiplication, division etc.,
• Support both unary and binary operations.
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (To find the reminder of a division)
(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 (True
/1 ) or (False/0).
Operator Operation
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal

https://csknowledgeopener.com 49 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

(3)Logical Operators
• A logical operator is used to evaluate logical by combining two relational expressions into one.
• The logical operators act upon the operands that are themselves called as logical expressions.
• AND, OR both are binary operators and NOT is a unary operator.
Operator Operation
&& AND
|| OR
! NOT
(4)Assignment Operator:
• = (equal to) is the Assignment operator is used to assign a value on the right hand side to a
variable which is on the left hand side .
• It is also a binary operator.
Operator Name of Operator
+= Addition Assignment
-= Subtraction Assignment
*= Multiplication Assignment
/= Division Assignment
%= Modulus Assignment
(5) Conditional Operator:
• ?: is a conditional Operator which is also known as Ternary Operator.
• This operator is used as an alternate to if … else control statement.
2. What are the types of Errors?
Type of Error Description
• Syntax is a set of grammatical rules to construct a program.
• Syntax errors occur when grammatical rules of C++ are violated.
Syntax Error • Example: if you type as follows, C++ will throw an error.
cout << “Welcome to Programming in C++”
• A Program has not produced expected result even though the program is
grammatically correct.
Semantic Error • It may be happened by wrong use of variable / operator / order of execution etc.
• So, Semantic error is also called as “Logical Error”.
• A run time error occurs during the execution of a program.
Run-time error • It occurs because of some illegal operation that takes place.
• Example: If a program tries to open a file which does not exist, it results in a
run-time error
DATA TYPES, VARIABLES AND EXPRESSIONS
Choose the correct answer (1 Mark)
1. How many categories of data types are 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

https://csknowledgeopener.com 50 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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 is allocated 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?
char ch = ‘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 (c) \0 (d ) \n
Very Short Answers (2 Mark)
1. Write a short note on const keyword with an example.
• const is the keyword used to declare a constant.
• const keyword modifies / restricts the accessibility of a variable.
• It is known as Access modifier.
For example,
int num = 100;
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.
4. What is a reference variable? What is its use?
• A reference provides an alias for a previously defined variable.
• Declaration of a reference consists of base type and an & (ampersand) symbol; reference variable
name is assigned the value of a previously declared variable.
Syntax: <type> <& reference_variable> = <original_variable>;
https://csknowledgeopener.com 51 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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


char ch = 67; char ch = ‘C’;
Yes, they are equal
• 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 56
• The suffix L forces the constant to be • This will be represented as int type
represented as long, which occupies 4 constant which occupies 2 bytes as per
bytes. Turbo C++.
7. Determine which of the following are valid constant? And specify their type.
(i) 0.5 (ii) ‘Name’ (iii) ‘\t’ (iv) 27,822
i) 0.5 – is a valid Floating constant.
ii) ‘Name’ – Invalid constant as single quote is not allowed.
iii) ‘\t’ – Escape sequence (or) non – graphical character (horizontal tab).
iv) 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 to do the above.
Answer:
double x=11.5; y=3.5;
int a,b;
a = int (x)
b = 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.
(i) int a; a = 3,014; (ii) int a; a=(3,014);
Answer:
i) int a; a = 3,014;  Invalid statement,
ii) int a; a=(3,014); is a valid statement, '014' is considered as an octal number and gives its equivalent
decimal value '12'.
Short Answers (3 Mark)
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.,
• The arithmetic operators are binary operators which requires minimum of two operands.

https://csknowledgeopener.com 52 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Unary Operators Binary Operators


• Require only one operand • Require two operands
• Ex: +, -, *, /, %, >, <, <=, AND, OR • Ex: ++ (Plus, Plus) Increment operator, – –
(Minus, Minus) Decrement operator, NOT, ~,
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;
(i) n = x + y / x; (ii) z = m * x + y; (iii) z *= x * m + x;
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)
10. FLOW OF CONTROL
Choose the correct answer (1 Mark)
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 be 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 branch 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

https://csknowledgeopener.com 53 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

9. Which of the following is called 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
Very Short Answers (2 Mark)
1. What is a null statement and compound statement?
Null Statement
• The "null or empty statement" is a statement containing only a semicolon which is used as
placeholders in iteration statements or as statements on which to place labels at the end of compound
statements or functions.
; // it is a null statement
Compound Statement:
• The group of statements enclosed by pair of braces {} is called as a compound statement or a block.
General Format:
{
statement1;
statement2;
statement3;
}
2. What is selection statement? write it's types?
• Selection statements are executed depending upon the conditional expression evaluates either true or
false.
Types:
• if statement
• if-else statement
• Nested if
• if -else-if ladder
• Alternative to if- else (?:)
• Switch statement
3. Correct the following code segment : if (x=1)
p= 100;
else
p = 10;
Corrected Coding:
if (x==1)  Relational operator should be used instead of assignment operator
p= 100;
else
p = 10;
4. What will be the output of the following code:
int year;
cin >> year;
if (year % 100 == 0)
https://csknowledgeopener.com 54 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

if ( year % 400 == 0)
cout << "Leap";
else
cout << "Not Leap year";
If the input given is (i) 2000 (ii) 2003 (iii) 2010?
Output:
i) Leap year
ii) Not Leap year
iii) Not Leap year
5. What is the output of the following code?
for (int i=2; i<=10 ; i+=2)
cout << i;
Output:
2 4 6 8 10
6. Write a for loop that displays the number from 21 to 30.
CODE:
for (int i=21; i<=30 ; i++)
cout << i;
7. Write a while loop that displays numbers 2, 4, 6, 8.......20.
Coding:
int i=2;
while(i<=20)
{
cout<<i<< "\t";
i+=2;
}
8. Compare an if and a ? : operator.
if ?:
• The if statement evaluates a condition, if • In the conditional operator or Ternary operator
the condition is true then a true-block (?:) the expression 1 is a condition which is
statements will be executed, otherwise the evaluated, if the condition is true, then the
true-block is skipped control is transferred to expression 2,
otherwise, the control passes to expression 3.
Syntax: Syntax:
if (expression)
true-block; expression 1? expression 2 : expression 3
statement-x;
Short Answers (3 Mark)
1. Convert the following if-else to a single conditional statement:
if (x >= 10)
a = m + 5;

https://csknowledgeopener.com 55 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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,total=0;
do
{
total+=v;
cout<<total;
v=v+1;
} while (v<=10);
3. Write a C++ program to print multiplication table of a given number.
Coding:
#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;
}
4. Write the syntax and purpose of switch statement.
Syntax:
switch(expression)
{
case constant 1:
statement(s);

https://csknowledgeopener.com 56 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

break;
case constant 2:
statement(s);
break;
.
.
default:
statement(s);
}
Purpose:
• The switch statement is a multi-way branch statement which provides an easy way to dispatch
execution to different parts of code based on the value of the expression.
• It replaces multiple if-else sequence.
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(int i=1; i<=40; i+=3)
{
cout<<i<<"\t";
}
return 0;
}
Explain in detail (5 Mark)
1. Explain control statement with suitable example.
• Control statements are statements that alter the sequence of flow of instructions.
A) SEQUENCE STATEMENT
• The sequential statement are executed one after another only once from top to bottom.
• The statements do not alter the flow of execution are called as sequential flow statements.

B) SELECTION STATEMENT
• The selection statement means the statement (s) executed depend upon a condition.
• If a condition is true, a true block (a set of statements) is executed otherwise a false block is executed.

https://csknowledgeopener.com 57 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• This statement is also called decision statement or selection statement.

C) ITERATION STATEMENT
• The iteration statement is a set of statement that are repetitively executed based upon a conditions.
• If a condition evaluates to true, the set of statements (true block) is executed again and again.
• This is also known as looping statement or iteration statement.
• The condition on which the execution or exit from the loop is called exit-condition or test-condition.

2. What is an entry control loop? Explain any one of the entry controlled loop with suitable
example.
Entry Controlled Loop:
• The for loop is an entry- controlled loop.
• It is the easiest looping statement which allows code to be executed repeatedly.
• It contains three different statements (initialization, condition or test-expression and update
expression(s)) separated by semicolons.
Syntax:
for (initialization(s); test-expression; update expression(s))
{
Statement 1;
Statement 2;
………….
}
Statement-x;

https://csknowledgeopener.com 58 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Working of for loop:


• The initialization part is used to initialize variables or declare variable which are executed only once,
then the control passes to test-expression.
• After evaluation of test-expression, if the result is false, the control transferred to statement-x.
• If the result is true, the body of the for loop is executed, next the control is transferred to update
expression.
• After evaluation of update expression part, the control is transferred to the test-expression part.
• Next the steps 3 to 5 is repeated. The workflow of for loop and flow chart are shown below.
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;
}
3. Write a program to find the LCM and GCD of two numbers.
#include<iostream>
using namespace std;
int main()
{
int a, b, x, y, temp, gcd, lcm;
cout<<"\n Enter Two Numbers : \n";
cin>>x>>y;
a = x;
b = y;
while(b !=0 )
{
temp = b;
b = a % b;
a = temp;
}
hcf = a;
lcm = (x * y) / hcf;
cout<<"\n GCD : "<<gcd<<"\n";
cout<<"\n LCM : "<<lcm<<"\n";
return 0;
}

https://csknowledgeopener.com 59 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Output:
Enter two numbers
20
30
GCD=10 LCM=60
4. Write programs to find the sum of the following series:

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int fact(int n)
{
int f=1;
for(int i=1;i<=n;i++)
f*=i;
return f;
}
int main()
{
int x,s=1;
float sum=0;
cout<<"Enter the value for x:";
cin>>x;
for(int i=1;i<=6;i++)
{
sum=sum+s*(pow(x,i)/fact(i));
s*=-1;
}
cout<<"Sum of series is "<<sum<<endl;
getch();
return 0;
}

#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
int x,n;

https://csknowledgeopener.com 60 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

float sum=0;
cout<<"Enter the value for x:";
cin>>x;
cout<<"Enter number of terms:";
cin>>n;
for(int i=1;i<=n;i++)
sum=sum+pow(x,i)/i;
cout<<"Sum of series is "<<sum<<endl;
getch();
return 0;
}
5. Write a program to find sum of the series
S = 1 + x + x2 +..... + xn
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
int x,n;
float sum=0;
cout<<"Enter the value for x";
cin>>x;
cout<<"Enter number of terms";
cin>>n;
for(int i=1;i<=n;i++)
sum=sum+pow(x,i);
cout<<"Sum of series is "<<sum<<endl;
getch();
return 0;
}
11. FUNCTIONS
Choose the correct answer (1 Mark)
1. 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
2. Which function is used to check whether a character is alphanumeric or not.
A) isalpha() B) isdigit() C) isalnum() D) islower()
3. Which function begins the program execution ?
A) isalpha() B) isdigit() C) main() D) islower()
4. 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)

https://csknowledgeopener.com 61 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

5. Which is return data type of the function prototype of add(int, int); ?


A) int B) float C) char D) double
6. Which of the following is the scope operator ?
A) > B) & C) % D) ::
Very Short Answers (2 Mark)
1. Define Functions.
• A large program can be split into small sub-programs (blocks) called as functions where each sub-
program can perform some specific functionality.
2. Write about strlen() function.
• The strlen() takes a null terminated string as its argument and returns its length.
• The length does not include the null(\0) character.
General Form:
strlen(string)
3. What are importance of void data type.
• To indicate the function does not return a value
• To declare a generic pointer.
4. What is Parameter and list its types?
• Arguments or parameters are the means to pass values from the calling function to the called function.
Types:
• Formal Parameters.
• Actual Parameters.
5. Write a note on Local Scope.
• A local variable is defined within a block begins and ends with curly braces { }.
• The scope of a local variable is the block in which it is defined and cannot be accessed from outside the
block of its declaration.
Short Answers (3 Mark)
1. What is Built-in functions?
• 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.
2. What is the difference between isupper() and toupper() functions ?
isupper() toupper()
• This function is used to check the given • This function is used to convert the given
character is uppercase. character into its uppercase.
• This function will return 1 if true otherwise 0. • 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.

https://csknowledgeopener.com 62 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

General Form: General Form:


isupper(char c) char toupper(char c);

3. Write about strcmp() function.


• The strcmp() function takes two arguments: string1 and string2.
• It compares the contents of string1 and string2 lexicographically.
General Form: strcpy(String1, String2)
The strcmp() function returns a,
• Positive value  string1 is greater than string2.
• Negative value  string1 is less than string2.
• 0  string1 and string2 are equal.
EXAMPLE: strcmp(“HELLO”,”HELLO”);  0
4. Write short note on pow() function in C++.
• The pow() function returns base raised to the power of an 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:
• base - the base value
• exponent - exponent of the base
5. What are the information the prototype provides to the compiler?
• The function prototype provides details about the return data type, name of the function and a list of
formal parameters or arguments.
Example:
• int display(int, int) // function prototype//
• The return value of the function is of type int.
• display is the name of the function.
• The function is called with two arguments of int data type.
6. What is default arguments? Give example.
• 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.
• When calling a function,
• For any missing arguments, complier uses the values in default arguments for the called function.
• The default value is given in the form of variable initialization.
Example : void defaultvalue(int n1, n2=100);
Explain in detail (5 Mark)
1. Explain Call by value method with suitable example.
• Call by value 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.
https://csknowledgeopener.com 63 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Example:
#include<iostream>
using namespace std;
void display(int x)
{
int a=x*x;
cout<<"\n\nThe Value inside display function:"<<a;
}
int main()
{
int a=5;
display(a);
cout<<"\n\nThe Value inside main function "<<a;
return(0);
}
2. What is Recursion? Write a program to find the factorial of the given number using recursion.
• A function that calls itself is known as recursive function.
• And, this technique is known as recursion.
Example to find Factorial of a Number Using Recursion:
#include <iostream>
using namespace std;
int factorial(int); // Function prototype //
int main()
{
int n=5;
cout << "\n Factorial of Number " << no <<" = " << factorial(n);
return 0;
}
int factorial(int m)
{
if (m > 1)
return m*factorial(m-1);
else
return 1;
}
3. What are the different forms of function return? Explain with example.
(I) A FUNCTION WITHOUT RETURN VALUE AND WITHOUT PARAMETER:
• The function accepts no value as a parameter and does not return any value to the call function.
• The name of the function is display(), its return data type is void and it does not have any argument.
Example:
#include<iostream>
using namespace std;

https://csknowledgeopener.com 64 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

void display()
{
cout<<"WELCOME";
}
int main()
{
display();
return(0);
}
II) A FUNCTION WITH RETURN VALUE AND WITHOUT PARAMETER:
• The name of the function is display(), its return type is int and it does not have any argument.
• The return statement returns a value to the calling function and transfers the program control back to
the calling statement.
Example:
#include<iostream>
using namespace std;
int display()
{
int a=5, b=5, s;
s=a+b;
return s;
}
int main()
{
int m=display();
cout<<"\nThe Sum="<<m;
return(0);
}
(III) A FUNCTION WITHOUT RETURN VALUE AND WITH PARAMETER:
• The name of the function is display(), its return type is void and it has two parameters or arguments x
and y to receive two values.
• The return statement returns the control back to the calling statement.
Example:
#include<iostream>
using namespace std;
void display(int x, int y)
{
int s=x+y;
cout<<"The Sum of Passed Values: "<<s;
}
int main()
{

https://csknowledgeopener.com 65 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

int a=5,b=5;
display(a,b);
return(0);
}
(IV) A FUNCTION WITH RETURN VALUE AND WITH PARAMETER:
• The name of the function is display(), its return type is int and it has two parameters or arguments x
and y to receive two values.
• The return statement returns the control back to the calling statement.
Example:
#include<iostream>
using namespace std;
int display(int x, int y)
{
int s=x+y;
return s;
}
int main()
{
int a=5,b=5;
int s=display(a,b);
cout<<"\nThe Sum of Passed Values: "<<s;
return(0);
}
4. Explain scope of variable with example.
• Scope refers to the accessibility of a variable.
• A scope is a region or life of the variable, where variables can be declared,
Types Of Scopes:
i) 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.
• Example:
if(a>5)
{
int t; // local to this if block
}
ii) Function Scope:
• The scope of variables declared within a function is extended to the function block, and all sub-
blocks therein.
• The life time of a function scope variable, is the life time of the function block.

https://csknowledgeopener.com 66 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• The scope of formal parameters is function scope.


• Example:
void add(int x)
{
int m; //Declaration of variable m in add ()
cout<<m;
}
iii) File Scope:
• A variable declared above all blocks and functions (including main ( ) ) has the scope of a file.
• The life time of a file scope variable is the life time of a program.
• The file scope variable is also called as global variable.
Example:
#include<iostream>
using namespace std;
int file_var=20; //Declared within File
void add(int x)
{
}
int main ( )
{
}
Class Scope:
• A class is a new way of creating and implementing a user defined data type.
• Classes provide a method for packing together data of different types.
• Data members are the data variables that represent the features or properties of a class.
class student The class student contains mark1, mark2 and
{ total are data variables. Its scope is within the
private : class student only.
int mark1, mark2, total;
};
5. Write a program to accept any integer number and reverse it.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int num,r,rev=0;

https://csknowledgeopener.com 67 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

cout<<"Enter a positive integer:";


cin>>num;
while(num>0)
{
r=num%10;
num=num/10;
rev=rev*10+r;
}
cout<<"The reversed number is"<<rev;
getch();
return 0;
}
OUTPUT:

12. ARRAYS AND STRUCTURES


Choose the correct answer (1 Mark)
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
2. int age[]={6,90,20,18,2}; How many elements are there in this array?
a) 2 b) 5 c) 6 d) 4
3. cin>>n[3]; To which element does this statement accept the value?
a) 2 b) 3 c) 4 d) 5
4. By default, a string ends with which character?
a)\0 b) \t c) \n d) \b
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
https://csknowledgeopener.com 68 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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 the dot operator is the name of
(a) structure variable (b) structure tag (c) structure member (d) structure function
Very Short Answers (2 Mark)
1. What is Traversal in an Array?
• 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”.
2. What is Strings?
• A string is defined as a sequence of characters where each character may be a letter, number or a
symbol.
• Every string is terminated by a null (‘\0’, ASCII code 0) character which must be appended at the end
of the string.
3. What is the syntax to declare two – dimensional array.
• The declaration of a 2-D array is
data-type array_name[row-size][col-size];
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 variables of mixed data types together into a single unit.
• Structure is declared using the keyword ‘struct.
5. What is the error in the following structure definition.
struct employee{ inteno;charename[20];char dept;}
Employee e1,e2;
Answer
struct employee
{
int eno;
char ename[20];
char dept;
}
employee e1,e2;

https://csknowledgeopener.com 69 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Short Answers (3 Mark)


1. Define an Array? What are the types?
• An array is a collection of variables of the same type that are referenced by a common name.
• Types Of Arrays :
• One-dimensional arrays
• Two-dimensional arrays
• Multi-dimensional arrays
2. Write note an Array of strings.
• 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.
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.
struct student {int exam no,lang,eng,phy,che,mat,csc,total;char name[15];};
int main()
{
student s[20];
for(int i=0;i<20;i++)
{ …………………….. //accept student details }
for(int i=0;i<20;i++)
{
…………………….. //check for name starts with letter “S”
……………………. // display the detail of the checked name
}
return 0;
}
Answer
struct student {int exam no,lang,eng,phy,che,mat,csc,total;char name[15];};
int main()
{
student s[20];
for(int i=0;i<20;i++)
{
Cout<<”Enter the students name one by one:”;
Cin>>name[i];
}
for(int i=0;i<20;i++)
{
if(name[0]==’s’)
Cout<<name[i];
https://csknowledgeopener.com 70 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

}
return 0;
}
4. How to access members of a structure? Give example.
• Once the objects of structure type are declared their members can be accessed directly.
• The syntax for that is using a dot (.) between the object name and the member name.
• For example, the elements of the structure Student can be accessed as follows by using the structure
objects balu:
balu.rollno
balu.age
balu.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;
} student;
• 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 .
Explain in detail (5 Mark)
1. Write a C++ program to find the difference between two matrix.
#include<iostream>
using namespace std;
int main()
{
int arr1[3][3], arr2[3][3], arr3[3][3], sub, i, j;
cout<<"Enter 3*3 Array 1 Elements : \n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>arr1[i][j];
}
}
cout<<"Enter 3*3 Array 2 Elements : \n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)

https://csknowledgeopener.com 71 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

{
cin>>arr2[i][j];
}
}
cout<<"Difference between two matrix ... \n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
arr3[i][j]=arr1[i][j]-arr2[i][j];
}
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cout<<arr3[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}

OUTPUT

https://csknowledgeopener.com 72 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. Write a C++ program to add two distances using the following structure definition
struct Distance{
int feet;
float inch;
}d1 , d2, sum;
CODING
#include <iostream>
using namespace std;
struct Distance{
int feet;
float inch;
}d1 , d2, sum;
int main()
{
cout << "Enter first distance" << endl;
cout << "Enter feet: ";
cin >> d1.feet;
cout << "Enter inch: ";
cin >> d1.inch;
cout << "\nEnter information for second distance" << endl;
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 << endl << "Sum of distances = " << sum.feet << " feet " << sum.inch << " inches";
return 0;
}
OUTPUT

https://csknowledgeopener.com 73 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

3.Write the output of the following c++ program


#include<iostream>
#include<stdio.h>
#include <string.h>
#include<conio.h>
using namespace std;
struct books {
char name[20], author[20];
} a[2];
int main()
{ cout<< "Details of Book No " << 1 << "\n";
cout<< "------------------------\n";
cout<< "Book Name :"<<strcpy(a[0].name,"Programming ")<<endl;
cout<< "Book Author :"<<strcpy(a[0].author,"Dromy")<<endl;
cout<< "\nDetails of Book No " << 2 << "\n";
cout<< "------------------------\n";
cout<< "Book Name :"<<strcpy(a[1].name,"C++programming" )<<endl;
cout<< "Book Author :"<<strcpy(a[1].author,"BjarneStroustrup ")<<endl;
cout<<"\n\n";
cout<< "================================================\n";
cout<< " S.No\t| Book Name\t|author\n";
cout<< "====================================================";
for (int i = 0; i < 2; i++) {
cout<< "\n " << i + 1 << "\t|" << a[i].name << "\t| " << a[i].author;
}
cout<< "\n=================================================";
return 0;
}
OUTPUT

https://csknowledgeopener.com 74 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

4. Write the output of the following c++ program


#include <iostream>
#include <string.h>
using namespace std;
struct student
{
int roll_no;
char name[10];
long phone_number;
};
int main(){
student p1 = {1,"Brown",123443},p2;
p2.roll_no = 2;
strcpy(p2.name ,"Sam");
p2.phone_number = 1234567822;
cout<< "First Student" <<endl;
cout<< "roll no : " << p1.roll_no <<endl<< "name : " << p1.name <<endl;
cout<< "phone no : " << p1.phone_number <<endl;
cout<< "Second Student" <<endl;
cout<< "roll no : " << p2.roll_no <<endl<< "name : " << p2.name <<endl;
cout<< "phone no : " << p2.phone_number <<endl;
return 0;
}
OUTPUT

https://csknowledgeopener.com 75 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

5. Debug the error in the following program CORRECT CODE


#include <istream.h> #include <iostream>
structPersonRec using namespace std;
{ struct PersonRec
charlastName[10]; {
chaefirstName[10]; string firstName[10];
int age; string lastName[10];
} int age[10];
PersonRecPeopleArrayType[10]; };
void main() int main()
{ {
PersonRecord people; PersonRec people;
for (i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
cout<<people.firstName<< ‘ ‘ <<people.lastName cout<< "Enter first name: ";
<<people.age; cin>>people.firstName[i];
} cout<< "Enter last name: ";
for (int i = 0; i < 10; i++) cin>>people.lastName[i];
{ cout<< "Enter age: ";
cout<< "Enter first name: "; cin>>people.age[i];
cin<<peop[i].firstName; }
cout<< "Enter last name: "; for (int i = 0; i < 10; i++)
cin>>peop[i].lastName; {
cout<< "Enter age: "; cin>> people[i].age;} cout<<people.firstName[i]<< '\t'
} <<people.lastName[i]<< '\t' <<people.age[i]<< '\n';
}
return 0;
}
OUTPUT:

https://csknowledgeopener.com 76 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

13. INTRODUTION TO OBJECT ORIENTED PROGRAMMING TECHNIQUES


Choose the correct answer (1 Mark)
1. The term is used to describe a programming approach based on classes and objects is
(A) OOP (B) POP (C) ADT (D) SOP
2. The paradigm which aims more at procedures.
(A) Object Oriented Programming (B)Procedural programming
(C) Modular programming (D)Structural programming
3. Which of the following is a user defined data type?
(A) class (B) float (C) int (D) object
4. The identifiable entity with some characteristics and behaviour is.
(A) class (B) object (C) structure (D) member
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
6. Insulation of the data from direct access by the program is called as
(A) Data hiding (B) Encapsulation (C) Polymorphism (D) Abstraction
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
8. Which of the following is the most important advantage of inheritance?
(A) data hiding (B) code reusability (C) code modification (D) accessibility
9. “Write once and use it multiple time” can be achieved by
(A) redundancy (B) reusability (C) modification (D) composition
10. Which of the following supports the transitive nature of data?
(A) Inheritance (B) Encapsulation (C) Polymorphism (D) Abstraction
Very Short Answers (2 Mark)
1. How is modular programming different from procedural programming paradigm?
Modular Programming Procedural Programming
• Modular programming consist of a list of • Procedural means a list of instructions were
instructions that instructs the computer to do given to the computer to do something.
something.
• Emphasis on algorithm rather than data • Emphasis on doing things.
• Programs are divided into individual modules • Programs are organized in the form of
subroutines or sub programs
2. Differentiate classes and objects.
Classes Objects
• Class is a user defined data type. • Objects are the basic unit of OOP.
• Class represents a group of similar objects. • Objects represents data and associated function
• Class is a blueprint representing a group objects together in to a single unit.
that share common properties and relationship. • An object is created from a class. They are
instances of class also called as class variables
3. What is polymorphism?
• Polymorphism is the ability of a message or function to be displayed in more than one form.

https://csknowledgeopener.com 77 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

4. How is encapsulation and abstraction are interrelated?


• 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.
5. Write the disadvantages of OOP.
• Size: Object Oriented Programs are much larger than other programs.
• Effort: Object Oriented Programs require a lot of work to create.
• Speed:
• Object Oriented Programs are slower than other programs, because of their size.
Short Answers (3 Mark)
1. What is paradigm? Mention the different types of paradigm.
• Paradigm is an approach to organize the principle of a program.
• There are different approaches available for problem solving using computer.
• They are Procedural programming, Modular Programming and Object Oriented Programming
2. Write a note on the features of procedural programming.
• Programs are organized in the form of sub programs
• All data items are global
• Suitable for small sized software application
• This is time consuming.
• Example: FORTRAN and COBOL.
3. List some of the features of 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.
4. What do you mean by modularization and software reuse?
• Modularisation: Where the program can be decomposed into modules.
• Software re-use: Where a program can be composed from existing and new modules.
5. Define information hiding.
• Data and Functions are bound together into a single unit is known as Encapsulation.
• Encapsulation of data from direct access by the program is called data hiding or information hiding.
Explain in detail (5 Mark)
1. Write the differences between Object Oriented Programming and procedural programming
Object Oriented Programming Procedural Programming
• Data and its associated operations are grouped • Programs are organized in the form of
into single unit using classes and objects. subroutines or subprograms.

https://csknowledgeopener.com 78 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• OOPS emphasizes on data rather than • Procedural programming emphasis on


algorithm doing things.
• All data items are global

• Programs are designed around the data being • Difficult to maintain and enhance the
operated. program code as any change in data type
needs to be propagated to all subroutines
that use the same data type.

• Example: C++, Java, VB.Net, Python etc. • Example: FORTRAN and COBOL.

2. What are the advantages of OOPs?


a) Re-usability:
• “Write once and use it multiple times” you can achieve this by using class.
b) 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.
c) Easy Maintenance:
• It is easy to maintain and modify existing code as new objects can be created with small differences to
existing ones.
d) Security:
• Using data hiding and abstraction only necessary data will be provided thus maintains the security of
data.
3 Write a note on the basic concepts that supports OOPs?
Main Features of Object Oriented Programming
Encapsulation
• Data and Functions are bound together into a single unit is known as Encapsulation.
• Encapsulation is about binding the data variables and functions together in class. It can also be called
data binding.
• 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.
• 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).

https://csknowledgeopener.com 79 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• 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.
14. CLASSES AND OBJECTS
Choose the correct answer (1 Mark)
1. The variables declared inside the class are known as
(A) data (B) inline (C) method (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 ........ functions
(A) inline (B) Non inline (C) Outline (D) Data
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
Very Short Answers (2 Mark)
1. What are called members?
• Class comprises of members called as Data Members and Member functions.
• Data members are the data variables that represent the features or properties of a class.
• Member functions are the functions that perform specific tasks in a class.
https://csknowledgeopener.com 80 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. Differentiate structure and class though both are user defined data type.
• The only difference between structure and class is the members of structure are by default public
where as it is private in class.
3. What is the difference between the class and object in terms of oop?
Class Object
• A class is a template that represents a group of • An identifiable entity with some
objects that share common properties and characteristics and behaviour is called
relationship. object.
• Class is a way to bind the data and its • The class variables are called object or
associated functions together. instance of class.
Example: Example:
Class Stud Stud s;
“Stud” is a class “s” is a object of class Stud.
4. Why it is considered as a good practice to define a constructor though compiler can
automatically generate a constructor?
• The compiler generates a constructor, in the absence of a user defined constructor.
• Declaring a constructor with arguments hides the compiler generated constructor.
• The constructor is executed automatically when the object is created
• It is a good practice to define a constructor, because it can be used explicitly to create new object of its
class type.
5. Write down the importance of 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 a object.
Short Answers (3 Mark)
1. Rewrite the following program after removing the syntax errors if any and underline the errors:
#include<iostream>
$include<stdio>
class mystud
{ int studid =1001;
char name[20];
public
mystud( ) { }
void register ( )
{cin>>stdid; gets(name); }
void display ( )
{cout<<studid<<”: “<<name<<endl;}
}
int main( )
{ mystud MS;
register.MS( );
MS.display( );

https://csknowledgeopener.com 81 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

}
CORRECT CODE
#include<iostream>
#include<stdio.h>
using namespace std;
class mystud
{
int studid;
char name[20];
public:
mystud()
{
cout<<"Enter the Stud id:";
cin>>studid;
}
void reg()
{
cout<<"Enter the Name:";
cin>>name;
cout<<"Student Id"<<'\t'<<"Name"<<'\n';
}
void display()
{
cout<<studid<<'\t'<<'\t'<<name<<endl;
}
};
int main()
{
mystud MS;
MS.reg();
MS.display();
return 0;
}
OUTPUT
Enter the Stud id: 1001
Enter the Name: CSKNOWLEDGEOPENER
Student Id Name
1001 CSKNOWLEDGEOPENER
=== Code Execution Successful ===
2. Write with example how will you dynamically initialize objects?
• When the initial values are provided during runtime then it is called dynamic initialization.
https://csknowledgeopener.com 82 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Example:
#include<iostream>
using namespace std;
class X
{
int n;
public:
X (int p)
{
n=p;
}
void disp()
{
cout<<"\n Roll number: " <<n;
}
};
int main()
{
int a ; float b;
cout<<"\n Enter the Roll Number:";
cin>>a;
X x(a); // dynamic initialization
x.disp();
return 0;
}
OUTPUT
Enter the Roll Number:1001
Roll number: 1001
=== Code Execution Successful ===
3. What are advantages of declaring constructors and destructor under public accessibility?
When constructor and destructor are declared under public:
1. We can initialize the object while declaring it.
2. We can explicitly call the constructor.
3. We can overload constructor and therefore use multiple constructors to initialize objects
automatically.
4. We can destroy the objects at the end of class scope automatically (free unused memory).
4. Given the following C++ code, answer the questions (i) & (ii).
class TestMeOut
{
public:
~TestMeOut() //Function 1
{cout<<“Leaving the exam hall”<<endl;}
TestMeOut() //Function 2
{cout<<“Appearing for exam”<<endl;}
void MyWork() //Function 3

https://csknowledgeopener.com 83 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

{cout<<“Answering”<<endl;} };
(i) In Object Oriented Programming, what is Function 1 referred as and when does it get invoked
/ called ?
1. Function 1 is the ‘destructor’.
• It is executed automatically when an object of the class TestMeOut goes out of scope.
(ii) In Object Oriented Programming, what is Function 2 referred as and when does it get invoked
/ called ?
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.

Explain in detail (5 Mark)


1. Mention the differences between constructor and destructor
CONSTRUCTOR DESTRUCTOR
• When an instance of a class comes into • When a class object goes out of scope, a
scope, a special function called the special function called the destructor gets
constructor gets executed. executed.

• The name of the constructor must be same • The destructor has the same name as that class
as that of the class prefixed by the tilde character ‘~’

• Constructor has no return type. • Destructor has no return type.


• A constructor can have parameter list. • The destructor cannot have arguments.
• They cannot be inherited but a derived • They cannot be inherited
class can call the base class constructor.
2. Define a class RESORT with the following description in C++ :
Private members:
Rno // Data member to store room number
Name // Data member to store user name
Charges //Data member to store per day charge
Days //Data member to store the number of days
Compute( ) /*A function to calculate total amount as Days * Charges and if the total amount
exceeds 11000 then total amount is 1.02 * Days *Charges */
Public member:
GetInfo( ) /* Function to Read the information like name , room no, charges and days*/
DispInfo( ) /* Function to display all entered details and total amount calculated using COMPUTE
function*/
CODING
#include<iostream>
using namespace std;
class RESORT
{
private:
https://csknowledgeopener.com 84 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

int Rno, Days, Charges;


char Rname[20];
int compute()
{
if( Days * Charges > 11000 )
return ( Days * Charges * 1.02 );
else
return ( Days * Charges);
}
public:
GetInfo()
{
cout<< "\n Enter customer name :";
cin>>Rname;
cout<< "\n Enter charges per day:";
cin>>Charges;
cout<< "\n Enter Number of days:";
cin>>Days;
cout<< "\n Enter Room Number:";
cin>>Rno;
}
DispInfo()
{
cout<< "\n Room Number:" <<Rno;
cout<< "\n Customer name:" <<Rname;
cout<< "\n Charges per day:" <<Charges;
cout<< "\n Number of days:" <<Days;
cout<< "\n Total Amount:" <<compute();
}
};
int main()
{
RESORT S;
S.GetInfo();
S.DispInfo();
}
OUTPUT:

https://csknowledgeopener.com 85 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

3. Write the output of the following


#include<iostream>
using namespace std;
class student
{
int rno, marks;
public:
student(int r,int m)
{ cout<<"Constructor "<<endl;
rno=r;
marks=m;
}
void printdet()
{
marks=marks+30;
cout<<"Name: Bharathi"<<endl;
cout<<"Roll no : "<<rno<<"\n";
cout<<"Marks : "<<marks<<endl;
}
};
int main()
{
student s(14,70);
s.printdet();
cout<< "Back to Main";
return 0;
}
OUTPUT

15. POLYMORPHISM
Choose the correct answer (1 Mark)
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

https://csknowledgeopener.com 86 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. Which of the following reduces the number of comparisons in a program?


(A) Operator overloading (B) Operations overloading
(C) Function Overloading (D) Member overloading
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(‘$’,10 times);
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.
5. Which of the following is invalid prototype for function overloading
a) void fun (intx); b) void fun (intx);
void fun (char ch); void fun (inty);
c) void fun (double d); d) void fun (double d);
void fun (char ch); void fun (inty);
Very Short Answers (2 Mark)
1. What is function overloading?
• The ability of the function to process the message or data in more than one form is called as function
overloading.
2. List the operators that cannot be overloaded.
Operator that are not overloaded are follows
• Scope operator (::)
• Sizeof
• Member selector (.)
• Member pointer selector (✳)
• Ternary operator (?:)
3. class add{int x; public: add(int)}; Write an outline definition for the constructor.
Answer:
add :: add (int temp)
{
x = temp; };
4. Does the return type of a function help in overloading a function?
• No. The return type of overloaded functions are not considered for overloading same data type.
5. What is the use of overloading a function?
• Function overloading reduces the number of comparisons in a program and makes the program to execute
faster.
• It also helps the programmer by reducing the number of function names to be remembered.
https://csknowledgeopener.com 87 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Short Answers (3 Mark)


1. What are the rules for function overloading?
1. The overloaded function must differ in the number of its arguments or data types
2. The return type of overloaded functions are not considered for overloading same data type
3. The default arguments of overloaded functions are not considered as part of the parameter list in
function overloading.
2. How does a compiler decide as to which function should be invoked when there are many
functions? Give an example.
• When you call an overloaded function, the compiler determines the most appropriate definition to use,
by comparing the argument types you have 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:
float area ( float radius);
float area ( float half, float base, float height );
float area ( float length , float breadth);
• The function “area” can be called using proper number of arguments in function call statement.
3. What is operator overloading? Give some examples of operators which can be overloaded.
• 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
• For example '+' operator can be overloaded to perform addition on various data types, like for Integer,
String(concatenation) etc.
4. Discuss the benefits of constructor overloading?
• A class can have more than one constructor with different signature.
• Constructor overloading provides flexibility of creating multiple type of objects for a class.
5. class sale ( int cost, discount ;public: sale(sale &); Write a non inline definition for constructor
specified;
class sale
{
int cost, discount;
public:
sale (sale&);
};
sale: : sale(sale &s)
{
cost = s.cost;
discount = s.discount;
}
Explain in detail (5 Mark)
1. What are the rules for operator overloading?
1. Precedence and Associativity of an operator cannot be changed.

https://csknowledgeopener.com 88 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

2. No new operators can be created, only existing operators can be overloaded.


3. Cannot redefine the meaning of an operator’s procedure. You cannot change how integers are added.
Only additional functions can be given to an operator
4. Overloaded operators cannot have default arguments.
5. 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 the following class.
class Book {
int BookCode ; char Bookname[20];float fees;
public:
Book( ) //Function 1
{ fees=1000;
BookCode=1;
strcpy(Bookname,"C++"); }
void display(float C) //Function 2
{ cout<<BookCode<<":"<<Bookname<<":"<<fees<<endl; }
~Book( ) //Function 3
{ cout<<"End of Book Object"<<endl; }
Book (intSC,char S[ ],float F) ; //Function 4
};
(i) In the above program, what are Function 1 and Function 4 combined together referred as?
• Overloaded Constructor
(ii) Which concept is illustrated by Function3? When is this function called/ invoked?
• Function3 is destructor. Destructor gets executed, when object goes out of scope.
(iii) What is the use of Function3?
• To remove the memory space of an object which was allocated by the constructor at the time of
creating an object.
(iv) Write the statements in main to invoke function1 and function2
• Function 1 invoke  Book() constructor function automatically when object b Created.
• Function 2 invoke  display(float C) function passing a float value.
(v) Write the definition for Function4 .
Book (int SC, char S[ ], float F)
SC - Bookcode
S - Bookname
F - Fees
fees=1000;
BookCode=1;
strcpy (Bookname,"C++");
3. Write the output of the following program
include<iostream>
using namespace std;
class Seminar
{ int Time;
public:
https://csknowledgeopener.com 89 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Seminar()
{ Time=30;cout<<"Seminar starts now"<<endl; }
void Lecture()
{ cout<<"Lectures in the seminar on"<<endl; }
Seminar(int Duration)
{ Time=Duration;cout<<"Welcome to Seminar "<<endl; }
Seminar(Seminar &D)
{ Time=D.Time;cout<<"Recap of Previous Seminar Content "<<endl;}
~Seminar()
{cout<<"Vote of thanks"<<endl; } };
int main()
{ Seminar s1,s2(2),s3(s2);
s1.Lecture();
return 0;
}
OUTPUT

4. Answer the questions based on the following program


#include<iostream>
#include<string.h>
using namespace std;
class comp {
public:
char s[10];
void getstring(char str[10])
{ strcpy(s,str); }
void operator==(comp);
};
void comp::operator==(comp ob)
{ if(strcmp(s,ob.s)==0)
cout<<"\nStrings are Equal";

https://csknowledgeopener.com 90 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

else
cout<<"\nStrings are not Equal"; }
int main()
{ comp ob, ob1;
char string1[10], string2[10];
cout<<"Enter First String:";
cin>>string1;
ob.getstring(string1);
cout<<"\nEnter Second String:";
cin>>string2;
ob1.getstring(string2);
ob==ob1;
return 0; }
(i) Mention the objects which will have the scope till the end of the program.
• Object ob and ob1 in the main() function will have the scope till the end of the program.
(ii) Name the object which gets destroyed in between the program
• Object ob in operator==(comp ob) function gets destroyed in between the program.
(iii) Name the operator which is over loaded and write the statement that invokes it.
• == is the overloaded operator in the program.
• The invoking statement of operator overloading in the program is ob == ob1;
(iv) Write out the prototype of the overloaded member function
• The prototype of the overloaded member function is void comp :: operator = = (comp ob)
(v) What types of operands are used for the overloaded operator?
• User defined datatype class objects are used for the overloaded operator.
(vi) Which constructor will get executed in the above program? Write the output of the program
• Constructor is not defined in the class. So compiler generated default constructor and it will executed

https://csknowledgeopener.com 91 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

16. INHERITANCE
Choose the correct answer (1 Mark)
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
2. Which of the following derives a class student from the base class school
(a) school: student (b) class student : public school
(c) student : public school (d) class school : public student
3. The type of inheritance that reflects the transitive nature is
(A) Single Inheritance (B) Multiple Inheritance
(C) Multilevel Inheritance (D) Hybrid Inheritance
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
5. Inheritance is a process of creating new class from
(A) Base class (B) abstract (C) derived class (D) Function
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
7. Which amongst the following is executed in the order of inheritance?
(A) Destructor (B) Member function (C) Constructor (D) Object
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
9. Based on the following class declaration answer the questions (from9.1 to 9.4 )
class vehicle
{ int wheels;
public:
void input_data(float,float);
void output_data();
protected:
int passenger;
};
class heavy_vehicle : protected vehicle {

https://csknowledgeopener.com 92 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

int diesel_petrol;
protected:
int load;
public:
void read_data(float,float)
void write_data(); };
class bus: private heavy_vehicle {
char Ticket[20];
public:
void fetch_data(char);
void display_data(); };
9.1. Which is the base class of the class heavy_vehicle?
(a) Bus (b) heavy_vehicle (c) vehicle (d) both (a) and (c)
9.2. The data member that can be accessed from the function displaydata()
(a) passenger (b) load (c) Ticket (d) All of these
9.3. The member function that can be accessed by an objects of bus Class is
(a) input_data(), output_data() (b) read_data() ,write_data()
(c) fetch_data(), display_data() (d) All of these
9.4. The member function that is inherited as public by Class Bus
(a) input_data(), output_data() (b) read_data(), write_data()
(c) fetch_data(), display_data() (d) none of these
Very Short Answers (2 Mark)
1. What is inheritance?
• The mechanism of deriving new class from an existing class is called inheritance.
2. What is a base class?
• A class that is used as the basis for creating a new class is called a super class or base class.
3. Why derived class is called power packed class?
• The derived class inherits all the properties of the base class.
• It is a power packed class, as it can add additional attributes and methods and thus enhance its
functionality.
4. In what multilevel and multiple inheritance differ though both contains many base class?
Multilevel Inheritance:
In multilevel inheritance, the constructors will be executed in the order of inheritance.
Multiple Inheritance:
If there are multiple base classes, then it starts executing from the left most base class.
5. What is the difference between public and private visibility mode?
public private
• When a base class is inherited with public • When a base class is inherited with private
visibility mode , the protected members of the visibility mode the public and protected
base class will be inherited as protected members of the base class become ‘private’
members of the derived class and the public members of the derived class
members of the base class will be inherited as
public members of the derived class.

https://csknowledgeopener.com 93 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Short Answers (3 Mark)


1. What are the points to be noted while deriving a new class?
i) The keyword class has to be used
ii) The name of the derived class is to be given after the keyword class
iii) A single colon (:)
iv) The type of derivation (the visibility mode), namely private, public or protected.
v) The name of the base class (parent class), if more than one base class, then it can be given separated
by comma.
2. What is difference between the members present in the private visibility 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 the 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.
3. What is the difference between polymorphism and inheritance though are used for reusability
of code?
Polymorphism:
• Reusability of code is implemented through functions (or) methods.
• Polymorphism is the ability of a function to respond differently to different message.
• Polymorphism is achieved through function and operator overloading.
Inheritance:
• Reusability of code is implemented through classes.
• Inheritance is the process of creating derived classes from the base class or classes.
• Inheritance is achieved by various types of inheritances namely single, multiple, multilevel, hybrid and
hierarchical inheritances.
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 called function overriding and this can be resolved by giving the base class name
followed by :: and the member function name.
5. Write some facts about the execution of constructors and destructors in inheritance
• Base class constructors are executed first, before the derived class constructors execution.
• Derived class cannot inherit the base class constructor but it can call the base class constructor by using
Base_class name: :base_class_constructor() in derived class definition
• If there are multiple base classes, then its start executing from the left most base class

https://csknowledgeopener.com 94 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

• In multilevel inheritance, the constructors will be executed in the order of inheritance. The destructors
are executed in the reverse order of inheritance.
Explain in detail (5 Mark)
1. Explain the different types of 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 inheritance
3. Hierarchical inheritance
When more than one derived classes are created from a single base class , it is known as Hierarchical
inheritance.
4. Multilevel Inheritance
The transitive nature of inheritance is 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.
Hence, it may be a combination of Multilevel and Multiple inheritance or Hierarchical and Multilevel
inheritance or Hierarchical, Multilevel and Multiple inheritance.

2. Explain the different visibility mode through pictorial representation


• An important feature of Inheritance is to know which member of the base class 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.
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

https://csknowledgeopener.com 95 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

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

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 as public members of the derived class.

3. Consider the following c++ code and answer the questions


class Personal
{
int Class,Rno;
char Section;
protected:
char Name[20];
public:
personal();
void pentry();
void Pdisplay(); };
class Marks:private Personal
{ float M{5};
protected:
char Grade[5];
public:
Marks();
void Mentry();
void Mdisplay(); };
class Result:public Marks
{
float Total,Agg;
public:
char FinalGrade, Commence[20];
Result();
void Rcalculate();
void Rdisplay();
};

https://csknowledgeopener.com 96 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

3. 1. Which type of Inheritance is shown in the program?


• Multilevel Inheritance
3. 2. Specify the visibility mode of base classes.
• Private  Marks class
• Public  Result class
3.3 Give the sequence of Constructor/Destructor Invocation when object of class Result is created.
• Constructor Personal, Marks, and Result are executed
• Destructor  Result, Marks and Personal will be executed
3.4. Name the base class(/es) and derived class (/es).
• Personal and Marks  Base classes
• Marks and Result  Derived class
3.5 Give number of bytes to be occupied by the object of the following class:
(a) Personal (b) Marks (c) Result
i) Personal : 29 bytes
ii) Marks : 45 bytes
iii) Result : 34 bytes
Explanation:
Personal: Marks: Result:
Class  4 bytes M  20 bytes Total  4 bytes
Rno  4 bytes Grade  5 bytes Agg  4 bytes
Section  1 byte Name  20 bytes FinalGrade  1 byte
Name  20 bytes Commence  20 bytes
Grade  5 bytes
-------------------------------------------------------------------------------------------------------------------------
Total Bytes  29 bytes Total Bytes  45 bytes Total Bytes  34 bytes
-------------------------------------------------------------------------------------------------------------------------
3.6. Write the names of data members accessible from the object of class Result.
FinalGrade
Commence[20]
3.7. Write the names of all member functions accessible from the object of class Result.
Mentry();
Mdisplay();
Rcalculate();
Rdisplay();

https://csknowledgeopener.com 97 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

3.8 Write the names of all members accessible from member functions of class Result.
Data Members Member Function
Grade[5] Mentry();
Total Mdisplay();
Agg Rcalculate();
FinalGrade Rdisplay();
Commence[20]

4. Write the output of the following program


#include<iostream>
using namespace std;
class A
{ protected:
int x;
public:
void show()
{cout<<"x = "<<x<<endl;}
A()
{ cout<<endl<<" I am class A "<<endl;}
~A()
{ cout<<endl<<" Bye ";} };
class B : public A
{protected:
int y;
public:
B(int x1, int y1)
{ x = x1;
y = y1; }
B()
{ cout<<endl<<" I am class B "<<endl; }
~B()
{ cout<<endl<<" Bye "; }
void show()
{ cout<<"x = "<<x<<endl;
cout<<"y = "<<y<<endl; } };
int main()
{A objA;
B objB(30, 20);
objB.show();
return 0; }
OUTPUT
I am class A
I am class A
x = 30
y = 20

https://csknowledgeopener.com 98 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Bye
Bye
Bye
Bye
5. Debug the following program
%include(iostream.h)
#include<conio.h>
class A()
{ public;
int a1,a2:a3;
void getdata[]
{ a1=15; a2=13; a3=13; } }
class B:: public A()
{ PUBLIC
voidfunc()
{ int b1:b2:b3;
A::getdata[];
b1=a1;
b2=a2;
a3=a3;
cout<<b1<<’\t’<<b2<<’t\’<<b3; }
void main()
{ B der;
der1:func(); }
CORRECT CODE:
#include <iostream>
#include<conio.h>
using namespace std;
class A
{
public:
int a1,a2,a3;
void getdata()
{
a1=15; a2=13; a3=13;
}
};
class B:public A
{
public:
void func()
{

https://csknowledgeopener.com 99 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
int b1,b2,b3;
A::getdata();
b1=a1;
b2=a2;
b3=a3;
cout<<b1<<'\t'<<b2<<'\t'<<b3;
}
};
int main()
{
B der;
der.func();
}
OUTPUT

17. COMPUTER ETHICS AND CYBER SECURITY


Choose the correct answer (1 Mark)
1. Which of the following is a set of moral principles that regulate the use of computers?
a. piracy b. programs c. virus d. computer ethics
2. Commercial programs made available to the public illegally are known as
a. freeware b. warez c. free software d. software
3. Which one of the following are self-repeating and do not require a computer program to attach
themselves?
a. viruses b. worms c. spyware d. Trojans
4. Which one of the following tracks a user visits a website?
a. spyware b. cookies c. worms d. Trojans
5. Which of the following is not a malicious program on computer systems?
a. worms b. Trojans c. spyware d. cookies
6. A computer network security that monitors and controls incoming and outgoing traffic is
a. Cookies b. Virus c. Firewall d. worms
7. The process of converting cipher text to plain text is called
a. Encryption b. Decryption c. key d. proxy server
8. e-commerce means
a. electronic commerce b. electronic data exchange
c. electric data exchange d. electronic commercialization.
9. Distributing unwanted e-mail to others is called.
a. scam b. spam c. fraud d. spoofing
10. Legal recognition for transactions are carried out by
a. Electronic Data Interchange b. Electronic Data Exchange
c. Electronic Data Transfer d. Electrical Data Interchange
https://csknowledgeopener.com 100 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
Very Short Answers (2 Mark)
1. What is harvesting?
• A person or program collects login and password information from a legitimate user to illegally gain
access s 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.
• “Cracking” means trying to get into computer systems in order to steal, corrupt, or illegitimately view
data.
• A cracker is a malicious or criminal hacker.
4. Write two types of cyber attacks.
SPYWARE
• Spyware can be installed on the computer automatically when the attachments are open, by clicking on
links or by downloading infected software.
RANSOMWARE
• Ransomware is a type of malicious program that demands payment after launching a cyber-attack on a
computer system.
5. What is a Cookie?
• A cookie is a small piece of data sent from a website and stored on the user's computer memory (Hard
drive) by the user's web browser while the user is browsing internet.
Short Answers (3 Mark)
1. What is the role of firewalls?
• A firewall is a computer network security-based system that monitors and controls incoming and
outgoing network traffic based on predefined security rules.
• A firewall commonly establishes a block between a trusted internal computer.
2. Write about encryption and decryption.
• Encryption and decryption are processes that ensure confidentiality that only authorized persons can
access the information.
• Encryption is the process of translating the plain text data (plaintext) into random and mangled data
(called cipher-text) which is used to protect data in communication system..
• Decryption is the reverse process of converting the cipher-text back to plaintext.
3. Explain about proxy server.
• A proxy server acts as an intermediary between the end users and a web server.
• A client connects to the proxy server, requesting some service, such as a file, connection, web page, or
other resources available from a different server.
• The proxy server examines the request, checks authenticity and grants the request based on that.
4. What are the guidelines to be followed by any computer user?
• Honesty: Users should be truthful while using the internet.
https://csknowledgeopener.com 101 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
• Confidentiality: Users should not share any important information with unauthorized people.
• Respect: Each user should respect the privacy of other users.
• Responsibility: Each user should take ownership and responsibility for their actions
5. What are ethical issues? Name some.
• An Ethical issue is a problem or issue that requires a person or organization to choose between
alternatives that must be evaluated as right (ethical) or wrong (unethical).
• These issues must be addressed and resolved to have a positive influence in society.
• COMMON ETHICAL ISSUES:
• Cyber crime
• Software Piracy
• Hacking
• Fraud
Explain in detail (5 Mark)
1. What are the various crimes happening using computer?
Crime Function
Cyber Terrorism • Hacking, threats, and blackmailing towards abusiness or a person.
Cyber stalking • Harassing through online.
Denial of service attack • Overloading a system with fake requests so that it cannot serve
normal legitimate requests.
Salami slicing • Stealing tiny amounts of money from each transaction.
Scam • Tricking people into believing something that is not true.
Spam • Distribute unwanted e-mail to a large number of internet users.
Spoofing • It is a malicious practice in which communication is send from
unknown source disguised as a source known to the receiver.
2. What is piracy? Mention the types of piracy? How can it be prevented?
• Software Piracy is “unauthorized copying of software”.
• It includes stealing of codes / programs and other information illegally and creating duplicate copies by
unauthorized means and utilizing this data either for one’s own benefit or for commercial profit.

• Most of the commercial software is licensed for use at a single computer site or for use by only one
user at any time.
• When a user buys any software, he becomes a licensed user for that software.
• He is allowed to make copies of the program for backup purposes, but it is against the law to distribute
duplicate copies to others.
• Such illegal copying and distribution of commercial software should not be practiced.

https://csknowledgeopener.com 102 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
• An entirely different approach to software piracy is called shareware, acknowledges the futility of
trying to stop people from copying software and instead relies on people’s honesty.

PREVENTION:
• To pretend being your friend and talk to you on Internet Relay Chat(IRC) or by Instant messenger,
e-mail can also be a source for them.
• They may send official e-mail requesting some sensitive information.
3. Write the different types of cyber-attacks.
S.No. Cyber Function
Attack
• A virus is a small piece of computer code that can repeat itself and spreads
from one computer to another by attaching itself to another computer file.
1. Virus • One of the most common virus is Trojan.

• Worms are self- repeating and do not require a computer program to attach
themselves.
2. Worms • Worms continually look for vulnerabilities and report back to the author of
the worm when weaknesses are discovered.
• Spyware can be installed on the computer automatically when the
3. Spyware attachments are open, by clicking on links or by downloading infected
software.
• Ransomware is a type of malicious program that demands payment after
4. Ransomware launching a cyber-attack on a computer system.
• This type of malware has become increasingly popular among criminals
and costs the organizations millions each year.
18. TAMIL COMPUTING
Very Short Answers (2 Mark)
1. List the search engines supported by Tamil language.
• Google
• Bing
• Yahoo
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.
https://csknowledgeopener.com 103 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
• This encoding scheme was registered in IANA (Internet Assigned Numbers Authority) a unit of
ICANN.
5. Write a short note on Tamil Virtual Academy.
• 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

PREPARED BY

J. ILAKKIA M.Sc., B.Ed., M.Phil.


Computer Instructor Grade-I
Govt. Hr. Sec. School
V.Pagandai, Villupuram 605 501.

https://csknowledgeopener.com 104 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

https://csknowledgeopener.com 105 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

HIGHER SECONDARY – FIRST YEAR


Practical manual
GENERAL INSTRUCTIONS:
1. Ten Exercises from C++ are practiced in the practical classes.
2. In Practical exams, the question paper will have two questions with internal choice.
3. One question should be chosen from the list of internal choice.
4. Distribution of Marks as follows:
Duration of Practical: 2½ Hrs Maximum Marks: 20
I. INTERNAL ASSESSMENT: 5 MARKS
Record Book 5 Marks
II. EXTERNAL ASSESSMENT: 15 MARKS
Writing Code 10 Marks
Execution 5 Marks
TOTAL 20 Marks

LIST OF SOFTWARES:
1. Dev-C++5.11 Version

SOFTWARE INSTALLATION LINK:


1. Dev-C++5.11 INSTALLATION, https://youtu.be/ozAVCkovZ4M

https://csknowledgeopener.com 106 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
INDEX

QUESTION
SL.NO PROGRAM NAME
NUMBER

1 CS1 GROSS SALARY

2 CS2 PERCENTAGE

3 CS3 PALINDROME

4 CS4 NUMBER CONVERSION

5 CS5 FIBONACCI PRIME SERIES

6 CS6 INSERT / DELETE ELEMENTS IN AN ARRAY

7 CS7 BOUNDARY ELEMENT OF A MATRIX

8 CS8 ABC PUBLISHERS

9 CS9 EMPLOYEE DETAILS USING CLASS

10 CS10 STUDENT DETAILS

https://csknowledgeopener.com 107 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS1 – GROSS SALARY
QUESTION:
Write a C++ program to input basic salary of an employee and calculate its Gross salary
according to following:
Basic Salary <25000 : HRA = 20%, DA = 80%
Basic Salary >= 25000 : HRA = 25%, DA = 90%
Basic Salary >= 40000 : HRA = 30%, DA = 95%
AIM:
To write a C++ program to input basic salary of an employee and calculate its Gross salary.
CODING:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float basic, gross, da, hra;
cout<<"Enter the Basic Pay of an Employee:";
cin>>basic;
if(basic<25000)
{
da=basic*80/100;
hra=basic*20/100;
}
else if(basic>=25000 && basic<40000)
{
da=basic*90/100;
hra=basic*25/100;
}
else if(basic>=40000)
{
da=basic*95/100;
hra=basic*30/100;
}
gross=basic+hra+da;
cout<<setw(25)<<"Basic Pay:"<<setw(10)<<basic<<endl;
cout<<setw(25)<<"Dearness Allowance:"<<setw(10)<<da<<endl;
cout<<setw(25)<<"House Rent Allowance:"<<setw(10)<<hra<<endl;

https://csknowledgeopener.com 108 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

cout<<setw(25)<<""<<setw(10)<<"----------"<<endl;
cout<<setw(25)<<"Gross Salary"<<setw(10)<<gross<<endl;
cout<<setw(25)<<""<<setw(10)<<"----------"<<endl;
return 0;
}

OUTPUT:
Enter the Basic Pay of an Employee:25000
Basic Pay: 25000
Dearness Allowance: 22500
House Rent Allowance: 6250
----------
Gross Salary: 53750
----------

RESULT:
Thus the C++ program to input basic salary of an employee and calculate its Gross salary
has been done and the output is verified.

https://csknowledgeopener.com 109 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS2 - PERCENTAGE
QUESTION:
Write a C++ program to check percentage of a student and display the division (distinction,
first, second, third or fail) scored using switch case
Percentage Division
>=80 Distinction
>=60 and <80 First division
>=50 and <60 Second Division
>=40 and <50 Third Division
<40 Fail

AIM:
To write a C++ program to check percentage of a student and display the division scored
using switch case.
CODING:
#include<iostream>
using namespace std;
int main()
{
float percent;
int x;
cout<<"Enter your percentage:";
cin>>percent;
cout<<"You Scored"<<percent<<"%"<<endl;
x=percent/10;
switch(x)
{
case 10:
case 9:
case 8:
cout<<"You have passed with Distinction";
break;
case 7:
case 6:
cout<<"You have passed with First Division";
break;

https://csknowledgeopener.com 110 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

case 5:
cout<<"You have passed with Second Division";
break;
case 4:
cout<<"You have passed with Third Division";
break;
default:
cout<<"Sorry: You have failed";
}
return 0;
}

OUTPUT 1:
Enter your percentage:79
You Scored 79%
You have passed with First Division

OUTPUT 2:
Enter your percentage:39
You Scored 39%
Sorry: You have failed

RESULT:
Thus the C++ program to check percentage of a student and display the division scored
using switch case has been done and the output is verified.

https://csknowledgeopener.com 111 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS3 – PALINDROME
QUESTION:
Write a C++ program to enter any number and check whether the number is palindrome or
not using while loop.
AIM:
To write a C++ program to enter any number and check whether the number is palindrome
or not using while loop.
CODING:
#include<iostream>
using namespace std;
int main()
{
int n, num, digit, rev=0;
cout<<"Enter a Positive Number:";
cin>>num;
n=num;
while(num)
{
digit=num%10;
rev=(rev*10)+digit;
num=num/10;
}
cout<<"The Reverse of the Number is:"<<rev<<endl;
if (n == rev)
cout<<"The Number is a Palindrome";
else
cout<<"The Number is not a Palindrome";
return 0;
}

https://csknowledgeopener.com 112 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

OUTPUT 1:
Enter a Positive Number:1234
The Reverse of the Number is:4321
The Number is not a Palindrome

OUTPUT 2:
Enter a Positive Number:1221
The Reverse of the Number is:1221
The Number is a Palindrome

RESULT:

Thus the C++ program to enter any number and check whether the number is palindrome or
not using while loop has been done and the output is verified.

https://csknowledgeopener.com 113 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS – 4 NUMBER CONVERSION
QUESTION:
Using do while loop create the following menu based C++ program
1.Convert a Decimal to binary number
2.Convert a binary number to Decimal
3. Exit
Depending on the choice accept the value and display the result. The program should
continue till the user select the third option

AIM:
To write a C++ program by Using do while loop create the menu based program for number
conversion.
CODING:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int dec, d, i, temp, ch;
long int bin;
do
{
dec=bin=d=i=0;
cout<<"\n\n\t\tMENU\n1. Decimal to Binary number\n2.Binary to Decimal number\n3.Exit\n";
cout <<"Enter your choice(1/2/3)";
cin>>ch;
switch (ch)
{
case 1: cout << "Enter a decimal number: ";
cin >> dec;
temp=dec;
while (dec!=0)
{
d = dec%2;
bin += d * pow(10,i);
dec /= 2;
i++;
https://csknowledgeopener.com 114 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

}
cout << temp << " in decimal = " << bin << " in binary" << endl ;
break;
case 2: cout << "Enter a binary number: "; cin >> bin;
temp=bin;
while (bin!=0)
{
d = bin%10;
dec += d*pow(2,i);
bin /= 10;
i++;
}
cout << temp << " in binary = " <<dec << " in decimal";
break;
case 3: break;
default : cout<<"Invalid choice";
}
} while (ch!=3);
return 0;
}

OUTPUT 1:
MENU
1. Decimal to Binary number
2.Binary to Decimal numbern3.Exit
Enter your choice(1/2/3)1
Enter a decimal number: 23
23 in decimal = 10111 in binary
MENU
1. Decimal to Binary number
2.Binary to Decimal numbern3.Exit
Enter your choice(1/2/3)2
Enter a binary number: 11001
11001 in binary = 25 in decimal
MENU
1. Decimal to Binary number
2.Binary to Decimal numbern3.Exit
Enter your choice(1/2/3)3

https://csknowledgeopener.com 115 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

OUTPUT 2:
MENU
1. Decimal to Binary number
2.Binary to Decimal number
3.Exit
Enter your choice(1/2/3)4
Invalid choice

MENU
1. Decimal to Binary number
2.Binary to Decimal number
3.Exit
Enter your choice(1/2/3)

RESULT:
Thus the C++ program by Using do while loop create the menu based program for number
conversion has been done and the output is verified.

https://csknowledgeopener.com 116 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS5 – FIBONACCI PRIME SERIES
QUESTION:
Write a C++ program using a user defined function to generate the Fibonacci series till n
terms and print if each term is prime or Composite.
AIM:
To write a C++ program using a user defined function to generate the Fibonacci series till n
terms and print if each term is prime or Composite.
CODING:
#include <iostream>
#include <stdlib.h>
using namespace std;
void Primechk (int a )
{
int j;
if ( a == 0 || a == 1 )
{
cout<< " NEITHER PRIME NOR COMPOSITE ";
}
else
{
for (j = 2 ; j<a; j++)
{
if (a%j==0)
{
cout<< "\tCOMPOSITE" ;
break ;
}
}
if ( a==j )
cout<< "\tPRIME" ;
}
}
void fibo ( int n )
{
int a = -1 , b = 1 ,c=0 ;
for ( int i = 1 ; i <= n ; i++)
{

https://csknowledgeopener.com 117 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
cout<<endl;
c=a+b;
cout<<c;
Primechk(c);
a = b;
b=c;
}
}
int main ()
{
int n ;
cout << " ENTER THE NUMBER OF REQUIRED FIBO TERMS " ;
cin >> n ;
cout<< "\n\tFIBONACCI SERIES\n " ;
fibo (n) ;
return 0;
}

OUTPUT:
ENTER THE NUMBER OF REQUIRED FIBO TERMS 10

FIBONACCI SERIES

0 NEITHER PRIME NOR COMPOSITE


1 NEITHER PRIME NOR COMPOSITE
1 NEITHER PRIME NOR COMPOSITE
2 PRIME
3 PRIME
5 PRIME
8 COMPOSITE
13 PRIME
21 COMPOSITE
34 COMPOSITE

RESULT:
Thus the C++ program to using a user defined function to generate the Fibonacci series till
n terms and print if each term is prime or Composite has been done and the output is verified.

https://csknowledgeopener.com 118 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS6 – INSERT / DELETE ELEMENTS IN AN ARRAY
QUESTION:
Write a menu driven C++ program to Insert and Delete elements in a single dimension array
of integers and print the array after insertion or deletion
AIM:
To write a C++ program to Insert and Delete elements in a single dimension array of
integers and print the array after insertion or deletion
CODING:
#include<iostream>
using namespace std;
int a[20],n, val, i, pos;
void display();
void insert();
void del();
int main()
{
int choice;
cout<<"\n Enter the size of the array elements:\t";
cin>>n;
cout<<"\n Enter the elements for the array:\n";
for (i=0;i<n;i++)
{
cin>>a[i];
}
do {
cout<<"\n\n--------Menu-----------\n";
cout<<"1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Exit\n";
cout<<"-----------------------";
cout<<"\nEnter your choice:\t";

https://csknowledgeopener.com 119 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

cin>>choice;
switch (choice)
{
case 1: insert();
break;
case 2: del();
break;
case 3:break;
default :cout<<"\nInvalid choice:\n";
}
} while (choice!=3);
return 0;
}
void display()
{
int i;
cout<<"\nThe array elements are:\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
}
void insert()
{
cout<<"\nEnter the position for the new element:\t";
cin>>pos;
cout<<"\nEnter the element to be inserted :\t";
cin>>val;
for (i=n; i>=pos-1; i--)

https://csknowledgeopener.com 120 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

{
a[i+1]=a[i];
}
a[pos]=val;
n=n+1;
display();
}
void del()
{
cout<<"\n Enter the position of the element to be deleted:\t";
cin>> pos;
val= a [pos];
for (i= pos;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
cout<<"\n The deleted element is = "<<val;
display();
}
OUTPUT:
Enter the size of the array elements: 5
Enter the elements for the array:
1
2
3
4
5
------Menu------
1. Insert
2. Delete
3. Exit
-------------------

https://csknowledgeopener.com 121 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Enter your choice: 1


Enter the position for the new element:3
Enter the element to be inserted: 26
The array elements are:
1 2 3 26 4 5
------Menu------
1. Insert
2. Delete
3. Exit
-------------------

Enter your choice: 2


Enter the position of the element to be deleted: 2
The deleted element is = 3
The array elements are:
1 2 26 4 5

------Menu------
1. Insert
2. Delete
3. Exit
-------------------
Enter your choice: 3
-------------------

RESULT:
Thus the C++ program to Insert and Delete elements in a single dimension array of integers
and print the array after insertion or deletion has been done and the output is verified.

https://csknowledgeopener.com 122 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS7 – BOUNDARY ELEMENT OF A MATRIX
QUESTION:
Write a C++ program to print boundary elements of a matrix
AIM:
To write a C++ program to print boundary elements of a matrix
CODING:
#include <iostream>
using namespace std;
void printBoundary (int a[][10], int m, int n)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (i==0|| j==0||i==m-1||j==n-1)
cout<<a[i][j]<<" ";
else
cout<<" "<<" ";
}
cout <<endl ;
}
}
int main()
{
int a[10][10] ,i,j,m,n;
cout<<"Enter more than 3 number of rows and columns"<<endl;
cin>>m>>n;
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
cout<<"enter the value for array["<<i+1<<"]"<<"["<<j+1<<"] :";
cin>>a[i][j];
}
}
system("cls");
cout<<"\n\nOriginal Array\n";
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
cout<<a[i][j]<<" ";

https://csknowledgeopener.com 123 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
}
cout<<endl;
}
cout<<"\n\n The Boundry element\n";
printBoundary(a, m, n);
return 0;
}

OUTPUT:

Enter more than 3 number of rows and columns


4 4
Enter the value for array [1][1] : 1
Enter the value for array [1][2] : 2
Enter the value for array [1][3] : 3
Enter the value for array [1][4] : 4
Enter the value for array [2][1] : 5
Enter the value for array [2][2] : 6
Enter the value for array [2][3] : 7
Enter the value for array [2][4] : 8
Enter the value for array [3][1] : 9
Enter the value for array [3][2] : 0
Enter the value for array [3][3] : 1
Enter the value for array [3][4] : 2
Enter the value for array [4][1] : 3
Enter the value for array [4][2] : 4
Enter the value for array [4][3] : 5
Enter the value for array [4][4] : 6

Original Array
1234
5678
9012
3456

The Boundary element


1234
5 8
9 2
3456

RESULT:
Thus the C++ program to print boundary elements of a matrix has been done and the output
is verified.

https://csknowledgeopener.com 124 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS8 – ABC PUBLISHERS
QUESTION:
Define a class named Publisher in C++ with the following descriptions

private members
Bookno integer
Title 20 characters
Author 10 characters
price float
Totamt float
Define a member function called calculate() to calculate the number of copies and the price
and return the total amount.
Public members
* A default constructor function to initialize all data members. The book number must be
automatically generated staring from 1001
* Readdata() function to accept values for Title, Author and price. Get the number of copies from
the user and invoke calculate().
* Display data () function display all the data members in the following format
ABC PUBLISHERS
~~~~~~~~~~~~~~~~~
INVOICE
~~~~~~~~~
==================================
Book Number :
Title :
Author Name :
Price Per Book :
Total Amount :
==================================
AIM:
To write a C++ program define a class named Publisher
CODING:
#include<iostream>
#include<stdlib.h>
using namespace std;
int id=1001;
class Publisher
{
int Bookno;
char Title[20];
char Author [10];
float Price;
https://csknowledgeopener.com 125 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
float Totamt;
float calculate (int);
public:
Publisher()
{
Bookno=id;
Title[0]='\0';
Author[0]='\0';
Price=0;
Totamt=0;
id++;
}
void Readdata();
void Displaydata();
};
void Publisher::Readdata()
{
int nocopies;
cout<<"Enter the Title name: ";cin>>Title;
cout<<"Enter the Author name: ";cin>>Author;
cout<<"Enter the Price: ";cin>>Price;
cout<<"Enter the Number of copies: ";cin>>nocopies;
Totamt=calculate(nocopies);
}
float Publisher::calculate(int x)
{
return x*Price;
}
void Publisher::Displaydata()
{
cout<<"\n\t\tABC PUBLISHERS\n";
cout<<"\t\t~~~~~~~~~~~~~~\n";
cout<<"\t\t INVOICE\n";
cout<<"\t\t ~~~~~~~\n";
cout<<"\n==================================\n";
cout<<"Book Number : "<<Bookno<<endl;
cout<<"Title : "<<Title<<endl;
cout<<"Author Name : "<<Author<<endl;
cout<<"Price Per Book : "<<Price<<endl;
cout<<"Total Amount : "<<Totamt<<endl;
cout<<"\n==================================\n";
}
int main()
{
int n,i;
Publisher p[10];
https://csknowledgeopener.com 126 http://www.youtube.com/c/csknowledgeopener
J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
cout<<"Enter the number of object to be created:";cin>>n;
for (i=0;i<n;i++)
p[i].Readdata();
for (i=0;i<n;i++)
p[i].Displaydata();
return 0;
}
OUTPUT:
Enter the number of object to be created: 2
Enter the Title name: C++Programming
Enter the Author name: Balagurusamy
Enter the Price: 500
Enter the Number of copies: 3
Enter the Title name: CoreJava
Enter the Author name: Xavier
Enter the Price: 250
Enter the Number of copies: 5
ABC PUBLISHERS
~~~~~~~~~~~~~~
INVOICE
~~~~~~~
==================================
Book Number : 1001
Title : C++Programming
Author Name : Balagurusamy
Price Per Book : 500
Total Amount : 1500
=================================
ABC PUBLISHERS
~~~~~~~~~~~~~~
INVOICE
~~~~~~~
==================================
Book Number : 1002
Title : CoreJava
Author Name : Xavier
Price Per Book : 250
Total Amount : 1250
=================================
RESULT:
Thus the C++ program to define a class named Publisher has been done and the output is
verified.

https://csknowledgeopener.com 127 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS9 – EMPLOYEE DETAILS USING CLASS
QUESTION:
Create a C++ program to create a class employee containing the following members in public.

Public members
eno integer
name 20 characters
des 20 characters
member Function
void get() to accept values for all data members
Declare the derived class called Salary which contain the following details.
Public members
bp, hra, da, pf, np float
member Function
void get1() to accept values for bp, hra, da and pf and invoke calculate()
calculate() calculate the np by adding bp, hra, da subtracting pf
display() Display all the details
Create the derived class object and read the number of employees. Call the function get(),get1()
for each employee and display the details
AIM:
To write a C++ program to create a class employee containing the following members in public.
CODING:
#include<iostream>
using namespace std;
class emp
{
public:
int eno;
char name[20], des[20];
void get()
{
cout<<"Enter the employee number:";
cin>>eno;
cout<<"Enter the employee name:";
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};
class salary:public emp
{

https://csknowledgeopener.com 128 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
float bp,hra, da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>bp;
cout<<"Enter the HouseRent Allowance:";
cin>>hra;
cout<<"Enter the Dearness Allowance :";
cin>>da;
cout<<"Enter the Provident Fund:";
cin>>pf;
}
void calculate()
{
np=bp+hra+da-pf;
}
void display()
{
cout<<eno<<"\t"<<name<<"\t"<<des<<"\t"<<bp<<"\t"<<hra<<"\t"<<da<<"\t"<<pf<<"\t"<<np<<
"\n";
}
};
int main()
{
int i, n;
char ch;
salary s[10];
cout<<"Enter the number of employee:";
cin>>n;
for (i =0; i < n; i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"\n\t\t\tEmployee Details\n";
cout<<"\n e_no \t e_name \t des \t bp \t hra \t da \t pf \t np \n";
for (i =0; i < n; i++)
{
s[i].display();
}
return 0;
}

https://csknowledgeopener.com 129 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
OUTPUT:

Enter the number of employee: 2


Enter the employee number: 1201
Enter the employee name: Ramkumar
Enter the designation: Engineer
Enter the basic pay:50000
Enter the House Rent Allowance:10000
Enter the Dearness Allowance :5000
Enter the Provident Fund:1000
Enter the employee number:1202
Enter the employee name: Viswanathan
Enter the designation: Engineer-Tech
Enter the basic pay:40000
Enter the House Rent Allowance:9000
Enter the Dearness Allowance :4500
Enter the Provident Fund:1000

Employee Details
e_no e_name des bp hra da pf np
1201 Ramkumar Engineer 50000 10000 5000 1000 64000
1202 Viswanathan Engineer-Tech 40000 9000 4500 1000 52500

RESULT:
Thus the C++ program to create a class employee containing the following members in
public has been done and the output is verified.

https://csknowledgeopener.com 130 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
CS10 – STUDENT DETAILS
QUESTION:
Write a C++ program to create a class called Student with the following details

Protected member
Rno integer
Public members
void Readno(int); to accept roll number and assign to Rno
void Writeno(); To display Rno.
The class Test is derived Publically from the Student class contains the following details
Protected member
Mark1 float
Mark2 float
Public members
void Readmark(float,float); To accept mark1 and mark2
void Writemark(); To display the marks
Create a class called Sports with the following detail
Protected members
score integer
Public members
void Readscore(int); To accept the score
void Writescore(); To display the score
The class Result is derived Publically from Test and Sports class contains the following details
Private member
Total float
Public member
void display() assign the sum of mark1 ,mark2,score in total.
invokeWriteno(),Writemark() and Writescore() .Display the total also.
AIM:
To write a C++ program to create a class called Student with the following details
CODING:
#include<iostream>
using namespace std;
class Student
{
protected:
int Rno;
public:
void Readno(int r)
{
Rno=r;
}

https://csknowledgeopener.com 131 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.
void Writeno()
{
cout<<"\nRoll no : "<<Rno;
}
};
class Test :public Student
{
protected:
float Mark1,Mark2;
public:
void Readmark (float m1,float m2)
{
Mark1=m1;
Mark2=m2;
}
void Writemark()
{
cout<<"\n\n\tMarks Obtained\n ";
cout<<"\n Mark1 : "<<Mark1;
cout<<"\n Mark2 : "<<Mark2;
}
};
class Sports
{
protected:
int score;
public:
void Readscore (int s)
{
score=s;
}
void Writescore()
{
cout<<"\n Sports Score : "<<score;
}
};
class Result :public Test,public Sports
{
int Total;
public:
void display()
{
Total = Mark1 + Mark2 + score;
Writeno();
Writemark();

https://csknowledgeopener.com 132 http://www.youtube.com/c/csknowledgeopener


J. ILAKKIA M.Sc., B.Ed., M.Phil. Computer Instructor Grade-I, GHSS – V.Pagandai, Villupuram.

Writescore();
cout<<"\n\n Total Marks Obtained : "<< Total<<endl;
}
};
int main()
{
Result stud1;
stud1.Readno(1201);
stud1.Readmark(93.5,95);
stud1.Readscore(80);
cout<<"\n\t\t\t HYBRID INHERITANCE PROGRAM\n";
stud1.display();
return 0;
}

OUTPUT:

HYBRID INHERITANCE PROGRAM


Roll no : 1201
Marks Obtained
Mark1 : 93.5
Mark2 : 95
Sports Score : 80
Total Marks Obtained : 268

RESULT:

Thus the C++ program to create a class called Student with the following details has been
done and the output is verified.
PREPARED BY

J. ILAKKIA M.Sc., B.Ed., M.Phil.


Computer Instructor Grade-I
Govt. Hr. Sec. School
V.Pagandai, Villupuram 605 501.
https://csknowledgeopener.com 133 http://www.youtube.com/c/csknowledgeopener

You might also like