11 CS Guide 2022 2023

You might also like

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

ILANGOVAN ,RMKMHSS - 601206 9677515019

11
Computer
Science GUIDE

ELANGOVAN

RMK MAT.HR.SCE.SCHOOL -601206


9677515019
1
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Unit I Fundamentals of Computers CHAPTER 1


Introduction to Computers
Third Generation 1964 -1971
Integrated Circuits (IC)replaced Transistors
1.What is a computer?  Computers were smaller, faster and more reliable
 A Computer is an electronic device.  Consumed less power
 It takes data as an input from the user.  High Level Languages were used
processes it under the control of a set of instructions (called Fourth Generation 1971-1980
program), Produces a result (output), Microprocessor ( Very Large Scale Integrated Circuits (VLSI) )
 Saves it for future use.  Smaller and Faster
 Microcomputer series such as IBM and APPLE were developed
2. What are the Characteristics of a computer?  Portable Computers were Introduced
The computer characteristics are Fifth Generation 1980 – till date
 It gives the desired output at a very fast rate and accurate. Ultra Large Scale Integration (ULSI)
 They are very versatile as they do a lot of different tasks.  Parallel Processing
 It can store and retrievedata.  Super conductors
 It works based on instructions.  Computers size was reduced.
 Computers can recognize Images and Graphics
3. Write the applications of computer.  Introduction of Artificial Intelligence(AI) and Expert Systems
The various applications of computer are,  Able to solve high complex problems including decision making and
 Business logical reasoning
 Education Sixth Generation - In future
 Banking  Here, computers works based on Artificial Neural Networks.
 Communication  Parallel and Distributed computing
 Weather forecasting,  Natural Language Processing (NLP) is a component of Artificial
 Booking airlines, railway or movie tickets Intelligence (AI).
Games  It provides the ability to understand human language.
 Development of robotics
4.Discuss the various generations of Computers
 The explosive growthof Wide Area Networking(WAN)
Based on various stages of development,
computers can be divided into six different generations. 5.Write the characteristics of sixth Generation computers.
First Generation 1940- 1956
Vacuum tubes were used  Here, computers works based on Artificial Neural Networks.
 Big in size  Parallel and Distributed computing
 Consumed more power  Natural Language Processing (NLP) is a component of Artificial
 Malfunction due to overheat Intelligence (AI).
 Machine Language was used  It provides the ability to understand human language.
 Ex. ENIAC , EDVAC , UNIVAC  Development of robotics
 The explosive growthofWide Area Networking(WAN)
Second Generation 1956- 1964
Transistors replaced Vacuum tubes 6.Define Data.
 Smaller and Consumed less power compared to first generation  Data is an un- processed collection of raw facts,
 Punched cards were used as input  It is an input of the computer.
 First operating system was developed .  It will not giving any meaningful message.
 Batch Processing and Multiprogramming Operating Systemwere Ex. 134, 16 „Kavitha‟, „C‟
introduced. 7.Define Information
 Assembly language was used.  Information is defined processed collection of facts.
 Information conveys some meaning.
 Information is output of the computer .
Ex. Vijay is 16 years old

8.Distinguish between data and information

2
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Ref. Q.No 4 & 5  It is also called main memory.


6.Explain the basic components of a computer with a neat diagram.  It is volatile.
The computer is the combination of hardware and software.  Temporary memory.
 Inputunit , Central processing unit ,Output unit and Memory unit Ex. RAM
are the important componentsof a computer. Secondary memory
 It is non volatile
Input -> Process -> Output cycle (IPO).  Permanent memory.
 Ex. Hard Disk, CD-ROM

Output Unit
 It conveysinformationto users in an understandable form.
 Example: Monitor, Printer, Speaker, plotter etc

7.What is Data Processing?


 Conversion ofdata into information is called data processing.

8.What are Hardware and Software?


 Hardware is the physical component of a computer
Ex.motherboard, memorydevices,monitor,keyboard etc.,
 Software is the set of programs or instructions.
Ex. System software ,Application
9.What are the important components of a Computer?
 Input unit , Central processing unit ,Output unit and Memory unit
Input Unit
 It is used to feed any form of data to the computer, 10.Define Input Unit. Or what is an input device ?Give two examples.
 Which canbe stored in the memory unit for further processing.  It is used to feed any form of data to the computer,
Example: Keyboard, mouse, etc. Example: Keyboard, mouse, etc
Central Processing Unit 11.Define Output Unit
 It controls the operation of all other components.  It conveysinformationto users in an understandable form.
 It accepts data as input, process the data according to the  Example: Monitor, Printer, Speaker, plotter etc
instructions and provide the result as output
It has three components, 12. Differentiate Input and Output unit
1.ALU ( Arithmetic and Logic unit) Ref. Q.No 10 & 11
2.Control unit
3.Memory unit 13.Define Central Processing Unit or
What are the components of a CPU?
ALU ( Arithmetic and Logic unit)
 The ALU performs arithmetic operations. Central Processing Unit
 The result of an operation is stored in internal memory of  It controls the operation of all other components.
CPU.  It accepts data as input, process the data according to the
 It gives the decision(Logical)-making ability of a computer instructions and provide the result as output
It has three components,
Control unit 1.ALU ( Arithmetic and Logic unit)
 It controls the flow of data between the CPU, memory and 2.Control unit
I/O devices. 3.Memory unit
 It also controls the entire operation of a computer.
14.Write short note on Arithmetic and Logic Unit(ALU) or
Memory unit What s the function of an ALU?
 It is used to storedata and instructions
 There are two types of memory, they are primary memory and ALU ( Arithmetic and Logic unit)
secondary memory  The ALU performs arithmetic operations and logical
instructions based on computer instructions
 Send the result to internal memory.

Primarymemory

3
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

15. Define control unit or  It is used for computer securityinstead of using passwords.
Write the functions of control unit.  It is a biometric technique.
 It is a very safe and convenient.
 It controls the entire operation of a computerthrough signals. Track Ball:
 In Track ball user spins the ball in various directions to navigate the
16. What is the function of memory? screen movements.
Retinal Scanner:
Memory unit  It performs a retinalscan.
 It is used to storedata and instructions.  It is a biometric technique .
 There are two types of memory, they are primary memory and Light Pen:
secondary memory  A light pen is a pointing device .
Primarymemory  It is connected to a monitor.
 It is also called main memory.  The tip of the light pen contains a light-sensitiveelement
 It is volatile.  It detects the light from the screen enabling the computer to
 Temporary memory. identify the location of the pen on the screen.
Ex. RAM Optical Character Reader:
Secondary memory  It is used to detect charactersprinted or written on a paper.
 It is non volatile  The Scanned document can be edited using a word processor.
 Permanent memory. 19.DefineBar Code
 Ex. Hard Disk, CD-ROM  A Bar code is a pattern printed in lines of differentthickness.
 The Bar code readerscans the information on the bar codes
17. Distinguish between Primaryand secondary memory. transmits to the Computer for further processing.
20.Define QR Code Reader: QR (Quick response) Code:
Primarymemory  The QR code is the 2D bar code which can be read by a camera .
 It is also called main memory. Define Voice Input Systems:
 It is volatile.  Microphone serves as a voice Input device.
 Temporary memory.  It captures the voice data and send it to the Computer.
Ex. RAM Define Digital Camera:
Secondary memory  It captures images / videos directly in the digital form.
 It is non volatile  It uses a CCD (Charge Coupled Device) electronic chip.
 Permanent memory.  It converts light rays into digital format.
 Ex. Hard Disk, CD-ROM Touch Screen:
 A touch screen is a display device that allows the user to
18.Explain Some Important Input Devices. interact with a computer by using the finger.
 Touch screens are used in computers, laptops, monitors, smart
Keyboard: phones, tablets, ATM etc..
 Keyboard is the most common inputdevice.
 It is used to give data and instructions to computer by typing on 21.Explain Some Output Devices.
the keyboard.
 The keys for letters, numbers and special characters are known Monitor:
as a character keys  Monitor is the most commonly used output device to display the
 Function keys are used to perform different functions. information.
 Other keysare enter and editing keys, function keys, navigation  Pictures are formed with picture elements called PIXELS.
keys, numeric keypad and lock keys etc..  It can be MonochromeorColour
Mouse:  CRT (Cathode Ray Tube),
It is an input device LCD (Liquid Crystal Display) and
 Mouse is a pointing device . LED (Light Emitting Diodes) are the types of monitor.
 It can be used to select icons, menus, commandbuttonsetc  Monitor works with the VGA (Video Graphics Array) card.
 Some mouse actions are i) move, ii)click, iii)double click,  VGA acts as an interface between the computer and monitor.
iv)right click, v)drag and drop. Plotter:
Scanner:  Plotter is used to produce graphical output on papers.
 It converts printed or writtenInformation into a digital  It uses single color or multi color pens to draw pictures.
format(file) into computer‟s memory.

Fingerprint Reader: Printers:

4
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 Printers are used to print the information on papers.  It spraysionised ink at a sheet of paper.
 They are two main categories:  It can spread millions of dots of ink at the paper every single
• Impact Printers • Non Impact printers second
 .
Laser Printers  It has colour cartridges which combined Magenta, Yellow and Cyan
 It works similar to photocopiers inks.
 It makes a laser beam scan back and front across a drum  A black cartridge is used for monochrome output.
inside the printer, make up a pattern.
 It can produce very good quality of graphic images. 21.Explain Booting of computer
Inkjet Printers: When a computer is switched on, there is no information in its RAM.
 Inkjet printers work by spraying ionised ink at a sheet of paper.  In ROM, the pre-written program called POST (Power on Self
 An Inkjet printer can spread millions of dots of ink at the paper Test) will be executed first.
every single second.  This program checks if the devices like RAM, keyboard, etc., are
 It hascolour cartridges which combined Magenta, Yellow and Cyan connected properly and ready to operate.
inks. Then the BIOS (Basic Input Output System) gets executed.
 A black cartridge is used for monochrome output.  This process is called Booting.
Speakers: Thereafter, a program called “Bootstrap Loader” transfers OS from
 Speakers produce voice output (audio) . hard disk into main memory(RAM).
 This has become very common in places like airlines, schools,  Now the OS gets loaded (Windows/Linux, etc.,) and will get
banks, railway stations, etc.. executed.
Booting process is of two types.
22.Differentiate between Impact and Non Impact printers. 1)Cold Booting 2) Warm Booting
Cold (Hard)Booting:
 computer starts from initial state
Impact Printers Non-Impact Printers  Booting process initiate by pressing Power button.
It prints with striking of do not use striking  All diagnostic testscould be carried out in this process.
hammers or pins on mechanism for printing. Warm (soft)Booting:
ribbon.  Does not start from initial state.
It can print by using They use electrostatic or  Booting process initiate by pressing Reset button.
mechanicalpressure laser technology.  All diagnostic tests need not be carried out in this process.
It makes noise . It is silent
Poor Quality and speed Good Quality and speed 22.Difference between cold and warm booting Ref above ans
Ex. Dot Matrix printers , Ex. Laser printers , Inkjet
Line matrix printers printers

23.Write the significant features of monitor


 Monitor is the most commonly used output device to display the
information.
 Pictures are formed with picture elements called PIXELS.
 It can be Monochromeor Colour
 CRT (Cathode Ray Tube),
LCD (Liquid Crystal Display) and
LED (Light Emitting Diodes) are the types of monitor.
 Monitor works with the VGA (Video Graphics Array) card.
 VGA acts as an interface between the computer and monitor.

24.Define Multimedia Projector:

 Itis used to produce computer output on a big screen.


 used to display presentations in meeting halls or in classrooms.

25.Define Inkjet Printers:


CHOOSE THE CORRECT ANSWER
5
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

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

6
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Unit I Fundamentals of Computers CHAPTER 2


Number Systems
Convert(98.46) to binary
1.What is Data? 2|98
 Data is an un- processed collection of raw facts, 2|9 0
 It is an input of the computer. 2|24 1
 It will not giving any meaningful message. 2|12 0
Ex. 134, 16 „Kavitha‟, „C‟ 2|6 0
2|3 0
2.What is radix of a number system? Give example |1 1 (98)10 = (1100010)2
What are the different types of Number System? 0.46 x 2 = 0.92 = 0
 Radix or base is number of digits in each number system. 0.92 x 2 =1.84 = 1
 Each number system is uniquely identified by its base value or 0.84 x 2 =1.68 =1
radix. 0.68 x 2 =1.36 = 1
 There are four number system, They are, 0.36 x 2 = 0.72 = 0
 Decimal number system( Base Value 10 ) 0.72 x 2 =1.44 = 1
0,1,2,3,4,5,6,7,8,9 …. Top to Bottom 011101
 Binary number system( Base Value 2 )0,1 (98.46)10 = 1100010 . 011101……
 Octal number system( Base Value 8 )
0,1,2,3,4,5,6,7 6.Explain 1‟s and 2‟s Complement representation.
 Hexadecimal number system( Base Value 16)  Used to represent signed numbers.
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F  This is for negative numbers only.
1‟s complement representation
3.Write short note on Binary Number System Step 1:Convert given Decimal number
 It consists of 0 and 1. The base is 2. into Binary
 The positional value as a power of 2. Step 2: if the binary number
 The left most bit in the binary number is called as the Most Less than 8 bits , make it as 8 bits.
Significant Bit (MSB) Step 3: Invert all bits (i.e. Change 1 as 0
 The right most bit in the binary number is called as the Least and 0 as 1)
Significant Bit (LSB) 2‟s Complement representation
Step 1. Invert all the bits in the binary
sequence.
4.Convert (46)10 into binary number. Step 2. Add 1 to (LSB).
Ref. above answer
2|46 7.Find 1‟s complement and 2‟s complement for (–96) 10
2|23 0 Step 1
2|11 1 Convert 96 to binary
2|5 1 2|96
2|2 1 2|48 0
|1 0 (46)10 = ( 101110)2 2|24 0
2|12 0
5.Write procedure to convert fractional Decimal to binary with an 2|6 0
example. 2|3 0
Convert (98.46)10 to binary 2|1 1
1100000
Step 1:Multiply the decimal fraction by 2. Step 2: Make it as 8 bits : 01100000
The integer part is either 0 or 1. Step3: invert 10011111
Step 2: Multiply the fractional part of the previous product by 2. Step4: add 1 to LSB 1
Step 3:Repeat Step 1until the same fraction repeats or terminates (0). Step 5 :2‟s complement 10100000
Step 4: The final answer is to be writtenfrom first to last integer part (-96)10 = (10100000)2
obtained.

7
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

8.Find 1‟s and 2‟s complement for (–135)10 12.Convert (150)10 into Binary, then convert that binary number
Ref. above answer into octal
9.We cannot find 1‟s complement for (28) 10 .
Reason: Because 28 is a positive number. 2|150
This is for negative numbers only 2|75 0
10.Binary Add a) -2210 + 1510 2|32 1
2|16 0
-22 2|8 0
2|22 2|4 0
2|11 0 2|2 0
2|5 1 2|1 0
2|2 1
2|1 0 (150)10 = (1000 0010)2

10110 Binary into octal


8 bit :00010110
Inverse : 11101001 1000 0010
Add 1 in LSB 1 010 000 010
11101010 2 0 2
-22 = 11101010
2|15 (1000 0010)10 = (201)8
2|7 1
2|3 1 13.List the encoding systems that represents characters in
2|1 1 memory. (or)
8 bit : 00001111 What are the encoding systems used for
-2210 + 1510 computer.?
11101010 There are several encoding systems used for
00001111 computer. They are,
--------------  BCD – Binary Coded Decimal
11111001  EBCDIC – Extended Binary Coded Decimal Interchange Code
 ASCII – American Standard Code for Information Interchange
b)2010 + 2510  Unicode
ref . above answer  ISCII - Indian Standard Code for Information Interchange
10.Add: 1101010 + 101101
14.Indian Standard Code for Information Interchange (ISCII)
1101010  ISCII is the system of handling the character of Indian local
101101 languages.
-------------  It is a 8-bit coding system.
10010111  Therefore it can handle 256 (2 8 ) characters.
--------------  It is recognized by Bureau of Indian Standards (BIS).
11.Subtract : 1101011 - 111010  It is integrated with Unicode.

1101011
111010
------------
0110001
-------------

8
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

23.Decimal to Binary Conversion


ADDITIONAL QUESTION AND ANSWERS Repeated Division by 2

15.How computers are handle the data? What is Machine language?


 Computer handles data in the form of „0‟(Zero) and „1‟ (One).
 Any kind of data like number, alphabet, special character should be
converted to „0‟ or „1‟ which can be understood by the Computer.
 Computer understandable language is called Machine language( 0
and 1)
15a)Define Bit, Nibble and Byte Sum of Powers of 2 method.
Bit - Binary Digit0 or 1 Given Number : 65
Nibble - collection of 4 bits
Byte - collection of 8 bits

16. Define Word length


 Word length refers to the number of bits processed by a
Computer‟s CPU.
 Ex. 8bits, 16 bits, 32 bits and 64 bits
17.How Computer memory is represented?
 Computer memory is normally represented in terms of KiloByte (KB)
or MegaByte (MB).
 In binary system, 1 KiloByte represents 1024 bytes that is 2 10 . 24.Decimal to Octal Conversion
18.How characters are represented in computer explain with Repeated Division by 8
examples?
 Bytes are used to represent characters in a text.
 Different types of coding schemes are used to represent the
character set and numbers.
 The most commonly used coding scheme is the American
Standard Code for Information Interchange (ASCII).
19.How speed of computer is described?
 The speed of a computer depends on the number of bits it can
process at once.
 For example, a 64- bit computer can process 64-bit numbers in one (65)10 = (101)8
operation
20.Write short note on Decimal Number system 25.Decimal to Hexadecimal Conversion
 It consists of 0,1,2,3,4,5,6,7,8,9 Repeated Division by 16
 The base is 10.
 It is used in our day to day life.
 The positional value as a power of 10.Ex. 28,11
21.Write short note on Octal Number System
 It consists of 0,1,2,3,4,5,6,7
 The base is 8.
 Each octal digit has its own positional value as a power of 8 (31)10 = (1F )16
22.Write short note on Hexa decimal Number System 26.Conversion of fractional Decimal ( 0.2 )to Binary
 It consists of 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
 The base is 16.
 The positional value as a power of 16.

9
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Note:
 Fraction repeats, the product is the same as in the first step. Conversion of fractional Binary to Decimal
 Write the integer parts from top to bottom. 30.Conversion of fractional Binary to Decimal equivalent
 Hence (0.2) 10 =(0.00110011…) 2
Binary to Decimal Conversion
27.Convert (1 1 0 0 1)2 into its equivalent decimal number.
11001
1 X 25 + 1 X24 +0 X 23 + 0 X 22 + 1 X 20
16 + 8 + 0 + 0 + 1
25
(11001)2 = (25)10
Conversion Table
Hex Oct Dec Binary
0 0 0 0 0 0 0 31.Convert the given Binary number (11.011) 2 into its decimal
1 1 1 0 0 0 1 equivalent Integer part (11) 2 = 3
2 2 2 0 0 1 0
3 3 3 0 0 1 1
4 4 4 0 1 0 0
5 5 5 0 1 0 1
6 6 6 0 1 1 0 3 + . (0x0.5 + 1 x 0.25 + 1 x 0.125)
7 7 7 0 1 1 1 3 + . 0 + 0.25 + 0.125
8 8 1 0 0 0 3 +.375
9 9 1 0 0 1 3 . 375
Octal to Decimal Conversion:
A 1 0 1 0
32.Convert (1265) 8 to equivalent Decimal number
B 1 0 1 1
Positional 8 3 82 81 80
C 1 1 0 0
Given
D 1 1 0 1 Weight 512 64 8 1
E 1 1 1 0 Number 1 2 6 5
F 1 1 1 1 (1265) 8 = 512 ×1 + 64×2 + 8×6 +1×5
Binary to Octal Conversion = 512 + 128 + 48 + 5
28.Convert (11010110)2 into octal equivalent number (1265) 8 = (693) 10
Step 1: Group the given number into 3 bits from right to left.
011 010 110 Hexadecimal to Decimal Conversion
Note: The left most groups have less than 3 bits, so 0 is added to its left 33.Convert (25F) 16 into its equivalent Decimal number.
to make a group of 3 bits. Weight 256 16 1
Step-2: Find Octal equivalent of each group Positional
011 010 110 Notation 16 2 16 1 16 0
3 2 6 Given number = (2 5 F)16
(11010110)2 = (326)8 (25F) 16 = 2×256 + 5×16 + 15×1
= 512 + 80 +15
Binary to Hexadecimal Conversion (25F) 16 = (607) 10
29.Convert (1111010110)2 into Hexadecimal number
Step 1:Group the given number into 4bits from right to left. Hexadecimal to Binary Conversion
0011 1101 0110
Note: 0‟s are added to the left most group 34.Convert (8BC) 16 into equivalent Binary number
To make it a group of 4 bits
0011 1101 0110
3 D 6
(1111010110)2 = (3D6) 16

10
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

How to Representation for Signed Numbers in Binary


CHOOSE THE CORRECT ANSWER
35.Define sign Bit.
 The left most bit in the binary number is called as the Most
Significant Bit (MSB)
 It is also called sign bit or parity bit. 1 .Which refers to the number of bits processed by a computer‟s CPU?
 If this bit is 0, it is a positive number A) Byte B) Nibble C) Word length D) Bit
 if it 1, it is a negative number.
36.Define Signed Magnitude 2. How many bytes does 1 KiloByte contain?
 The simplest method to represent negative binary numbers is called A) 1000 B) 8 C) 4 D)1024
Signed Magnitude.
37.How Numbers are represented in Computers? 3. Expansion for ASCII
 Signed Magnitude representation A) American School Code for Information Interchange
Ex. +43 or 43 is a positive number
–43 is a negative number B) American Standard Code for Information Interchange
C) All Standard Code for Information Interchange
39.Define Binary Coded Decimal (BCD).
 This encoding system is not in the practice right now. D) American Society Code for Information Interchange
 This is 2 6 bit encoding system. 4. 2^50 is referred as
 This can handle 2 6 = 64 characters only.
A) Kilo B) TeraC) Peta D) Zetta
40.Define American Standard Code for
Information Interchange (ASCII). 5. How many characters can be handled in Binary Coded Decimal System?
 This is the most popular encoding System
A) 64 B) 255 C) 256 D) 128
 English characters only.
 This can handle 2 7bit which means 128 characters.. 6. For 11012 what is the Hexadecimal equivalent?
Ex. 1000001
A) F B) E C) D D) B
 The new edition (version) ASCII -8, has 2 8 bits and can handle 256
characters .. 7. What is the 1‟s complement of 00100110?
Ex.01000001
A) 00100110 B)11011001 C) 11010001 D) 00101001
 Each character has individual number.
The ASCII value for 8. Which amongst this is not an Octal number?
 blank space is 32
A) 645 B) 234 C) 876 D) 123
 0 is 48.
 Thelower case alphabets is from 97 to 122
 The upper case alphabets is from 65 to 90.
41.Extended Binary Coded Decimal Interchange Code (EBCDIC)
 It is 8 bit representation.
 It is formulated by International Business Machine(IBM).
 It can handle 256 characters.
