Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 99

F.C.P.I.T.

LAB
FILE

S.U.S.C.E.T. TANGORI
(MOHALI)

SUBMITTED TO :-
Ms. HARMAN

SUBMITTED BY:-
SHANKY GUPTA
CSE B 90690363100

1
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Practical 1: Familiarization of the


computer system and on hand practice
on power on and power off.
Computer hardware consists of the components that can be physically handled. The function of
these components is typically divided into three main categories: input, output, and storage.
Components in these categories connect to microprocessors, specifically, the computer’s central
processing unit (CPU), the electronic circuitry that provides the computational ability and control
of the computer, via wires or circuitry called a bus.
The main parts of a computer that we'll be focusing on are the Power Supply, Access Slots,
Motherboard, Hard Drive, CPU, RAM, CD-Rom, and Floppy Drive.
First, let's look at two simple diagrams of the inside of a computer.

POWER SUPPLY

The power supply is vital to the computer as it is the source of power. The power supply is
usually a small metal box in the top corner of a case (tower).

ACCESS SLOTS

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Access slots or expansion slots are openings in a computer where a circuit board can be inserted
to add new capabilities to the computer. Examples of drives that may go here would be modems,
USB drives, networking cards, video adapters, and sound cards.

MOTHERBOARD

The motherboard contains various circuit cards performing various functions all plug into many
similar sockets on a common circuit board.
The motherboard contains many circuits and slots .The motherboard is home to the processor
(CPU) along with the access slots and RAM.If we look at the diagram above I've labeled the
parts of the motherboard that I wanted to discuss. The objects labeled 1 a re the access slots. 2 is
the processor slot and 3 are slots to hold memory (RAM).

CPU

The CPU, or processor, is the heart of your computer no matter what type (PC, Server, and
Laptop). There are many brands for processors such as Intel and Athlon all with different
processors for your computer. The CPU processes everything that your computer does, therefore
the better the processor, the faster the computer.

RAM

Random Access Memory (RAM) is the form of memory contained in most computers. RAM is
considered "random access" because you can access any memory cell directly if you know the
row and column that intersect at that cell. When an application is running it stores its information
in the RAM. When you close the application the information is deleted from the RAM. This is
why you need certain amounts of RAM to run applications. The more RAM you have the faster
your computer will be, and the more applications you'll be able to run without loosing speed.

HARD DRIVE

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Nearly every desktop computer and server in use today contains one or more hard-disk drives.
These hard disks do one thing well - they store changing digital information in a relatively
permanent form. They give computers the ability to remember things when the power goes out.
A hard drive stores all your files and information in a permanent form unlike storing it in RAM
(which is temporary). The larger your hard disk (drive) the more information and files you're
able to store. Today's average hard drive is 40 GB although slowly 80 GB hard drives are
becoming used more often.

CD-ROM

The CD-Rom is quite simple, it reads CD's. CD-Rom completely stands for Compact Disk Read
Only Memory. The revolution of CD's is that they hold much more data than a floppy disk,
although are not as flexible when it comes to rewriting and storing personal data. Using CD-RW
you can make your own CD's and use them more like a floppy disk. These are becoming more
and more popular although you still need a CD-Rom to read them.

FLOPPY DRIVE

A floppy drive reads the popular floppy disk. Floppy disk are easy to use, rewritable,
compact,and great for storing information. The floppy drive is simple and allows you to read,
write to, and write over information stored on a floppy disk.
Now you have a basic knowledge of the parts of your own PC. In the future you'll be able to read
more advanced articles and have an understanding of the parts of a PC.

STEPS TO SWITCH ON THE COMPUTER:


1) Switch on the UPS.
2) Switch on the monitor.
3) Press the power key of the CPU to start the machine.

STEPS TO SWITCH OFF THE COMPUTER:


1) Click on START.
2) Select TURN OFF YOUR COMPUTER OPTION.
3) Click on SHUT DOWN to turn off.
4) Switch off the monitor. 5) Switch off the UPS.

Practical 2: Practice with MS-Word,


operating and closing document,

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Preparation of document, setting of


document, familiarization with various
tools, mail-merge practice.
Introduction to MS-Word:
History-Evolution of Word:

