Xi - CS em Minimum Study Material 2024-2025
Xi - CS em Minimum Study Material 2024-2025
Xi - CS em Minimum Study Material 2024-2025
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
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
2 NUMBERS SYSTEMS
3 COMPUTER ORGANISATION
9 INTRODUCTION TO C++
10 FLOW OF CONTROL
11 FUNCTIONS
15 POLYMORPHISM
16 INHERITANCE
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.
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.
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
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
(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.
(150)10 = (10010110)2
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.
2 15 LSB
2 7 -1
2 3 -1
MSB 1 -1 The Binary equivalent of 1510 = (1111)2
−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
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
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.
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
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.
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.
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.
2. How AND and OR can be realized using NAND and NOR gate.
(i) Realized AND Gate using NAND 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.
������� = 1� = 0
C = (1.1)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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) (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
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.
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
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.
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)
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
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.
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.
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 :
• 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.
•
Recursive process of covering a corner-covered board of size 2 x 23
•
• 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
}
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.
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.
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.
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.
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.
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.
• 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.
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.
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.
• 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 ‘~’
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.
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.
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.
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
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.
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.
• 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.
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.
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]
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
• 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.
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
LIST OF SOFTWARES:
1. Dev-C++5.11 Version
QUESTION
SL.NO PROGRAM NAME
NUMBER
2 CS2 PERCENTAGE
3 CS3 PALINDROME
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.
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;
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.
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.
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
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.
OUTPUT:
ENTER THE NUMBER OF REQUIRED FIBO TERMS 10
FIBONACCI SERIES
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.
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--)
{
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
-------------------
------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.
OUTPUT:
Original Array
1234
5678
9012
3456
RESULT:
Thus the C++ program to print boundary elements of a matrix has been done and the output
is verified.
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.
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
{
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.
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;
}
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:
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