42.Define Unicode
 It is used in most of the modern computers.
 This is 16 bit code and can handle 65536characters.
 Unicode can handle Universal languages.
 Unicode scheme is denoted by hexadecimal numbers.

11
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Part - II - Boolean Algebra


1.What is Boolean algebra? 7.Explain about NOT operator
 Boolean algebra is used for designing digital Circuitsin a digital  The NOT Operator has one input and one output
computer.  The NOT operator inverts the input.
 It describes the relation between inputsand outputs of a digital Algebraic expression : Y = 𝑨
circuit. TRUTH TABLE

2.Define Logical Operation ( or )What are the basic logical operators NOT GATE
(fundamental operators)?
 AND(+) , OR (.) and NOT(-)

3.Define TRUTH TABLE 9.Explain the fundamental gates with expression and truth table.
 All the possible input along with all the possible output of given Ref.5,6,7
A Y=𝐴
combination of truth values is known as Truth Table.
0 1
8.Consider the following equation
4.What is Gate? What are the fundamental gates? 1 0
D = A + (𝐵 . C) Write truth table and Find the
 Gate is a basic electronic circuit. output of D when inputs A=0,B=1,and C=0.
 It operates on one or more input signals to produce an output A B C 𝐵 (𝐵.C) D =A + (𝐵 .C )
signal. 0 0 0 1 0 0
 There are three fundamental gates namely AND, OR and NOT. 0 0 1 1 1 1
0 1 0 0 0 0
5.Explain about AND operator
0 1 1 0 0 0
 The AND operator hastwo or moreinput variables and one
output. 1 0 0 1 0 1
The output is TRUE when all the Inputs are TRUE. 1 0 1 1 1 1
Algebraic expression : Y=A . B 1 1 0 0 0 1
TRUTH TABLE 1 1 1 0 0 1
A B Y=A.B Result: D=0
0 0 0 9.What are derived gates?
0 1 0  The gates which are derived from fundamental gates are called
1 0 0 derived Gate.
1 1 1 Ex. NAND ,NOR,XOR,XNOR etc…..
AND GATE
10.Why the NAND and NOR gates are called universal gate?
 NAND and NOR gates are called Universalgates, because the
fundamental logic gates can be realized through them
11.Explain NOR Operator with an example.
6.Explain about OR operator
 The NOR is the combination of NOT and OR
 The OR operator has two or more input variables and one output .
 NOR=inverting the output of an ORoperator.
The output is TRUE if at least one input is TRUE.
Algebraic expression : Y= 𝑨 + 𝑩
Algebraic expression : Y = A + B
TRUTH TABLE
TRUTH TABLE
A B A+B Y=𝐴+𝐵
A B Y=A+B
0 0 0 1
0 0 0
0 1 1 0
0 1 1
1 0 1 0
1 0 1
1 1 1 0
1 1 1
LOGIC CIRCUIT
OR GATE

LOGIC SYMBOL
12
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

TRUTH TABLE
12.Explain Bubbled AND Gate
A B 𝐴 𝐵 Y=𝐴 +𝐵
0 0 1 1 1
0 1 1 0 1
1 0 0 1 1
1 1 0 0 0
NOR = BUBBLED AND
 They are identical. NAND = BUBBLED OR
So the circuits are interchangeable  They are identical.
TRUTH TABLE So the circuits are interchangeable.
A B „A „B Y= 𝑨 .𝑩
Algebraic expression : 𝑨. 𝑩 = 𝑨 + 𝑩
0 0 1 1 1
De Morgan's Second theorem – Proved.
0 1 1 0 0
1 0 0 1 0
16.De Morgan's Second theorem – Prove. Ref.14 & 15
1 1 0 0 0
17. How AND and OR can be realized using NAND and NOR gate. (Ref.
Algebraic expression : 𝑨 + 𝑩 = 𝑨 . 𝑩 11,12 & 14 , 15)
De Morgan's First theorem – Proved
13.Prove – De Morgan First theoremRef. 11 & 12 18.Explain XOR Gate withTruth Table.
 It is called exclusive - OR gate
14.Explain NAND operator with Truth Table.(or)  The output is TRUE if the inputs are different,
Write short note on NAND gate: otherwiseFALSE.
 The NAND is the combination of NOT and AND
 NAND=inverting the output of an AND operator
Algebraic expression :Y = 𝐴. 𝐵
TRUTH TABLE
A B A.B Y = 𝐴. 𝐵
0 0 0 1
0 1 0 1
Algebraic expression : C = 𝑨 .B + A . 𝑩
1 0 0 1
TRUTH TABLE
1 1 1 0
A B 𝐴 𝐵 𝐴 .B A.𝐵 𝐴 .B+A.𝐵
All inputs are TRUE , output is FALSE
0 0 1 1 0 0 0
LOGIC CIRCUIT
0 1 1 0 1 0 1
1 0 0 1 0 1 1
1 1 0 0 0 0 0
LOGIC SYMBOL ⊕or "encircled plus"stands for the XOR
Therefore
C = A ⊕B
Logic Symbol

15.Explain Bubbled OR Gate 19.Write short note on XNOR Gate with Truth Table
Algebraic expression : C= 𝑨 + 𝑩  It is also called exclusive - NOR gate
LOGIC CIRCUIT
 It is a combination XOR gate followed by NOT.
 The output is FALSE if the inputs are different,
Otherwise TRUE .

LOGIC SYMBOL Algebraic expression : C = 𝑨 .B + A . 𝑩


13
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

A B 𝐴 𝐵 𝐴 .B A.𝐵 𝐴 . B+A.𝐵 C=A⊙B


0 0 1 1 0 0 0 1
0 1 1 0 1 0 1 0
1 0 0 1 0 1 1 0
1 1 0 0 0 0 0 1

⊙ or "included dot" stands for the XNOR.


Therefore, C = A ⊙ B
Logic Symbol Ref book

20.Prove the following Absorption law by using Truth Table A + (A . 24.Explain the Derived gates with expression and truth table.
B) = A Ref. 9,11,14,15,& 16

A B A.B A+(A.B) CHOOSE THE CORRECT ANSWER


0 0 0 0
0 1 0 0
1 0 0 1 1. Which is a basic electronic circuit which operates on one or more
1 1 1 1 signals?
Hence, A + (A . B) = A is proved (A) Boolean algebra (B) Gate
21.Write De Morgan‟s laws (C) Fundamental gates (D) Derived gates
First Law : 𝑨 + 𝑩 = 𝑨 . 𝑩 2. Which gate is called as the logical inverter?
Second Law : 𝑨. 𝑩 = 𝑨 + 𝑩 (A) AND (B) OR ( C) NOT (D) XNOR
22. Write the associative laws? 3. A + A = ?
1)A + (B + C) = (A + B) + C (A) A (B) O (C ) 1 (D) A
2) A . (B . C) = (A . B) . C 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

23.Explain the theorems of Boolean Algebra

14
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Unit I Fundamentals of Computers CHAPTER 3


Computer Organization

1.Differentiate between computer architecture and Computer 5. What are the parameters which influence the characteristics of a
organization microprocessor? Or
Computer Architecture What are the Characteristics of Microprocessors.?Explain
 It deals with the engineering considerations. There are three important Characteristics of Microprocessors. They are,
 It is used in designing a computer. a) Clock speed
Computer Organization b) Instruction set
 It deals with the hardware components. c) Word size
 It is used forProgrammer.
Clock speed
2.What is microprocessor? Define microprocessor.  Every microprocessor has an internal clock.
 The microprocessor is a programmable multipurpose silicon chip.  The speed of instruction execution in microprocessor is called the
 It is controlled by clock pulses. clock speed.
 It accepts input as a binary data and after processing, it  Clock speed is measured in MHz (Mega Hertz) or in GHz (Giga
provides the output data as per theinstructions stored in the Hertz).
memory. Instruction set
 Instruction is a commandused to perform an operationbased on
data.
 Basic setof instructions to execute by microprocessor is called
an instruction set.
Types of operations
 Data transfer
 Arithmetic operations
3.What are the main units of Microprocessor(CPU)? Explain  Logical operations
Microprocessor is made up of 3 main units. They are,  Control flow
1. Arithmetic and Logic unit (ALU)  Input/output
2. Control unit Word size
3. Registers (Internal Memory)  The number of bits that can be processed by a processor in a
Arithmetic and Logic unit (ALU): single instruction is called its word size.
 The ALU performs arithmetic operations and logical 
instructions based on computer instructions 6.What is an Instruction?
 Send the result to internal memory.  Instruction is a commandused to perform an operationbased on
Control unit: data.
 To control the overalloperations of the computer through
signals. 7.How to determine architecture of themicroprocessor?
Registers (Internal Memory):  Total number of input and output pins determine the architecture of
 They are used to hold the instructionand data for the execution the microprocessor
of the processor.
8.What is the use of program counter? Or What is a Program
counter?
4.What is System Bus?  The Program Counter (PC) is a special register in the CPU which
 A bus is a collection of wires used forcommunication between the always keeps the address of the next instruction to be executed.
Microprocessor and otherdevices.
There are 3 types of buses, they are
1. Address bus
2. Data bus
3. Control bus

15
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

9.Explain how Data communication between CPU and memory. Or Random access,
How the read and write operations are performed by a processor?  Any byte of memory can be accessed directlywithoutorderly
Explain manner from starting to end.
19.Differentiate between RAM and ROM
 The Central Processing Unit(CPU)has a Memory Data Register (MDR) 20.Write short note on Read Only Memory (ROM).
anda Memory Address Register (MAR). 21.Write short note on Random Access Memory (RAM).
 MDR keeps the data. RAM
 MAR keeps the address of data.  It is volatile memory
 The program counter(PC) is a special register in the CPU. It is  Operating System,Application Programs and the data in
currentuse are kept temporarily
used to keep the address of the next instruction.
 It allows both read and write
 The Data bus is connected with MDR.  Stores temporarily
 The address bus is connected with MAR.  When the power is turned off, whatever data stored in RAM is
 The word in the RAM has the same size as MDR. lost
 The read operation transfers the data from word(RAM) to MDR.  They are two types SRAM,DRAM
 The write operation transfers the data from MDR to Word(RAM) ROM
 It is non-volatile memory
 ROM stores critical programs during the manufacturing .
 It can only be read.
 Stores permanently
 It retainsits contents even when the computer is turned off.
 They are PROM,EPROM,EEPROM

17.Write the types of RAM.


There are two basic types of RAM
• Dynamic RAM (DRAM)
• Static RAM (SRAM)
11.How microprocessors are classified ? Dynamic RAM (DRAM)
 based on the Data Width  Dynamic RAM being a common type needs to berefreshed
 based on Instruction Set frequently.
12.How Microprocessors are classified based on the Data Width or  Slower than SRAM
size of the data?  Less expensive.
 Depending on the datawidth, microprocessors can process Static RAM (SRAM)
instructions.  Static RAM needs to be refreshed less often.
It can be classified as follows:  It is faster.
• 8-bit microprocessor  It is expensive .
• 16-bit microprocessor
• 32-bit microprocessor 22.What are the types of ROM?Explain.
• 64-bit microprocessor  Programmable Read Only Memory (PROM)
 Erasable Programmable Read Only Memory (EPROM)
14.What are the types of microprocessors based on instruction set?  Electrically Erasable Programmable Read Only Memory (EEPROM)
There are two types, they are Programmable Read Only Memory (PROM)
 Reduced Instruction Set Computers (RISC)  It is a non-volatile memory.
Ex.Pentium IV, Intel P6, AMD K6 and K7  Data can be written only once.
 Complex Instruction Set Computers (CISC)  Content cannot be erased.
Ex.Intel 386 & 486, Pentium, Pentium II and III, and Motorola 68000  The process of programming a PROM is called burning the PROM.
Erasable Programmable Read Only Memory (EPROM)
16.What are the methods of accessing memory?  It is a non-volatile memory.
 There are two types of accessing methods to access (read or write)  Data can be written many times.
the memory.  The content can be erased using ultraviolet rays.
 They are sequential access and random access  Used in personal computers.
Sequential access, Electrically Erasable Programmable Read Only Memory (EEPROM)
 The memory is accessed in an orderly manner from  It is a non-volatile memory.
starting to end.  It can be erased by an electrical charge.
 It is slower in performance.

16
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

23 Differentiate between EEPROM and PROM . ref.above ans 32.Explain different types of Ports and Interfaces in computer.
Differentiate between EEPROM and EPROM . ref.above ans Serial Port: To connect the external devices like screen
Which source is used to erase the content of a EPROM.ref.aboveans Parallel Port: To connect the printers.
24.Define Cache Memory. USB Ports:
 It is a very high speed and expensive memory  To connect external devices like cameras, scanners, mobile
 It is closer to CPU. phones, external hard disks and printers to the computer.
 It is in between the CPU and the main memory.  It stands for Universal Serial Bus (USB)
25.Define Access Time.  USB 3.0, USB 3.1 ,USB 3.2 can transfer data up to 5GB/Sec.
 How quickly the memory can respond to a read / write request is VGA Connector: To connect a monitor,LCD projector.
called as Access Time. Audio Plugs: To connect sound speakers, microphone and headphones.
26.List some secondary storage Devices. PS/2 Port: To connect mouse and keyboard to PC.
1.Hard Disk 2.Compact Disc (CD) SCSI Port: To connect the hard disk drives and network connectors.
3.Digital Versatile Disc (DVD) 4.Flash Memory Devices. 5. Blu-Ray Disc
27.Write short note on Hard disk. 33.Define High Definition Multimedia Interface (HDMI) or What is
 Hard disk is a magnetic disk used to store data. HDMI?
 It has the stacked arrangement of disks accessed by a pair of  It is an audio/video interface .
heads for each of the disks.  It transfers the uncompressed video and audiodata from a
 The hard disks come with a single or double sided disk. video controller, to computer monitor, LCD projector, digital
television etc.
28.Differentiate CD and DVD( ref. above answers) 32.Arrange the memory devices in ascending order based on the
Compact disk(CD) access time
 CD is made up of polycarbonate plastic material. 1.Cache Memory.
 A thin layer of aluminum or gold is applied to the surface.  It is a very high speed and expensive memory
 In CD, data is represented as "pits" encoded in a spiral track on top.  It is closer to CPU.
 The areas between pits are known as "lands".  Itis in between the CPU and the main memory.
 A motor within the CD player rotates the disk. 2.Main Memory
 The capacity is 700MB RAM
Digital Versatile Disc (DVD)  It is volatile memory
 DVD is an optical disc  It allows both read and write
 DVDs are read with a laser.  Stores temporarily
 The disc can have one or two sides, and one or two layers per side;  When the power is turned off, whatever data stored in RAM is
 Single layer has 4.7 GB capacity, lost
 Double layer has 8.5 GB capacity.  They are two types SRAM,DRAM
 Double-layered sides are usually gold-coloured ROM
 Single-layered sides are usually silver-coloured, like a CD  It is non-volatile memory
30.How will you differentiate a flash memory and an EEPROM?  ROM stores critical programs during the manufacturing process
Flash memory itself i.ebooting
 Flash memory is non-volatile.  can only be read.
 It can be electrically erased and reprogrammed.  Stores permanently
 It offers fast access times  They are PROM,EPROM,EEPROM
 They are either EEPROM or EPROM. 3.Secondary Storage Devices
Ex. Pendrives, Memory cards etc  They are non-volatile in nature.
EEPROM  Secondary storage devices are used to store data and programs
 It is a non-volatile memory. permanently
 It can be erased by an electrical charge.  They are also called as Backup storage
 It is slower in performance. They are Hard Disk,C, D,DVD,Flash memory ,Blue Ray Disk etc..

31.Define Blu-Ray Disc


 It is a high-density optical disc similar to DVD.
 It can store up to 50GB of data.
 DVD uses a red laser to read and write data.
 Blu-ray uses a blue-violet laser to write.
 Hence, it is called as Blu-Ray.

17
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

CHOOSE THE CORRECT ANSWER

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
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 thememory 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 disc
7. How many memory locations are identified by a processor with 8 bits
address busat 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

18
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT - I Fundamental of Computers CHAPTER 4


Theoretical concepts of Operating System
1.Define Software. 8.What is User Interface?
 A software is set of instructions that perform specific task.  User interface is used to make interaction with a Computer.
 It interacts with the hardware to generate the output. 9.What is GUI ?
2.What are the types of software?Explain.  It stands for Graphical User Interface
Software is classified into two types:  The GUI is a window based system with a pointingdevice to
1) Application Software direct I/O
2) System Software  Graphical elements Menus,Windows,Tabs,icons
Application Software: are attract the user very easily.
 Application software is a set of programs to perform specific
task. Ex. MS-word ,VLC ,flash etc.. 10.What are the points to be considered when user interface is
System Software: designed?
 System software is designed to run the computer‟s hardware  It should enable the user to retain a longer time.
and application programs.  It should save user‟s time.
Ex. Operating System , Language Processor  Create graphical elements Menus,Window,Tabs,icons etc
3.What is operating system?  It should reduce of errors committed by the user.
 An operating System(OS) is a System software.  It is to satisfy the customer.
 It serves as an interface between a user and a computer.
 It controls input, output and other peripheral devices. 11.What is Memory Management in OS? or
 Operating System manages all the Software and Hardware. What are the advantages of memory management in Operating
 Ex.Windows,Linux,Unix ,Android and iOS as Mobile OS. System?
4.Explain the main purpose of an operating system. (or)  Memory Management is the process of controlling and
List out any two uses of operating system. (or) coordinating computer‟s main memory.
 Easy interaction between the users and computers.  it ensures the availability of memory .
 Starting computer operation automatically when power is  it involves the allocationand de-allocation of memory blocks
turned on (Booting).
 ControlInput and Output Devices 12.What are the categories of computer process?
 Manage the utilization of mainmemory.  system code
 Providing security to user programs  user code
5.What are the types of Operating System?Explain.
Two types, 13. List the algorithms used to allocate the job in computer.
 Single User Operating Systems Explain.or
 Multi-user Operating Systems Explain the algorithms used in process management.
Single User Operating Systems  Process management includes creating and deleting processes
 It allows only a single user to perform a task at atime.Ex.MS-DOS The algorithms used to allocate the job in computer are,
Multi-user Operating Systems 1. FIFO 2. SJF 3. Round Robin4. Based on Priority
 It allows multiple user to perform a task at a time Ex. Windows, 1. FIFO (First In First Out)Scheduling:
Linux and UNIX  It is based on queuing technique
6.What is the multi-user Operating system?  First isexecuted first by the CPU, followed by the next and so on.
 It allows multiple user to perform a task at a time Ex. Windows, 2. SJF (Shortest Job First)Scheduling:
Linux and UNIX  It works based on the size of the job .
7.List out the key features of Operating System  Consider two jobs A and B.
 User Interface 1) A = 6KB 2) B = 9KB
 Memory Management First the job “A” will be assigned and then job “B” 3.Round Robin
 Process management Scheduling
 Security Management  It is based ontime sharing .
 Fault Tolerance Ex.Take three jobs A, B, C.
 File Management First the job A is assigned to CPU then job B and job C and then again A,
 Multi-Processing B and C and so on.
 Time-sharing
4.Based On Priority
19
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 It is based on a Priority. What are the advantages and disadvantages of Time-sharing


Take two jobs A and B. Let the priority of A be 5 and priority B be 7. features?
 Job B is assigned first.  The division of timeto multiple processis called Time- sharing.
 The processor switches rapidly between various processes .
14.Explain Security Management in OS. Or Disadvantages.
What are the Security levels in OS.  Problem of data communication.
What are the security management features available in Operating  Problem of reliability
System ? Assume3processes called P1, P2, P3.
 It is used to protect data from hackers. Time allocated for each process 30, 40,50 min.res.
 The Operating System provides three levels of securities. They are  If P1 completes within 20 minutes
(1) File access level  Then processor takes P2.
(2) System level  If P2 could not complete within 40 minutes,
(3) Network level  then P2 will be paused and switch over to the next P3.
(1) File access level
File creator generate access permission
(2) System level 21.What is Distributed Operating Systems?
It is offered by the password Explain the concept of a Distributed Operating System
(3) Network level
It is indefinable  The Distributed Operating System is used to access shared data
and files in any machine around the worldusing internet /
15.Define Fault Tolerance of computer. intranet
 OS have fault tolerance capabilities and retain the existing state  The user can handle the data from differentlocations.
of system. The advantages of distributed Operating System
16.What is File Allocation Table (FAT)?  The resources available from one location toanother location.
 File Allocation Table (FAT) is a file management technique in OS.  Many computer resources can be added easily in the network
 Any type of data in a computer is stored in the form of files  Improves the interaction with the customers and clients.
and directories/folders through File Allocation Table (FAT).  Reduces the load on the host computer.
 The FAT stores general information about files like filename,
type ,size, starting address and access mode. 23.Give some list of Prominent OS. Or
17.Explain File Management in OS. What are the different Operating Systems used in computer?
 OS manages the files, folders and directory systems on a  UNIX
computer.  Microsoft Windows
 Any type of data in a computer is stored in the form of files  Linux
and directories/folders through File Allocation Table (FAT). For mobile
 The FAT stores general information about files like filename,  iOS
type (text or binary), size, starting address and access  Android
mode.
 OS helps to create, edit, copy, allocate memory to the files.
 There are few other file management techniques available like
1.Next Generation File System (NTFS)
2.ext2(Linux).
18.Write short note on Multi-Processing.

 It has two or moreprocessors for a singlerunning process


(job).
 Processing takes place in parallel is known as parallel
processing.
 Itincreases the power of computing.

19.Explain how Time-sharing works on computer with an example?or


Define Time-sharing. CHOOSE THE CORRECT ANSWERS

20
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

1.Operating system is a
A)Application Software B) Hardware C)System Software D)Component
2) Identify the usage of Operating Systems
A)Easy interaction between the human and computer
B)Controlling input & output Devices
C)Managing use of main memory
D)All the above
3) Which of the following is not a function of an Operating System?
A)Process Management B)Memory Management
C)Security management D)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)NFT

21
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT - I Fundamental of Computers CHAPTER 5


Working with Windows Operating System
Windows Vista -2006
1.Define operating system? • Updated the look and feel of Windows.
 An operating System(OS) is a System software. Windows 7 -2009
 It serves as an interface between a user and a computer. • Booting time was improved, introduced new user
 It controls input, output and other peripheral devices. interfaces like Aero Peek, pinning programs to
 Operating System manages all the Software and Hardware. taskbar,handwriting recognition etc.
 Ex.Windows,Linux,Unix ,Android and ioS as Mobile OS. Windows 8 -2012
• Windows 8 is faster than previous versions of
2.Define Multitasking. Windows.
 Multiple applications can execute simultaneously in • Start button was removed.
Windows O.S is known as “Multitasking”. • multi-core processing, solid state drives (SSD), touch
screensintroduced.
3.What are the functions of Windows O. S? • common for mobile and computer.
 Access applications (programs) on the computer Windows 10 -2015
 Load any new program on the c o m p u t e r. • Start Button was added again.
 Manage hardware such as printers, scanners,mouse, digital • Multiple desktop.
cameras etc., • Cortana voice activated personal assistant.
 File management activities . 5.What are the mouse actions?
 Change computer settings . Point to an item ,Click, Right click ,Double-click ,Drag and drop