Many concepts and ideas of word were brought from bravo, the original GUI word
processor developed at Xerox PARC. Bravo’s creator Charles Simonyi left Xerox PARC to work
for Microsoft in 1981. Simonyi hired Richard Brodie, who had worked with him on Bravo, away
from PARC that summer. On February 1, 1983, development on what was originally named
Multi-Tool Word began. Having renamed it Microsoft Word, Microsoft released the program
October 25, 1983, for the IBM PC. Free demonstration copies of the application were bundled
with the November 1983 issue of PC World, making it the first program to be distributed on-disk
with a magazine. However, it was not well received, and sales lagged behind those of rival
products such as WordPerfect.
Word featured a concept of “What You See Is What You Get”, or WYSIWYG, and was
the first application with such features as the ability to display bold and italics text on an IBM
PC. Although MS-DOS was a character based system, Microsoft Word was the first word
processor for the IBM PC that showed actual line breaks and typeface markups such as bold and
29 italics directly on the screen while editing, although this was not a true WYSIWYG system
because available displays did not have the resolution to show actual typefaces. Other DOS word
processors, such as WordStar and WordPerfect, used simple text-only display with markup codes
on the screen or sometimes, at the most, alternative colors.
Word 2007 is the most recent version of Word. This release includes numerous changes,
including a new XML-based file format, a redesigned interface, an integrated equation editor,
bibliographic management, and support for structured documents. It also has contextual tabs,
which are functionally specific only to the object with focus, and many other features like Live
Preview (which enables you to view the document without making any permanent change(s),
Mini Toolbar, Super-tooltips, Quick Access toolbar, SmartArt, etc.

File Formats:
Word document formats (.DOC) as of early 2000s were a de facto standard of document file
formats due to their popularity. Though usually just referred to as “Word document format”, this
term refers primarily to the range of formats used by default in Word version 2-2003. In addition
to the default Word binary formats, there are actually a no of optional alternate file formats that
Microsoft has used over the years. Rich Text Formats (RTF) was an early effort to
create a format for interchanging formatted text between applications. RTF remains an optional

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

format for word that retains most formatting and all content of the original document.
Later, after HTML appeared, Word supported an HTML derivative as an additional fullfidelity
roundtrip format similar to RTF, with the additional capability that the file could be
viewed in a web browser. Word 2007 uses the new Microsoft Office Open XML format as its
default format, but retains the older Word 97-2003 format as an option. It also supports (for
output only) PDF and XPS format.

COMPONENTS OF WORD WINDOW


When user opens a Microsoft Word window on the screen, it has number of different parts.
These
parts are given as under:

(a) Title Bar


(b) Menu Bar
(c) Tool Bar
(d) The Ruler
(e) Status Area or Status Bar
(f) Scroll Bar
(g) Frame
(h) Working Area or Document Window Area
(i) View Button Bar

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

The main ones are explained as below:

(a) Title Bar:


The title bar of the MS-Word window displays the name of the program as
“Microsoft Word”. It also displays the name of the document, which is currently opened. If we
are creating a new document, then it will be “document1” in the title bar with the
“Microsoft Word”. When after typing the textual information you save the document by
pressing the Ctrl+S key combination from the keyboard, it will ask you for the name of the
document. When you assign the name of the document, it will replace “Document1” with your
entered name. You can move the window anywhere on the screen by moving the mouse to title
bar. Here click the left mouse button once and by holding the mouse, you drag it anywhere.

(b) Menu Bar:


The next line or bar of the Word window contains the menu bar. Word’s menus
are pulled down from the Menu Bar, located across the top of the screen. The menu bar
contains several menu items on the menu pads. Various menus are File, Edit, View, Insert,
Format, Tools, Table, and Window and Help having menu pads. Menus are accessed by
picking a menu name from the menu pad with the mouse pointer or by pressing Alt+X key
combination from the keyboard, where X is the underlined letter in the menu name. On selecting

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

a particular menu pad, Word displays the corresponding pull-down menu. Once a menu is pulled
down, you can pick one of the selections with the mouse pointer or again by typing the
underlined letter of the desired selection. These various types of menu selections on the pull
down menu are also called Menu commands. When a menu command is highlighted, you can get
Help information about that selected command by pressing the Function key F1.
Now we will study various Pull-down menus as:

1. File:
The File menu displays several menu commands. The File menu is used to perform a
variety of file and printing operations. The main menu selections or commands in the File
pull down menu are New, Open, Close, Save, Save As…, Save All, Properties…,
Templates…, Page setup…, Print Preview, Print, Send, Exit and some currently
used and saved document files.
We can create a new document by selecting New command or pressing the Ctrl+N key
combination from the keyboard. You can open an existing document by clicking the open menu
command and close it by selecting and clicking the close menu command or menu option. You
can save your text or document by clicking the Save Command. If you want to save your
document in another drive or directory, then click the Save As command. If you want to save all
opened documents then select the Save All command. The properties selection displays
information about the current document. You can set the templates by clicking the Templates
command. You can set the size, margins and orientation of a page by selecting Page setup
command. You can print the document and also take print preview before printing by selecting
Print and Print Preview Commands respectively. You can send your document to E-mail by
selecting Send to command or option. Ellipses (…) following a menu items or commands
indicate that dialogue boxes appear after the menu selection that performs an operation. Exit
selection will quit the user from MS-Word. Word also displays recently saved files at the bottom
of the file menu. You can open a recently used file by picking it with mouse pointer or by typing
the corresponding number.

2. Edit:
The Edit menu displays several menu selections as Undo, Clear, Repeat, Cut, Copy,
Paste, Paste Special, Select all, Find, replace, Go to, Auto text, and Book mark.
The Edit Menu is used to delete, Copy and move blocks of the text. It also includes Undo (to
cancel last executed command) and Repeat the selection (i.e. redo operation). It will also find
and replace the text. The paste special selections used to link pasted objects from other
applications. You can move to any page with the help of Go to command. The Bookmark
selection inserts reference points within a document. Auto text does the alignment of the text.

3. View:
The View menu displays the menu commands such as Normal, Outline, Page
Layout, Footer, Footnotes, Annotations, and Zoom. The view menu lets you to display your
document in no. of ways including Normal, Outline, Page layout, Master

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Document(which gives you the document’s underlying structure) and Full screen. You can select
any one of these views and take the decision which is better for the viewing the information or
textual data. View can also turn off and on the display of the tool bars, the ruler, footnotes and
annotations. It can also zoom the page size to different percentages. View is used to create, edit
header and footers and also set.

4. Insert:
The Insert menu displays the several menu commands of Break, Page Number,
Annotations, Date and Time, Field, Symbol, Form Field, Footnote, Caption, Cross-
Reference, Index and Tables, File, Frame, Picture, Object and Database. Insert selection
gives you the ability to insert a variety of things into your document. This menu is used to insert
page and section breaks, page numbers, the current date and time, footnotes, annotations, special
symbols, forms, files, pictures, frames, objects, including equations, databases and captions for
figures, tables or equations. You can also identify text for an index or table of contents.

5. Format:
The Format menu displays menu commands like Font, Paragraph, Tabs Bullets and
Numbering, Heading Numbering, Auto format, Style gallery, Style, Frame, Pictureand
Drawing objects.
The format menu lists options for setting and modifying various fonts,
one or all paragraphs formats, to set the borders and apply shading on Borders, to insert or delete
columns, to set Bullets and set the Numbers, to set heading numbering, to do auto formation, to
apply various style settings, set picture in text and apply drawing objects.

6. Tools:
The Tool menu has the main selections as Spelling, Grammar, Thesaurus,
Hyphenation, Language, Word count, Auto correct, Mail Merge, Envelopes and Labels,
Protect Document, Revisions, Macro, Customize, and Options. In this the user can use the
built in spelling checker, grammatical error remover and Thesaurus. User can count the words in
the document, set the special characters corresponding to different languages, turns hyphenation
on or off, prepares the envelopes and labels, mail merge the documents, create and run macros,
customize the various toolbars menus and shortcut keys. It can also protect and unprotect
document and set the many Word options.

7. Table: The Table menu displays the selections of Insert row, Delete row, Merge cells,
Split cells, Select row, Select column, Select table, Table Autoformat, Cell height
and width, Headings, Convert table or text, Sort, Formula, Split Table, and
Gridlines.

8. Window:
The window menu displays several menu commands like New Window, Arrange All,
Split, and some document filenames. The window menu is used to create, arrange and
select document windows when more than one document is open.

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

9. Help:
The Help menu comprises of Microsoft Word Help topics, Answer Wizard, The
Microsoft Network, Word perfect Help, and about Microsoft Word. By using the help menu
option, one can review the information about Word operations. You can press F1 at any selection
and get the required help. We can use the Help index and search features to locate specific
information. The Answer Wizard can be useful for direct Help.

(c) Tool bars:


Each Office application comes with a set of tool bars. Word 6.0 and its advanced
versions come with several predefined toolbars. Each tool bar has a set of tools that are
appropriate for a particular type of task. By default, the standard and Formatting toolbars are
displayed but you can display other toolbars at any time by selecting these from the View menu.
You can also hide all the toolbars if you want to see more of your document on the screen. The
main toolbars in Word 6 for Windows 3.x (3.0/3.1/3.11) are standard, formatting, Border,
Database, Drawing, Forms, Microsoft, Word for Windows 2.0 and Tip Wizard .
PAGE SETUP (MARGINS AND GUTTERS):

Clicking the file menu displays the page setup command. The page setup command will set the
margins (top, bottom, left, right, set gutter), define the paper size and its orientations (portrait or
landscape), and find the paper source (tray and others) and set the page layout. To work with
page setup, first of all click the file menu and select page setup command. When you click this
command, a page setup dialog box will be displayed.

CHANGING STYLE, FONTS AND FONT STYLE:

Styles:
Ms-Word comes with a number of built in styles (several paragraph styles and flow

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

character styles) that can be applied to both the document heading and normal text. A style is a
named set of formatting characteristics which can quickly and easily paragraph and
character formatting to text. You define the style by giving it a name and various paragraphs
or character formatting properties. The paragraph or selected text automatically takes on the
formatting characteristics assigned to the style. The primary purpose of style is to simplify
and standardize formatting. You can create any number of styles according to your
requirement.
Ms-Word has mainly two types of styles as:
Paragraph style and
Character styles.
A paragraph style applies to an entire paragraph and improves the paragraph’s
appearance. Some common paragraph formatting characters are line spacing, Indent icon,
Tab stops, Border and Font properties. Every paragraph has a style. The default paragraph
style is called normal. Character style applies only to selection of text rather than the entire
paragraph but you can apply it to whole paragraph. Some common character Paragraph styles
are Type face, Face size, Bold, Italics and Underline.

Applying style to a text:


You can apply a style to a paragraph before or after you type the
text in the paragraph. To apply style to a paragraph or character move the mouse pointer to
the desired location and highlight the text to which you want to apply style if text is already
written otherwise when you type the text, it will automatically take the selected style. Now
select the style from the style drop-down list in the Formatting toolbar. This list provides you
a preview of each style within the list including the type face and font characteristics. You
can also apply style by pressing the Ctrl+Shift+N key combination and to activate the Font
drop-down list press the Ctrl+Shift+F key combinations. Also we can apply style by selecting
the style command from the Format menu.

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

PAGE BREAKS :

MS-Word automatically warps text to the following page based on page margins, paragraphs
indents and other criteria. You can insert a manual page break any time you want to force
Word to start a new page. To insert a page break, move the cursor where you want to set the
page break. Now there are two ways to set page breaks between the continuous texts. First
you can select Break Command from the Insert menu and click the break command. If it is
not selected then you can click the Page Break radio button and click the ok button form the
break dialog box.

HEADERS AND FOOTERS:

Header and Footer appear at the top and bottom respectively of a document. Header is a
special text, which is often used for repeating the title of document from a page to page and
entering page numbers at the top of the document. Also graphics symbol can be displayed at
Header. Title of the book is shown on every page of the book work as Header. Footers are
often used for the same purpose but at the bottom of a document. You have to enter the text
for a header or footer only once. Headers and Footers are also useful for placing backgrounds

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

and watermarks on a page.

Auto text:

Cut and Copy both store information on the Clipboard. Each time you store new information
on the Clipboard, the old information is lost. If you wish to store text permanently so you can
use it repeatedly, use Auto text. For this purpose following are the steps:
a. Type the following:

Auto text information is stored permanently.


b. Highlight “Auto text information is stored permanently.”
c. Choose Insert> Auto text> New from the menu.
d. Microsoft Word suggests a name. The suggestion displays in the dialogue box. Change the
name by typing AT in the Please Name Your Auto text Entry Field.
e. Click OK.
f. Click anywhere in the text area to remove the highlighting.
g. Place the cursor between the period in the sentence you just typed and the paragraph marker.
h. Press the spacebar twice to leave two blank spaces.
i. Type AT.
j. Press F3.
k. Your text should now read:
“Auto text information is stored permanently. Auto text is stored permanently.”
The Tab Key:

The default tab setting for Microsoft Word is .5 inches. When you press the Tab Key, the cursor
moves ½ inches across the page and an arrow appears on the screen. The arrow is a non printing
character, when you print your document the arrow does not print. Press the Tab key a few
times. Note how the cursor moves across the page.

Printing the document file:

We can print a document, table, chart or any text or graphics materials from the document file.
Note that before using the Print command, document should be opened. Also note that before
using the Print command, you should take the view of your printed document using the print
preview facility.

PREVIEWING Documents:

Previewing is the procedure to view the document before printing i.e. in other words Previewing
a document means viewing a screen representation of one or more pages before you print them.
To print preview a document, the procedure can be taken as:
a. Select the Print Preview option from the file menu. Alternatively, click on the Print Preview
button on the standard toolbar.
b. Use the magnifier button or select the Zoom options from the view menu to enlarge the

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

document. When you use Print Preview, several preview buttons are displayed on the Print
Preview toobar

Background printing:

Some printing jobs take hours to complete. In such situations, you can use the background
printing utility offered by Word. Background printing enables you to do other things while the
printer prints in the background. You can also check and control the status of multiple print jobs.
In background printing, the system sends the print jobs to a file on the hard disk rather than
directly to the printer. It then sends it to the printer in the background.

MAIL MERGE
The term mail merge is typically used to describe the process of merging some form of address
data base with a form of letter to create a group of individual letters. It is a good feature of the
Microsoft Word. Mail merge is used to print letters, envelopes, mailing labels etc.
Mail merging uses two files. Actually Mail merging means to combine two different
files in one at the time of printing. Mail merge uses the main file or main document and picks
the first Name, address from the data files or label files and combine these file into one.
Similarly it picks the second address and combines it with general letter and creates the second
letter. Again similarly it will continue this process until last address in the data file.

How to create a mail merge file:

Mail merge list summarizes the steps involved in performing a mail merge operation:
a) Create the Main letter: It has the general body of letter.
b) Create the Data source: It has the label address of the letter.
c) Define merge files in the main document: User defines merge fields in the main document.
These fields tell the Ms-Word where to insert specific data items from the data source.
d) Merge the data with the Main document: when the main document and the data source are
ready, you can merge two. The result is a single document containing all the personalized
documents with page break separating one document from another.
e) Print the document: as all personalized documents are placed in a single document file, you
can
print all documents in one operation.

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Types of documents you can create:

The main document in a mail merge operation is the one that contains the boilerplate text and
graphics, which are the same in all resulting documents. There are few types of main documents
used in Mail merge:-

i. Formal letter:
when you want to create a formal letter, Ms-Word merges the main document and the
data source to create a single document that contains all he personalized letters, with each letter
in its own section.

ii. Envelopes:
Ms-Word automates the process of creating envelopes, enabling you to specify the
envelope type, print options and other variables.

iii. Labels:
Word allows you to specify the type of label having size, number per page etc. and
then
creates a main document consisting of page label. Each label cell contains the fields to insert the
address information. The resulting merged document contains multiple pages of labels all in one
section.

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

iv. Catalog:
A catalog is much like a form letter which has resulting merged document contains all
the data in one section instead of individual sections.

Practical 3: Practice with C++ with the


help of simple
exercises giving on hand practice and
understanding of various features.
C++ is a general-purpose programming language. It is regarded as a middle-level language, as it

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

comprises a combination of both high-level and low-level language features.[1] It was developed
by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C programming
language and originally named "C with Classes". It was renamed to C++ in 1983.
C++ is widely used in the software industry. Some of its application domains include systems
software, application software, device drivers, embedded software, high-performance server and
client applications, and entertainment software such as video games. Several groups provide both
free and proprietary C++ compiler software, including the GNU
Project, Microsoft, Intel, Borland and others.
The language began as enhancements to C, first adding classes, then virtual functions, operator
overloading, multiple inheritance, templates, and exception handling among other features
C++ is a statically typed, free-form, multi-paradigm, compiled language where compilation
creates machine code for a target machine hardware.