4.Explain the Various versions of Windows. 6.Write short note on Desktop.
Windows 1.x - 1985  The opening screen of Windows is called “Desktop”.
• Introduction of GUI in 16 - bit. processor  It shows the Start button, Taskbar, Notification Area and date
• Mouse was introduced as an input device. and time.
Windows 2.x -1987 7.Define Icon
• Supports to minimize or maximize windows.  Icon is a graphic symbol representing the window elements
• Control panel feature was introduced . like files, folders, shortcuts etc.,
Windows 3.x -1992 There are three types of icons, they are
• Introduced the concept of multitasking. 1.Standard Icons 2. Shortcut icons 3. Disk drive icons
• Supported 256 colours. 8.What are called Standard Icons?
Windows 95 -1995  Standard icons are available on desktop by default while
• Introduced Start button, the taskbar, Windows installing Windows OS .
Explorer and Start menu.  Ex.My Computer, Documents and Recycle Bin.
• Introduced 32 - bit processor.
Windows 98 -1998 9. Define Shortcut Icons.
• Integration of the Web browser (Internet Explorer)  Shortcut icons can be created for any application or file or
with the Operating System. folder.
• Windows based games improved. 10. Define Disk drive icons
• Plug and play feature was introduced. The disk drive iconsgraphically represent five disk
Windows NT drive options.
• Designed to act as servers in network. 1. Hard disk
Windows Me -2000 2. CD-ROM/DVD Drive
• It introduced automated system diagnostics and 3. Pen drive
recovery tools. 4. Removable storage
5. Network drives .
Windows 2000 -2000 11.Differentiate between Application window and Document window.
• for business desktop,laptop and server.. Application window
Windows XP -2001  It contains current application such as Word or Paint.
• Introduced 64-bit Processor.  It is larger window.
 It helps the user to communicate with the Application program.

22
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Document window 18.Differentiate Files and Folders.


 It is inside the Application Window, Files
 It is smaller window.  In computer, all information and programs are stores in the form of
 It is used to display the contents of a document. files.
 This Window is used for typing, editing,drawing, and formatting  Each file has name with extension.
the text and graphics. Ex. Myfile.docx
12. Write a note on the elements of a windows Folder
Title Bar  Folders contain files and sub-folders.
 The title bar will display the name of the application and the  Folder has name without extension.
document.
 It will also contain minimize, maximize and close button. 19.What is the use of a file extension?
Menu Bar  File extension is used to know that in which application the file is
 The menu bar is seen under the title bar. associated with
 Menus in the menu bar can be accessed by pressing Alt key 20.What is Wordpad?
(or)F10and the letter appears underlined.  Wordpad is an in-built word processor application in Windows OS
 To visible menu bar click organize -> Layout to create and manipulate text documents.
The Workspace 21.How to open Wordpad?
 Place to enter or type the text of your document.  Click Start → All Programs → Accessories →Wordpad or
Scroll bars  Run → type Wordpad, click OK.
 The scroll bars are used to scroll the workspace horizontally or  Double click on Wordpadicon
vertically.
Corners and borders 22.How to create file in wordpad? How to save first time in
 Ithelps to drag and resize the windows. wordpad?
13.What is the use of start menu? Select File → Save or Ctrl + S.
Start menu, used tostart any application.  In Save As dialog box ,
14.Define Task bar  select the location by using look in drop down list box.
 A horizontal bar at the bottom of the screen is called the taskbar.  Type the name of the file in the file name text box.
 This bar contains the Start button and shortcuts to various  Click save button.
programs. 23.Differentiate Save and save As option.
 The system tray in the right corner consist of volume
control,network,date and time etc. Save Save As
15.How to start an application in windows? Save as dialog box appears first Save as dialog box appears
 Click Start button ->All Programs. time only always
Point to the group and click the application name Used to save the modification Used to save the modification
 Click Run on start menu and enter the application without changing name and with changing name and location
16.How to Quit an application? location of file of file.
 Click the Close button
 File →Close and File -> Exit 24.Explain how to find(search) a file or folder in windows 7
17.Write the methods to create folder. Method 1 (Using Start menu)
Method I:  Click the Start button, select search box
 Open Computer Icon.  Type the name of the file or the folder you want to search.
 Open any drive (For example select D:)  It will display the list of files or folders starting with the specified
 Click on File → New → Folder. name.
 A new folder is created with the default name “New folder”.  Just click and open that file or the folder.
 Type in the folder name and press Enter key. Method 2 (using computer icon)
Method II:  Click Computer Icon .
 (For example in the Desktop), right click → New  Select any disk drive screen.
 → Folder.  At the top right corner of that screen, there is a search box
 A new folder is created with the default name “New folder”. option.
 Type in the folder name and press Enter key.  Type the name of the file or the folder you want to search.
 It will display the list of files or folders starting with the specified
name.
 Just click and open that file or the folder.

23
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

25.How will you Rename a File? 28.Differentiate cut(Move) and copy options.
Using the FILE Menu copy Cut (move)
 Select the File or Folder . It leaves the files or text from It removes the files or text
 Click File→ Rename. source location and place them from source location and place
 Type in the new name. in the destination location them in the destination location
 Press Enter To copy, ctrl + c , Edit - To cut(move), ctrl + X,
Using the Right Mouse Button >copy Edit - >cut
 Select the file or folder . 29.How to Deleting Files and Folders in Windows 7?
 Right click - > Rename  Select the file or folder.
 Type in the new name.  SelectRight- click -> Deleteor
 Press Enter.  Click File → Delete or press Delete key from the keyboard.
Using the Left Mouse Button  The file will be deleted and moved to the Recycle bin.
 Select the File or Folder. 30.How to delete a file or folder permanently in windows ?
 Press F2 .  To permanently delete a file or folder (i.e. to avoid hold down the
 Type in the new name. SHIFT key, and press delete on the keyboard.
 Press Enter. 31.Write a note onRecycle bin?
 Recycle bin is a special folder to keep the files or folders
26.Explain the different methods of copy and cut(Move) Files and deleted by the user,
Folders.  The user cannot access the files or folders in the Recycle bin
Method I - COPY and PASTE withoutrestoring it.
 Select the file or folder To restore file or folder from the Recycle Bin
 Click Edit → Copy or Ctrl + C or right click → Copy In recycle bin
 Move to new location and paste it using  Right click on a file or folder .
 Click Edit → Paste or Edit -> Paste or Ctrl + V Or Right click  Select Restore for one .
→ Paste  Restore all for multiple files or folders
 The file will be pasted in the new location. To delete
Method II-CUT and PASTE  select Empty the Recycle Bin.
 Select the file or folder 32.How to Creating Shortcuts on the Desktop
 Click Edit → Cut or Ctrl + X or right click → cut Select the file or folder
 Move to new location and paste it using • Right click on the file or folder.
 Click Edit → Paste or Edit -> Paste or Ctrl + V Or Right click • Select Send to->Desktop (create shortcut)
→ Paste • A shortcut for the file or folder will now appear on your desktop.
 The file will be pasted in the new location.
Method III – Drag and Drop 33.How to shutting down or logging off a computer n Windows.?
 Click and drag the selected file and/or folder . Close your all open programs.
 drop it where you want to copy the file and/or folder. Click start → log off or Start → Shutdown .
 Your file(s) or folder(s) will now appear in the new area. • Switch User: Switch to another user account on the computer
27.How to Copying Files and Folders to removable disk? without closing your open programs and Windows processes.
Method - I • Log Off: Switch to another user account.
 Select the file or folder • Lock: Lock the computer
 Click Edit → Copy or Ctrl + C or right click → Copy • Restart: Reboot the computer.
 Click Start→Computer. • Sleep: Puts the computer into a low-power mode that retains all
 Double-click on the Removable Disk drive . running programs and open Windows for a super-quick restart.
 In Removable Disk window, right-click -> Paste • Hibernate (found only on laptop computers): Puts the computer into a
Your file(s) or folder(s) will now appear in the new area. low-power mode after saving all runningprograms and open windows
METHOD II - Send To for a quick restart.
• Plug in the USB flash driveand open
• Right-click on the file you want to transfer to your removable 34.Differentiate between Hibernate and Sleep .
disk. ref. above answer
• Click Send To->Removable Disk

24
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

CHOOSE THE CORRECT ANSWER

1.From the options given below, choose the operations managed by the
operatingsystem.
a. Memoryb. Processorc. I/O devicesd. 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 afile or folder?
a.Windows 7 b.Windows 8
c.Windows10 d. None of the 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 remain a file in windows
a. F2 b.F4 c.F5 d.F6

25
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Unit II Algorithmic Problem Solving CHAPTER 6


Specification and Abstraction
4.Define function or define Decomposition
Define Algorithm.  Some algorithms can become very complex,
 An algorithm is a step-by-step sequence of instruction to solve a In such situations,
problem.  The parts of an algorithm are known as functions.
 Construct each part (function)separately,
1.Distinguish between an algorithm and a process. and then integrate the parts to the complete algorithm.
Algorithms. 5.What are the basic principles and techniques for designing
 An algorithm is a step-by-step sequence of instruction to solve a algorithms?.
problem. 1. Specification
Process. 2. Abstraction
 Processes are generated by executing algorithms to solve the 3. Composition
given problem. 4. Decomposition
2.When do you say that a problem is algorithmic in nature? Specification
 The construction of an algorithminvolves to solve the  The first step in problem solving is specification.
algorithmic problem.  Specification of algorithm must state the name of the alogorithm,
3. What are the building blocks of Algorithms? Explain the input property and desired output.
 Data Abstraction
 Variables The process of providing only the essentials and hiding the details is
 Control flow known as abstraction
 Functions Composition
Data  An algorithm is composed of assignment and control flow
 Algorithms take input data, process the data, and produce statements.
output data  A control flow statement tests a condition of the state
Variables  depending on the value of the condition,
 Variables are named boxes for storing data.  decides the next statement to be execute
Control flow Decomposition
 An algorithm is a sequence of statements.  A function is like a sub algorithm.
 The order of execution of statements is known as the control flow.  Construct each part (function)separatelyand then integrate the
There are three important control flow statements. parts to the complete algorithm.
 Sequential control flow
 Alternative control flow 6.What is abstraction? Ref. above ans.
 Iterative control flow 7.Define State.
Sequential control flow  The process of providing only the essentials and hiding the details
 Statements are executed one after another in the same order is known as abstraction
Alternative control flow  State is a basic and important abstraction.
A condition of the state is tested,  A computational process starts with an initial state.
 if the condition is true, one statement is executed;  As actions are performed, It ends with a final state.
 if the condition is false, an alternative statement is executed
Iterative control flow 8.Define Assignment statement. Or
 A condition of the state is tested, What is the form and meaning of assignment statement?
 if the condition is true,  Assignment operator (=)is used to assignVariable on the left side
 A statement is executed and executing the statement are and a value on the right side.
repeated until the condition becomes false.  Ex. variable = value/expression; a:=2 (variable a stores value
2)
Define control flow in algorithm. or 9.Define Equality operator.
What are the types of control flow ?Explain. or  Equality operator(==) is used to compareboth the value .
Differentiate between alternative control flow and iterative control  Results in either true or false.
flow.  Ex.Variable1 = = variable 2
Ref.above answer What is the difference between assignment operator and equality
operator? Ref.Q6 & 7
26
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

10.What is command statements? How commands are indicated? quadratic_solve (a, b, c)


 Comments statements are used to add notes to a program -- inputs : a,b,c are real numbers .
 It is not executed by the computer. -- outputs: x 1 , x2 are real numbers
 A double dash-- indicates a comment
11.Initially, X1 =
−𝑏+ 𝑏 2 −4𝑎𝑐
Farmer, goat, grass, wolf = L, L, L, Land the farmer crosses the 2𝑎
−𝑏− 𝑏 2 −4𝑎𝑐
river with goat. X2 = 2𝑎
Model the action with an assignment statement.
 Let us name the variables farmer, goat, grass,wolf.
 Their possible values L and R. 17.Exchange the contents: Given two glasses marked A and B. Glass
 A value of L means "at the left side". A is full of appledrink and glass B is full of grape drink. For
 A value of R means "at the right side". exchanging the contents of glasses A and B,represent the state by
 In the initial state, all four variables suitable variables, and write the specification of the algorithm.
 farmer, goat, grass, wolf have the value L. Exchange(A,B)
--farmer, goat, grass, wolf = L, L, L, L --input: A , B are integers
The farmer crosses the river with goat. --output: A,B are integers T=0
--input : farmer,goat = R,R T:=A
--output: farmer, goat, grass, wolf = R,R, L, L A:= B
12.What is the format of the specification of an algorithm? B:= T
 Let P be the required property of the inputs
 Q the property of the desired outputs. 1.Which of the following activities is algorithmic in nature?
Then the algorithm S is specified as (a) Assemble a bicycle. (b) Describe a bicycle.
1. Algorithm_name (inputs) (c) Label the parts of a bicycle. (d) Explain how a bicycle works.
2. -- inputs : P 2. Which of the following activities is not algorithmic in nature?
3. -- outputs: Q (a) Multiply two numbers. (b) Draw a kolam.
13.Specify a function to find the minimum of two numbers. (c) Walk in the park. (d) Braid the hair.
1.Minimum (a,b) 3. Omitting details inessential to the task and representing only the
2.--inputs: a,b are integers or real numbers essential features of the task is
3.--outputs: a is minimum if a<b known as
B is minimum if b<a (a) specification (b) abstraction
14.If √2 = 1.414, and the square_root() function returns -1.414, does(c) composition (d) decomposition
it violate thefollowing specification? 4. Stating the input property and the as :-output relation a problem
-- square_root (x) is known
-- inputs: x is a real number , x ≥ 0 (a) Specification (b) statement
-- outputs: y is a real number such that y2 =x (c) algorithm (d) definition
Ans .Yes. 5. Ensuring the input-output relation is
15.Write the specification of an algorithm hypotenuse whose inputs (a) the responsibility of the algorithm and the right of the user.
are the lengths of the two shorter sides of a right angled triangle, (b) the responsibility of the user and the right of the algorithm.
and the output is the length of the third side. (c) the responsibility of the algorithm but not the right of the user.
(d) the responsibility of both the user and the algorithm.
Hypotenuse (S1,S2) 6. If i = 5 before the assignmenti := i-1 after the assignment, the
--inputs: S1 and S2 are Integersorreal numbers value of i is
--output: l 2 = S1 2 + S2 2 l is a real or integer (a) 5 (b) 4 (c) 3 (d) 2
16.Suppose you want to solve the quadratic equation ax2 + bx + c = 0 7. If 0 <i before the assignment i := i-1 after the assignment, we can
by an algorithm. conclude that
quadratic_solve (a, b, c) (a) 0 <i (b) 0 ≤ i (c) i = 0 (d) 0 ≥i
-- inputs : ?
-- outputs: ? Answers:
You intend to use the formula and you are prepared to handle only 1.a 2.d 3.b 4.a 5.d 6.4 7.b
real number roots.
Write a suitable specification.

27
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Unit - II Algorithmic Problem CHAPTER 7


SolvingSolvingFundamentals of
ComputerFundamentals Composition and Decomposition
of Computers
1.What are the notations for representing algorithms? 8.Distinguish
Part – I : Working between an algorithm
with Windows OSand a Program.
Or Explain the Notations of algorithm. (QN. 2,3,4)
 Programming language, pseudo code, and flowchart are Algorithm Program
notations for expressing algorithms.
An algorithm is a finite set of Program is set of instruction in a
2.Define Programming language
 Set of Instruction in programming Language is called Program. instructions to do a particular programming language
 Programs must obey the grammar of the programming language task.
exactly. It is a step-by-step procedure Set of Instruction
 There is a translator which translates the program into for solving a given problem.
instructions executable by the computer suitable for any programming for particular language with
 Ex. C , C++ , Python etc…
language. specific syntax
3.Define Pseudo code
 Pseudo code is a mix of programming language and English. with no specific rules
 pseudo code is not for computers but for human readers.
4.What is a Flowchart 9.What are the types of control flow?
 Flowchart is a diagrammatic notation for representing There are three types, they are ,
algorithms.  Sequential
 A flowchart is a collection of boxes containing statements and  Alternative
conditions  Iterative
 which are connected by arrows showing the order of
execution 10.Write about sequential control flow with flowchart.
5.List the symbols used in flowchart.  Statements are executed one after another in the same order
 Start / End - start / end of an execution Let S1 and S2 be statements.
A sequential statement of S1 and S2 is ..
 Parallelogram- represent inputs/outputs S1
S2
 Rectangular- to indicate a process
 11.Write about Alternative control flow with flowchart
 Diamond-represent acondition with two outgoing arrows,labeled A condition of the state is tested,
true and false.  if the condition is true, one statement is executed;
 if the condition is false, an alternative statement is executed.
Let S1 and S2 – Statements
C - Condition
If C
6.List out the disadvantage of Flowchart. S1
 Flowcharts are less compact else
 They cannot display clearly hierarchical structure of the algorithms. S2
 Flowcharts do not show disciplined control flow structures 1.Test whether C is true or false.
2.If C is true, then do S1; otherwise do S2.
7.Distinguish between a condition and a Statement 12.Explain Conditional Statement with Flowchart.
Statement. OR
 A statement is a phrase that commands the computer to do an Draw a flowchart for conditional statement.
action.  if the condition is true, one statement is executed;
Condition.  if the condition is false, Do nothing
 A condition is a phrase that describes a test of the state. Let S – Statements C - Condition
if C
S
1.Test whether C is true or false.
2.If C is true then do S; otherwise do
nothing.

28
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

13.Both conditional statement and iterative statementhave a 17.Why is function an abstraction?


condition and a statement. How do they differ?  The process of providing only the essentials and hiding the details
is known as abstraction
Conditional statement Function is an abstraction of an algorithm,.
 A conditional statement is executed only if the condition is  A function is like a sub algorithm.
trueotherwise, nothing is done  Construct each part (function)separately,
Iterative Statement and then integrate the parts to the complete algorithm.
 An Iteration statement is a set of statements that are 18.How do we refine a statement? OR
repeatedly executed until a condition is TRUE. Define Refinement.
14.What is case analysis? After decomposing a problem into smaller subproblems,
Write about Case analysis control flow with flowchart.  Each subproblem can be expanded into more detailed steps.
 Case analysis is a multiple branching statement,  Each step can be further expanded.
 Based on a condition, the control is transferred to oneof the many  This is known as refinement.
possible points.
If C1,C2,C3 are conditions True 19.Consider the problem of testing whether a triangle is right-
S1,S2,S3 ,S4 are Statements angled, given its three sides a, b, c, where c is thelongest side. The
C1
case C1 S1 triangle is right-angled, if c2 = a2 + b2
S1 False Here a function square() is specified as
case C2 S2 Square(y)
C2
S2 --input : y
case C3 -- output : y2 (y*y)
S3 Flowchart for square()
else C3 S3
S4 Input y
END
 For each case,the problem is S4
solved independently. Y*y
 If case condition is TRUE ,the
corresponding statement is
executed. Algorithm
 If none of case is TRUE then the default case S4 is executed. Right_angled(a,b,c)
The cases are exhaustive : At least one case is TRUE --input: c>=a,c>=b
The cases are disjoint : The case analysis always execute one case. --output: ifc2 = a2 + b2is true result = TRUE otherwise
15.Write an algorithm that compares two numbers and produce the result = FALSE
result as if ( square(c ) == square(a) + square(b) )
1.Compare (a,b) result: = TRUE it is right angle triangle
2.Case a<b else
3. Result= -1 result: = FALSE it is not a right angle triangle
4.Case a=b Flowchart
5. Result =0
6.Else – a>b start
7. Result = 1
16.Write about Iterativecontrol flow with flowchart
 An Iteration statement is a set of statements that are Input a,b,c
repeatedly executed until a condition is TRUE.
The iterative statement is commonly known as a loop
If C is a condition and S is a statement, then
C2==a2+b2
while C T TRUE
S
This describes the following action: F
1. Test whether C is true or false.
FALSE End
2. If C is true, then do S and go back
to
step 1; otherwise do nothing.

29
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

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


1 S1 23.Circulate the contents: Write the specification and construct an
2 -- C is false algorithm to circulate the contents of the variables A, B and C as
3 if C shown below: The arrows indicate that B gets the value of A, C gets
4 S2 the value of B and A gets the value of C.
5 else
6 S3 Algorithm
7 S4 Contents(a,b,c)
If test condition C is FALSE --input : a=10,b=20,c=30
S3 ,S4 statements are executed. --output: a=c,b=a,c=b
a=30,b=10 , c=20
20.Draw a flowchart for -3case analysis using alternative Algorithm
statements. Start
Read a,b,c
t=b
Case b=a
F==’A’ a=c
“ APPLE” c=t
print a,b,c
End
24.Trace the step-by-step execution of the algorithm for
Case factorial(4).
F==’B’ “BALL” 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
Case
F==’C’ Algorithm
“CAT” Read n=4
’ f=1,i=1
check i<=n if true execute the following loop
{
f=f*i
i=i+1
Default Statement End }
If false comes out of the loop and
21.Define a function to double a number in two different ways: (1) n + Print f
n, (2) 2 x n Output: 24
(1) n + n 2)2*n
Double 1(n) Double2(n)
-- input(n) --input(n)
--output y=n+n --output y= 2 x n 1. Suppose u,v = 10 ,5 before the assignment .What are the values of
22.Exchange the contents: Given two glasses marked A and B. Glass u and v after the sequence of assignments?
A is full of apple drink and glass B is full of grape drink. Write the 1 u := v
specification for exchanging the contents of glasses A and B, and 2 v := u
write a sequence of assignments to satisfy the specification (a) u, v = 5 ,5 (b) u, v = 5 ,10 (c) u, v = 10 ,5 (d) u, v = 10 ,10
Exchange(a,b) 2. Which of the following properties is true after the assignment (at
--input: A , B are integers line 3) ?
--output: A,B are integers T=0 1 -- i+j = 0
T:=A 2 i, j := i+1, j-1
A:= B 3 -- ?
B:= T (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

30
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

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

Answers:
1.a 2.c 3.b 4.a 5.a 6.b

31
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Unit II Algorithmic Problem Solving CHAPTER


8
Iteration and Recursion
1.Define Iteration. 8.Define factorial of a natural number recursively.
 An Iteration statement is a set of statements that are Factorial(n)
repeatedly executed until a condition is TRUE. --input :n
 Each time the loop body is executed, the variables are --output: factorial of n
updated. get n
2.Define Recursion f=1
 Recursion is an algorithm design technique. i=1 -- base case
 It is similar to iteration, but more powerful. loop(i<n) true
 A function definition which call itself is called recursive function f=f*I – recursion step
3.What is an invariant? False: factorial of n
 An expression involving variables, which remains unchanged by an 9.There are 7 tumblers on a table, all standing upside down. You are
assignment. allowed to turn any 2 tumblers simultaneously in one move. Is it
 These variables are called an invariant of the assignment possible to reach a situation when all the tumblers are right side
4.Define a loop invariant. up? (Hint: The parity of the number of upside down tumblers is
 An invariant for the loop body is known as a loop invariant invariant.)
5.Does testing the loop condition affect the loop invariant? Why? Output : To turn all tumblers up
No. It does not affect the loop invariant. The number of tumblers up is u;
Because a loop invariant is true Model
 at the start of the loop 1.
 at the start of each iteration Two tumblers upside up
 at the end of each iteration u increments by 2
 at the end of the loop . u:=u+2
6.What is the relationship between loop invariant, loop condition and 2.
the input- output recursively? Two tumblers upside down
 Establish the loop invariant at the start of the loop. u decrementsby 2
 The loop body should be update the variables and maintain the u:=u - 2
loop invariant, at the same time. 3.
 When the loop ends, the termination condition and the loop One tumbler is upside down and another is proper
invariant should establish the input-output relation. u is not changed
7.What is recursive problem solving? u is either incremented or decremented
To solve a problem recursively, So we can ignore of u not being changed.
 Each solver receives an input and reduces the problem to sub- Now
problems, Invariants are u + 2 , u – 2
 and calls another instance of the solver, known as sub-solver, 10.A knockout tournament is a series of games. Two players
to solve the sub-problem is known as recursive call. compete in each game; the loser is knocked out (i.e. does not play
 The input size to a sub-problem is smaller than the input size to any more), the winner carries on. The winner of the tournament is
the originalproblem. the player that is left after all other players have been knocked out.
From the solution to the sub-problem, the solver constructs the Suppose there are 1234 players in a tournament. How many games
solution to the original problem. are played before the tournament winner is decided?
a recursive solver has two cases: No. of Players : p
Base case: The problem size is small enough to be solved directly. No. of Games : g
Recursion step: The problem size is not small enough. Deconstruct Initially : p=1234 , g = 0
the problem into a sub-problem, strictly p,g := p – 1 , g + 1
smaller in size than the given problem. Invariant is p + g
Finally Winner player is 1 , p = 1
p + g : = 1234
g =1234 - 1
g = 1233 ( No.of games played = 1233)

32
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

11.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 CHOOSE THE CORRECT ANSWER
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 1.A loop invariant need not be true
1000 heads, can it ever die? (Hint:The number of heads mod 3 is (a) at the start of the loop. (b) at the start of each iteration (c) at the
invariant.) end of each iteration (d) at the start of the algorithm
2.We wish to cover a chessboard with dominoes, the number of
If the dragon has 1000 heads we start at 1000=1(mod 3) we cannot get to black squares and the number of white squares covered by
0 .so the dragon lives. 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
12.Assume an 8 × 8 chessboard with the usual coloring. 3. If m x a + n x b is an invariant for the assignment a, b : = a + 8, b
"Recoloring" operation changes the color of all squares of a row or + 7, the values of m and n are
a column. You can recolor re-peatedly. The goal is to attain just one (a) m = 8, n = 7 (b) m = 7, n = -8 (c) m = 7, n = 8 (d) m = 8, n = -7
black square. Show that you cannot achieve the goal. (Hint: If a row 4. Which of the following is not an invariant of the assignment? m, n
or column has := m+2, n+3
b black squares, it changes by (|8 - b) - b|). (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
White squares W = 32 to evaluate F(4), how many times F() is applied?
Black squares B = 32 (a) 3 (b) 4 (c) 8 (d) 9
6. Using this recursive definition
W+ B = 64 , W – B = 0 = 0 mod 4 how many multiplications are needed to calculate a10?
But the required state has 63 W 1 B (a) 11 (b) 10 (c) 9 d) 8
So W – B = 63 – 1 = 62 = 2 mod 4
Which is impossible. Answers:
1.d 2.a 3.b 4.d 5.b 6.9
13.Power can also be defined recursively as

Construct a recursive algorithm using this definition. How


many multiplications are
needed to calculate a 10 ?

Power (a,n)
--inputs : n integer
n
--output : a
If( n=0 ) --base case
1
else if(n is odd)
a x power (a,an-1) -- recursion step
else (n is even)
a x power (a n/2 x a n/2 ) -- recursion step

33
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Unit III Introduction to C++ CHAPTER 9


Introduction to C++
1.History of C++ Describe the differences between keywords and Identifiers?
 C++ was developed by BjarneStroustrup at AT& T Bell Laboratory Ref.6 and 7
during 1979
 it was referred “New C” and “C with Classes”. 8.What are the Rules for naming an identifier?
 In 1983, the name was changed as C++ by Rick Mascitti.  Only alphabets, digits and underscore(_) are permitted.
2.Benefits of learning C++  Other special characters ,space are not allowed.
 C++ is called as Hybrid Language.  The first character of an identifier must be an alphabet or an
 C++ is for multi-device, multi-platform app development. underscore (_).
 C++ has a rich function library • keywords cannot be used as an identifier name.
 C++ is a powerful, efficient and fast language.
 It finds a wide range of applications 9.What is meant by literals/Constants? How many types of Integers
 C++ is an object-oriented programming language. are available in C++?
 It includes classes, inheritance, polymorphism, data abstraction  Literals are called as Constants.
and encapsulation  Literals are data items whose values do not change during the
3.List the languages which are influenced by C++ execution of a program.
 C# (C-Sharp), D, Java and newer versions of C C++ has several kinds of literals:
4.What are the Character set in C++?  Numeric Constants:
 Character set is a set of characters which are  Boolean Literals
allowed to write a C++ program. They are  Character constant
 String constant.
10.Numeric Constants: What are numeric constant and its types.
The numeric constants are only numeric values,
They are,
1. Integer Constants (or) Fixed point constants. Ex. 28
2. Real constants (or) Floating point constants.Ex.28.11

11.How many types of integer literals(or) Fixed point constants


5.What are Lexical units or Lexical elements or Tokens. in C++? available in C++? or
 The smallest individual unit in a program is known as a Lexical unit Explain the types of integer literals in C++.
or Lexical elements or Token.  It is a numeric constant without a decimal point.
They are  It may be signed (negative )or unsigned.
 Keywords  Commas and blankspaces are not allowed.
 Identifiers Three types : (i) Decimal (ii) Octal (iii) Hexadecimal
 Literals Decimal
 Operators  Consists of digits (0 …. 9)Ex. 28 , -28
 Punctuators Octal
6.What are Keywords. Can key words be used as Identifiers?  Consists of digits (0.. 7)begins with 0 Ex.022 , - 022
 Keywords are the reserved words. Hexadecimal
 It conveys specific meaning to the C++ compiler.  Consists of digits (0…9 ,A..F)
 All the keywords must be in lower case in C++.  begins with 0x or 0X Ex. 0x28 , 0X3AC
 keywords cannot be used as an identifier name. 13. What are Real constants (or) Floating point constants
Ex. if ,for ,this, cout , cin, while etc….  It is a numeric constant with a decimal point
7.What are Identifiers?  It may be signed (negative )or unsigned with decimal point
 Identifiers are the user-defined names given to variables,  It may be written in fractional or in exponent form.
functions, arrays, classes etc., Exponent form consists of two parts:
 Identifier can be in any case (1) Mantissa and (2) Exponent.
 keywords cannot be used as an identifier name  The mantissa followed by a letter E or e and the exponent.
Ex. ab,a8,a_5 EX.28.11 , 7.8E3

34
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

14. How to write 58000000 . 00 in Exponent form.?


It may be written as 0.58 × 10 8 or 0.58E8. 19.How to represent a long and unsigned constant ?
Other Example:  The suffix L or lused to represent long constant Ex.25Ls
5.864 E-1 - 5.864 × 10 1 - 58.64  The suffix U or u used to represent unsigned constant. Ex. 25U
5864 E-2 - 5864 × 10 -2 -
58.64
2
0.5864 E-2 - 0.5864 × 10 - 58.64 20.The following constants are of which type?
15.What is Boolean Literals? 1)39 2)032 3)OXCAFE 4)04.14
 Used to represent Boolean values(True (1) or false(0)).