Language features

C++ inherits most of C's syntax and the C preprocessor. The following is a Hello world
program which uses the C++ standard library stream facility to write a message to standard
output:
#include <iostream>
int main()
{
std::cout << "Hello, world!";
}
Operators and operator overloading

C++ provides more than 30 operators, covering basic arithmetic, bit manipulation, indirection,
comparisons, logical operations and more. Almost all operators can be overloaded for
userdefined
types, with a few notable exceptions such as member access (. and .*). The rich set of
overloadable operators is central to using C++ as a domain specific language. The overloadable
operators are also an essential part of many advanced C++ programming techniques, such
as smart pointers. Overloading an operator does not change the precedence of calculations
involving the operator, nor does it change the number of operands that the operator uses (any
operand may however be ignored).

Objects

C++ introduces object-oriented (OO) features to C. It offers classes, which provide the four
features commonly present in OO (and some non-OO)
languages: abstraction, encapsulation, inheritance, andpolymorphism. Objects are instances of
classes created at runtime. The class can be thought of as a template from which many different
individual objects may be generated as a program runs.

Encapsulation

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Encapsulation is the hiding of information. C++ implements encapsulation by allowing all


members of a class to be declared as either public, private, or protected. A public member of the
class is accessible to any function. A private member is accessible only to functions that are
members of that class and to functions and classes explicitly granted access permission by the
class ("friends"). A protected member is accessible to members of classes that inherit from the
class in addition to the class itself and any friends.
The OO principle is that all of the functions (and only the functions) that access the internal
representation of a type should be encapsulated within the type definition. C++ supports this (via
member functions and friend functions), but does not enforce it: the programmer can declare
parts or all of the representation of a type to be public, and is allowed to make public entities that
are not part of the representation of the type. Because of this, C++ supports not just OO
programming, but other weaker decomposition paradigms, like modular programming.
It is generally considered good practice to make all data private or protected, and to make public
only those functions that are part of a minimal interface for users of the class. This hides all the
details of data implementation, allowing the designer to later fundamentally change the
implementation without changing the interface in any way.
Inheritance

Inheritance allows one data type to acquire properties of other data types. Inheritance from a base
class may be declared as public, protected, or private. This access specifier determines whether
unrelated and derived classes can access the inherited public and protected members of the base
class. Only public inheritance corresponds to what is usually meant by "inheritance". The other
two forms are much less frequently used. If the access specifier is omitted, a "class" inherits
privately, while a "struct" inherits publicly. Base classes may be declared as virtual; this is
called virtual inheritance. Virtual inheritance ensures that only one instance of a base class exists
in the inheritance graph, avoiding some of the ambiguity problems of multiple inheritance.

Multiple inheritance

It is a C++ feature sometimes considered controversial. Multiple inheritance


allows a class to be derived from more than one base class; this can result in a complicated graph
of inheritance relationships. For example, a "Flying Cat" class can inherit from both "Cat" and
"Flying Mammal". Some other languages, such as Java or C#, accomplish something similar
(although more limited) by allowing inheritance of multiple interfaces while restricting the
number of base classes to one (interfaces, unlike classes, provide only declarations of member
functions, no implementation or member data).

Polymorphism

Polymorphism enables one common interface for many implementations, and for objects to act differently
under different circumstances.
C++ supports several kinds of static (compile-time) and dynamic (run-time) polymorphisms.
Compile-time polymorphism does not allow for certain run-time decisions, while run-time

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

polymorphism typically incurs a performance penalty.

Static polymorphism

Function overloading allows programs to declare multiple functions having the same name (but
with different arguments). The functions are distinguished by the number and/or types of
their formal parameters. Thus, the same function name can refer to different functions depending
on the context in which it is used. The type returned by the function is not used to distinguish
overloaded functions.
When declaring a function, a programmer can specify default arguments for one or more
parameters. Doing so allows the parameters with defaults to optionally be omitted when the
function is called, in which case the default arguments will be used. When a function is called
with fewer arguments than there are declared parameters, explicit arguments are matched to
parameters in left-to-right order, with any unmatched parameters at the end of the parameter list
being assigned their default arguments. In many cases, specifying default arguments in a single
function declaration is preferable to providing overloaded function definitions with different
numbers of parameters.
Templates in C++ provide a sophisticated mechanism for writing generic, polymorphic code. In
particular, through the Curiously Recurring Template Pattern it's possible to implement a form of
static polymorphism that closely mimics the syntax for overriding virtual functions. Since C++
templates are type-aware and Turing-complete they can also be used to let the compiler resolve
recursive conditionals and generate substantial programs through template metaprogramming.

Dynamic polymorphism
Inheritance

Variable pointers (and references) to a base class type in C++ can refer to objects of any derived
classes of that type in addition to objects exactly matching the variable type. This allows arrays
and other kinds of containers to hold pointers to objects of differing types. Because assignment
of values to variables usually occurs at run-time, this is necessarily a run-time phenomenon.
C++ also provides a dynamic_cast operator, which allows the program to safely attempt
conversion of an object into an object of a more specific object type (as opposed to conversion to
a more general type, which is always allowed). This feature relies on run-time type
information (RTTI). Objects known to be of a certain specific type can also be cast to that type
with static_cast, a purely compile-time construct which is faster and does not require RTTI.
Virtual member functions

Ordinarily when a function in a derived class overrides a function in a base class, the function to
call is determined by the type of the object. A given function is overridden when there exists no
difference, in the number or type of parameters, between two or more definitions of that
function. Hence, at compile time it may not be possible to determine the type of the object and
therefore the correct function to call, given only a base class pointer; the decision is therefore put
off until runtime. This is called dynamic dispatch. Virtual member functions or methods allow
the most specific implementation of the function to be called, according to the actual run-time
type of the object. In C++, this is commonly done using virtual function tables. If the object type

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

is known, this may be bypassed by prepending a fully qualified class name before the function
call, but in general calls to virtual functions are resolved at run time.
In addition to standard member functions, operator overloads and destructors can be virtual. A
general rule of thumb is that if any functions in the class are virtual, the destructor should be as
well. As the type of an object at its creation is known at compile time, constructors, and by
extension copy constructors, cannot be virtual. Nonetheless a situation may arise where a copy of
an object needs to be created when a pointer to a derived object is passed as a pointer to a base
object. In such a case a common solution is to create a clone() (or similar) function and declare
that as virtual. The clone() method creates and returns a copy of the derived class when called.
A member function can also be made "pure virtual" by appending it with = 0 after the closing
parenthesis and before the semicolon. Objects cannot be created of a class with a pure virtual
function and are called abstract data types. Such abstract data types can only be derived from.
Any derived class inherits the virtual function as pure and must provide a non-pure definition of
it (and all other pure virtual functions) before objects of the derived class can be created. An
attempt to create an object from a class with a pure virtual function or inherited pure virtual
function will be flagged as a compile-time error.

Practical 4: Implementation of simple C+


+ programs.
1. WAP to print hello on screen

#include<iostream.h>
#include<conio.h>
void main()
{

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

clrscr();
cout<<"HELLO";
getch();
}

Output

2. WAP to find sum of two numbers

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter first number : ";
cin>>a;
cout<<"enter second number : ";

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cin>>b;
c=a+b;
cout<<"sum of two numbers is : "<<c;
getch();
}

Output

3. WAP to find product of two numbers

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter first number : ";
cin>>a;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"enter second number : ";


cin>>b;
c=a*b;
cout<<"product of numbers is : "<<c;
getch();
}

Output

4. WAP to swap two numbers using third variable

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter first number : ";
cin>>a;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"enter second number : ";


cin>>b;
c=a;
a=b;
b=c;
cout<<a<<endl<<b;
getch();
}

Output

5. WAP to find area of circle

#include<iostream.h>
#include<conio.h>
void main()
{
float r,a;
clrscr();
cout<<"enter radius of circle : ";

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cin>>r;
a=3.14*r*r;
cout<<"area of circle is : "<<b;
getch();
}

Output

6. WAP to find square root of any number

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
long float a,b;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

clrscr();
cout<<"enter any number : ";
cin>>a;
b=sqrt(a);
cout<<"square root of number is : "<<b;
getch();
}

Output