16.Differentiate between Character constant and String constant? 1)Integer 2)Octal
What is Character constant in C++? 3)Hexadecimal 4) Floating point
 It must contain one character
 must be enclosed within a single quote. 21.Write the following real constants into the exponent form:
Ex. „p‟ , „6‟ , „+‟ 1)23.197 2)7.214 3)0.00005 4)0.319
 Each single character constant has an equivalent ASCII value. For
2
„A‟ is 65. 1)0.23197 X 10 =>0.23197E2
What is String Literals? 2)0.7214 X 101 =>0.7214E1
 Set of characters are called Stringliterals. 3)0.5 X 10 -4 =>0.5E -4
 It enclosed within double quotes (“ “ ) . 4)0.0319 X 101 =>0.0319E1
 String should be terminated with a „\0‟ (NULL) character..
 Size of “welcome” is not 7 but 8 including \0 . Evaluate Yourself
Ex. “S” , “Elango” , “123” ,”ELANGO\0” 2. What kind of constants are following?
i) 26 ii) 015 iii) 0xF iv) 014.9
17.What is the significance of null (\0) character in a string? 5. Write the following real constants into exponent form: i) 32.179
 String should be terminated with a „\0‟ (NULL) character Ex. ii) 8.124 iii) 0.00007
,”ELANGO\0” Ans : i)32.179E3 ii)8.124E3 iii)0.7E-4
18.What is Escape sequences (or) Non-graphic Characters (or ) 6. Write the following real constants into fractional form: i) 0.23E4
non- Printable Characters ? ii) 0.517E-3 iii) 0.5E-5 iv)5E-5
 Non-printable characters are also called as Non-graphic Ans: i)2300 ii)0.000517 iii)0.000005 iv) 0.00005
characters.
 These can be represented by using escape sequences. 22.What are Operators and Operands
 An escape sequence is represented by a backslash ( \ ) followed What is the use of Operators?
by one or two characters.  The symbols which are used to do some mathematical or
Ex.\a ,\n , \t etc… logical operations are called as “Operators”.
 The values that the operators act upon are called as “Operands”.
A + B : + operator A , B - Operands
23.How are the operators classified based on operand
requirements?
1. Unary Operators - Require only one operand
2. Binary Operators - Require two operands
3. Ternary Operators - Require three operands
24.How are the C++ Operators are classified based on their
function?
(1)Arithmetic Operators
(2) Relational Operators
(3) Logical Operators
(4) Bitwise Operators
(5) Assignment Operators
(6) Conditional Operator
(7) Other Operators

35
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

25.Define Arithmetic Operators


 Arithmetic operators are binary operators because it require 33.Write short note on Logical Operators
two operands.  Logical operators are binary operator
 It performs operations like addition, subtraction, multiplication,  They are used to combine the results of one or moreconditions.
division etc.,  C++ provides three logical operators.
Ex.+ (Addition ) , - (subtraction ) *( Multiplication ) 1. AND(&&), OR(||) are binary operators
/ (division – Quotient of the division) 2. NOT (!) is an unary operator
% (Modulus – Remainder of the division ) AND(&&) – The result is 1 (TRUE) when all condition are 1 (TRUE)
26.What does the modulus operator % do? OR(||) - The result is 1 (TRUE) when atleast one condition is 1 (TRUE)
 It gives the remainder of the division NOT (!) – it inverts , The result is 1 (TRUE ) when condition is False and
Ex let x=5; x%2; the result is 1 vice versa.
27. What will be the result of 8.5 % 2? Ex. if a = 5, b = 6, c = 7;
 Ans: Error occurs because Modulus operator % cannot be used on Expression Result
floating point data. (a<b) && (b<c) 1 (True)
28.Write short note on Increment and Decrement Operators. (a>b) && (b<c) 0 (False)
 Increment ( + + ) Operator and Decrement ( - - ) Operator are (a<b) || (b>c) 1 (True)
unary operators !(a>b) 1 (True)
 The Increment ( + + ) Operator adds 1 to its operand
 The Decrement ( - - ) Operator subtracts 1 to its operand. 34.Define Assignment Operator.
 x++ is the same as x = x+1;  It is used to assign a value to a variable.
It adds 1 to the present value of x  = is commonly used as the assignment operator.
 ++ x is the same as x = x+1;  This operator copies the value at the right side to the left side
It adds 1 to the present value of x variable.
 x-- is the same as to x = x–1;  It is also a binary operator.
It subtracts 1 from the present value of x Syntax : Variable = Value\ constant\ expression ;
 --x is the same as to x = x–1; Ex. a = 10;