7. WAP to find area of triangle using hero`s formula

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

{
long float a,b,c,s,area;
clrscr();
cout<<"enter the value of three sides of triangle : ";
cin>>a>>b>>c;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"area of triangle is : "<<area;
getch();
}

Output

8. WAP to swap two numbers without using third variable

#include<iostream.h>
#include<conio.h>
void main()

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

{
long int a,b;
clrscr();
cout<<"enter first number : ";
cin>>a;
cout<<"enter second number : ";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<a<<endl<<b;
getch();
}

Output

9. WAP to find area & circumference of circle, volume &


circumference of sphere and average of three numbers

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

#include<iostream.h>
#include<conio.h>
void main()
{
long float r,r1,a,c,v1,c1,x,y,z,average;
clrscr();
cout<<"enter radius of circle : ";
cin>>r;
cout<<"enter radius of sphere : ";
cin>>r1;
cout<<"enter any three numbers : ";
cin>>x>>y>>z;
a=3.14*r*r;
c=2*3.14*r;
v1=(4/3)*3.14*r1*r1*r1;
c1=4*3.14*r1*r1;
average=(x+y+z)/3;
cout<<"area of circle is : "<<a<<endl;
cout<<"cirumference of circle is : "<<c<<endl;
cout<<"volume of sphere is : "<<v1<<endl;
cout<<"cirumference of sphere is : "<<c1<<endl;
cout<<"average of three numbers is : "<<sum;
getch();
}

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

10. WAP to print 5 on screen

10

9
#include<iostream.h>
#include<conio.h>
void main()

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

{
int a=5,b,c;
clrscr();
cout<<a<<endl;
b=a*2;
c=b-1;
cout<<b<<endl<<c;
getch();
}
Output

11.WAP to find reverse of any number


#include<iostream.h>
#include<conio.h>
void main()
{
long int r,s,n;
clrscr();
cout<<endl<<"enter any number : ";
cin>>n;
s=0;
while(n>0)

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

{
r=n%10;
s=s*10+r;
n=n/10;
}
Cout<<reverse :<<s;
getch();
}
Output

12. WAP to print 4 on screen

20

22
#include<iostream.h>
#include<conio.h>

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

void main()
{
int a=5,b,c;
clrscr();
cout<<a<<endl;
b=a*2;
c=b-1;
cout<<b<<endl<<c;
getch();
}

Output

13. WAP to convert integer number to float number


#include<iostream.h>
#include<conio.h>
void main()
{
int a;
float b,c;
clrscr();
cout<<"enter any two numbers not completely divisible : ";

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cin>>a>>b;
c=a/b;
cout<<"output :"<<c;
getch();
}

Output

14. WAP to find greatest of three numbers using nested if Statement

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"enter first number a : ";


cin>>a;
cout<<"enter second number b : ";
cin>>b;
cout<<"enter third number c : ";
cin>>c;
if(a>b&&b>c)
cout<<"a is greatest";
else if(b>a&&b>c)
61
cout<<"b is greatest";
else
cout<<"c is greatest";
getch();
}

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

15. WAP to find total marks and percentage

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,c,d,e,t,p;
clrscr();
cout<<"enter marks in engg. mathematics : ";
cin>>a;
cout<<"enter marks in FCPIT : ";
cin>>b;
cout<<"enter marks in EME : ";
cin>>c;
cout<<"enter marks in chemistry : ";
cin>>d;
cout<<"enter marks in E.D. : ";
cin>>e;
t=a+b+c+d+e;
p=(t/150)*100;
cout<<"total marks : "<<t<<endl;
cout<<"pecentage of marks : "<<p<<"%";
getch();
}

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

16. WAP to print 12 as 1

#include<iostream.h>

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter any two digit number : ";
cin>>a;
b=a/10;
c=a%10;
cout<<b<<endl<<c;
getch();
}

Output

17. WAP to calculate sum of values enter to corresponding years

#include<iostream.h>
#include<conio.h>
void main()
{
long int a,b,c,d,e,t;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

clrscr();
cout<<"enter value corresponding to year 1992 : ";
cin>>a;
cout<<"enter value corresponding to year 1994 : ";
cin>>b;
cout<<"enter value corresponding to year 1996 : ";
cin>>c;
cout<<"enter value corresponding to year 2000 : ";
cin>>d;
cout<<"enter value corresponding to year 2007 : ";
cin>>e;
t=a+b+c+d+e;
cout<<"sum of all corresponding value are : "<<t;
getch();
}

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

18. WAP to caluclate bonus of employee using nested if statement

# include <iostream.h>
# include <conio.h>

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

void main()
{
clrscr();
int code;
float salary, bonus;
cout<<" enter the code of employee =";
cin>>code;
cout<<" enter the salary of employee =";
cin>>salary;
if(code==1)
{
if(salary>5000)
{
bonus=.05*salary;
}
else
{
bonus=0.02*salary;
}
}
else
{
bonus=0.10*salary;
}
cout<<" bonus is:"<<bonus;
getch();
}

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

19. WAP to find grade of student using switch case statement


#include<iostream.h>
#include<conio.h>
void main()

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

{
clrscr();
int p,c,m,t,per;
char g;
cout<<"enter the marks of 3 subjects: ";
cin>>p>>c>>m;
t=p+c+m;
per=t/3;
switch(per/10)
{
case 10:
case 9:
case 8:
g='A';
cout<<"distinction";
break;
case 7:
case 6:
g='B';
cout<<"first division";
break;
case 5:
case 4:
g='C';
cout<<"second division";
break; ;
default:
g='F';
cout<<"fail";
}
cout<<" grade is = "<<g;
getch();
}

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

20. WAP to check number is palindrome or not

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c=0,temp;
cout<<"enter the number : ";
cin>>a;
temp=a;
while(temp>0)
{
b=temp%10;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

temp=temp/10;
c=c*10+b;
}
cout<<"reverse : "<<c<<endl;
if(a==c)
cout<<"palindrome";
else
cout<<"not palindrome";
getch();
}

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

21. WAP to show the working of a preliminary calculator:

#include<iostream.h>
#include<conio.h>
#include<math.h>

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

void main()
{
int n, n1, n2, c, x;
float r=0;
xyz:
clrscr();
gotoxy(36,2);cout<<"CALCULATOR";
cout<<"\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Exit";
cout<<"\nEnter Choice(1,2,3,4,5) :";
cin>>c;
switch(c)
{
case 1 :cout<<"How many numbers?\n";cin>>n;
for (x=1; x<=n; x++)
{ cout<<"\nEnter value :";cin>>n1;
r = r+n1; }
cout<<"\nSum is :"<<r;
getch();
goto xyz;
case 2 :cout<<"Enter first number :";cin>>n1;
cout<<"\nEnter second number :";cin>>n2;
r = n1 - n2;
cout<<"\nDifference :"<<abs(r);
getch();
goto xyz;
case 3 :r = 1;
cout<<"How many numbers?\n";cin>>n;
for (x=1; x<=n; x++)
{ cout<<"Enter Value :";cin>>n1;
r = r*n1; }
cout<<"Product :"<<r;
getch();
goto xyz;
case 4 :cout<<"Enter first value :";cin>>n1;
cout<<"\nEnter second value :";cin>>n2;
r = n1/n2;
cout<<"Result is :"<<r;
getch();
goto xyz;
case 5 :break;
default :cout<<"\nYou have entered a Wrong Choice!";
getch();
goto xyz;
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output:

22. WAP to print Fibonacci series


#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int n;
cout<<"enter the last limit for the series(>2)";
cin>>n;
int a=1,b=1,c=0;
cout<<a<<"\n"<<b<<"\n";
for(int i=1;i<=n-2;i++)
{
c=a+b;
cout<<c<<"\n";

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

a=b;
b=c;
}
getch();
}

output:

23. WAP to print table of a number:

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i;
cout<<"\nEnter a Number :";
cin>>n;
for(i=1; i<=10; ++i)
cout<<"\n "<<n<<”*”<<I<<”= ”<<n*i;
getch();
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output:

24. WAP to print the following pattern for n rows

**

***

**

#include<conio.h>
#include<iostream.h>
void main( )

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

{
int i,j,x,u,k,l;
clrscr( );
for(i=1;i<=5;i++)
{
for(j=40-i;j>=1;j--)
{
cout<<" ";
}
for(x=1;x<=i;x++)
{
cout<<"*"<<" ";
}
cout<<"\n";
}
for(u=4;u>=1;u--)
{
for(k=40-u;k>=1;k--)
{
cout<<" ";
}
for(l=1;l<=u;l++)
{
cout<<"*"<<" ";
}
cout<<"\n";
}
getch( );
}

Output:

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

25.WAP to calculate factorial of a no.

#include<conio.h>
#include<iostream.h>
void main( )
{
clrscr( );
float fac=1;int n;
cout<<"enter number";
cin>>n;
for(int i=n;i>=1;i--)
{
fac=fac*i;
}
cout<<"\n the fatorial of "<<n<<" is "<<fac;
getch( );
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output:

26. WAP to do addition of matrix:

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int m[3][3] = {{1,1,1},{2,2,2},{3,3,3}}, n[3][3] = {{1,1,1},{2,2,2},{3,3,3}};
int r, c;
cout<<"Matrix M\n--------\n";
for (r=0; r<3; r++)
{
for (c=0; c<3; c++)

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

{
cout<<setw(3)<<m[r][c];
}
cout<<"\n";
}
cout<<"\nMatrix N\n--------\n";
for (r=0; r<3; r++)
{
for (c=0; c<3; c++)
{
cout<<setw(3)<<n[r][c];
}
cout<<"\n";
}
cout<<"\nSum of Matrices\n--------\n";
for (r=0; r<3; r++)
{
for (c=0; c<3; c++)
{
cout<<setw(3)<<m[r][c] + n[r][c];
83
}
cout<<"\n";
}
getch();
}

Output:

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

27. WAP for multiplication of matrix:


#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
void main()
{
clrscr();
int x[20][20], y[20][20], z[20][20], m, n, p, q, k, r, c;
cout<<"Enter size of matrix X (for row and column) :";
cin>>m>>n;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"\n\nEnter size of matrix Y (for row and column) ;";


cin>>p>>q;
if (n!=p)
{
cout<<"\n\nMultiplication is not possible.";
getch();
exit(0);
}
else
{
for (r=0; r<m; r++)
{
for (c=0; c<n; c++)
{
cout<<"Enter value of matrix X : ";
cin>>x[r][c];
}
}
for (r=0; r<p; r++)
{
for (c=0; c<q; c++)
{
cout<<"Enter value for matrix Y : ";
cin>>y[r][c];
}
}
for (r=0; r<m; r++)
{
for (c=0; c<q; c++)
{
z[r][c] = 0;
for (k=0; k<n; k++)
{
z[r][c] = z[r][c] + x[r][k]*y[k][c];
}}}
clrscr();
cout<<"Matrix X\n--------\n\n";
for (r=0; r<m; r++)
{
for (c=0; c<n; c++)
{
cout<<setw(5)<<x[r][c];
}
cout<<"\n";}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"\n\nMatrix Y\n--------\n\n";
for (r=0; r<m; r++)
{
for (c=0; c<n; c++)
{
cout<<setw(5)<<y[r][c];
}
cout<<"\n";
}
cout<<"\n\nMatrix Z\n--------\n";
for (r=0; r<m; r++)
{
for (c=0; c<n; c++)
{
cout<<setw(5)<<z[r][c];
}
cout<<"\n";
}
getch();
}

OUTPUT

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

28.WAP to find sum of first 10 numbers using while loop.

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int sum=0,i=1;

cout<<"The natural numbers are : ";

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

for(i=1;i<11;i++)

cout<<"\t"<<i<<endl;

sum=sum+i;

cout<<"The Sum of first 10 natural numbers is : "<<sum;

getch();

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

29. WAP to find the sum of rows and columns of a matrix:

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int a[4][4]= {{1,5,6,3},{5,2,6,3},{3,4,1,7},{6,8,2,0}}, r, c, tr=0, tc=0;
for (r=0; r<4; r++)
{
for (c=0; c<4; c++)
{
cout<<setw(4)<<a[r][c];
tr = tr + a[r][c];
}
cout<<" "<<tr<<'\n';
tr=0;
}
cout<<"-----------------\n";
for (r=0; r<4; r++)
{
for (c=0; c<4; c++)
{
tc = tc + a[c][r];
}
cout<<setw(4)<<tc;
tc=0;
}
getch();
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output:

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

30. WAP to input 2 numbers and swap them(application of call by


reference method of functions)
#include<iostream.h>
#include<conio.h>
void swap_ref (int &a, int &b)
{
int t=0;
t=a;
a=b;
b=t;
}
void main()
{
int x,y;
cout<<"Enter Values for x and y :\n";
cin>>x>>y;
swap_ref(x,y);
cout<<"x="<<x<<" y="<<y;
getch();
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output:

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

31.WAP to calculate addition, multiplication, transpose and trace of a


matrices by switch case.
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a[20][20],b[20][20],c[20][20],i, j, k, m, n, r, p, q, sum=0;

cout<<"Enter the no of rows for first matrice "<<endl;

cin>>m;

cout<<"Enter the no of columns for first matrice "<<endl;

cin>>n;

cout<<"Enter the no of rows for second matrice "<<endl;

cin>>p;

cout<<"Enter the no of columns for second matrice "<<endl;

cin>>q;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

if(m= =p || n= =q)

cout<<"Enter the values of matrice A :"<<endl;

for(i=0; i<m; i++)

for(j=0;j<n; j++)

cin>>a[i][j];

cout<<"Enter the values of matrice B :"<<endl;

for(i=0; i<p; i++)

for(j=0; j<q; j++)

cin>>b[i][j];

cout<<"The entered values of matrice A are"<<endl;

for(i=0; i<m; i++)

cout<<"\n";

for(j=0; j<n; j++)

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<" "<<a[i][j];

cout<<endl;

cout<<"The entered values of matrice B are"<<endl;

for(i=0; i<p; i++)

cout<<"\n";

for(j=0; j<q; j++)

cout<<" "<<b[i][j];

cout<<"\n";

cout<<" 1. For addition of two matrices"<<endl;

cout<<" 2. For multiplication of two matrices "<<endl;

cout<<" 3. For transpose of matrices"<<endl;

cout<<" 4. For trace of matrices"<<endl;

cout<<"Enter your choice"<<endl;

cin>>r;

switch(r)

case 1:

for(i=0; i<m; i++)

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

for(j=0; j<n; j++)

c[i][j]= a[i][j] + b[i][j];

cout<<"The result of addition of two matrices"<<endl;

for(i=0; i<m; i++)

cout<<"\n";

for(j=0; j<n; j++)

cout<<c[i][j];

break;

case 2:

for(i=0; i<m; i++)

for(j=0; j<n; j++)

c[i][j]=0;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

for(i=0; i<m; i++)

for(j=0; j<q; j++)

for(k=0; k<q; k++)

c[i][j]=c[i][j]+ a[i][k]*b[k][j];

for(i=0; i<m; i++)

cout<<"\n";

for(j=0; j<q; j++)

cout<<" "<<c[i][j];

break;

case 3:

cout<<"The transpose of a matrice A"<<endl;

for(i=0; i<m; i++)

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"\n";

for(j=0; j<q; j++)

cout<<a[j][i];

cout<<"The transpose of a matrice B"<<endl;

for(i=0; i<m; i++)

cout<<"\n";

for(j=0; j<q; j++)

cout<<b[j][i];

break;

case 4:

cout<<"The trace of first matrice A"<<endl;

for(i=0; i<m; i++)

for(j=0; j<n; j++)

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

if(i==j)

sum=sum+a[i][j];

cout<<sum<<endl;

break;

default:

cout<<"Enter the right choice"<<endl;

};

else

cout<<"Please enter the same values of rows and columns"<<endl;

getch();

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

32. WAP to illustrate the working of structures.


#include<iostream.h>
#include<conio.h>
struct distance
{
int feet;
int inches;
};
int main()
{
clrscr();
distance length1,length2;
void prnsum(distance l1, distance l2);
cout<<"Enter length 1:"<<"\n";
cout<<"feet:";
cin>>length1.feet;
cout<<"\n"<<"inches:";
cin>>length1.inches;
cout<<"\n\n enter length 2: "<<"\n";
cout<<"feet:";
cin>>length2.feet;
cout<<"\n"<<"inches:";
cin>>length2.inches;
prnsum(length1, length2);
}
void prnsum(distance l1, distance l2)
{
distance l3;
l3.feet=l1.feet+l2.feet+(l1.inches+l2.inches)/12;
l3.inches=(l1.inches+l2.inches)%12;
93
cout<<"\n\n Total Feet:"<<l3.feet<<"\n";
cout<<"Total Inches:"<<l3.inches;
getch();
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

OUTPUT:

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

33.WAP to swap two numbers using Call by value.

#include<iostream.h>

#include<conio.h>

void swap(int, int);

void main()

{ clrscr();

int a=10, b=20;;

cout<<"Before swapping values of : "<<"a="<<a<<" and"<<" "<<"b="<<b;

swap(a,b);

cout<<"\n Swapped values are : "<<a<<" and"<<" "<<b;

getch(); }

void swap(int x,int y)

{ int t;

t=x;

x=y;

y=t;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"\n Swapped value in function are : "<<x<<"\t"<<y;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

34. WAP to illustrate single level inheritance.

#include<iostream.h>
#include<stdio.h> //for gets
#include<conio.h> //for clrscr
const int LEN = 25;
class employee
{
char name[LEN];
long enumb;
public:
void getdata()
{
cout<<"Enter Name pleez : ";
gets(name);
cout<<"Enter Employee No.:" ;
cin>>enumb;
}
void putdata()
{
cout<<"Name is :"<<name<<"\t";
cout<<"Employee no. is :"<<enumb<<"\t";
cout<<"Basic Salary is :"<<basic;
}
protected:
float basic;
void getbasic()
{cout<<"Please enter Basic Pay :"; cin>>basic; }
};
class Manager : public employee //manager is derived
{
private :
char title[LEN];
public :
void getdata()
{
employee :: getdata();
getbasic();
cout<<"Enter Title : ";
gets(title); cout<<"\n";
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

void putdata()
{
employee::putdata();
cout<<"\nTitle is : "<<title<<"\n";
}
};
void main()
{
clrscr();
Manager m1,m2;
cout<<"Manager1\n"; m1.getdata();
cout<<"Manager2\n"; m2.getdata();
cout<<"\t\tManager1 Details\n"; m1.putdata();
cout<<"\t\tManager2 Details\n"; m2.putdata();
getch();
}

output:

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

35.WAP to swap two numbers using Call by reference.

#include<iostream.h>

#include<conio.h>

void swap(int &,int &);

void main()

{ clrscr();

int a=10,b=20;;

cout<<"Before swapping voalues are : "<<a<<"\t"<<b;

swap(a,b);

cout<<"\n Swapped values are : "<<a<<" and"<<" "<<b;

getch(); }

void swap(int &x,int &y)

{ int t;

t=x;

x=y;

y=t;

cout<<"\n Swapped value in function are : "<<x<<"\t"<<y;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

36.WAP to find area of circle using inline function.


#include<iostream.h>

#include<conio.h>

inline float area(float r)

return(3.14*r*r);

void main()

clrscr();

float n;

cout<<"Enter the radius of the circle: ";

cin>>n;

cout<<"\n The area of circle is: "<<area(n);

getch();

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

37. WAP using classes and objects to simulate result preparation system
for 20 students. The data for each student include roll no, name and
marks in 3 subjects. The percentage marks and grade are to be
calculated from the above info. The percentage marks are the average
marks and the grade system is calculated as follows: percentage marks ,
grade : <50 F, 77>50<60 D, >60<75 C, >75<90 B, >90<100 A
#include<iostream.h>
const int obj=2;
const int size=3;
class student
{
int rollno;
char name[21];
float marks[size];
float perc;
char grade;
public:
void getval(void)
{
char ch;
cout<<"enter data";
cout<<"\n"<<"roll no:";
cin>>rollno;
cin.get(ch);
cout<<"\n"<<"Name:";
cin.getline(name,21);
for(inti=0,i<size,i++)
{
cout<<"\n"<<"enter marks for subject"<<(i+1)<<":";
cin>>marks[i];
}
cout<<"\n";
}
void calculate(void);
void prnresult (void);
};
void student::calculate(void)
{
float total;
total= marks[0]+marks[1]+marks[2];
perc=total/3;
if(perc<50)

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

grade='F';
else if(perc<60)
grade='D';
else if(perc<75)
grade='C';
else if(perc<90)
grade='B';
else
grade='A';
}
void student:: prnresult(void)
{
cout<<"\n"
cout<<"rollno: "<<rollno<<"\n";
cout<<"name: ";
cout.write(name,21);
cout<<"\n";
cout<<"marks in subject 1: "<<marks[0]<<"\n";
cout<<"marks in subject 2: "<<marks[1]<<"\n";
cout<<"marks in subject 3: "<<marks[2]<<"\n";
cout<<"total marks: "<<(marks[0]+marks[1]+marks[2])<<"\n";
cout<<"percentage marks:"<<perc<<"\n";
cout<<"grade:"<<grade<<"\n";
cout<<"\n";
}
student std10[obj];
int main()
{
int i=0;
for(i=0;i<obj,i++)
{
cout<<"student"<<(i+1)<<"\n";
std10[i].getval();
}
for(i=0,i<obj.i++)
{
std10[i].calculate();
cout<<"result of students "<<(i+1)<<"\n";
std10[i].prnresult();
}
return 0;
}

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

output:

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

38.WAP which can collect employee information (such as employee


name, id, gender, date of birth etc.)

#include<iostream.h>
#include<conio.h>
class employee
{
private:
char employeename[30];
int emplyid;
char gender[10];
int dob;
public:
void getdata()
{
cout<<”Enter name:”;
cin>> employeename;
cout<<”Enter employee id”;
cin>>emplyid;
cout<<”Enter gender:”;
cin>>gender;
cout<<”Enter date of birth”;
cin>>dob;
}
void putdata{
cout<<employeename;
cout<<emplyid;
cout<<gender;
cout<<dob;
}
}
void main()
{
employee object;
object.getdata();
object.putdata;
getch(); }

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

39.WAP which can collect employee information (such as employee


details and bank acc details).
#include<iostream.h>

#include<conio.h>

void main()

clrscr( );

struct customer

char name[20];

char add[50];

int age;

struct account

char branch[20];

float accno;

float bal;

}a[10];

}c[20];

int n, m, i ;

cout<<"enter no. of customers : ";

cin>>n;

cout<<"Enter customer details in a sequence like name,address,age"<<endl;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

for(i=1;i<=n;i++)

cin>>c[i].name>>c[i].add>>c[i].age;

cout<<"enter account details "<<endl;

cout<<"Enter branch, accno.and then balance"<<endl;

for(i=1;i<=n;i++)

cin>>c[i].a[i].branch>>c[i].a[i].accno>>c[i].a[i].bal;

cout<<"customer details are "<<endl;

for(i=1;i<=n;i++)

cout<<"Name of the customer"<<c[i].name<<endl;

cout<<"Address of the customer"<<c[i].add<<endl;

cout<<"Age of the customer"<<c[i].age<<endl;

cout<<"\naccount details : "<<endl;

for(i=1;i<=n;i++)

cout<<"\nbranch is : "<<c[i].a[i].branch;

cout<<"\naccount is : "<<c[i].a[i].accno;

cout<<"\nbalance is : "<<c[i].a[i].bal;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

getch();

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

40.WAP to show virtual base class.

#include<iostream.h>
#include<conio.h>
class base
{
public:
int a;
}
class d1:virtual public base
{
public:
int b;
};
class d2:virtual public base
{
public:
int c;
};
class d3: public d1,public d2
{
public:
int total;
};
int main()
{
clscr();
d3 ob;
ob.a=25; //now unambiguous
ob.b=50;
ob.c=75;
cout<<ob.a<<ob.b<<ob.c;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

return o;
getch();
}

41.WAP to show operator overloading.

#include<iostream.h>

#include<conio.h>

class demo

int x,y;

public:

void getdata(int,int);

void display();

void operate();

};

void demo::getdata(int a,int b)

x=a;

y=b;

cout<<"Values of x and y before operator overloading"<<endl;

cout<<"x= "<<x<<endl;

cout<<"y= "<<y<<endl;

void demo::display()

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

cout<<"Value of x and y after operator overloading"<<endl;

cout<<"x= "<<x<<endl;

cout<<"y= "<<y<<endl;

void demo::operate()

x=-x;

y=-y;

void main()

clrscr();

demo d1;

d1.getdata(2,4);

d1;

d1.operate();

d1.display();

getch();

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

42.WAP to show unary operator overloading

#include<iostream.h>
#include<conio.h>
class point
{
private:
int x;
int y;
public:
void getdata(int xp,int yp);
void print(void );
friend void operator- (point&p);
};
void point:: getdata(int xp, int yp)
{
x=xp;
y=yp;
}
void point::print (void)
{ cout<<x<<y;
}
void operator- (point&p)
{
p.x= - p.x;
p.y= - p.y;

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

}
void main()
{
point p;
p.getdata(10,15);
p.print ();
cout<<”Now the point is in third quadrant”<<endl;
-p;
p.print(); getch(); }

42.WAP to illustrate single level inheritance.

#include<iostream.h>
#include<conio.h>
class abc
{
int a;
public:
int b;
int get_a();
void get_ab();
void show_a();
};
class xyz: public abc
{
int c;
public:
void multi();
void display();
};
void abc::get_ab()
{
a=5;
b=7;
}
int abc::get_a()
{
return (a);

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

}
void abc::show_a()
{
cout<<"a="<<a;
}
void xyz::multi()
{
c=b*get_a();
}
void xyz::display()
{
cout<<get_a();
cout<<b;
cout<<c;
}
void main()
{
clrscr();
xyz x1;
x1.get_ab();
x1.multi();
x1.show_a();
x1.display();
getch();
}
Output

Shanky 90690363100
S.U.S.C.E.T.
F.C.P.I.T. LAB FILE

Shanky 90690363100

You might also like