It subtracts 1 from the present value of x 35.What are Shorthand assignment operators?
Example:  +=, -= ,*= , /= , %=
let n=2
Prefix Postfix 36.Write about Binary operator used in C++
a=++n a=n++ Binary operators – Require two operands
First increment the value of First a gets the value of n, then  Arithmetic Operators
n by 1 increment it by 1  Relational Operators
then a gets the value.  Logical Operators
value of a=3 , n=3 value of a=2 , n=3  Assignment Operators
a=--n a=n- -
*First decrements the value *First a gets the value of n, Arithmetic Operators
of n by 1 *then decrement it by 1  Arithmetic operators are binary operators because it require
*then a gets the value value of a=2, n=1 two operands.
of a=1 ,n=1`  It performs operations like addition, subtraction, multiplication,
29. Assume that R starts with value 35. What will be the value of S from division etc.,
the following expression? S=(R--)+(++R) Ex.+ (Addition ) , - (subtraction ) *( Multiplication )
Result: S = 70 / (division – Quotient of the division)
30. What will be the value of j = - - k + 2k. if k is 20 initially ?Result j = % (Modulus – Remainder of the division )
57
31.What will be the value of p = p * ++j where j is 22 and p = Relational Operators
3initially?Result is 69  Relational operators are binary operators.
 Relational operators are used to compare numeric values
32.Write short note on Relational Operators  A relational expression is consists of any two operands with a
 Relational operators are binary operators. relational operator Ex. 10 > 5
 They are used to compare numeric values  The result will be a Boolean value(1(TRUE)or 0(FALSE) ) They are
 A relational expression is consists of any two operands with a > , < , <= , >= ,== ,!=
relational operator Ex. 10 > 5
 The result will be a Boolean value(1(TRUE)or 0(FALSE) ) They are
> , < , <= , >= ,== ,!=

36
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Logical Operators
 Logical operators combine the results of one or more conditions. 42.Order of precedence of C++ Operators
 C++ provides three logical operators.
AND(&&), OR(||) are binary operators
NOT (!) is an unary operator
Assignment Operator
 It is used to assign a value to a variable.
 = is commonly used as the assignment operator.
 This operator copies the value at the right side to the left side
variable.
 It is also a binary operator.
Syntax : Variable = Value\ constant\ expression ;
Ex. a = 10;

37.Define Conditional Operator:


 This is a Ternary Operator.
 ?: is a conditional Operator.
 This operator is used as an alternate to if … else
Syntax :( Condition ) ? Statement 1 : Statement 2 ;
 If condition is TRUE Statement 1 is executed.
 If condition is FALSE Statement 2 is executed
38.Define comma operator.
 Comma ( , ) is an operator in C++ used to separate group of
expressions.

39.What is sizeof operator or Define compile time operator Evaluate Yourself….


 This is called as compile time operator.
 It returns the size of a variable in bytes. 43. Give that i = 8, j = 10, k = 8, What will be result of the following
 Ex. int x = 10; cout<<sizeof(a); expressions?
Output : 2 bytes (i) i< k (ii) i< j (iii) i> = k (iv) i = = j (v) j ! = k
40.What is Association or Define order of precedence. Result: i) 0 ii)0 iii)1 iv)0 v)1
 Operators are executed in the order of precedence. 44. Write an expression involving a logical operator to test, if marks
 The operands and the operators are grouped in a specific logical are 75 and grade is 'A'.
way for evaluation.  If (marks > 75) && ( marks == 75)
 This logical grouping is called as an Association. cout<<”Grade is A”;
45. What will be the order of evaluation for the following
41.What is Punctuators ? expressions?
 Punctuators are symbols, which are used as delimiters in (i) i + 3 >= j - 9 (ii) a +10 < p - 3 + 2 q
C++program,
 They are also called as “Separators”.

{ } - indicate the start and the end of a I/O Operators


block of code.Ex. {int a; a=10;}
( ) - indicate functioncalls and function
parameter. Ex add(); main()
46. What is the use of a header file or Library file?
[ ] - indicates arrays ex.int a[5];
 A header file contain definitions ofpredefined functions.
, - comma is used as separator ex, inta,b,c;
 It instructs the compiler to do the required job.
; - used to terminate statement ex. int a;
 It includes by using a preprocessor directive (#
: - used to label a statement. Ex.private:
include statement) .
// - single line comment
Syntax : # include <header file>
/* */- Multi line comment
Ex #include<iostream>

37
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

47.Define Input operator or define Input statement . 50.What is the use of namespace std; or Define namespace std;
 The operator >> is called as “Stream extraction” or “get from”  It tells the compiler to use standard namespace.
operator.  Namespace collectsidentifiers used for class ,object and variables.
 >> operator to get input. 51.What are the importance of main() function?
 It extracts the value through the keyboard and assigns it to the  Every C++ program must have a main function.
variable on its right.  The main() function is the starting point where all C++ programs
 The first operand is cin that identifies keyboard as the input begin their execution.
device.  The executable statements should be inside the main() function.
 The second operand must be a variable.
Syntax : cin>>variable; ex. cin>>a; 52.How to creating and executing a C++ program
cin>>var1>>var2>>var3; ex. cin>>a>>b;
(1) Creating Source code
 Type and edit the valid C++ code .
(2) Saving source code with extension .cpp
 Code should be saved with the extension .cpp
(3) Compilation
48.Define Output Operator:or output statement?  Compiler links the library files with the source code and verifies
each and every line of code.
 The operator<< is called the “Stream insertion” or “put to”  If any mistake or error is found, it will inform you to make
operator. corrections.
 << operator to perform output operation.  If there are no errors, it translates the source code into machine
 It is used to send the string or the values of the variables on its readable objectfile with an extension .obj
right to the object on its left. (4) execution
 The first operand is cout that identifies monitor.  The object file becomes an executable file with extension .exe.
 The second operand may be a constant, variable or an express  An executable file, can run your application.
Syntax : cout<<variable; Ex. cout<<a;
53.What is IDE in C++?
 Integrated Development Environment (IDE) makes it easy to
create, compile and execute a C++ program.
49.What is cascading of I/O operation? 54.List some Familiar C++ Compilers with IDE
The multiple use of input(>>) and output(<<) operators in a single
statement is known as cascading operators.
cin>>a>>b;

For yourself:
 To display the contents of the variable:
Syntax : cout<<variable; Ex.cout<<a;
 To display the Message only
Syntax : cout<<”Message”; Ex. cout<<”INDIA”;
 To display the Escape Sequence only 55.Explain how to work with Dev C++?
Syntax : cout<<”\escape seq.”; Ex. cout<<”\n”;  Double clickDev C++ icon to open IDE
 To display the Message with Escape Sequence  To create a source file,
Syntax : cout<<”Message esc.seq.”;  Select File →New →Source file or Press Ctrl + N.
Ex. cout<<”INDIA\n”;  After save, Click Execute → Compile and Run or press F11 key.
 To display the result of expression  If your program is without any error, output will appear in output
cout<<a+b; console.
 To display the constant or data. 56.What are the types of Errors?
cout<<7; orcout<< 2+3; Some common types of errors are ,
 To display Message escape ,sequence ,variable Syntax error
cout<<”Message”<<‟\n‟<<variable;  Syntax error occur when grammatical rules of C++ are violated.
ex. cout<< “ The Result is..”<< „\t‟ << c;  Ex. cout<<”INDIA” - it will throw an error because It does not end
with a semicolon.

Semantic error or logical error .

38
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 It may be happened by wrong use of variable / operator /order of (a) Rick Mascitti (b) Rick Bjarne(c) Bill Gates (d) Dennis Ritchie
execution etc.
4. The smallest individual unit in a program is:
 Here program is grammatically correct but it contains some
logical error. (a) Program (b) Algorithm(c) Flowchart (d) Tokens
Run time error.
5.Which of the following operator is extraction operator of C++? (a) >>
 A run time error occurs during the execution of a program.
 It occurs because of some illegal operation that takes place. (b) << (c) <> (d) ^^
6. Which of the following statements is not true?
What is the difference between “Run time error” and “Syntax
error”? Ref. above answer (a) Keywords are the reserved words convey specific meaning to the C++
What are the differences between “Logical error” and “Syntax compiler.
error”? ref.above answer
(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
Evaluate Yourself….
point.
1. Match the following (d) Exponent form of real constants consists of two parts
A B
(a) Modulus (1) Tokens(d) 7. Which of the following is a valid string literal?
(b) Separators (2) Remainder of a division(a) (a) „A‟ (b) „Welcome‟ (c) 1232 (d) “1232”
(c) Stream extraction (3) Punctuators(b)
(d) Lexical Units (4) get from(c) 8. A program written in high level language is called as
2. Is C++ case sensitive? What is meant by the term “case (a) Object code (b) Source code (c) Executable code (d) All 9.
sensitive”?
 C++ is case sensitive as it treats upper and lower- case 9.Assume a=5, b=6; what will be result of a&b?
characters differently. (a) 4 (b) 5 (c) 1 (d) 0

3. Differentiate “=” and “==”. 10. Which of the following is called as compile time operators?
= (a) sizeof (b) pointer (c) virtual (d) this
1.It is an assignment operator
2.used to assign avalue to a variable Data Types, Variables and Expressions
3.Ex. int a=5;
== 60.What are the categories of Data types?
1.It is a relational operator. In C++, the data types are classified as three main categories
2.used to compare two values will be either equal or not. (1) Fundamental data types
3.Ex. a==b (2) User-defined data types and
(3) Derived data types
4. Why is main function special?
 Every C++ program must have a main() function.
 C++ programs begin their execution from main() function.
 The executable statements should be inside the main() function.

CHOOSE THE CORRECT ANSWER

1. Who developed C++?


(a) Charles Babbage (b) BjarneStroustrup
(c) Bill Gates (d) Sundar Pichai
2. What was the original name given to C++?
(a) CPP (b) Advanced C
(c) C with Classes (d) Class with C
3. Who coined C++? 61.Write about Fundamental data types.

39
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 Predefined data types are Fundamental data types available with  Because more fractions accommodated in double than in float type
C++. 5. What is the use of void data type?Ref.61
 There are five fundamental data types in C++: char, int, float, 62.What are the Memory representation of Fundamental Data types
double and void. in C++?
int data type:  C++ compiler allocates specific memory space for each and every
 Integers are whole numbers without any fraction. data .
 Integers can be positive or negative.  Every data is stored inside the computer memory in the form of
 Itaccepts and returns only integer numbers. binary digits
 .Ex. int a = 5; int x = -4 ;
int a= 4.5 (it will accept only 4)

char data type:


 Character data type accepts and returns all valid ASCII
characters.
 It is an integer type.
 All the characters are represented in memory by their associated
ASCII Codes.
Ex. „A‟ represent 65
63.Write a short note on modifiers Or qualifiers .
float data type:
 Modifiers can be used to modify (expand or reduce) the memory
 Float data type accepts floating point values with 6 digits of
allocation of any fundamental data type.
precision.
 They are also called as Qualifiers
 It includes integer portion, a decimal point ,fractional portion and
There are four modifiers used in C++. They are:
an exponent.
(1) signed (2) unsigned (3) long (4) short
Ex. float a =3.14;
Integer type
There are two advantages of using float data types.
(1) They can represent values between the integers.
(2) They can represent a much greater range of values.
Disadvantage
 Floating point operations are slower than integer operations.
double data type
 double data type accepts double precision floating point
numbers with 14 digits of precision.
 This type occupies double the space than float type
Ex. double a=3.456744;
void data type
 It is used as a return type for functions that do not return any
value.
 Ex. void main() , void add()
What are the advantages and disadvantages of float data type ? Ref.
above answer

Evaluate Yourself….

1.What do you mean by fundamental data types?Ref.61


2. The data type char is used to represent characters. then why is
it often termed as an integer type?
 Character data type accepts and returns all valid ASCII
characters.
 All the characters are represented in memory by their associated
ASCII Codes. integer type accepts only 2 bytes of data
 ASCII codes are an integer type. long accepts 2 bytes
3. What is the advantage of floating point numbers over
integers?Ref. 61. char type

40
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Variables
65.Define variables.
 Variables are user-defined names.
 Variables are memory locations in which the values are stored.
 Variables are also identifiers.
 These are called as symbolic variable because these are named
location.
 They are R-value and L-value.
Floating point type • R-value is data stored in a memory location
• L-value is the memory address .
 The memory addresses are in the form of Hexadecimal values
 Ex.Let int a = 5; Here Variable name is a ;R value is 5 ; L value is
0x12b(for example)

66.How to Declare of Variables in C++?


 Declaration is a process to instruct the compiler to allocate
memory as per the data type along with the variable name.
Syntax : Data type space variable name ;
Ex. int a;
Declaration of more than one variable:
Syntax : Data type space var1,var2,var3 ;
Ex. inta,b,c; (comma is used to separating the variables).
Memory allocation by Turbo C++ and Dev C++ 67. What is meant by Junk” or “Garbage”?
 If you declare a variable without any initial value, variable will be
occupied with some unknown value.
 These unknown values are called as “Junk” or
“Garbage” values.

68.How to initialize the variable in C++?


 Assigning an initialvalue to a variable during its declaration is
called as “Initialization”.
Suntax: Data type space variable name = value;
Ex. int a = 10;
 Variables that are of the same type can be initialized in a single
statement.
int x1 = -1, x2 = 1;
69.What is Dynamic Initialization?
 A variable can be initialized during the execution of a program.
 It is known as “Dynamic initialization”. Ex.int c = a+b;

70.Define Access modifier or qualifier or const qualifier.


 const is a qualifier .
 It specifies that the value of a variable will not change during the
run time of a program.
 Any attempt to alter the value, an error message will be displayed.
64.What is Number Suffixes in C++?
 There are different suffixes for integer and floating point numbers.
 Suffix can be used to assign the same value as a different type.
Ex.To store 45 in long int suffix letter L : 45L
Unsignedint : 45U for float : 3.14F
Evaluate Yourself….

41
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

(iii) Floating Expression


1.What is modifiers? What is the use of modifiers?63. (iv) Relational Expression
2.What is wrong with the following C++ statement: (v) Logical Expression
long float x;there is no long float (vi) Bitwise Expression
3.What is variable ? Why a variable called symbolic varible?65. (vii) Pointer Expression
4. What do you mean by dynamic initialization of a variable? Give an (i) Constant Expression
exmple.69  Consist only constant value Ex.int a=10;
5. What is wrong with the following statement? (ii) Integer Expression
constint x;  Consist of integer and character values\ variables \ expression
 Error because const modifier should be used during  Produce integer results
initialization. Here value is not initialized. Ex.avg=sum/5;
(iii) Floating Expression
71. What is References variable?  Consist of floating point values\ variables \
 A reference provides an alias for a previously defined variable. expression.
 Reference variable name is assigned the value of a previously  Produce floating point results
declared variable. Ex. float a= 3.14*r*r;
Syntax: (iv) Relational Expression
Data type &reference_variable = original_variable;  Consist of values\ variables with relational operators.
Ex. int a=10; int &b=a;  Produce either True(1) or False(0).ex. a>b
 The output of a is 10 and the output of b is 10 (v) Logical Expression
72. What are Manipulators?  Consist of values\ variables with Logical operators.
 Manipulators are used to format the output of any C++ program.  Produce either True(1) or False(0).
 Ex.: endl, setw, setfill, setprecision and setf.  Ex. (a>b) && (a>c)
 endl is a member of iostream header file. (vi) Bitwise Expression
 setw, setfill, setprecision and setf are members of iomanip  Consist of values\ variables with Bitwise operators
header file. (vii) Pointer Expression
73. Explain some formatting output or Manipulators  A Pointer is a variable that holds a memory address.
1)endl (End the Line)  Pointer declaration statements:
 endl– Inserts a new line and clean the buffer Syntax : Data type space *variable; ex. int *a;
75.What is Type Conversion? Give examples
 „\n‟ - Inserts onlya new line. The process of converting one fundamental type into another is
2)setw ( ) called as “Type Conversion”.
setw manipulator sets the width of the field assigned for the output. C++ provides two types of conversions.
Syntax:setw(number of characters) (1) Implicit type conversion
(2) Explicit type conversion.
3)setfill ( )
76.Define Implicit type conversion. (or) What is type promotion?
 It is usually used after setw.
cout<< "\n H.R.A : " <<setw(10) <<setfill (0) <<hra;  Compiler automatically converts.
from above example ,  It is also called as “Automatic conversion”.
 setw creates a field to show the presented value,  Compiler converts smaller type into wider type which is called Type
 setfill is used to fill un-occupied spaces with 0 Promotion
Ex.int a=6; float b=3.14; cout<<a+b;
 if hra=1200,The output will be, 0000001200.
The output is 9.14(float is wider than int)
4)setprecision ( )
77.Define Explicit type conversion.What is Type casting?
 This is used to display numbers with fractions in specific number of
digits.
 Performed by the programmer in the program itself.
Syntax: setprecision (number of digits);
Ex.  Explicit conversion is converting of variables or expressions from
one data type to another specific data type.
 float hra = 1200.123;
 cout<<setprecision (5) <<hra;  It is called as “type casting”.
Syntax. : (type-name) expression;
 The output will be 1200.1(including fraction)
Ex. float varf=78.685; cout<<(int) varf;
 setprecision can also be used to set the number of decimal
output is 78
places to be displayed.
74.Explain the types of Expression in C++?
There are seven types of expressions, and they are:
(i) Constant Expression
(ii) Integer Expression Evaluate Yourself..

42
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

1. What is meant by type conversion?77


2. How implicit conversion different from explicit
conversion?76 , 77
3. What is difference between endl and \n?73.
4. What is the use of references?71
5. What is the use of setprecision ( ) ?73

1. What is the difference between a keyword and an identifier?


2. What are literals in C++? How many types of literals are
allowed in C++?
3. How many ways are there in C++ to represent an integer
constant?
4. What is the different between „a‟ and “a” in C+?
 Character enclosed in single quotes are character constant
 The size of „a‟ is 1 character.
 Character enclosed in double quotes are string constant
 \0 (null) used to terminate the string
 The size of “a” is 2 character.
5. Who was developer of C++? Ref 1
6. What was the original name given to C++? Who gave the name
“C++”?
7. What is meant by token? Name the token available in C++.
8. What are keywords? Can keywords be used as identifiers?
9. What is an identifier ? what are the rules to form an
identifiers?
10. What are literals ?how many types of integer literals are
available in c++?
11. How are integer constants represented in C++? Explain with
example
12. What kind of constant are the following? 14 , 011 ,
4.324, „a‟ , “rmk” , 0X2A
13. How are non-graphic characters represented in c++?
14. What kind of program element (token) are the following? 28 , a
, for , // , +
15. Which escape sequence represent the newline & null
character?
16. Which character is automatically added to string in C++?
17. What header file must you include with your source file to use
cout and cin?
18. What are the main data types of C++?
19. Explain fundamental data types.
20. Why is char often treated as integer data type?
21. Consider the following two C++ statements.
Are they equivalent.. char g=65; char g=‟A‟;
Yes both are equivalent ASCII code value of „A‟ is 65
22. What is the different between 25L and 25
25L - long integer constant
25 - integer constant.

43
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT -III INTRODUCTION TO C++ CHAPTER 10


Flow of Control
8.Explain if statement with an example.
1. Define statements. It is selection or decision statement.
 A computer program is a set of statements or instructions Syntax:
to perform aspecific task. if (expression)
There are two kinds of statements used in C++. {
(i) Null statement True – Block;
(ii) Compound statement }
2.What is Null statement? What is the use of null or empty  if the condition is true then a true block- is executed, otherwise the
Statements? true-block is skipped.
 The " null or empty statement" is a statement containing only a #Include<iostream.>
semicolon ( ; ). using namespace std;
 Null statements are commonly used as placeholders in iteration int main()
statements. {
3.What isCompound statement ? int a;
 This group of statements is called as a compound statement cin>>a;
or a block. if(a>=18)
 It is enclosed by pair of braces {}. {
cout<<”Eligible for Vote..”;
{ }}
Statement 1; Here,
Statement 2; if condition is True(Nonzero),
… output: Eligible for Vote
} if condition is false
output: nothing
4.What is control statement.? 9.Explain if …else statement with an example.
 Control statements are statements that alter the sequence of flow It is selection or decision statement
of instructions. Syntax:
 There are three kinds, They are if (expression)
1)Sequence Statement {
2) Selection Statement. True – Block;
3)Iteration ( Loop) Statement. }
5.What is Sequential Statements? else
 The sequential statement are executed one after another only {
once from top to bottom. False- block;
 do not alter the flow of execution. }
 They are always end with a semicolon (;).  if the condition is true then a true block- is executed, otherwise
false block is executed.
6.What is Selection Statements? #Include<iostream>
 It is also called decision statement. using namespace std;
 If a condition is true, a true block (a set of statements) is executed int main()
otherwise a false block is executed. {
 Two types of selection statements, int a
i) if ii)switch …case cin>>a;
7.What is Iteration statement? if(a>=18)
 It is also called Looping Statement (or) control flow statements {
 An Iteration statement is a set of statements that are cout<<”Eligible for Vote”;
repeatedly executed until a condition is TRUE. }
 Three types of iteration statements. else
 They are, i) for ii) while iii) do…while {
cout<<”Not Eligible for Vote”;
}}
44
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

if condition is True(Nonzero), else


output: Eligible for Vote {
if condition is false if (condition-3)
output: Not Eligible for Vote { True block 3 }
10.Explain Nested if statements with suitable example. else
 An if statement containsanother if statement is called nested if { False block 3 }
statement. }
It has three forms. 11.Explain if -else-if ladder statement with an example.
1.Nested if inside if part  The if-else ladder is a multi-path decision making statement.
2.Nested if inside else part In this type of statement,
3.Nested if inside both if part and else part  'if' is followed by one or more else if statements
and finally end with an else statement.
1. Nested if inside if part Syntax:
If(condition-1) if(condition-1)
{ { block – 1}
if (condition-2) else if (condition – 2 )
{ True block 2} { block – 2}
else else if (condition – 3 )
{ False block 2} { block – 3}
} else
else { default block}
{
False block 1;  When the respective Condition becomes TRUE, the respective
} block is executed and skippedfrom ladder.
Case 1  If none of the conditions is true, then the final else statement will
If condition 1 & condition 2 are TRUE be executed.
True Block 2 will be executed Example.
Case 2 #Include<iostream>
If condition 1 is TRUE and Condition 2 is FALSE using namespace std;
False block 2 will be executed int main()
Case3 {
If Condition 1 is FALSE float b,g,d,h;
False block 1 will be executed. cout<<"Enter Basic Salary : \t ";
cin>>b;
2. Nested if inside else part if (b<25000)
Syntax: {
if(condition-1) d=b*80/100;
{ h=b*20/100;
TRUE block 1; }
} else if (b>=25000 && b<40000)
else {
{ d=b*90/100;
if (condition-2) h=b*25/100;
{ True block 2 } }
else else if (b>=40000)
{ False block 2 } {
} d=b*95/100;
3. Nested if inside both if part and else part h=b*30/100;
if(condition-1) }
{ else
if (condition-2) {
{ True block 2 } cout<<” Enter only valid Amt.”;
else g=b+d+h;
{ False block 2 } cout<<"\nGross Salary :\t"<<g;
} }}

45
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

12.Explain conditional operator with an example. default: cout<<"\n , You have Failed..";
 The conditional operator(?:) (or) Ternary operatoris an alternative } }
for „if else statement‟. output
 It takes three operands. Enter your Mark 79
Syntax:Condition ? expression 2 : expression 3 You scored 79%
First division
Working of a program
* If x=76
* case 7 statement will execute directly and terminated by break;
 if the condition is true (Non-zero),
* If switch expression gets other then the case value default statement
 then the control is transferred to expression 2, otherwise, the
will execute
control passes to expression 3.
Example:
14.Differentiate between switch and if…else statement.
#include<iostream>
if…else switch
using namespace std;
Condition/ Expression decide Condition/Expression decide
int main()
whether if block or else block is which case to execute
{
execute.
inta,b,g;
cin>>a>>b; Uses multipleexpression for Uses singleexpression for
g=(a>b)?a:b; multiple choices. multiple choices
cout<<g<<" IS GREATER"; logical expressionchecks only for expression
return 0; It evaluates integer ,char It evaluate only char,int and enum
} ,float,pointer or Boolean data data type
13.Explain switch statement with an example. (or) type
Write the syntax and purpose of switch statement. If expression is false, else If expression is false, default
 The switch statement is a multi-waybranch statement. statement will be execute. statement will be execute.
 Based on a condition, the control is transferred to one of the many Difficult to edit Easy to Edit
possible points.
 It replaces else if statement. 15.Explain an Iteration or Loop statements ( or )
Syntax: Define Iteration Statements
switch (expression/variable)  It is also called Looping Statement.
{  An Iteration statement is a set of statements that are
case 1 : action block 1; break; repeatedly executed until a condition is TRUE.
case 2 : action block 2; break;  It is also calledcontrol flow statements.
default : action block 3;  C++ supports three types of iteration statements.
}  They are, i) for ii) while iii) do…while
 When expression value matches against the casevalue, 16.Explain the Parts of a loop.
 that respective set of statements are executed. Every loop has four elements .They are
 Otherwise, the defaultstatement isexecuted.  Initialization expression
Example:  Test expression
#include<iostream>  Update expression
using namespace std;  The body of the loop
int main() Initialization expression(s):
{  The control variable(s) must be initializedbefore enters into loop.
intp,x;  It is executed only once in the beginning of the loop.
cout<<"\n Enter your mark "; Test Expression:
cin>>p;  If condition is TRUE, the loop-body will be executeotherwise the
cout<<" \nYou scored "<<p<<"%\n"; loop is terminated.
x=p/10; Update expression:
switch( x )  used to change the value of the control variable.
{ The body of the loop:
case 10: case 9: case 8: cout<<"\nDistinction" ; break;  Set of statements forms a body of the loop that are executed
case 7: case 6 : cout<<"\nFirst division" ; break; repetitively.
case 5:cout<<"\nSecond division" ; break;
case 4: cout<<"\nThird division" ; break;

46
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

17.What are the difference between Entry controlled loop and Exit 22.Define infinite loop.
controlled loop?.  If condition is absent in a for loop is called infinite loop.Ex. for(i=0; ;
Entry controlled Exit controlled ++i) ( or ) for( ; ; )
Test-expression/condition is Test-expression/condition is
placed at the beginning of the placed at the end of the body of 23.Differentiate between empty and infinite loop . Ref above ans
body of the loop the loop 24.What is the output of the following code?
First the test-expression is First the body of the loop is inti;
evaluated. executed for(i=0;i<=5;i++);
The body of loop will be The body of loop will be executed { cout<< “ We are Indians”; }
executedonly when condition is at least one time  It is an empty loop
true  The body of loop contains a null statement(;)
Ex.for , while do…while 25.Explain While loop with an example.
18.Explain for loop with an example  It isan Entry controlled loop.
 It is an Entry controlled loop.  The condition (Test –Expression) placed at the beginning of the
 Test-expression/condition is placed at the beginning of the body body of the loop.
of the loop Syntax:
 for loop contains initialization , test expression and update Initialization;
expression but these are optional. while ( Test expression )
Syntax: {
for(Initialization ; test-Expression ; update expression) Body of the loop;
{ Update expression;
Statements; }
} General working for loop
General working for loop 1.First the control variable is initialized
1.First thecontrol variable is initialized 2. If the condition is false, the control exit from loop.
2.If the condition is false, the control exit from loop. 4. If the condition is true, the body of the loop is
4.If the condition is true, the body of the loop is executed,
executed, 5. Next the control is to update expression.
5. Next the control is to update expression. 6.After this, the control is again transferred to the condition.
6.After this, the control is again transferred to the condition. Example:
7.Next the steps 3 to 5 is repeated. #Include<iostream>
Example: using namespace std;
#Include<iostream> int main()
using namespace std; {
int main() int n=1;
) while(n<5)
{ {
for(int n=1;n<5;n++) cout<<n;
{ n++;
cout<<n }
} }
} Output: 1234
Output
1234 26.What is the following code?
19.Why always prefer prefix increment/decrement operator over int main()
postfix when to be used alone? {
 Because prefix operators are executed faster than postfix. inti=0;
20.Give an example of infinity loop and empty loop while(++i<100)
for( inti=0 ;; i++) - infinity loop return 0; }
for( ; ; ) - infinity loop  This is empty loop
21.What is an empty loop?  It does not contain any statement.
 Empty loop means a loop has no statement in its body is called an
empty loop.
Ex.for( inti=0 ; i<4 ; i++);
The body of loop contains a null statement(;)

47
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

27.What is the output of the following code? 29.Explain Nesting of Loop with an example.
int main()  A loop which contains another loop is called as a nested loop.
{  The inner loop must be completely nestedinside the body of the
inti=0; outer loop.
while(i<100)  An outer loop and inner loop cannot have the same control
cout<<I; variable, as it will lead to logical errors.
return 0; Syntax:
} Loop 1() for(int i = 1; i<= 3; i++)
 It is an infinity loop { {
 Because no update statement Loop 2() int j = 1;
{ while (j <= i)
28.Explain do..while loop with an example. block 2; {
 do.. while is an Exit controlled loop, } cout<< “* “;
 The condition placed at the end of the body of loop. block 1; j++;
 The body of loop will be executed at least one time. } }
Syntax: cout<< ‘\n’;
Initialization; }
do
{ working of the above program:
statement; The iterations of the nested loops are as follows;
update expression; For loop While loop
} while (condition); I=1 Is executed once(j<=1)
I=2 Is executed twice (j=1,2)
General working do..while loop I=3 Is executed thrice(j=1,2,3)
1.Firstthe control variable is initialized. 30.Define jump statements
2.The body of the loop is executed, and update expression. It is used to transfer the control from one part of the program to
3.Then to condition. another with out condition. They are,
4 .If the condition is false, the control exit from loop.  gotostatement
5. If the condition is true, the body of the loop is  break statement
executed, .  continue statement
Example 31.Explain goto statement with an example (or) explain
#Include<iostream> unconditional statement in C++.
using namespace std;  It is an unconditional statement.
int main()  It is used to transfer the control from one part of the program to
{ another with out condition.
Int n=1; Syntax:
do goto label; Syntax
{ cout<<n ………………. Label:
n++; ……………….. …..
}while(n <3); ………………. ……..
} Label: goto Label;
Return o;
} Here ,
 Label is an identifier.
 When gotolabel; is encountered, the control of program jumps
to label: and executes the code below it.
Example:
#Include<iostream>
using namespace std;
int main()
{
inta,b;
cin>>a>>b;
if(a>b)
goto true;

48
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

else 8. Compare an if and a ? : operator


cout<<”B is greater”; If
true:  It is a control statement
cout<<”A is greater”; }  If condition is true then true block is executed otherwise else block
is executed.
32.Difference between Break and Continue  Syntax
If(condition) {True block;}
break continue ?:
Terminate the execution Forces the loop to execute next  It is conditional operator.
iteration.  It is an alternative forif… else statement.
Breaks the iteration Skips the iteration  It is ternary operator
The control is transferred normal The code inside the loop following  Syntax:
execution after the body of the the continue statement will be Condition ? True : False
loop skipped and next iteration will
begin. 1.Convert the following if-else to a single conditional statement:
Used with loops and switch case Used only in loops if (x >= 10)
a = m + 5;
else
Book Exercise a = m;
3. Correct the following code segment:
if (x=1) a=(x>=10) ? m+5 : m
p= 100;
else 2.Rewrite the following code so that it is functional:
p = 10; v = 5;
correction : (x==1) do;
4. What will be the output of the following code: {
int year; total += v;
cin>> year; cout<< total;
if (year % 100 == 0) while v <= 10
if ( year % 400 == 0) int v=5;
cout<< "Leap"; do
else {
cout<< "Not Leap year"; total +=v;
If the input given is (i) 2000 (ii) 2003 (iii) 2010? cout<< total;
i)Leap }while(v<=10);
ii)Not Leap Year
iii) Not Leap Year
5. What is the output of the following code? 3.Write a C++ program to print multiplication table of a given number
for (inti=2; i<=10 ; i+=2)
cout<<i; #include<iostream>
Output: 2 4 6 8 10 using namespace std;
6. Write a for loop that displays the number from 21 to 30. int main()
for (inti=21; i<=30 ; i++) {
cout<<i; int n;
7. Write a while loop that displays numbers 2, 4, 6, 8.......20. cout<<"Table No";
inti=2; cin>>n;
while(i<=20) for(inti=1;i<=10;i++)
{ {
cout<<I; cout<<"\n"<<i*n;
i=i+2; }
} return 0;
}

49
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Write a short program to print following series: s=s+pow(x,i);


(a) 1 4 7 10...... 40 }
#include<iostream> cout<<s;
using namespace std; return 0;
int main() }
{
CHOOSE THE CORRECT ANSWER
For(inti=1;i<=40;i+=3)
{
cout<<"\n"<<i; 1. What is the alternate name of null statement?
}
return 0; (A) No statement (B) Empty statement
} (C) Void statement (D) Zero statement

Write a program to find the LCM and GDC of two numbers 2. In C++, the group of statements should enclosed within:
include<iostream> (A) { } (B) [ ] (C) ( ) (D) <>
using namespace std;
int main() 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
int n1,n2,a,b,gcd,lcm;
cin>>n1>>n2; 4. The multi way branching statement:
a=n1; (A) if (B) if … else (C) switch (D) for
b=n2;
while(n1!=n2) 5. How many types of iteration statements?
{ (A) 2 (B) 3 (C) 4 (D) 5
if(n1>n2)
n1=n1-n2; 6. How many times the following loop will execute? for (inti=0; i<10; i++)
else (A) 0 (B) 10 (C) 9 (D) 11
n2=n2-n1;
} 7. Which of the following is the exit control loop?
gcd=n1; (A) for (B) while (C) do…while (D) if…else
cout<<"GCD"<<gcd;
lcm=(a*b)/gcd; 8. Identify the odd one from the keywords of jump statements:
cout<<"LCM"<<lcm; (A) break (B) switch (C) goto (D) continue
return 0;
} 9. Which of the following is the exit control loop?
(A) do-while (B) for (C) while (D) if-else
Write a program to find sum of the series
S = 1 + x + x2 +..... + xn 10. A loop that contains another loop inside its body:
#include<iostream> (A) Nested loop (B) Inner loop (C) Inline loop (D) Nesting of loop
#include<math.h>
using namespace std;
int main()
{
intx,n,i,s=0;

UNIT -III INTRODUCTION TO C++ CHAPTER 11


Functions
cout<<"Enter x value";
cin>>x;
cout<<"Enter n value";
cin>>n;
for(i=0;i<=n;i++)
{
50
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

1.Define Functions. What is functions ? What ate the isdigit()


advantage of functions in C++?  It is used to check whether a character is a digit or not.
 A large program can be split into small sub-  It returns 1 if a character is a digit.
programs (blocks) called as functions. Otherwise it returns 0.
 Functions are the executable segments in a program. Syntax:intisdigit (char c);
 Functions are the building blocks of C++ programs islower()
Advantage of function  It is used to check whether a character is in
 Reduce the size of the program. lower case or not.
 Reusability of code  It returns 1 if a character is a lower case .
Functions can be classified into two types. Otherwise it returns 0.
1.Pre - Defined or Build – in or Library functions. Syntax:intislower (char c);
2.User - Defined Functions. isupper()
2.Differentiate between Pre - Defined and User - Defined Functions.  It is used to check whether a character is in
Pre - Defined User - Defined Functions. upper case or not.
These are already New functions to perform  It returns 1 if a character is a upper case .
written, debugged and specific task by the user. Otherwise it returns 0.
compiled for various task. Syntax:intisupper (char c);
Definition are stored in Header The name of task and data 6.Explain some string functions in C++.(string.h)
Files. required are decided by the String functionsare defined in string.h
user. strcpy()
Ex. gets(),strlen() Ex. int add(int r);  The strcpy() function takes two arguments: target
3.Define Header file. and source.
 Declaration and definitions for pre-defined functions are grouped  It copies the string by the source to the
and stored in files called Header files. memory location by the target.
 It is also called as Library files.  The null character (\0) is also copied.
 Their file extension is .h Syntax: strcpy(target,source);
 A single header file may contain multiple pre definedfunctions. strlen()
Ex.stdio.h , iostream.h ,conio.h , string.g , iomanip.h  The strlen() returns length of a character.
4.Explain some Standard input/output(stdio.h)  The length does not include the null(\0) character.
predefined functions in C++. Syntax: strlen(source);
input/output functions are defined in stdio.h strcmp()
getchar()  It is used to compares(ASCII values are compared)
 To get a single character from keyboard the two given strings.
putchar()  if string1 = string2 (equal) it returns 0
 To display a single character.  if string1> string2 it returns 1(Positive)
gets()  if string1< string2 it returns -1 (Negative)
 It reads and stores stringinto the variable. syntax: strcmp(string 1,string2);
 It treats spaces as part of string strcat()
puts()  It is used to merge two strings: target and source
 It prints the string read by gets(). syntax: strcat(target,source);
5.Explain few Character functions(ctype.h) in C++. strupr()
Character functionsare defined in ctype.h  The strupr() function is used to convert the given
isalnum() string into Uppercase letters.
 To check whether a character is an alphanumeric or not.
 It returns 1 if a character is an alphanumeric.
Otherwise it returns 0. strlwr()
Syntax: intisalnum (char c);  The strlwr() function is used to convert the given
string into Lowercase letters.
7.Explain some of Mathematical functions (math.h) in C++.
isalpha() Mathematical functions are defined in math.h header
 It is used to check whether a character is an file .
alphabet or not. cos()
 It returns 1 if a character is an alphabet .  The cos() function takes a single argument in
Otherwise it returns 0. radians.
Syntax:intisalpha (char c);  It returns the value in the range of [-1, 1].

51
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 The returned value is either in double, float, or long double. statement. definition
sqrt() The constant, variables or Only data type with variables are
 The sqrt() function returns the square root of the expressions are used. used
given value of the argument.
 It takes a single positive value only,otherwise a domain error
occurs. 15.How to access a function?
sin()  A function can be called or invoked from another
 The sin() function takes a single argument in radians. function by using its name and the required
 It returns the value in the range of [-1, 1]. arguments.
 The returned value is either in double, float, or long double.  The compiler refers to the function prototype to
pow() check whether the function has been called
 The pow() function returns the power of exponent. correctly.
 The returned value is either in double, float, or long double.  If the argument type does not match exactly with
 The pow() function takes two arguments: the prototype, the compiler will perform type conversion, if
1. base 2. exponent possible.
Syntax: pow(base,exponent) ;Ex . pow(3,2); otherwise, the compiler generates an error message.
9.Define Function Definition. Ex . swap(x,y);
 A function must be defined before it is used
anywhere in the program. 16.Explain Default arguments with an example.
Syntax:  The default value is given in the form of variable
Return_Data_TypeFunction_name(parameter list) initialization. Ex : void area (int n1=10, n2=100);
{  The default arguments facilitate the function call
Body of the function statement with partial or no arguments.
}  The default values can be included in the function
10.Define function prototype. prototype from right to left,
 Functions should be declared before they are used in a program.  Default value cannot be include between the
 function prototype is used to declare a function . argumentlist.
 The declaration statement may be given outside the main() Ex : void area (int n1=10, n2);//invalid prototype
function. void area(int n1, n2 = 10);//valid prototype
 It helps the compiler to check the data requirementof the function. Example
syntax Return type function name(arguments); #include <iostream >
11.What are the information the prototype provides to the compiler ? using namespace std; Output:
The prototype provides the following information to the int area (int l = 10, int b=20)
compiler: { return (l * b); } 80
1.Number and type of arguments void main ( )
2.The type of return values { int s1 = 4, s2 = 6;
3.Name of the function. cout<<area (s1);
syntax Return type function name(arguments); }
12.Write the information to the compiler from the 17.Define constant argument. What is const modifier?
following prototype. long fact(int a ,double b);  const Keyword used to declared the constant variable.
 The return data type is long.  It enables to assign an initialvalue to a variable
 fact is the name of the function.  value cannot be changed.
 The function is called with two arguments: Syntax : const datatype variable=value;
 The first argument is of int data type. Example: const int a=10;
 The second argument is of double data type.
13.What are the uses of void ? 18.Explain the Methods of calling functions.
 To indicate the function does not return a value What are the different ways of passing parameters in
 To declare a generic pointer. C++ functions?
Ex. void fun(void)  The call statement communicates with the function
14.Differentiate between actual parameters and formal parameters. through arguments or parameters.
Actual parameters Formal parameters  There are two ways of passing parameters in C++
Parameters The parameters associated functions .
associated with call with function header. 1.Call by value 2. Call by reference.
statement.
It is within calling It is within function 19.Explain call by value in C++ with an example.

52
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 The formal parameter creates new variables and stores the memory space.
value from actual parameter • Reduce the complexity of using STACKS.
 This method copies the values of actual parameters into the formal Ex.
parameters #include <iostream >
 Any change in the formal parameter is not reflectedback to the using namespace std;
actual parameter. inline void swap (int a)
Ex. { a=8;
#include <iostream > cout<< „\n‟<< a;
using namespace std; }
void swap (int a) int main ( )
{ a=8; {
cout<< „\n‟<< a; int m1 = 10;
} cout<<m1 ;
int main ( ) swap (m1);
{ cout<< „\n‟<< m1;
int m1 = 10; }
cout<<m1 ;

swap (m1); 22.What are the different forms of user defined


cout<< „\n‟<< m1; function ?
} 1. Function without return value and without
Output: parameter
10 #include<iostream.h>
8 void display()
10 {
Note: cout<<"No return value& without parameter ";
m1 -> Actual parameter a -> Formal Parameter }
20.Explain call by reference in C++ with an example void main()
 The formal parameters become alias to the actual parameters. {
 It is working on the original data. display();
 Any change made in the formal parameter is reflected back in the }
actual parameter
Ex. Function name: display()
#include <iostream > Return data type: void
using namespace std; Argument: No argument
void swap (int &a) 2.A Function with return value and without parameter
{ a=8; Output: #include <iostream >
cout<< „\n‟<<a; 10 using namespace std;
} int display()
int main ( ) 8 {
{ Int a =10;
int m1 = 10; 8 cout<<"With return value& without parameter ";
cout<<m1 ; return a;
swap (m1); }
cout<< „\n‟<< m1; }
Note: m1 -> Actual parameter a -> Formal Parameter void main()
21.Explain inline function with example {
 An inline function inserts the function‟s code directly into the cout<<display();
calling program. }
 Insert the keyword inline in the function header Function name: display()
(Ex inline void swap (int a)) Return data type: int
 It is just a request to the compiler Argument: No argument
Sometimes the compiler will ignore the request  The return statement returns a value of a (10) to
Advantages of inline functions: the calling function
• Inline functions execute faster but requires more

53
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

3. A Function without return value and with parameter char name(); char
#include <iostream > 25.Explain the Returning non integer values(string) in C++?
using namespace std; #include <iostream >
void display( int a) using namespace std;
{ char *display()
cout<<a; { return („‟Chennai‟‟); }
cout<<"Without return value& with parameter "; int main()
} {
int main() Char a[10];
{ Cout<<display();
int x=10; }
display(a); Output: Chennai
} 26.What is Recursive function ?
Function name: display() A function that calls itself is known as recursive function.
Return data type: void Example:
Argument: one parameters (int a) int add(inta,int b)
{
4. A Function with return value and with parameter ……
#include <iostream > …..add(a,a+b);
using namespace std; }
int display( int a) void main()
{ {
Int b=5 add(x,y);
Int c=a+b; }
cout<<"With return value& with parameter "; 27.Explain about the different scopes of a variable in
return c; C++ with an example.
}  Scope refers to the accessibility of a variable.
void main() There are four types of scopes in C++.
{ They are: 1. Local scope, 2. Function scope, 3. File
int x=10; scope 4.Class scope
cout<< display(a); 1. Local scope
}  A local variable is defined within a local block.
Function name: display()  A local variable cannot be accessed from outside the block.
Return data type: int  A block of code begins and ends with curly braces{ }.
Argument: one parameters (int a)  It is created upon entry into its block and remove upon exit .
 The return statement returns with c value to the
calling statement 2. Function scope
23.Define return statement in C++.  The variable declared within afunction
 The return statement is used to return from a  The scope of variable is extended to the functionblock, and all sub-
function to the calling function. blocks.
 It is a jump statement.  The life time of a function scope variable, is the lifetime of the
 A return may or may not have a value associated function block.
with it.  Formal parameter is a function scope
 A return statement without parameter can be used
to terminate the function.
Syntax: return expression/variable; 3. File scope
Example : return(a+b); return(a); return;  It is also called as globalvariable.
24.Explain the returning value in C++?  declared above main ( ).
 The functions that return no value is declared as  The life time of a file scope variable is the life time of a program.
void. #include <iostream >
 Default return data type is int. using namespace std;
 if no data type is explicitly mentioned, it is treated as int. Int b=10;
Ex. int add (int, int); add (int, int); void swap (int a)
In both prototypes, the return value is int, { int c = a+b;
float area(float); float cout<< c;

54
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

} 3. Which function begins the program execution ?


int main ( ) A) isalpha() B) isdigit() C) main() D) islower()
{ 4. Which of the following function is with a return value and without any
int m1 = 10; argument ?
cout<<m1 ;
swap (m1); A) x=display(int, int) B) x=display()C) y=display(float) D) display(int)
cout<< „\n‟<< m1;
5. Which is return data type of the function prototype of add(int, int); ?
}
Here, A) intB) float C) char D) double
a - Function scope variable b - File scope variable
c - Local variable 6. Which of the following is the scope operator ? A) >B) &C) % D) ::
7.Functions are the building blocks of C++ programs
4. Class scope
 A class is a new way of creating and implementing a
user defined data type.
 Access specifiers are , Private , protected and public.

class name
{
Private:
{ declaration; }
Protected:
{ declaration; }
Public:
{ declaration; }
};

28.Explain the use of scope operator with an example?


 :: is called scope resolution operator
 It is used to refer variables declared at file level.
 It is used when the local and file scope variables have the same
name.
Example: #include <iostream >
using namespace std;
int x=45;
int main() {
int x = 10;
cout<<::x + x;} Output: 55

UNIT -III Introduction of C++ CHAPTER


Arrays and Structures
12

Choose the best answer


1. Which of the following header file defines the standard I/O predefined
functions ? A) stdio.hB) math.h C) string.h D) ctype.h
2. Which function is used to check whether a character is alphanumeric 1.What is an Arrays?
or not. ..A) isalpha() B) isdigit() C) isalnum()D) islower()
55
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 An array is a collection of variables of the same type that are 6.How to Accessing array elements
referenced by a common name.  Array elements can be used anywhere in a program like a
 It is derived data type. normal variable.
There are different types of arrays used in C++. They are:  The elements of an array are accessed with the array name
 One-dimensional arrays followed by the subscript index within the square bracket.
 Two-dimensional arrays Ex. cout<<num[3];
 Multi-dimensional arrays The following for statement is used to display the values.
2.Define One-dimensional array for(inti=0; i<5; i++)
 This is the simplest form of an array. {
 A one dimensional array represents values that are stored in a cout<<num[i];
single row or in a single column. }
Declaration 7.What is Traversal in an Array?
Syntax:  Accessing each element of an array at least once to perform
data type array_name [size]; any operation is known as “Traversal”.
Example:  Displaying all the elements in an array is an example of
int num[10]; “traversal”.
3.State the following array declaration are valid or Invalid. 8.What are strings? Give an example.What is Array of Characters?
(a)int array [100.5]; - invalid  A string is defined as a sequence of characters where each
(b)int a [10]; - valid character may be a letter,number or a symbol.
(c)char name [15]; - valid  Each element occupies one byte of memory.
(d)const j = 15; double val [ j ]; - valid  Every string is terminated by a null („\0‟)
(e)int d[ ] ={ 1, 2, 3, 4, 5, 6, 7 } - valid  a string as an one-dimensional character array.
4.Write a statement for the following. To declare Character array
(a) Read 6 th element = cin>> n [5] Syntax: char array_name[size];
(b)assigns the contents of the 4 th element of the array to its 5 th #include <iostream>
element = n [4] = n [3] void main()
(c) increments the value stored as 5 th element by 1 = n [4] ++ {
5.Explain the types of Array Initialization char country[6];
 An array can be initialized at the time of its declaration. cin>>country;
 Unless an array is initialized, all the array elements contain cout<<" The name of the country is "<<country;
garbage values. }
Syntax: OUTPUT
Datatypearray_name [size] = {val-1,val-2,. ,val-n}; INDIA
 int a[3] = { 2,3,4); The name of the country is INDIA
a[1] = 5; a[0]= 10;
More examples of array initialization: 9.How to Initialize one dimension character array ?
 float x[5] = {5.6, 5.7, 5.8, 5.9, 6.1};  The character array can be initialized at the time of its
 char vowel[6] = {'a', 'e', 'i', 'o', 'u', '\0'}; declaration. The syntax is shown below:
 Accepting values to an array during run time : by using cin char a_nam[size]={ list of characters separated by comma or a
cin>>a[2] ; string } ;
using loop char country[6]=“INDIA”;
#include <iostream> char country[6]={„I‟, „N‟, „D‟, „I‟, „A‟, „\0‟};
using namespace std; char country[]=“INDIA”;
int main() char country[]={„I‟, „N‟, „D‟, „I‟, „A‟, „\0‟};
{ Example
int num[5]; Char a[5] ={ „b‟,‟e‟,‟4‟}
 a[0] --- b
 a[1] --- e
for(inti=0; i<5; i++)  a[2]--- 4
{  a[3] --- NULL
cin>>num[i];  A[4] ----NULL
} Char b[2] ={ „b‟,‟e‟,‟4‟} -- invalid(array elements cannot be initialized
} more than its size)
In the above program, a for loop has been constructed to execute the 12.Define Two-dimensional array
statements within the loop for 5 times.

56
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

 Two-dimensional (2D) arrays are collection of similar elements using namespace std;
where the elements are stored in certain number of rows and inti;
columns. int main()
ex.int arr[3][3]; {
13.How to Declare 2-D array in C++? Write the syntax of int m1[10][10], m2[10][10], sub[10][10];
Declaration of 2-D array. cout<< "Enter the elements of first matrix:\n ";
data-type array_name[row-size][col-size]; for (i = 0;i<2;i++ )
Ex. int a[3][4]; for (j = 0;j<2;j++ )
 Array size must be Positiveinteger value cin>>m1[i][j];
 In arrays, column size is compulsory but row size is optional. cout<< "Enter the elements of second matrix:\n ";
14.How to calculate the size of the array? for (i = 0;i<2;i++ )
one dimension array size = memory required (data type ) x No. of the for (j = 0;j<2;j++ )
elements in the array cin>>m2[i][j];
Ex. int n[5] = 2 x 5 = 10 bytes ( one integer is 2 bytes) cout<<"Output: \n";
Two dimension array = Number of elements (Row x column ) x memory for (i = 0;i<2;i++ )
required for (j = 0;j<2;j++ )
Ex. int n [2] [3] = (2 x 3) x 2 = 12 bytes {
15.How to initialize a two dimensional array . sub[i][j]=m1[i][j] + m2[i][j];
 The array can be initialized in more than one way at the time of 2-D cout<<sub[i][j]<<‟\t‟;
array declaration. }
Ex. int a [2][2] = { {1,2},{3,4}}; }
 Array‟s row size is optional but column size is compulsory. getch();
 Accessing the two-dimensional array }
A[0][1] = 10; assign 10 to 2 nd element of first row 21.Write a C++ program to find the difference between two matrix.
16.Define Memory representation of 2-D array #include <iostream>
 A 2-D array is stored in sequential memory blocks. using namespace std;
 There are two types of 2-D array memory representations. They inti;
are: int main()
Row-Major order {
 All the elements are stored row by row in continuous memory int m1[10][10], m2[10][10], sum[10][10];
locations, cout<< "Enter the elements of first matrix:\n ";
Column-Major order for (i = 0;i<2;i++ )
 All the elements are stored column by column in continuous for (j = 0;j<2;j++ )
memory locations, cin>>m1[i][j];
17.What is array of string? cout<< "Enter the elements of second matrix:\n ";
 Set of strings for (i = 0;i<2;i++ )
 An array of strings is a two-dimensional character array. for (j = 0;j<2;j++ )
 The size of first index (rows) determines the number of strings and cin>>m2[i][j];
the size of second index determines maximum length of each cout<<"Output: \n";
string. for (i = 0;i<2;i++ )
Ex. char day[2][10] ={“Sunday \0”,“Monday\0”}; for (j = 0;j<2;j++ )
S u n d a y \0 {
sum[i][j]=m1[i][j]-m2[i][j];
M 0 n d a y \0
cout<<sum[i][j]<<‟\t‟;
}
}getch();}
18.Write a C++ program to accept and print your Name.
Structures …
#include <iostream>
using namespace std;
int main()
22.What is Structure? Or Define Structure.
{
 Structure is a user-defined data type.
char n[]=”ELANGO”;
 This allows to group of variables with different data types
cout<<”Myname is …”<<n;
together into a single unit.
}
23. Declaring and defining structures
20.Write a C++ program to find the sum of two matrix.
Structure is declared using the keyword „struct‟.
#include <iostream>

57
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Syntax: struct A{ float f[3]; char ch[5];long double d;};


structstructure_name struct B{ A a; intarr[2][3];}b[3]
{ struct A{ float f[3]; char ch[5];long double d;};
type member_name1; 1.4x3 = 12
type member_name2; 2.1x 5 =5
} object ; 3.2+8 =10
Total = 27 bytes
24.Define global objects. struct B{ A a;intarr[2][3];}b[3]
 Objects declared along with structure definition are called global 4 x 6 = 24
objects 24+24+24 =72bytes
25.What is an Anonymous Structure? 30.Is the following snippet is fully correct. If not identify the error.
 A structure without a name/tag is called anonymous structure. struct sum1{ int n1,n2;}s1;
struct struct sum2{int n1,n2}s2;
{ cin>>s1.n1>>s1.n2;
long rollno; s2=s1;
int age; Error because s1,s2 are separate objects for two separate structures.
float weight;
} student; 31.Differentiate array and structure.
Array Structure
26.To store 100 integer number which of the following is good to An array is a collection of This allows to group of variables
use? Array or Structure variables of the same data with differentdata types
Array because Array is a set of variable of same data type type that are referenced by a together into a single unit.
27.What is the error in the following structure definition. commonname
struct employee It is a derived data type It is a user-defined data type.
{
Inteno; There are different types. Only one type
Char ename[20];
char dept; 32.How to referencing structure elements in C++?
} How to success members of a structure ?Give example.
Employee e1,e2;  The structure members can be accessed directly.
 Structure is not terminated with ;  The syntax for that is using a dot (.) between the object name and
 Data type and variable name should be separate(inteno; char the member name.
ename;) Ex. x.rollno , x.age .
 Employee should be employee 34.What are the different ways to initialize the structure members?
Correct definition How values are assigned to structure elements?
struct employee How to Initializing structure elements?
{  similar to assigning values to variables.
inteno; balu.rollno= “702016”;
char ename[20]; balu.age= 18;
char dept; balu.weight= 48.5;
};  similar to assigning values to Arrays.
employee e1,e2; balu={702016, 18, 48.5};
 Structures can be assigned directly.
Structure assignment is possible only if both structure
variables/objects are same type.
28.Write a structure definition for the structure student containing
examno, name and an array for storing five subject marks. 35.Define Structure Assignments in c++
struct student  Structures can be assigned directly.
{  Structure assignment is possible only if both structure
intexamno; variables/objects are same type.
char name; Ex.
int marks[5]; struct student
}; {
29.What is the size of the following highlighted variable in terms of I
byte if it is compiled in devc++ int age;

58
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

float height,weight; double price;


} priya,usha; };
priya ={19,165.7,56.4}; int main()
usha=priya; {
It will assign the same age,height and weight to usha. ShoeType shoe1, shoe2;
shoe1.name = "Adidas";
shoe1 (a) Adidas # 9.99 (b) Adidas # 9.99 (c) Adidas # 9.99 (d) Adidas # 9.11
Choose the correct answer .pric Adidas # 1.11 Adidas # 9.11 Adidas # 11.11 Adidas # 11.11
e=
9.99;
1. The data elements in the structure are also known as cout<< shoe1.name<< " # "<< shoe1.price<<endl;
(a) objects (b) members (c) data (d) records shoe2 = shoe1;
2. Structure definition is terminated by shoe2.price = shoe2.price / 9;
(a) : (b) } (c) ; (d) :: cout<< shoe2.name<< " # "<< shoe2.price;
3. What will happen when the structure is declared? return 0;
(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
4. What is the output of this program?
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
struct student
{
int n;
char name[10];
};
student s;
s.n = 123;
strcpy(s.name, "Balu");
cout<<s.n;
cout<< s.name <<endl;
return 0; }
(a) 123Balu (b)BaluBalu (c) Balu123 (d) 123 Balu
5. 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

UNIT -IV Object Oriented Programming with C++ CHAPTER


Arrays and Structures
13
6. What will be the output of this program?
#include <iostream>
using namespace std;
structShoeType
{
string name;
59
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

1.What is paradigm ?Mention the different types of paradigm?  The members and functions declared under private are not
 Paradigm means organizing principle of a program. accessible by members outside the class, this is referred to data
 It is an approach to programming hiding.
 They are Procedural programming, Modular Programming and 9.Differentiate classes and objects.
Object Oriented Programming Class object
2.How is modular programming different from procedural Class is a way to bind the data Represents data and its
programming paradigm? and its associatedfunctions associated function together
together. into a single unit.
Modular programming Procedural programming
Emphasis on algorithm rather This emphasis on doing things. User defined data type They are instances of
than data Class ( class variable)
Programs are divided into Programs are organized into Class represents a group Basically an object
individual modules subroutines or sub programs of similar objects is created from a class.
Each modules are independent All data items are global
and have their own local data
Modules can work with its own Difficult to maintain and 10.What is polymorphism?
data enhance theprogram code .  Polymorphism is the ability of a message or function to be
Ex.Pascal and C Ex. FORTRAN and COBOL. displayed in more than oneform.
3.Write the differences between Object Oriented Programming and 11.What are the Advantages of OOP
procedural programming Re-usability:
Code can be use any number of times.
Modular programming Object Oriented Programming Redundancy:
Emphasis on algorithm rather Emphasizes on data rather Inheritance is the good feature for data redundancy.
than data than algorithm Easy Maintenance:
Programs are divided into Data and its associated It is easy to maintain and modify existing code
individual modules operations are Security:
grouped in to single unit Data hiding and abstraction are used to give the security of data.
Each modules are independent Data abstraction is introduced 12.Write the disadvantages of OOP.
and have their own local data Size:
Modules can work with its own Relationships can becreated  Object Oriented Programs are much larger than other programs.
data. between similar Effort:
 Object Oriented Programs require a lot of work to create.
Ex.Pascal and C Ex.C++, Java, VB.Net, Python Speed:
etc.  Object Oriented Programs are slower than other programs, because
of their size.
4.What are the Main Features of Object Oriented 13.What is Modularity ?
Programming? Advantages of oop.  Programs aredivided into individual modules is called
 Data Abstraction Modularity.
 Encapsulation 14.Define Software re-use:
 Modularity  A program can be composed from existing and newmodules
 Inheritance
 Polymorphism
5.How is encapsulation and abstraction are interrelated? Or
6.Define encapsulation.
 The mechanism by which the data and functions are bound
together into a single unit is known as Encapsulation
 It can also be called data binding.

7.Define Abstraction
 Abstraction refers to showing only the essential features
without revealing background details
8.Define Data Hiding or information Hiding.

60
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT -IV Object Oriented Programming with C++ CHAPTER 14


Classes and objects
6.How to Define class members ?or .What are data members and
1.Define Class in C++. tures
member functions of a class? or
 Class is a way to bind the data and its associated functions What does a class comprise of?
together. What are class ( called )member?
 It is used to create user defined data type. Differentiate between Data Members and Member functions.
2.Write the syntax of Declaration of a class or How to Declare a
class in C++?  Class Members are classified as Data Members and Member
General Form functions.
classclass_name Data members
{  Data members are the data variables that represent the features
private: or properties of a class.
variable declaration  Data members are also called as attributes.
function declaration  Separate space is allocated for member variables when each
protected: object is created
variable declaration Member functions
function declaration  Member functions are the functions that perform specific tasks in
public: a class.
variable declaration  Members functions are called as methods,
function declaration  No separate space is allocated for member functions when the
}; objects are created.
 The keyword class followed by the name of the class. 7.What are the methods of defining methods (functions) in a class?
 The body of a class is enclosed within braces and is terminated by a Two types.
semicolon ; (1) Inside the class definition (inline)
 The class body contains the declaration of variables(data) and (2) Outside the class definition (outline)
functions (1) Inside the class definition (inline function)
 The class body has three access specifiers ( visibility labels) viz.,  A member function is defined inside a class,
private , public and protected  It behaves like inline functions.
3.What is the use of Data Hiding in C++?  These are called Inline member functions.
 The members and functions declared under private are not (2) Outside the class definition (outline function)
accessible by members outside the class, this is referred to data  A Member function defined outside the class.
hiding.  It behaves like normal function definition .
4.What are the three access specifiers of class members? (or) List  It is called as outline member function or non-inline member
out the accessibility levels in C++. function.
 The key words public, private, andprotected are called access  Scope resolution operator (::) is used for this purpose.
specifiers. The syntax for defining the outline member function is
The Private Members return_typeclass_name::function_name (parameters)
 It can be accessed only within the class by class members and {
friend functions. function definition
 It cannot be accessed from outside the class. }
 It is a default access specifier. Ex.
The Protected Members void add :: display()
 It can be accessed from within the class by class members and {
from the members of the inherited classes. }
 It cannot be accessed from outside the class. 8.Differentiate structure and class though both are user defined
The Public Members data type.
 It can be accessed from within the class by class members. structure Class
 It can be accessed from outside the class by using objects. User defined data type User defined data type
5.Differentiate between private and public specifier in C++. ( ref. struct keyword used class keyword used
Q4) public as default private as default

61
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

9.What is the difference between the class and object in terms of


oop?
Class object
Class is a way to bind the data Represents data and its
and its associated functions associated function together
together. into a single unit. S1 = 4+4+4 = 12 Bytes S2 = 4+4+4 = 12 Bytes
How are the class members accessed? Or
User defined data type They are instances of 13.How class members are referencing in C++?
Class ( class variable)  The members of a class are referenced (accessed) by using the
Class represents a group Basically an object object of the class followed by the dot (membership) operator
of similar objects is created from a class. and the name of the member.
10.What are the methods of creating class object in C++? syntax :
Objects can be created in two methods, Object_name .function_name(actualparameter);
(1) Global object (2) Local object Ex. stud.execute();
Global Object 14.Define Array of objects.
 If an object is declared outside all the function bodies or  An array of objects can be created for a class .
 Byplacing their names immediately after the closing brace of the classstu
class declaration then it is called as Global object. {,…. ……
 These objects can be used by any function in the program } a[3];
Ex. class xyz Here,a[0],a[1] , a[2] are the array of object of the class stu.
{ 15.What is nesting of member functions in C++?
}a;  A member function can call another member function of thesame
Local Object class directly without using the dot operator.
 If an object is declared with in a function then it is called local  This is called as nesting of member functions.
object. 16.What are the ways of objects can be passed as arguments?
 It cannot be accessed from outside the function. Objects can also be passed in both ways
Ex.
class xyz (1) Pass By Value
{ (2) Pass By Reference
}; 17.Explain how the objects can be passed in pass by valuemethod.
main()  When an object is passed as argument by value ,new object is
{ created in formal parameter.
xyz a;}  The objects from actual parameter copied in to formal parameter.
 Any changes made to the object inside the formal parameter ,do
11.How memory is allocated to the objects of a class.? not affect the actual object.
The member functions are created and placed in the memory space #include <iostream>
only when they are defined as a part of the class specification. using namespace std;
No separate space is allocated for member functions when the class sample
objects are created. {
Separate space is allocated for membervariables(data)when each public:
object is created. void pass(sample obj)
 Separate memory allocations for the objects are essential because the {
member variables will hold different data values for different objects. --------
12.What is the size of the objects s1, s2? }
class sum };
{ int n1,n2; int main()
public: {
void add() sample s1,s2;
{int n3=10;n1=n2=10; s2.pass(s1);
} } s1,s2; return 0;
}

62
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

18.Explain how the objects can be passed in pass by reference void square()
method. {
 object in formal parameter alias the object of actual parameter. n.prn();
 The formal object works directly on the actual object. x=2;
 Any changes made to the object inside the formal parameter cout<< x * x;
,affect the actual object. }
#include <iostream> };
using namespace std;
class sample int main()
{ {
private: enclose e;
public: e.square();
void pass(sample &obj) }
{
-------- In the above program
}  The inner class nest is defined inside the outer class enclose.
};  nest is accessed by enclose by creating an object of nest
int main()
{ Declaring an object of a class as a member to another class
sample s1,s2;  Whenever an object of a class is declared as a member of another
s2.pass(s1); class it is known as a container class.
return 0;  In the container-ship the object of one class is declared in another
} class.
19.What is nested class? #include<iostream>
 When one class become the member of another class then it is using namespace std;
called Nested class. class outer
20.What are the ways the classes can be nested? {
Classes can be nested in two ways. int data;
1. Defining a class within another class public:
2. Declaring an object of a class as a member to another class void get();
Defining a class with in another };
 When a class is declared with in another class, class inner
 The inner class is called as Nested class . {
 The outer class is known as Enclosing class. int value;
 Nested class can be defined in private as well as in the public outer ot;
section of the Enclosing class. public:
#include<iostream> voidgetdata();
using namespace std; };
class enclose Intmain()
{ {
private: Inner x;
int x; }
class nest In the above program
{  Classouter and inner are defined separately.
private :  But both the classes areconnected by the object 'ot' which is a
int y; member of class inner.
public: 21.What is Container class?
void prn()  Whenever an object of a class is declared as a member of another
{ class it is known as a container class.
y=3; 22.Write the example how will you dynamically initialize objects?
cout<<y;  When the initial values are provided during runtime is called
} dynamic initialization.
}; Example
nest n; #include<iostream>
public: using namespace std;

63
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

26.Define constructor overloading. Types of constructor.


class add  Function overloading can be applied for constructors, are called
{ constructor overloading .
public: Three types of constructors, they are
void add(int a, int b) 1.Non-Parameterized constructor or default constructor
{ 2.Parameterized constructor
cout<<a+b; 3.copy constructor
} 27.DefineNon-Parameterized constructor or default constructor.
};  A constructor that accepts no parameter is called default
int main( ) constructor.
{  The compiler automatically generates default constructorwhen the
Intx,y; object is created
cin>>x>>y; Advantage :
add(x,y); // dynamic initialization  It helps to create objects withoutinitial value.
 It is also used to create array of objects.
} Ex.
class add
Introduction to Constructors& Destructors {
public:
add();
23.What is a constructor?
{
 Constructors are special member functions. }
 The name of the constructor must be same as the class name. };
 Used to allocatememory space and initialize the data member of int main()
the class object {
 It has no return type add x;
 Constructor can have parameter list }
 Constructor can be overloaded 28.Define Parameterized Constructors
 They cannot be inherited but a derived class can call the base  A constructor with arguments is called parameterized constructor
class constructor .
 Default constructor is public member function  It helps to createobjects withinitial values.
 Parameterized constructor can havedefault arguments.
Syntax: Ex.
Class class_name class add
{ {
public: public:
class_name() add(int a)
{ {
} }
}; };
24.What are the functions of constructors? int main()
 Used to allocate memory space and initialize the data member {
of the class object add x(5);
25.What are the Characteristics of Constructors? Or }
What are the rules of constructors?
 A constructor is a special member function 29.What are the ways to create an object using parameterized
 The name of the constructor must be same as the class name. constructor?
 Used to allocate memory space and initialize the data member There are two ways to create an object using parameterized constructor
of the class object 1)Implicit call 2) Explicit call
 It has no return type Implicit call
 Constructor can have parameter list  In this method ,the parameterized constructor is invoked
 Constructor can be overloaded automatically whenever an object is created.
 They cannot be inherited but a derived class can call the base For example simple s1(10,20);
class constructor  In this for creating the object s1 parameterized constructor is
 Default constructor is public member function automatically invoked.

64
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Explicit call 35. Why it is considered as a good practice to define a constructor


 In this method , the object can be created and initialized though compiler can automatically generate a constructor ?
For example simple s1=simple(10,20);  Default constructors are automatically generate a constructor
 An explicit call to constructor creates temporary instance(object).  It simply allocates memory for the object.
 It is also used to create array of objects.
30.Explain copy constructor with an example.
 Copy Constructor is used to create a copy of an already existing 36.Mention the differences between constructor and destructor.
object of a class type. Constructor Destructor
 In copy constructor the argument (object) should be passed only by The name of the constructor must The destructor has the same
reference not by value method. be same as that of the class name as the
Ex, simple (simple&x) - simple- class name. class tag prefixed by the ~
(tilde)
Calling copy constructors The constructor is executed The destructor is executed
A copy constructor is called automatically when the object is automatically when the control
1.When an object is passed as a parameter to any of the created reaches the end of class scope
member functions
Example:void simple::putdata(simple x); Used to allocatememory space Destructor function removes
2.When a member function returns an object and initialize the data member of the memory of an object
Example:simplegetdata() { } the class object
3.When an object is passed by reference to an object of its own
class It has no return type It has no return type
Example:simples1, s2(s1); Constructor can have parameter Destructor can nothave
list parameter list
32.DefineDistructors.
 A destructor is a special member function. Constructor can be overloaded Destructor cannot be
 The destructor has the same name as the class tag(name) overloaded
prefixed by the ~ (tilde) They cannot be inherited but a They cannot be inherited
 The destructor is executed automatically when the control reaches derived class can call the base
the end of class scope class constructor
 Itremoves the memory of an object
Default constructor is public Destructor is public member
Syntax: member function function
class simple
{ class class_name class simple
Public: { {
~simple() public: Public:
{ class_name() ~simple()
{ {
} }
}; }; }
};
33.What are the rules or Characteristics of Destructors?
 A destructor is a special member function
 The destructor has the same name as the class tag(name)
prefixed by the ~ (tilde)
 The destructor is executed automatically when the control reaches
the end of class scope
 It removes the memory of an object
 It has no return type ******************
 Destructor cannothave parameter list
 Destructor cannot be overloaded
 They cannot be inherited
34.Write down the importance of Destructor.
 It removes the memory of an object

65
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT -IV Object Oriented Programming with C++


Polymorphism
CHAPTER 15
7.Define Constructor overloading.
tures
1.What is Function overloading?  Function overloading can be applied for constructors, called as
 The ability of the function to process the message or data in more Constructor overloading .
than one form is called as function overloading.  A class can have more than one constructor with different
Ex. float area (float r); signature.
float area (float l,float b);  Constructor overloading provides flexibility of creating multiple type
2.What is function's signature? of objects for a class.
 The number and types of a function's parameters are called the
function's signature. 8.class add{int x; public: add(int)}; Write an outline definition for the
3.Define Overloaded resolution. constructor.
 The process of selecting the most appropriate overloaded add ::add(int y)
function or operator is called overload resolution. {
4.What are the advantages of function overloading? or y=x;
What is the use of overloading a function? }
 Function overloading is used to reduces the number of comparisons 9.How does a compiler decide as to which function should be
in a program invoked when there are many functions? Give an example.
 It makes the program to execute faster. When you call an overloaded function,
 It also helps the programmer by reducing the number of function  The compiler determines the most appropriatedefinition to use,
names to be remembered.  by comparing the number of argument and their types to call the
5.Explain Function over loading with an example. function definitions.
 The ability of the function to process the message or data in more  The process of selecting the most appropriateoverloaded
than one form is called as function overloading. function or operator is called overload resolution.
Ex. float area (float r); area(float r)
float area (float l,float b); {
cout<<3.14*r*r;
Rules for function overloading }
 The overloaded function must differ in the number of its arguments area( float l,float b)
or datatypes. {
 The return type of overloaded functions are not considered for cout<<l*b;
overloading same data type }
 The default arguments of overloaded functions are not void main()
considered as part of the in function overloading parameter list. {
Example: area(4.6);
#include <iostream> area(5.7,4.3);
using namespace std; }
float area ( float r )
{ return ( 22/7 * r * r );} 10.class sale ( int cost, discount ;public: sale(sale &);
float area ( float l, float b ) Write a non inline definition for constructor specified;
{ return ( l *b ) ;} sale :: sale(sale &a)
void main() {
{ cout<<”circle”<<area(5.2); cost=s.cost;
cout<<”Rectangle”<<area(5.3,8.2); discount=s.discount;
} }

11.Define Operator overloading


 The mechanism of giving special meaning to an operator is known
6.Does the return type of a function help in overloading a function? as operator overloading.
 Operator overloading provides new definitions for most of the C++
No,The return type of overloaded functions are not considered for operators
overloading same data type

66
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

12.List out the operators that cannot be overload in C++ Rules or Restrictions on Operator Overloading
 scope operator (:: )  Precedence and Associativity of an operator cannot be changed.
 sizeof  No new operators can be created,
 member selector ( . )  Only existing operators can be overloaded.
 member pointer selector (* )  Cannot redefine the meaning of an operator‟s procedure.
 ternary operator ( ?: )  Overloaded operators cannot have default arguments.
13.How to define operator overload in C++  When binary operators are overloaded, the left hand object must be
 The definition of the overloaded operator is given using the keyword an object of the relevant class
'operator' followed by an operator symbol.
Syntax:
Inline:
ReturnType operator operatorSymbol(argument)
{
}
Ex. complex operator +( complex c2)
{
}
Outline:
ReturnTypeclassname : : operator operatorSymbol(argument)
{
}

14. What are the Rules or Restrictions on Operator Overloading?


 Precedence and Associativity of an operator cannot be changed.
 No new operators can be created,
 Only existing operators can be overloaded.
 Cannot redefine the meaning of an operator‟s procedure.
 Overloaded operators cannot have default arguments.
 When binary operators are overloaded, the left hand object must be
an object of the relevant class

15.Define and explain the operator overloading?


Define :
 The mechanism of giving special meaning to an operator is known
as operator overloading.
 Operator overloading provides new definitions for most of the C++
operators
The definition of the overloaded operator is given using the keyword
'operator' followed by an operator symbol.
Syntax:
Inline:
ReturnType operator operatorSymbol(argument)
{
}
Ex. complex operator +( complex c2)
{
}
Outline:
ReturnTypeclassname : : operator operatorSymbol(argument)
{
}

67
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT -IV Object Oriented Programming with C++


Inheritance
CHAPTER 16
tures
1.What is inheritance? What are the advantages of inheritance? 6.What are the points to be noted while deriving a new class?
 It is a process of creating new classes called derived classes,  The keyword class has to be used
from existing or base classes.  The name of the derived class is to be given after thekeyword
 Inheritance allows us to inherit all the code (except declared as class
private) of one class to another class  A single colon
The main advantage of inheritance is  The type of derivation (the visibility mode ), namely private, public
• It represents real world relationships well or protected.
• It provides reusability of code Default visibility mode is private.
• It supports transitivity  The names of all base classes(parent classes) separated by
2.What is base class? comma.
 A class that is used as the basis for inheritance is called a class derived_class_name :visibility_modebase_class_name
superclass or base class. {
3.Define derived class. Or why derived class is called power // members of derivedclass
packed class? };
 A class that inherits from a superclass is called a subclass or Ex. Class boys : public student
derived class {
 The derived class is a power packed class, as it can add additional
attributes and methods and thus enhance its functionality };
4.What are the types of Inheritance ? 7.Differentiate between access specifier and visibility modes
 There are different types of inheritance viz., Single Inheritance,  Access specifiers control the accessibility of the class
Multiple inheritance, Multilevel inheritance, hybrid inheritance and memberswith in the class
hierarchical inheritance.  Visibility modes control the access of inherited members with in
5.Explain the types of Inheritance. the class
There are different types of inheritance viz., Single Inheritance, Multiple 8.Explain the different visibility mode in inheritance.
inheritance, Multilevel inheritance, hybrid inheritance and hierarchical  The accessibility of base class by the derived class is controlled by
inheritance. visibility modes.
1. Single Inheritance  The three visibility modes are private, protected and public.
When a derived class inherits only from one  The default visibility mode is private.
base class, it is known as single inheritance. Private visibility mode
When a base class is inherited with private visibility,
2. Multiple Inheritance
 The public and protected members of the base class become
When a derived class inherits from multiple „private‟ members of the derived class
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.
Protected visibility mode
4. Multilevel Inheritance
When a base class is inherited with protected visibility.
 The transitive nature of inheritance.
 The protected and public members of the base class become
 In multilevel inheritance a derived class
„protected members „ of the derived class
itself acts as a base classto derive
another class.

5. Hybrid inheritance
A combination of more than one type of
inheritance is known as hybrid inheritance.
It may be a combination of Multilevel and Multiple
or Hierarchical and Multilevel or Hierarchical,
68
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Public visibility mode int main()


When a base class is inherited with public visibility, {
 The protected members of the base class will be inherited as Rectangle Rect;
protected members of the derived class. Rect.setWidth(5);
 The public members of the base class will be inherited as public Rect.setHeight(7);
members of the derived class. cout<< "Total area: "<<Rect.getArea() <<endl;
return 0;
}
Output
Total area: 35
 W
hen
classes are inherited the private members of the base class are not The following table contain the members defined inside each class
inherited they are only visiblei.e continue to exist in derived before inheritance
classes, and cannot be accessed
9.Differentiate between private and public visibility modes.Ref.above
ans.

10.What is the size of following class?


classx
{ The following table contain the details of members defined after
}; inheritance
 A class without any declaration will have 1 byte size.
So ,x occupies 1 byte. In case the class rectangle is derived with private visibility mode

11.Explains the significance of different visibility modes from


following program.
#include <iostream>
using namespace std;
class Shape
{
private:
int count;
protected:
int width; Suppose the class rectangle is derived with protected visibility
int height;
public:
voidsetWidth(int w)
{
width = w;
}
voidsetHeight(int h)
{
height = h;
Suppose the class rectangle is derived with publicvisibility
}
};
class Rectangle: public Shape
{
public:
intgetArea()
{
return (width * height);
}
};

69
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

}
12.WriteSome Facts about the execution of constructor in Output:
inheritance. Constructor of base class...
 Base class constructors are executed first ,before the derived Constructor of derived ...
class constructors execution Constructor of derived1 ...
 Derived class can not inherit the base class constructor. Destructor of derived1 ...
 If there are multiple base classes ,then its start executing from the
Destructor of derived ...
left most base class
 In multilevel inheritance, the constructors will be executed in the
Destructor of base class....
order of inheritance
14.How the size of derived class object is calculated?
13.Find the output of the following program.
#include<iostream>
Size of derived class object =
using namespace std;
Size of all base class data members + size of all derived class data
classbase
members.
{
15.What do you mean by overriding /Shadowing?
public:
 When a derived class member function has the same name as
base()
that of its base class member function ,
{
 The derived class member function shadows/hides the base
cout<<"\nConstructor of base class...";
}
class‟s inherited function .
~base()  This situation is called function overriding /Shadowing .
{  This can be resolved by giving the base class name followed by ::
cout<<"\nDestructor of base class.... "; and the member function name
} Ex.employee :: display();
};
Classderived:public base 16.Define“this” pointer
{  this pointer used to refer the current objects members
public :  'this' pointer is a constant pointer that holds the memory address
derived()
of the current object. .
{  It identifies the currently calling object.
cout<< "\nConstructor of derived ...";  It is useful when the argument variable name in the member
function and the data member name are same. Syntax: this->data
}
member name
~derived()
{ #include<iostream>
cout<< "\nDestructor of derived ..."; using namespace std;
} class T
}; {
class derived1 :public derived public:
int x;
{
void foo()
public : {
derived1() x = 6; // same as this->x = 6;
{ this->x = 5; // explicit use of this->
cout<< "\nConstructor of derived1 ..."; cout<<endl<<x<<" "<<this->x;
}
}
void foo(int x)
~derived1() {
{ this->x = x; // unqualified x refers to the parameter.'this->' required
cout<< "\nDestructor of derived1 ..."; for disambiguation
} cout<<endl<<x<<" "<<this->x;
}; }};
int main()
{
derived1 x;
return 0;

70
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Constructor of publisher
Constructor of branch
17.Answer the following questions based on the given program. Constructor of author
#include<iostream> Destructor of author
#include<string.h> Destructor ofbranch
#include<stdio.h> Destructor of publisher
usingnamespacestd; d. Name the base class(/es) and derived class (/es).
class publisher Base class: publisher, branchDerivedclass:author
{ e. Give number of bytes to be occupied by the object of the following
charpname[15]; class: (a) publisher (b) branch (c) author
charhoffice[15]; publisher:93 bytes branch:64 bytes author: 28 bytes
char address[25]; f. Write the names of data members accessible from the object of class
double turnover; author.
protected: Phone,no_of_emp, bphone,aut_code,aname,income
char phone[3][1O]; g. Write the names of all member functions accessible from the object of
void register(); class author.
public: getdata(),putdata(),give data(),have data(),disp data(), enter data();
publisher(); h. Write the names of all members accessible from member functionsof
~publisher(); class author
void enter data(); getdata(),putdata(),give data(),have data(),disp data(), enter
voiddisp data(); data(),register()
}; Phone,no_of_emp, bphone,aut_code,aname,income
class branch 18.Consider the following c++ code and answer the questions
{
class Personal
charbcity[15]; {
charbaddress[25]; IntClass,Rno;
protected: char Section;
intno_of_emp; protected:
public: char Name[20];
charbphone[2][10]; public:
branch(); personal();
~branch(); voidpentry();
void have data(); voidPdisplay();
void give data(); };
};
ClassMarks:private Personal
{
class author: public branch, publisher float M{5};
{ protected:
Intaut_code; char Grade[5];
Charaname[2O]; public:
float income; Marks();
public: void M entry();
author(); void M display();
~author(); };
voidgetdata(); classResult:public Marks
voidputdata(); {
};
floatTotal,Agg;
public:
charFinalGrade, Commence[20];
a.Which type of Inheritance is shown in the program?
Result();
Multiple inheritance void R calculate();
b.Specify the visibility mode of base classes. void R display();
public: }:
c. Give the sequence of Constructor/Destructor Invocation when object a. Which type of Inheritance is shown in the program?
of class author is created.

71
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

Multilevel Inheritance protected:


b. Specify the visibility mode of base classes. int y;
private , public public:
c Give the sequence of Constructor/Destructor Invocation when object of B(int x, int y)
class Result is created.
Constructor {
Personal() this->x = x;
Marks() this->y = y;
Result() }
Destructor B()
Result() {
Marks() cout<<endl<<" I am class B "<<endl;
Personal() }
d. Name the base class(/es) and derived class (/es). ~B()
Base :Personal,MarksDerived : Marks , Result {
e.Give number of bytes to be occupied by the object of the following class: cout<<endl<<" Bye ";
(a) Personal turbo 25bytes,devc++ 29bytes }
(b) Marks 25 bytes(c) Result 29bytes void show()
{
f. Write the names of data members accessible from the object of class cout<<"x = "<<x<<endl;
Result. cout<<"y = "<<y<<endl;
Name,Grade,total,Agg,FinalGrade.Commence }
g. Write the names of all member functions accessible from the object of };
class Result. int main()
R calculate(),R display(),M entry(),M display(),personal();void {
pentry(); voidPdisplay(); AobjA;
h. Write the names of all members accessible from member functionsof B objB(30, 20);
class Result. objB.show();
R calculate(),R display(),M entry(),M display(),personal();void return 0;
pentry(); voidPdisplay(); }
Output:
19.Write the output of the following program I am class A
#include<iostream> I am class B
using namespace std; X=30
class A Y=20
{ Bye
protected: Bye
int x; 20.Debug the following program
public:
void show() Output
{ -------------
cout<<"x = "<<x<<endl; 15
} 14
A() 13
{ Program :
cout<<endl<<" I am class A "<<endl; -------------
} %include(iostream.h)
~A() #include<conio.h>
{ Class A
cout<<endl<<" Bye "; {
} public;
}; int a1,a2:a3;
class B : public A Void getdata[]
{ {
{ a1=15;
a2=13;a3=13;

72
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

}
}
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()
{
clrscr()
B der;
der1:func();
getch();
}
To Know Yourself
Define Pointer variable
 A pointer is a variable that hold a memory address of other variable
 In Pointer ,the memory location of a variable can be directly
accessed.
 The address of ( & ) and the value at operator (*)are deals with
pointer.
To declare
Syntax :data type *Variable name;
Ex. Int *abc;- Here The variable abc can only
store addresses.
Initialization of pointer variable:
Int *abc , n;
n=10;
abc = &n;
 Pointer variable can store the address of other variables
 Pointer variable and assigning variable should have same data type.
---------------------------------------------------
For example
Int *abc ; float n;
n=10.5;
abc = &n;
Compiler shows an error because,
Pointer variable and assigning variable should have same data type
==============================================

73
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT -IV Computer Ethics and Cyber Security CHAPTER 17


11.What is the role of firewalls?( layered security)
 Firewalls also vary in type depending on where communication
1.What is cyber-crime? originates, where it is intercepted, and the state of communication
 A cyber-crime is a crime which involves computer and network. being traced.
2.What is Computer ethics 12. Write about encryption and decryption.
 Computer ethics is set of moral principles that regulate the use  Encryption is the process of translating the plain text data
of computers by users (plaintext) into random and mangled data (called cipher-text).
3. What are ethical issues? Name some.  Decryption reverse process of converting the cipher-text back to
An Ethical issue is a problem or issue that requires a person or plaintext.
organization to choose between alternatives  Encryption and decryption are done by cryptography
 Cyber crime 13. Explain symmetric key encryption.
• Software Piracy  Symmetric encryption is a technique to use the same key for both
• Unauthorized Access encryption and decryption. (Secret key)
• Hacking  To exchange the key used to encrypt the data before they can
• Use of computers to commit fraud decrypt it
• Sabotage in the form of viruses 14. What are the guidelines to be followed by any computer user?
• Making false claims using computers  Honesty: Users should be truthful while using the internet.
4.What is Harvesting?  Confidentiality: Users should not share any important information with
 A person or program collects login and password information unauthorized people.
from a legitimate user to illegally gainaccess to others‟  Respect: Each user should respect the privacy of other users.
account(s).  Professionalism: Each user should maintain professional conduct.
5.What is Malware?  Obey The Law: Users should strictly obey the cyber law in computer
 Malicious programs that can perform a variety of functions including usage.
stealing, encrypting or deleting sensitive data, altering or hijacking
 Responsibility: Each user should take ownership and responsibility for
core computing functions and monitoring user‟s computer activity
their actions
without their permission
6.Write two types of cyber attacks. ref.aboveans
15.Define software piracy.(or)What is piracy? Mention the types of
Differentiate between scam and spam
piracy? How can it be prevented?
Scam
 Software Piracy is about the copyright violation of software created
 Tricking people into believing something that is not true.
originally by an individual or an institution
Spam Type of Piracy Function
 Distribute unwanted e-mail to a large number of internet users 1 Unauthorized access
7.What is spoofing?  Unauthorized access is when someone gains access to a website,
 It is a malicious practice in which communication is send from program, server, service, or other system by breaking into a user
unknown source disguised as a source known to the receiver account.
8.What are Warez? 2 Hacking
 Commercial programs that are made available to the public illegally  Hacking is gaining unauthorized access to s computer system
are often called warez. without the owner‟s permission.
3 Cracking
9. Write a short note on cracking.  Cracking is where someone edits a program source so that the code
 Cracking is where someone edits a program source so that the code can be exploited or modified.
can be exploited or modified.  A cracker (also called a black hat or dark side hacker) is a malicious
 A cracker (also called a black hat or dark side hacker) is a malicious or criminal hacker
or criminal hacker. Prevented Action:
10. What is a Cookie?  Stop to chat on Internet Relay Chat(IRC) or by Instant messenger.
 A cookie is a small piece of data sent from a website and stored on  e-mail can also be a source for them.
the user's computer memory (Hard drive) by the user's web
browser while the user is browsing internet.
 Type of cookies: HTTP cookie, web cookie, Internet cookie, browser
cookie, or simply cookie

74
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

16.Explain the types of cyber attacks.


1. Virus Choose the correct answer
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 1. Which of the following deals with procedures, practices and values?
computer file. a. piracy b. programs c. virus d. computer ethics
2. Worms 2. Commercial programs made available to the public illegally are known
Worms are self- repeating and do not require a computer program to
as
attach themselves.
3. Spyware a. freeware b. warez c. free software d. software
Spyware can be installed on the computer automatically when the 3. Which one of the following are self-repeating and do not require a
attachments are open, by clicking on links or by downloading infected computer program to attach themselves?
software. a. viruses b. worms c. spyware d. Trojans
4. Ransom ware 4. Which one of the following tracks a user visits a website?
Ransomware is a type of malicious program that demands payment after a. spyware b. cookies c. worms d. Trojans
launching a cyber-attack on a computer system.
5. Which of the following is not a malicious program on computer
17.Define cyber law. systems?
“Cyber law or Internet law is a term that encapsulates the legal issues a. worms d. Trojans c. spyware d. cookies
related to use of the Internet 6. A computer network security that monitors and controls incoming and
18.Define digital signature. outgoing traffic is
a. Cookies b.Virus c. Firewall d. worms
 Digital signatures are based on asymmetric cryptography and can
7. The process of converting cipher text to plain text is called
provide assurances of evidence to origin, identity and status of an
electronic document, transaction or message, as well as a. Encryption b. Decryption c. key d. proxy server
acknowledging informed by the signer 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

75
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

UNIT -IV Computer Ethics and Cyber Security Tamil CHAPTER 18


Computing
1.What are Search Engines? Write the List of the search engines
supporting Tamil.
 Search Enginesare portal or website .
 Used to search any information from the cyber space.
 Google and Bing provide searching facilities in Tamil.

2.Define e – Governance:
 Getting Government services through internet is known as e-Governance.
 One can get important announcements, government orders, and
government welfare schemes from the web portal of Govt.
 Ex.www.tn.gov.in\ta

3.Define e-Library
 E-Libraries are portal or website of collection of e-books.
 E-Library services provide thousands of Books as e-books mostly at free
of cost.
 Ex.www.chennailibrary.com

4.What are the keyboard layouts used in Android?


 Sellinam and Ponmadal – are familiar Tamil keyboard layouts that
works on Android operating system

5.What are the Tamil keyboard interfaces softwares?


 NHM Writer, E-Kalappai and Lippikar – are familiar Tamil keyboard
interfaces software

6.Name and define Tamil Translation Applications


 Thamizpori is a Tamil translation application.
 Using this application, we can translate small Englishsentences into Tamil.
7.Write a short note about Tamil Programming Language.
 Based on Python programming language, the first Tamil programming
language “Ezhil” is designed.
 It is used to write simple programs in Tamil.
8.What TSCII?
 TSCII (Tamil Script Code for Information Interchange) is the first
coding system to handle Tamil languageeasily in computer and electronic
devices, including non-English computers.
 This encoding scheme was registered in IANA (Internet Assigned
Numbers Authority) unit of ICANN.
9. Write a short note on Tamil Virtual Academy.
 Tamil Virtual Universitywas established on 17th February2001 by the
Govt. of Tamilnadu.
 Now, it is called as “Tamil Virtual Academy”.
 This organisation offers different courses regarding Tamil language,
Culture, heritage etc., from kindergarten to under graduation level.

76
www.rmkmhsselango.blogspot.com 9677515019
ILANGOVAN ,RMKMHSS - 601206 9677515019

E.ElangovanM.Sc;B.Ed;M.Phill;P.G.D.C.A;
11/100.B.K.Puram,
Gummidipundi – 601201
elango2811@gmail.com
rmkmhsselango.blogspot.com
9677515019

77
www.rmkmhsselango.blogspot.com 9677515019
11
COMPUTER SCIENCE
PRACTICAL

9677515019
www,rmkmhsselango.blogspot.com

ElangovanM.Sc,B.Ed,M.Phil
Head of the Dept.
R.M.K.Matric.Hr.Sce.School,
R.S.M.Nagar,601206.
CS1 - GROSS SALARY

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 input basic salary of an employee and calculate its Gross salary
CODING:
#include<iostream>
using namespace std;
int main()
{
floatb,g,d,h;
cout<<"Enter Basic Salary of an Employee"; cin>>b;
if (b<25000)
{
d=b*80/100;
h=b*20/100;
}
else if (b>=25000 && b<40000)
{
d=b*90/100;
h=b*25/100;
}
else if (b>=40000)
{
d=b*95/100;
h=b*30/100;
}
g=b+d+h;
cout<<"\nBasic\t"<<b;
cout<<"\nDA\t"<<d; Output:
cout<<"\nHRA\t"<<h; Enter basic salary of an employee: 25000
cout<<"\nGross Salary\t"<<g; Basic 25000
} DA 22500
HRA 6250
Gross Salary : 53750
CS2 - PERCENTAGE
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 check percentage of a student and display the division

CODING:

#include<iostream>
using namespace std;
int main()
{
intp,x;
cout<<"\n Enter Your Percentage"; cin>>p;
cout<<" \nYou Scored "<<p<<"%\n";
x=p/10;
switch(x)
{
case 10: case 9: case 8:cout<<"\nDistinction";break;
case 7: case 6 :cout<<"\nFirst division";break;
case 5:cout<<"\nSecond division";break; Output 1
case 4:cout<<"\nThird division";break; Enter your percentage 79
You scored 79%
default:cout<<"\nSorry , You have Failed.."; First division
Output 2
} Enter your percentage: 39
You scored 39%
} Sorry: You have failed
CS3 - PALINDROME
Write a C++ program to enter any number and check whether the number is palindrome
or not using while loop.
AIM: To enter any number and check whether the number is palindrome
CODING:
#include<iostream>
using namespace std;
int main()
{
intn,x,d,r=0;
cout<<"\nEnter a Positive Number";
cin>>n;
x=n;
while(n!=0)
Output 1
{ Enter a positive number: 1234
r=(r*10)+n%10; The Reverse number is: 4321
NOT A PALINDROME
n=n/10;
} Output 2
Enter a positive number: 1221
cout<<"\nThe Reverse Number is "<<r; The Reverse number is: 1221
if(x==r) PALINDROME

cout<<"\nPALINDROME";
else
cout<<"\n NOT A PALINDROME";

}
CS4 NUMBER CONVERSION
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. ExitDepending on the choice accept the value and display the result .The program should continue till the user
select the third option
AIM:To Convert a Decimal to binary number and a binary number to Decimal in menu based using do..while loop
CODING:
#include<iostream>
#include<math.h> Output
using namespace std; 1.Decimal to Binary number
int main() 2.Binary to Decimal number
{ 3.Exit
int d=0,c,i; Enter your choice(1/2/3)1
long int b=0; Enter a Decimal Number: 23
do In decimal … 10111
{
cout<<"\n1.Decimal to Binary\n2.Binary to Decimal\n3.Exit"; 1.Decimal to Binary number
cout<<"\nEnter Your Choice (1 / 2 / 3)"; 10
cin>>c; 2.Binary to Decimal number
switch(c) 3.Exit
{ Enter your choice(1/2/3)2
case 1:cout<<"\nEnter a Decimal Number"; Enter a Binary Number: 11001
cin>>d; In binary … 25
i=0;
while(d!=0) 1.Decimal to Binary number
{ 2.Binary to Decimal number
b+=d%2*pow(10,i); 3.Exit
d/=2; Enter your choice(1/2/3) 3
i++;
}
cout<<"\n In Binary “<<b; break;
case 2:cout<<"\nEnter a Binary number";
cin>>b;
i=0;
while(b!=0)
{
d+=b%10*pow(2,i);
b/=10;
i++;
}
cout<<"\n\n Decimal"<<d; break;
case 3: break;
default:cout<<"\nEnter only 1 / 2 / 3:";
}
} while(c!=3);
}
CS5 - FIBONACCI PRIME SERIES
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 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 prime (int a )
{
if( a == 0 || a == 1 )cout<< "\tNEITHER PRIME NOR COMPOSITE ";
else
{
for (int j = 2 ; j<a; j++)
{
if(a%j==0){ cout<< "\tCOMPOSITE" ;break ; }
}
if( a==j )cout<< "\tPRIME" ;
} Output
} ENTER THE NUMBER OF TERMS 10
void fib ( int n ) FIBONACCI SERIES
{ 0 NEITHER PRIME NOR COMPOSITE
int a = -1 , b = 1 ,c=0 ; 1 NEITHER PRIME NOR COMPOSITE
for ( inti = 1 ; i<= n ; i++) 1 NEITHER PRIME NOR COMPOSITE
{ 2 PRIME
cout<<”\n”; 3 PRIME
c=a+b; 5 PRIME
cout<<c; 8 COMPOSITE
prime(c); 13 PRIME
a = b; 21 COMPOSITE
b=c; 34 COMPOSITE
}
}
int main ()
{
int n ;
cout<< " \n ENTER THE NUMBER OF TERMS " ;cin>> n ;
cout<< "\n FIBONACCI SERIES\n " ;
fib (n) ;
}

CS6 - INSERT / DELETE ELEMENTS IN AN ARRAY


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 Insert and Delete elements in a single dimension array of integers and print the array after insertion
or deletion
CODING:
#include<iostream.h>
#include<conio.h>
intp,e,n, a[20] , b[20] , c[20];
void dis()
{ Output 1
cout<<"The Elements are...\n";
for(inti=0;i<n;i++) Enter the size of the array elements: 5
{ Enter the elements for the array:
1
cout<<a[i]<<'\n';
2
}
3
} 4
void ins() 5
{ --------Menu-----------
inte,p; 1.Insert
cout<<"\nEnter new element..\t";cin>>e; 2.Delete
3.Exit
cout<<"\nEnter position \t";cin>>p;
-----------------------
for(inti=n;i>=p-1;i--) Enter your choice: 1
{
a[i+1]=a[i]; Enter the position: 3
} Enter the element to be inserted : 26
a[p-1]=e; The array elements are:
1 2 26 3 4 5
n=n+1;
dis(); Output 2
} --------Menu-----------
void del() 1.Insert
{ 2.Delete
cout<<"Enter the Position:\t";cin>>p; 3.Exit
-----------------------
e=a[p];
Enter your choice: 2
for(inti=p;i<n-1;i++) Enter the position: 2
{ The deleted element is = 2
a[i]=a[i+1]; The array elements are:
} 1 3 26 4 5
n=n+1;
cout<<"\n After deletion...\n";
dis();
}
void main()
{
clrscr();
intch;
cout<<"\nEnter the size of the Array:\t";cin>>n;
cout<<"\nEnter the element....\n";
for(inti=0;i<n;i++)
{
cin>>a[i];
}
do
{
cout<<"\n\n\nMENU\n\n";
cout<<"\n1.Insert\n2.Delete\n3.Exit\n";
cout<<"-----------------------";
cout<<"\nEnter Your Choice..\t";cin>>ch;
switch(ch)
{
case 1:ins(); break;
case 2:del(); break;
case 3: break;
default: cout<< "\nEnter only 1/2/3";
}
}while(ch!=3);
getch();
}
CS 7 - Boundary Element of a Matrix
Write a C++ program to print boundary elements of a matrix
AIM: To print boundary elements of a matrix
Coding
#include <iostream>
using namespace std; Output
voidprintBoundary (int a[][10], int m, int n) Enter more than 3 x3
{ 4 4
for (inti = 0; i< m; i++) { 1
for (int j = 0; j < n; j++) 2
{ 3
4
if (i==0|| j==0||i==m-1||j==n-1)
5
cout<<a[i][j]<<" ";
6
else 7
cout<<" "; 8
} 9
cout<<endl ; 0
} 1
} 2
int main() 3
{ 4
int a[10][10] ,i,j,m,n; 5
6
cout<<"Enter more than 3 x3 "<<endl;
cin>>m>>n;
Original Array
for (i=0;i<m;i++) 12 3 4
{ 5678
for (j=0;j<n;j++) 9012
{ 3456
cout<<"enter the values for array;
cin>>a[i][j]; The Boundary element
} 1 2 3 4
} 5 8
system("cls"); 9 2
3 4 5 6
cout<<"\n\nOriginal Array\n";
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\n\n The Boundry element\n";
printBoundary(a, m, n);
return 0;
}
CS8 - ABC PUBLISHERS
Define a class named Publisher in C++ with the following descriptions
AIM:To create a class named Publisher with given descriptions.
Coding
#include<iostream>
#include<stdlib.h>
using namespace std;
int id=1001;21
class Publisher
{
intBookno;
char Title[20];
char Author [10];
float Price;
float Totamt;
float calculate (int);
public:
Publisher()
{Bookno=id;
Title[0]='\0';
Author[0]='\0';
Price=0;
Totamt=0;
id++;
}
voidReaddata();
voidDisplaydata();
};
void Publisher::Readdata()
{
intnocopies;
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)
{22
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()
{
intn,i;
Publisher p[10];
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 created2
Enter the Title name C++Programming
Enter the Author name Balaguru23
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 : Balaguru
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
==================================
CS9 - EMPLOYEE DETAILS USING CLASS
Create a C++ program to create a class employee containg the following members
AIM: To create a class employee contain the following members
Coding
#include<iostream>
using namespace std;
class emp{
public:
inteno;
char name[20], des[20];
void get(){
cout<<"Enter the employee number:";
cin>>eno;
cout<<"Enter the employee name:";25
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};
class salary :public emp
{
floatbp,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(){
inti, n;26
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<<"\ne_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;
}

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
CS10 -STUDENT DETAILS
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 create a class called Student
Coding
#include<iostream>
using namespace std;
class Student
{
protected:
intRno;
public:
voidReadno(int r)
{
Rno=r;
}
voidWriteno()
{
cout<<"\nRoll no : "<<Rno;
}
};
class Test :public Student
{
protected:
float Mark1,Mark2;
public:
voidReadmark (float m1,float m2)
{
Mark1=m1;
Mark2=m2;
}
voidWritemark()
{
cout<<"\n\n\tMarks Obtained\n ";
cout<<"\n Mark1 : "<<Mark1;29
cout<<"\n Mark2 : "<<Mark2;
}
};
class Sports
{
protected:
int score;// score = Sports mark
public:
void Readscore (int s)
{
score=s;
}
void Writescore()
{ Output
cout<<"\n Sports Score : "<<score; HYBRID INHERITANCE PROGRAM
}
Roll no : 1201
};
Marks Obtained
class Result :public Test,public Sports
{ Mark1 : 93.5
int Total; Mark2 : 95
public: Sports Score : 80
void display() Total Marks Obtained : 268
{
Total = Mark1 + Mark2 + score;
Writeno();
Writemark();
Writescore();
cout<<"\n\n Total Marks Obtained : "<< Total<<endl;
}
};
int main()30
{
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;
}
E.ElangovanM.Sc;B.Ed;M.Phill;P.G.D.C.A;
11/100.B.K.Puram,
Gummidipundi – 601201
elango2811@gmail.com
rmkmhsselango.blogspot.com
9677515019

You might also like