Common Lab Manual Print
Common Lab Manual Print
HTML
programs
Prg - 1
<html>
<head>
<title> Bold Italics </title>
</head>
<body>
<b> this is bold text.</b>
<i> this is italics text.</i>
</body>
</html>
Prg – 2
<html>
<head>
<title> Strong and Emphasized</title>
</head>
<body>
<strong> this is strong text. </strong>
<b> this is bold text. </b>
<em> this is emphasized text. </em>
<i> this is italics text. </i>
</body>
</html>
Prg – 3
<html>
<head>
<title> Superscript and Subscript</title>
</head>
<body>
<p> Na<sub>2</sub>S<sub>2</sub>O<sub>3</sub></p>
<p> 1 amu = 1.66 x 10<sup>-24</sup> g</p>
</body>
</html>
Prg – 4
<html>
<head>
<title> Delete text and Insert text</title>
</head>
<body>
<p> <del> this text is deleted </del> </p>
<p> <ins> this text is inserted </ins> </p>
</body>
</html>
Prg – 5
<html>
<head>
<title> Mark Tag</title>
</head>
<body>
Do not forget to buy <mark>Fruits</mark> today.
</body>
</html>
Prg – 6
<html>
<head>
<title> To change the background color of Mark Tag</title>
</head>
<body>
Do not forget to buy <mark style="color:white; background-
color:blue"> Fruits </mark> today.
</body>
</html>
Prg – 7
<html>
<head>
<title> Normal, Big and Small Tags</title>
</head>
<body>
<p> this text is normal text </p>
<p> <Big> this text is big text </big> </p>
<p> <small> this text is small text </small> </p>
</body>
</html>
Prg – 8
<html>
<head>
<title> Nesting of Big and Small Tags</title>
</head>
<body>
<p> this text is normal text </p>
<p> <Big> <Big> <Big>this text is big text </big> </big> </big>
</p>
<p> <small> <small> <small> this text is small text </small>
</small> </small> </p>
</body>
</html>
Prg – 9
<html>
<head>
<title> Headings </title>
</head>
<body>
<h1>This is a heading one </h1>
<h2>This is a heading two </h2>
<h3>This is a heading three </h3>
<h4>This is a heading four </h4>
<h5>This is a heading five </h5>
<h6>This is a heading six </h6>
</body>
</html>
Prg – 10
<html>
<head>
<title> Headings with style options </title>
</head>
<body>
<h1 style="color:blue;">This is a heading with color blue</h1>
<h2 style="font-family:verdana;">This is a heading with different
font </h2>
<h3 style="font-size:300%;">This is a heading with font size
300%</h3>
<h4 style="text-align:center;">Centered aligned Heading</h4></body>
</html>
Prg – 11
<html>
<head>
<title> Font Size, color and face</title>
</head>
<body bgcolor="black" text ="red">
<p> <Font size="6" face="courier new" color="white"> this font size
is 6 </font> </p>
<p> this text is normal text in red color</p>
</body>
</html>
Prg – 12
<html>
<head>
<title> Paragraph </title> </head>
<body>
<p> this is paragraph 1 </p>
<p > this is paragraph 2 </p>
</body>
</html>
Prg – 12
<html>
<head>
<title> Paragraph with style attributes </title>
</head>
<body>
<p> this is paragraph 1 default left aligned</p>
<p align="left" style="color:red;"> this is paragraph 2 </p>
<p align="center" style="font-family:courier;">
this is paragraph 3 </p>
<p align="right" style="font-size:160%;"> this is paragraph 4</p>
<b style="color:red;"> Note: </b>
Style option can contain more than one effects.
<p align="left" style="color:green; font-family:courier; font-
size:300%"> Style option can contain more than one effects. </p>
</body>
</html>
Prg – 13
<html>
<head>
<title> Center </title>
</head>
<body>
<center> this text is center aligned </center> <br>
this text is normal text
</body>
</html>
Prg – 14
<html>
<head>
<title> Center with style effects </title>
</head>
<body>
<center style="color:green; font-family:courier; font-size:300%;">
this text is center aligned </center> <br>
this text is normal text
</body>
</html>
Prg – 15
<html>
<head>
<title>DIV</title> </head>
<body>
<div >div text 1</div>
<div >div text 2</div>
<div >div text 3</div>
</body> <html>
Prg – 16
<html>
<head>
<title>DIV with align</title>
</head>
<body>
<div align="left">div text 1</div>
<div align="center">div text 2</div>
<div align="right">div text 3</div>
</body>
<html>
Prg – 17
<html>
<head>
<title>DIV with style effects </title>
</head>
<body>
<div style="color:red"; align="center">center text</div>
<div style="color:purple"; align="right">right text</div>
<div style="color:blue"; align="left">left text</div>
</body>
<html>
Prg – 18
<html>
<head>
<title>UL default </title>
</head>
<body>
<h2>Unordered List with Default Bullets</h2>
<ul >
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Note: By default the UL tag will always display disc option if you do
not mention it.
</body>
</html>
Prg - 19
<html>
<head> <title> UL Disc </title> </head>
<body><h2>Unordered List with Default Bullets</h2>
<ul type=“disc” >
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li> </ul>
</body> </html>
Prg – 20
<html>
<head>
<title>UL Circle </title>
</head>
<body>
<h2>Unordered List with Circle Bullets</h2>
<ul type=“circle”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Prg – 21
<html>
<head>
<title>UL Square </title>
</head>
<body>
<h2>Unordered List with Square Bullets</h2>
<ul type=“square”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Prg – 22
<html>
<head>
<title>UL None </title>
</head>
<body>
<h2>Unordered List with None</h2>
<ul type=“None”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Prg – 22
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with Default Numbers</h2>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 23
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with default start numbers</h2>
<ol start="5">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 24
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with Capital Alphabets</h2>
<ol type=“A”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 25
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with Capital Alphabets with default start</h2>
<ol type=“A” start=“3”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 26
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with small Alphabets</h2>
<ol type=“a”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg - 27
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with Small Alphabets with default start</h2>
<ol type=“a” start=“3”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 28
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with Capital Roman Numbers</h2>
<ol type=“I”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 29
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with Capital Roman Numbers with default start</h2>
<ol type=“I” start=“3”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 30
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Ordered List with small Roman numbers</h2>
<ol type=“i”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 31
<html>
<head>
<title> OL Lists </title>
</head>
<body>
<h2>Ordered List with Small Roman numbers with default start</h2>
<ol type=“i” start=“3”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Prg – 32
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Reversed Ordered List </h2>
<ol reversed>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<b style="Color:red;">Note: </b> Does not work in<b>Internet
Explorer</b>
</body>
</html>
Prg – 33
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Reversed Ordered List with default start numbers</h2>
<ol reversed start="5">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<b style="Color:red;"> Note: </b>
Does not work in <b> Internet Explorer</b>
</body> </html>
Prg – 34
<html>
<head>
<title> OL Lists </title>
</head>
<body>
<h2> Reversed Ordered List with default roman numbers </h2>
<ol reversed type = "i">
<li> Coffee </li>
<li> Tea </li>
<li> Milk </li>
</ol>
<b style="Color:red;">Note: </b>
Does not work in<b>Internet Explorer</b>
</body>
</html>
Prg – 35
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Reversed Ordered List with default roman start numbers</h2>
<ol reversed type="i" start="5">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<b style="Color:red;">Note: </b>
Does not work in<b>Internet Explorer</b>
</body>
</html>
Prg – 36
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Reversed Ordered List with Capital Alphabets</h2>
<ol reversed type="A" >
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<b style="Color:red;">Note: </b>
Does not work in<b>Internet Explorer</b>
</body> </html>
BIPU Lab Manual: Cpp programs – 12
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 37
<html>
<head>
<title>OL Lists </title>
</head>
<body>
<h2>Reversed Ordered List with Capital Alphabets</h2>
<ol reversed type="A" start=”7”>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<b style="Color:red;">Note: </b>
Does not work in<b>Internet Explorer</b>
</body>
</html>
Prg – 38
<html>
<head> <title> LI Types </title> </head>
<body>
<ul>
<li> Bullet types I like </li>
<ul>
<li type="disc">Discs</li>
<li type="circle">Circles</li>
<li type="square">Squares</li>
<li type="none">None</li>
</ul>
<li> Bullet types I don't like </li>
<ol>
<li type="I">Roman Numerals</li>
<li type="i">Lowercase Roman Numerals</li>
</ol>
</ul>
<b style="Color:red;">Note: </b>
Does not work in<b>Internet Explorer</b>
</body>
</html>
Prg – 39
<html>
<head> <title>Li Values </title> </head>
<body>
<ol>
<li> One </li> <li> Two </li> <li> Skip a few </li>
<li value="99"> Ninety Nine </li> <li> and Hundred </li>
</ol>
</body> </html>
BIPU Lab Manual: Cpp programs – 13
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg - 40
<html>
<head>
<title> Description Lists </title>
</head>
<body bgcolor="#ffaabb">
<dl>
<dt>Parents</dt>
<dd>Jamie</dd>
<dd>Charlie</dd>
<dt>Children</dt>
<dd>Landry</dd>
<dd>Oakley</dd>
<dd>Skyler</dd>
<dt>Pets</dt>
<dd>Cat</dd>
<dd>Dog</dd>
<dd>Gerbil</dd>
</dl>
</body>
</html>
Prg - 41
<html>
<head>
<title> Description Lists with CSS effects</title>
</head>
<body bgcolor="#ffaabb">
<dl>
<dt style="font-weight:bold;">Parents</dt>
<dd>Jamie</dd>
<dd>Charlie</dd>
<dt style="font-style:italic;">Children</dt>
<dd>Landry</dd>
<dd>Oakley</dd>
<dd>Skyler</dd>
<dt style="font-style:oblique;">Pets</dt>
<dd>Cat</dd>
<dd>Dog</dd>
<dd>Gerbil</dd>
</dl>
<b style="Color:red;">Note: </b> oblique - The text is "leaning" it is
very similar to italic, but less supported.
</body>
</html>
Prg – 42
<html>
<head>
<title> Description Lists with CSS effects with letter spacing</title>
</head>
<body bgcolor="#ffaabb">
<dl>
<dt style="font-weight:bolder; letter-spacing: 7px">Parents</dt>
<dd>Jamie</dd>
<dd>Charlie</dd>
<dt style="font-style:italic; letter-spacing: 5px">Children</dt>
<dd>Landry</dd>
<dd>Oakley</dd>
<dd>Skyler</dd>
<dt style="font-style:oblique; letter-spacing: 3px">Pets</dt>
<dd>Cat</dd>
<dd>Dog</dd>
<dd>Gerbil</dd>
</dl>
<b style="Color:red;">Note: </b> oblique - The text is "leaning" it is
very similar to italic, but less supported.
</body>
</html>
Prg - 43
<html>
<head>
<title> Description Lists with CSS effects</title>
</head>
<body bgcolor="#ffaabb">
<dl>
<dt style="font-variant:small-caps;">Parents</dt>
<dd>Jamie</dd>
<dd>Charlie</dd>
<dt style="font-variant:small-caps;">Children</dt>
<dd>Landry</dd>
<dd>Oakley</dd>
<dd>Skyler</dd>
<dt style="font-variant:small-caps;">Pets</dt>
<dd>Cat</dd>
<dd>Dog</dd>
<dd>Gerbil</dd>
</dl>
</body>
</html>
Prg - 44
<html>
<head>
<title> Nested Lists</title>
</head>
<body>
<ul>
<li style="background-color:brown; font-variant:small-caps;
width:3.5%; color:white;"> Coffee </li>
<ol>
<li>Espresso (Short Black)</li>
<li>Double Espresso (Doppio)</li>
<li>Short Macchiato</li>
<li>Long Black (Americano)</li>
<li>Cappuccino</li>
</ol>
<li style="background-color:brown; font-variant:small-caps;
width:2%; color:white;"> Tea </li>
<ol>
<li>White Tea</li>
<li>Black Tea</li>
<li>Green Tea</li>
<li>Herbal Tea</li>
<li>Plain Tea</li>
</ol>
<li style="background-color:brown; font-variant:small-caps;
width:10%; color:white;"> Fruit-Flavored Tea </li>
<ol>
<li>Orange Tea</li>
<li>Lemon Tea</li>
<li>Raspberry Tea</li>
<li>Pineapple Tea</li>
<li>Mango Tea</li>
</ol>
</ul>
</body>
</html>
Prg – 45
<html>
<head> <title> Lists with images using CSS effects </title> </head>
<body>
<ul style="list-style-image:url(miniowl.jpg);">
<li>Espresso (Short Black)</li>
<li>Double Espresso (Doppio)</li>
<li>Short Macchiato</li>
</ul>
</body> </html>
Prg – 47
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg);">
</body>
</html>
Prg – 48
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:repeat-x;">
</body>
</html>
Prg – 49
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:repeat-y;">
</body>
</html>
Prg – 50
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:no-repeat;">
</body>
</html>
Prg – 51
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:no-repeat; background-position:right top;">
</body>
</html>
Prg – 52
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-repeat:no-
repeat; background-position:right bottom;">
</body>
</html>
Prg – 53
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:no-repeat; background-position:left top;">
</body>
</html>
Prg – 54
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:no-repeat; background-position:left bottom;">
</body>
</html>
Prg – 55
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:no-repeat; background-position:center;"> </body>
</html>
Prg – 56
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg);">
<h1>Hello Reader!</h1>
<p>The background image is displayed, but it is disturbing the
reader! </p>
</body>
</html>
Prg – 57
<html>
<head> <title> background image with CSS effects </title> </head>
<body style="background-image:url(treeowl.jpg); background-
repeat:repeat-x;">
<h1>Hello Reader!</h1>
<p>Here, a backgound image is repeated only horizontally!</p>
</body>
</html>
Prg – 58
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-
repeat:repeat-y;">
<h1>Hello Reader!</h1>
<p>Here, a backgound image is repeated only vertically!</p>
</body>
</html>
Prg – 59
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-repeat:no-
repeat;">
<h1>Hello Reader!</h1>
<p>The background image is only showing once, but it is disturbing
the reader!</p>
</body>
</html>
Prg – 60
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-repeat:no-
repeat; background-position:right top; ">
<h1> Hello Reader! </h1>
Now the background image is only shown once, and positioned away from
the text. In this example the text is overlapping on the image on the
right side, so the background image is disturbing the text.
</body>
</html>
Prg – 61
<html>
<head>
<title> background image with CSS effects </title>
</head>
<body style="background-image:url(treeowl.jpg); background-repeat:no-
repeat; background-position:right top; margin-right:200px;">
<h1>Hello Reader!</h1>
Now the background image is only shown once, and positioned away from
the text. In this example we have also added a margin on the right side,
so the background image will never disturb the text.
</body>
</html>
Prg – 62
<html>
<head>
<title> Links </title>
</head>
<body>
<a href="prg24.html">prg24</a>
</body>
</html>
Prg – 63
<html>
<head>
<style>
a:link { color: green; background-color: cyan; text-decoration: none; }
a:visited { color: blue; background-color: transparent; text-decoration:
none; }
a:hover { color: red; background-color: transparent; text-decoration:
underline; }
a:active { color: green; background-color: transparent; text-decoration:
underline; }
</style>
</head>
<title> Links - With Colors</title>
<body>
<font size="5">
<a href="prg24.html">move your mouse pointer over me</a>
</font>
</body>
</html>
Prg – 64
<html>
<head>
<style>
a:link { color: green; background-color: cyan; text-decoration: none; }
a:visited { color: blue; background-color: transparent; text-decoration:
none; }
BIPU Lab Manual: Cpp programs – 20
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 70
<html>
<head> <title> table borders</title> </head>
<body> Table with outer border / frame (void)
<table border=“1” frame=“void”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 71
<html>
<head> <title> table border </title> </head>
<body> Table with outer border / frame (above)
<table border=“1” frame=“above”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 72
<html>
<head> <title> table border </title> </head>
<body> Table with outer border / frame (below)
<table border=“1” frame=“below”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 73
<html>
<head> <title> table border </title> </head>
<body> Table with outer border / frame (left)
<table border=“1” frame=“lhs”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 74
<html>
<head> <title> table borders</title> </head>
<body> Table with outer border / frame (right)
<table border=“1” frame=“rhs”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 75
<html>
<head> <title>Table border </title> </head>
<body> Table with outer border / frame (above and below)
<table border=“1” frame=“hsides”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 76
<html>
<head> <title>Table border </title> </head>
<body> Table with outer border / frame (right and left)
<table border=“1” frame=“vsides”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 77
<html>
<head> <title>Table border </title> </head>
<body> Table with outer border / frame (box)
<table border=“1” frame=“box”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 78
<html>
<head> <title>Table border </title> </head>
<body> Table with border color
<table border=“2” bordercolor=“#ffff00”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 79
<html>
<head> <title>Table border </title> </head>
<body> Table with background color
<table border=“2” bgcolor=“#ffff00”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 80
<html>
<head> <title>Tables</title> </head>
<body> Table with background image
<table border=“2” background=“url”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 81
<html>
<head> <title> Table alignment </title> </head>
<body> Table align (left, right, center)
<table border=“2” align=“right”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 82
<html>
<head> <title> Table alignment </title> </head>
<body> Table align (left, right, center)
<table border=“2” align=“left”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 83
<html>
<head> <title> Table alignment </title> </head>
<body> Table align (left, right, center)
<table border=“2” align=“center”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 85
<html>
<head> <title>Table cell padding </title> </head>
<body> Table cell padding
<table border=“2” align=“right” cellpadding=“25”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 86
<html>
<head> <title> Table cell spacing </title> </head>
<body> Table cell spacing
<table border=“2” align=“right” cellspacing=“20”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 87
<html>
<head> <title> Table cell spacing and cell padding </title> </head>
<body> Table cell spacing and cell padding
<table border=“2” align=“right” cellspacing=“40” cellpadding=“5”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 88
<html>
<head> <title> Table Width and Height </title> </head>
<body> Table Width and Height
<table border=“2” align=“right” width=“40%” height=“75%”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table>
</body>
</html>
Prg – 89
<html>
<head> <title>Table row and cell properties </title> </head>
<body> Row and Cell properties
<table border=“2” align=“center” width=“40%” height=“75%”>
<tr>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
</table> </body> </html>
Prg – 90
<html>
<head> <title> Align content </title> </head>
<body> Align content row wise (center / right). Note: The alignment is
always left by default.
<table border=“2” align=“center” width=“40%” height=“75%”>
<tr align=“right”>
<td> row one, column one </td>
<td> row one, column two</td>
</tr>
<tr align=“center”>
<td> row two, column one </td>
<td> row two, column two </td>
</tr>
</table> </body> </html>
Prg – 91
<html>
<head> <title> Vertical Align</title> </head>
<body> Vertical Align content row wise. Note: Vertical alignment can be done
either top, bottom or center.
<table border=“2” align=“center” width=“40%” height=“75%”>
<tr align=“right” valign=“top”>
<td>This is row one</td>
</tr>
<tr align=“center” valign=“center”>
<td>This is row two </td>
</tr>
<tr align=“left” valign=“bottom”>
<td>This is row three </td>
</tr>
</table> </body> </html>
Prg – 92
<html>
<head> <title> color change </title> </head>
<body> Row wise background color change
<table border=“2” align=“center” width=“40%” height=“75%”>
<tr align=“right” valign=“top” bgcolor=“cyan”>
<td>This is row one </td>
</tr>
<tr align=“center” valign=“center” bgcolor=“teal”>
<td> This is row two. </td>
</tr>
BIPU Lab Manual: Cpp programs – 29
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 96
<html>
<head> <title>Tables</title> </head>
<body> Column wise background color change
<table border=“2” align=“center” width=“40%” height=“75%”>
<tr height="150">
<td align="right" valign="top" bgcolor="lime">This is row one </td>
<td align="left" valign="bottom" bgcolor="gray">This is row one</td>
<td align="center" valign="middle" bgcolor="pink">This is row one
</td>
</tr>
</table> </body> </html>
Prg – 97
<html>
<head> <title>Tables</title> </head>
<body> Column wise border color change
<table border=“2” align=“center” width=“40%” height=“75%”>
<tr height="150">
<td align="right" valign="top" bordercolor="red">This is row one, left
side.</td>
<td align="left" valign="bottom" bordercolor="gray">This is row one,
left side.</td>
<td align="center" valign="middle" bordercolor="pink">This is row one,
left side.</td>
</tr>
</table> </body> </html>
Prg – 98
<html>
<head> <title>Tables</title> </head>
<body> column wise background image
<table border=“2” align=“center” width=“40%” height=“75%”>
<tr height="150">
<td align="right" valign="top" background=“url”>This is row one, left
side.</td>
<td align="left" valign="bottom" background=“url”>This is row one,
left side.</td>
<td align="center" valign="middle" background=“url”>This is row one,
left side.</td>
</tr>
</table> </body> </html>
Prg – 99
<html>
<head> <title>Tables</title> </head>
<body> Column wise width
<table border=“2” align=“center” width=“40%”>
<tr>
<td align="right" valign="top" bordercolor="red" width="50">This is
row one, left side. </td>
<td align="left" valign="bottom" bordercolor="gray" width="100">This
is row one, left side. </td>
<td align="center" valign="middle" bordercolor="pink" width="250">This
is row one, left side. </td>
BIPU Lab Manual: Cpp programs – 31
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
</tr>
</table> </body> </html>
Prg – 100
<html>
<head> <title> Table with Column Span (Merging) </title> </head>
<body> Column Span: Merging
<table border="1" width="50%">
<tr>
<th colspan = "3"> Computer Marks </th>
</tr>
<tr>
<td>Ravi</td> <td>Kumar</td> <td>99</td>
</tr>
<tr>
<td>Mohan</td> <td>Reddy</td> <td>100</td>
</tr>
<tr>
<td>Swaroop</td> <td>M</td> <td>100</td>
</tr>
</table> </body> </html>
Prg – 101
<html>
<head> <title> Table with Width, Align, Cell Spacing, and Cell Padding
</title> </head>
<body> Row Span: Merging
<table border="1" width="50%" align="right" cellspacing="5"
cellpadding="10">
<tr>
<th rowspan="5"> Neo BS - II </th>
</tr>
<tr>
<th colspan = "3"> Computer Marks </th>
</tr>
<tr>
<td>Ravi</td> <td>Kumar</td> <td>99</td>
</tr>
<tr>
<td>Mohan</td> <td>Reddy</td> <td>100</td>
</tr>
<tr>
<td>Swaroop</td> <td>M</td> <td>100</td>
</tr>
</table> </body> </html>
Prg – 102
<html>
<head>
<style>
div
{
width:130px;
height:50px;
-ms-transform:rotate(45deg); /* IE 9 */
-moz-transform:rotate(270deg); /* Firefox */
-webkit-transform:rotate(270deg);/*Safari & Chrome */
-o-transform:rotate(270deg); /* Opera */
}
</style>
<title> Vertical Text </title></head>
<body> Vertical Text in Tables
<div> vertical text </div>
</body> </html>
Prg – 103
<html>
<head> <title> Preformatted Text </title> </head>
<body> Preformatted Text. It preserves both spaces and line breaks.
The pre tag is good for displaying computer code:
<pre>
This is
preformatted text.
It preserves both spaces
and line breaks.
</pre>
<p>The pre tag is good for displaying computer code:</p>
<pre>
for i = 1 to 10
print i
next i
</pre>
</body> </html>
Prg – 104
<html>
<head> <title> Bidirectional Override </title> </head>
<body> Bi-directional Override. If your browser supports bi-directional
override (bdo), then the line will be written from the right to the left
(rtl):
<p> This is normal text BELLARY </p>
<p> Here comes Bidirectional Override text for BALLARI</p>
<bdo dir=“rtl”>
BALLARI
</bdo> </body> </html>
Prg – 105
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> Marquee: An HTML marquee is a scrolling piece of text displayed
either horizontally across or vertically down your webpage depending on the
settings.
Note: The HTML <marquee> tag may not be supported by various browsers so its
not recommended to rely on this tag, instead you can use Java script and CSS
to create such effects.
<marquee>This is basic example of marquee</marquee>
</body> </html>
Prg – 106
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (left to right)
<marquee direction="right"> This text will scroll from left to right
</marquee> </body> </html>
Prg – 107
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (up)
<marquee direction="up"> This text will scroll from bottom to up </marquee>
</body> </html>
Prg – 108
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (down)
<marquee direction="down"> This text will scroll from up to bottom
</marquee> </body> </html>
Prg – 109
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (width)
<marquee width="50%"> This example will take only 50% width </marquee>
</body> </html>
Prg – 110
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (height)
<marquee height="500" direction=“up”> This example will take 500 pixels in
height. </marquee>
</body> </html>
Prg – 111
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (behavior - scroll)
<marquee behavior="scroll"> This text will scroll </marquee>
</body> </html>
Prg – 112
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (behavior - slide)
<marquee behavior="slide"> This text will slide </marquee>
</body> </html>
Prg – 113
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (behavior - alternate)
<marquee behavior="alternate"> This text will alternate </marquee>
</body> </html>
Prg – 114
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee(scroll amount)
<marquee behavior="scroll" scrollamount="10"> This text will scroll
</marquee>
<marquee behavior="scroll" scrollamount="20"> This text will scroll
</marquee>
<marquee behavior="scroll" scrollamount="30"> This text will scroll
</marquee>
<marquee behavior="scroll" scrollamount="40"> This text will scroll
</marquee> </body> </html>
Prg – 115
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee(scroll delay)
<marquee behavior="scroll" scrolldelay="250"> This text will scroll dealy
250 = ¼ second
</marquee>
<marquee behavior="scroll" scrolldelay="500"> This text will scroll
</marquee>
<marquee behavior="scroll" scrolldelay="750"> This text will scroll
</marquee>
<marquee behavior="scroll" scrolldelay="1000"> This text will scroll
</marquee> </body> </html>
Prg – 116
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (loop)
<marquee behavior="scroll" loop="1"> This text will loop 1 time </marquee>
<marquee behavior="scroll" loop="2"> This text will loop 2 times </marquee>
<marquee behavior="scroll" loop="3"> This text will loop 3 times </marquee>
<marquee behavior="scroll" loop="4"> This text will loop 4 times </marquee>
</body> </html>
Prg – 117
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (bgcolor)
<marquee behavior="alternate" bgcolor="cyan">
marquee with bgcolor
</marquee> </body> </html>
BIPU Lab Manual: Cpp programs – 35
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 118
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (hspace)
<marquee behavior="alternate" bgcolor="cyan" hspace="250%"> marquee with
bgcolor
</marquee> </body> </html>
Prg – 119
<!DOCTYPE html>
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> The simple marquee (vspace)
<marquee behavior="alternate" bgcolor="cyan" hspace="250%" vspace="150%">
marquee with bgcolor
</marquee> </body> </html>
Prg – 120
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> Miscellaneous HTML Marquee Tags <center>
<marquee scrollamount="5" width="250" bgcolor="cyan"> <<<
</marquee>
Opposite Direction Marquees
<marquee scrollamount="5" direction="right" width="250" bgcolor="lime">
>>>
</marquee></center> </body> </html>
Prg – 121
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> Miscellaneous HTML Marquee Tags
<marquee behavior="alternate"> <marquee width="200" bgcolor="cyan">
Reoccuring Marquee
</marquee> </marquee> </body> </html>
Prg – 122
<html>
<head> <title>HTML marquee Tag</title> </head>
<body> Miscellaneous HTML Marquee Tags
<marquee direction="down" behavior="alternate" height="200" bgcolor="cyan">
<marquee behavior="alternate" width="1000" >
<font size="7" color="red">?</font>
</marquee> </marquee> </body> </html>
Prg – 123
<html>
<head> <title> HTML Frames </title> </head>
<frameset cols="120,*">
<frame src=“url”>
<frameset rows="*,50">
<frame src=“url”>
<frame src=“url”>
</frameset>
</frameset>
</html>
BIPU Lab Manual: Cpp programs – 36
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 124
<html>
<head> <title> HTML Frames </title> </head>
<frameset cols="120,*">
<frame src="url" >
<frame src="url">
</frameset> </html>
Prg – 125
<html>
<head> <title> HTML Frames DEFAULT PAGES </title> </head>
<frameset cols="120,*" >
<frame src="menu.html" name="menu" >
<frame src="frontf.html" name="main" >
</frameset> </html>
Prg – 126
<html>
<head> <title> HTML Frames Borders</title> </head>
<frameset cols="120,*" frameborder="0" border="0“ framespacing="0">
<frame src="menu.htm" name="menu" >
<frame src="frontf.htm" name="main" >
</frameset> </html>
Prg – 127
<html>
<head> <title>My Frames Page</title> </head>
<frameset rows="16%,84%">
<frame src="top.htm" name="top">
<frame src="bottom.htm" name="bottom">
</frameset> </html>
Prg – 128
<html>
<head> <title>My Frames Page</title> </head>
<frameset rows="16%,84%">
<frameset cols="50%,50%">
<frame src="tl.htm" name="tl">
<frame src="tr.htm" name="tr">
</frameset>
<frame src="bottom.htm" name="bottom">
</frameset> </html>
Prg – 129
<html>
<head> <title>My Frames Page</title> </head>
<frameset rows="16%,84%">
<frame src="top.htm" name="top">
<frameset cols="50%,50%">
<frame src="left.htm" name="left">
<frame src="right.htm" name="right">
</frameset>
</frameset> </html>
Prg – 130
<html>
<head> <title>My Frames Page</title> </head>
<frameset rows="50%,50%" cols="50%,50%">
<frame src="topleft.htm" name="topleft">
<frame src="topright.htm" name="topright">
<frame src="botleft.htm" name="botleft">
<frame src="botright.htm" name="botright">
</frameset>
</html>
Prg – 131
<html>
<head><title>My Frames Page</title></head>
<frameset rows="50%,50%" cols="50%,50%">
<frame src="topleft.htm" name="topleft">
<frame src="topright.htm" name="topright">
<frame src="botleft.htm" name="botleft">
<frameset rows="50%,50%">
<frameset cols="50%,50%">
<frame src="brtl.htm" name="brtl">
<frame src="brtr.htm" name="brtr">
</frameset>
<frame src="botrbot.htm" name="botrbot">
</frameset>
</frameset>
</html>
Prg – 132
<html>
<head> <title> Forms - Text Fields </title> </head>
<body> defines a password field:
Note: The characters in a password field are masked (shown as asterisks or
circles).
<form>
First name: <input type="text" name="firstname" Value="First Name"
Size="25"><br>
Last name: <input type="text" name="lastname" Value="Last Name" Size="25">
</form> </body> </html>
Prg – 133
<html>
<head> <title> Forms - Password Field </title> </head>
<body> defines a radio button. Radio buttons let a user select ONLY ONE of a
limited number of choices:
<form> Password: <input type="password" name="password"> </form>
</body> </html>
Prg – 134
<html>
<head> <title> Forms - Radio Buttons </title> </head>
<body>
<form>
<input type="radio" name="gender" value="male" checked>Male<br>
<input type="radio" name="gender" value="female">Female
</form> </body> </html>
BIPU Lab Manual: Cpp programs – 38
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 135
<html>
<head> <title> Forms - Check Box </title> </head>
<body> defines a checkbox. Checkboxes let a user select ZERO or MORE options
of a limited number of choices.
<form>
<input type="checkbox" name="vehicle" value="Bike" checked>I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car
</form> </body> </html>
Prg – 136
<html>
<head> <title> Forms - File Upload </title> </head>
<body> is used to upload file to the web server.
<form>
Select a File: <input type="file" name="fileupload">
</form> </body> </html>
Prg – 137
<html>
<head> <title> Forms – Push Button </title>
<script>
function msg( )
{
alert("Hello world!");
}
</script>
</head>
<body> A clickable button, that activates a JavaScript when it is clicked:
<form>
<input type="button" value="Click me" onclick="msg()">
</form> </body> </html>
Prg – 138
<html>
<head> <title> Forms - Submit </title> </head>
<body> It causes the browser to send the names and values to the CGI
application.
<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
<p>Click on the submit button to submit the form.</p>
</body> </html>
Prg – 139
<html>
<head> <title> Forms - Image </title> </head>
<body> Allows you to substitute an image for the standard submit button.
<form action="demo_form.asp">
First name: <input type="text" name="fname"> <br>
Last name: <input type="text" name="lname"> <br>
<input type="image" src="img_submit.gif" alt="Submit" width="48"
height="48">
</form> </body> </html>
BIPU Lab Manual: Cpp programs – 39
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 140
<html>
<head> <title> Forms - Reset </title> </head>
<body> It allows the surfer to clear all the input in the form to default
values
<form action="demo_form.asp">
Email: <input type="text" name="email"> <br>
Password: <input type="text" name="pin" maxlength="4"> <br>
<input type="reset" value="Reset">
<input type="submit" value="Submit">
</form>
<p>Click on the reset button to reset the form.</p>
</body> </html>
Prg – 141
<html>
<head> <title> Forms - Text Area </title> </head>
<body> It allows the user to enter free from text entry.
<form action="demo_form.asp">
<textarea name="Remarks" rows="5" cols="50" wrap="virtual">
Your Comment goes here:
</textarea> </form> </body> </html>
Prg – 142
<html>
<head> <title> select - Drop Down List </title> </head>
<body> Create a drop-down list with four options:
<form >
<select name=“dropdown”>
<option value="PCMB">PCMB</option>
<option value="PCMC">PCMC</option>
<option value="HEBA">HEBA</option>
<option value="CEBA">CEBA</option>
</select>
</form> </body> </html>
Prg – 143
<html>
<head> <title> select - List Box </title> </head>
<body> It shows a declared number of text rows and gives the visitor a list
of choices. Similar to the drop list, the list box length is determined by
the length of the longest OPTION
<form >
<select name="listbox" size="3">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</form> </body> </html>
Prg – 144
<html>
<head> <title> select - List Box Pre-selected</title> </head>
<body> List Box Pre-selected
<form >
<select name="listbox" size="3">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel" selected="selected">Opel</option>
<option value="audi">Audi</option>
</select>
</form> </body> </html>
Prg – 144(1)
<html>
<head> <title> select - List Box Pre-selected</title> </head>
<body> List Box Pre-selected
<form >
<select name="listbox" size="3">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi" selected="selected">Audi</option>
</select>
</form> </body> </html>
Prg – 145
<html>
<head> <title> select - Option Group</title> </head>
<body> The opt group is used to group related options in a drop-down list.
If you have a long list of options, groups of related options are easier to
handle for a user.
<form >
<select>
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
</form> </body> </html>
Prg – 146
<html>
<head> <title> select - Option Group Disabled</title> </head>
<body>
<form>
<select>
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
BIPU Lab Manual: Cpp programs – 41
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
Prg – 149
<html>
<head> <title> Span Tags </title> </head>
<body> A span element used to color a part of a text.
The span tag is used to group inline-elements in a document.
<p>My mother has <span style="color:blue; font-weight:bold">blue</span> eyes
and my father has <span style="color:darkolivegreen; font-weight:bold"> dark
green </span> eyes.</p>
</body> </html>
I PUC
Text
book
programs
if(number % 2 == 0)
cout << number << " is even";
else
cout << number << " is odd";
}
/* C++ program to input choice (1 or 2).If choice is 1, print the area of a circle
otherwise print the circumference of circle. Accept the radius of the circle from
user */
# include <iostream.h>
void main( )
{
float radius, Area, Circum;
int choice;
cout << " Circle problem menu\n ";
cout << "1. Area of the circle " << endl;
cout << "2. Circumference of the circle " << endl;
cout << "Enter your choice ";
cin >> choice;
cout << "Enter the radius of the circle ";
cin >> radius;
if(choice == 1)
{
Area = 3.142 * radius * radius;
cout << endl << "Area of the circle = "<< Area;
}
else
{ Circum = 2 * 3.142 * radius;
cout << "Circumference of the circle = " << Circum;
}
}
/*C++ program to find largest of three numbers using nested if */
# include <iostream.h>
void main( )
{
int a, b, c, Big;
cout << "Enter three numbers " << endl;
cin >> a >> b >> c;
if(a > b)
if(a > c)
Big = a;
else
Big = c;
else
if(b > c)
Big = b;
else
Big = c;
cout << "Largest of " << a << "," << b << " and " << c << " = "
<< Big << end;
}
/* C++ program to find the largest, second largest and smallest of three
numbers */
# include <iostream.h>
void main( )
{
int a, b, c, largest, small, seclar;
cout << "Enter three numbers " << endl;
cin >> a >> b >> c;
if(a > b)
{
largest = a; small = b;
}
else
{
largest = b; small = a;
}
if(largest < c)
largest = c;
else if(small > c)
small = c;
cout << "Largest number = " << largest << endl;
cout << "Smallest number = " << small << endl;
seclar = (a + b + c) - (largest + small);
cout << "Second Largest = " << seclar << endl;
}
/* C++ program to check whether a date is valid or invalid */
# include <iostream.h>
void main()
{
int dd, mm, yy, valid = 1;
cout << "Input a date ";
cin >> dd >> mm >> yy;
if((dd <= 0) || (dd > 31) || (mm <= 0) || (mm > 12) || (yy <= 0))
valid = 0;
else if((mm == 4 || mm == 6 || mm == 9 || mm == 11) && (dd > 30))
valid = 0;
else if(mm == 2)
{
if(yy % 4 == 0)
{
if(dd > 29)
valid = 0;
}
else if( dd > 28)
valid = 0;
}
cout << dd << " / " << mm << " / " << yy;
if(valid)
cout << " Date is valid";
else
cout << " Date is invalid";
}
switch(op)
{
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': if(num2 != 0)
result = num1 / num2;
else
{
cout << "Warning: Division by zero";
result = 0;
}
break;
default: cout << "Unknown operator"; result = 0;
}
cout << " " << result;
}
/* C++ program to calculate sum of first 100 natural numbers */
# include <iostream.h>
void main( )
{
int sum = 0, num = 1;
while(num <= 100)
{
sum = sum + num;
num = num + 1;
}
cout << "Sum = " << sum;
}
/* C++ program to display the digits of a number */
# include <iostream.h>
void main( )
{
int num, digit;
cout << "Enter a number " << endl;
cin >> num;
while(num > 0)
{
digit = num % 10;
num = num / 10;
cout << "digit = " << digit << endl;
}
}
/* C++ program to reverse a number */
# include <iostream.h>
void main( )
{
long rev = 0, n, num;
int digit;
cout << "Enter a number ";
cin >> num;
n = num;
while(num != 0)
{
digit = num % 10;
num = num / 10;
rev = rev * 10 + digit;
}
cout << "The number is " << n << endl;
cout << "Reverse of a number = " << rev;
}
/* C++ program to calculate the average of numbers entered by the user. The
list terminates when the number entered is zero */
# include <iostream.h>
void main( )
{
int num, sum = 0, count = 0;
float avg;
cout << "Input a number (Enter 0 to exit) ";
cin >> num;
while(num!=0)
{
sum = sum + num; count++;
cout << "Input a number (Enter 0 to exit) ";
cin >> num;
}
avg = (float) sum / count;
cout << "Total numbers = " << count << endl;
cout << "Sum of " << count << " numbers = " << sum << endl;
cout.precision(6);
cout << "Average of " << count << " numbers = "<< avg;
}
/* C++ program to generate the multiplication table of 5 */
# include <iostream.h>
void main( )
{
int result, num, count = 1;
cout << "Enter a number ";
cin >> num;
cout << "The table is " << endl;
do
{
result = num * count;
cout << num << "*" << count << "=" << result << endl;
++count;
}while(count <= 10);
}
// C++ program to calculate the compound interest using DO-WHILE
# include <iostream.h>
void main()
{ float p, amt, r, ci;
int time, year = 1;
cout << "Enter principal amount, rate of interest and time ";
cin >> p >> r >> time;
amt = p;
BIPU Lab Manual: Cpp programs – 54
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
do
{
amt = amt * (1 + r / 100);
++year;
}while(year <= time);
ci = amt - p;
cout << "Compound Interest earned = " << ci;
}
/* A Company gives 10% commission for toothpaste and 15% commission for
soaps. Calculate and output the total commission for each salesmen.*/
# include <iostream.h>
void main( )
{
int slno;
float paste, soap, commission;
char ch;
do
{
cout << "Enter salesman number ";
cin >> slno;
cout << "Enter the total sales of toothpastes and soaps ";
cin >> paste >> soap;
commission = (paste * 0.1 + soap * 0.15);
cout << "Salesman number = " << slno << endl;
cout << "commission = " << commission << endl;
cout <<"continue(y/n)?";
cin >> ch;
}while((ch == 'y') || (ch == 'Y')); }
/* C++ program to generate N natural number using for loop */
# include <iomanip.h>
main( )
{
int n;
cout << endl << "Enter the upper limit ";
cin >> n;
for(int i = 1; i <= n; i++)
cout << i << setw(7);
return 0;
}
/* C++ program to calculate and print the sum of even and odd integers of the
first N natural number */
# include <iostream.h>
void main()
{ int n, even = 0,odd = 0;
cout <<"Enter the upper limit ";
cin >> n;
for(int i = 0; i <= n; i++)
{
if(i % 2 == 0)
even = even + i;
else
odd = odd + i;
}
BIPU Lab Manual: Cpp programs – 55
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
# include <iostream.h>
void main()
{
int i, j;
for(i = 1; i <= 5; i++)
{
if(i == 1 || i == 5)
for(j = 1; j <= 20; j++)
cout << "*";
else
{
cout << "*";
for(j = 1; j <= 18; j++)
cout << " ";
cout << "*";
}
cout << endl;
}
}
/* C++ program to generate N natural number using goto */
# include <iomanip.h>
void main()
{
int n, i = 1;
cout << "Enter number ";
cin >> n;
loop:
cout << setw (4) << i++;
if(i <= n)
goto loop;
}
//program to find the given number is prime or not using break function
# include <iostream.h>
void main()
{
int n, i, prime;
cout << "Input a number ";
cin >> n;
prime = 1;
for(i = 2; i <= n / 2; i++)
{
if(n % i == 0)
{
prime = 0;
break;
}
}
if(prime == 1)
cout << "it is prime";
else
cout << "It is not prime";
}
/* C++ program to display all numbers from 1 to N which are not divisible by 5
using continue */
# include <iomanip.h>
main( )
{
int n, i = 0;
cout <<" Input a number ";
cin >> n;
while(i < n)
{
i++;
if(i % 5 == 0)
continue;
cout << setw(3) << i;
}
return 0;
}
// C++ program to check whether a number is prime or not using exit function
# include <iostream.h>
# include <stdlib.h> // for exit command
void main( )
{
int n, i;
cout << "Input a number ";
cin >> n;
for(i = 2; i <= n / 2; i++)
{
if(n % i == 0)
{
cout << n << " is not a prime";
exit(0);
}
}
cout << n << " is a prime";
}
//greatest common divisor
# include <iostream.h>
void main( )
{
int x, y;
cout << "Enter x and y values";
cin >> x >> y;
while(x != y)
{
if(x > y)
x = x – y;
else
y = y – x;
}
cout << x;
}
cout << "In put " << n << " student marks: " << endl;
for(i = 0; i < n; i++)
{
cout << "Input marks of student " << (i + 1) << " = ";
cin >> marks[i];
total = total + marks[i];
}
avg = (float) total / n;
cout.precision(4);
cout << "class average marks = " << avg;
}
/* C++ program to read marks of N students in the range of 1-100 then make 11
groups G0(0-9), G1(10-19) G3(20-29) ..... G10(100)*/
# include <iomanip.h>
void main()
{
int marks[100], n, i;
int group[11] = {0};
cout << "Input number of students ";
cin >> n;
cout << "Input " << n << "students marks:" << endl;
for(i = 0; i < n; i++)
{
cout << "Input marks for student " << (i + 1) << " = ";
cin >> marks[i];
group [ marks [i] / 10] ++;
}
cout << "*********************" << endl;
cout << setw(13) << "group" << setw(13) << "Frequency \n";
for(i = 0;i <= 10; i++)
cout << setw(10) << i << setw(10) << group[i] << endl;
}
/* C++ program to check whether an array is in ascending order, descending
order or unsorted one */
# include <iostream.h>
void main()
{
int n, i, a[100], ascend = 1, descend = 1;
cout << "Input number of elements in the array ";
cin >> n;
cout << "Input " << n << " numbers: " << endl;
for(i = 0;i < n; i++)
{
cout << "Input number " << (i + 1) << " value = ";
cin >> a[i];
}
for(i = 0; i < n – 1; i++)
{
if(a[i] > a[i + 1]) ascend = 0;
if(a[i] < a[i + 1]) descend = 0;
}
if(ascend == 1)
cout << "Numbers are arranged in ascending order ";
else if(descend == 1)
cout << "Numbers are in descending order ";
else
cout << " array is unsorted one ";
}
/* C++ program to reverse a one-dimensional array of integers */
# include <iomanip.h>
void main()
{
int n, i, r, temp, a[100];
cout << "Input number of elements in the array ";
cin >> n;
for(i = 0; i < n; i++)
{
Cout << "Input number " << (i + 1) << "value = ";
cin >> a[i];
}
cout << "Original array elements are ";
for(i = 0; i < n; i++)
cout << setw(5) << a[i];
for(i = 0, r = n – 1; i < n / 2; i++, r--)
{
temp = a[i];
a[i] = a[r];
a[r] = temp;
}
cout << endl << "Reverse array elements are " << endl;
for(i = 0; i < n; i++)
cout << setw(5) << a[i];
}
/* C++ program to accept temperature of each day of the month and print
maximum temperature and its day in that month, minimum temperature and
its day in that month, and also find the average temperature of the month */
# include <iomanip.h>
main( )
{
int n, i, maxday, minday;
float temp[31], tottemp = 0, maxtemp, mintemp, avgtemp;
cout << "Input number of days in the month ";
cin >> n;
cout << "Input " << n << " days temperature " << endl;
for(i = 0; i < n; i++)
{
cout << "Input temperature of day " << (i + 1) << " = ";
cin >> temp[i];
}
tottemp = temp[0];
maxtemp = temp[0];
maxday = 0;
mintemp = temp[0];
minday = 0;
BIPU Lab Manual: Cpp programs – 65
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
/* C++ program there are N students. Each student will take the examination in
3 subjects.
I. The marks obtained by each student in different subjects.
II. Total marks and average marks obtained by each student.
III. The maximum marks from three subjects. */
# include <iomanip.h>
void main()
{
int n, i, j, marks[10][3];
int total, max;
float avg;
cout << " Input number of students in a class ";
cin >> n;
cout << " Input " << n << " students marks in 3 subjects " << endl;
for(i = 0; i < n; i++)
{
cout << " Student " << (i + 1) << " ";
for(j = 0; j < 3; j++)
cin >> marks[i][j];
}
cout << setw(16) << "sub 1" << setw(7)
<< "sub 2" << setw(7) << "sub 3";
cout << setw(7) << " total " << setw(10)
<< " average" << setw(15);
cout << "max marks " <<endl;
for(i = 0; i < n; i++)
{
total = 0;
max = marks[0][0];
cout << "student" << (i + 1);
for(j = 0; j < 3; j++)
{
total = total + marks[i][j];
if(max < marks[i][j])
max = marks[i][j];
cout << setw(7) << marks[i][j];
}
cout << setprecision(4);
avg = (float) total / 3;
cout << setw(7) << total << setw(9) << avg << setw(12) << max;
}
return 0;
}
// C++ program to read a matrix of order MxN and display its transpose
# include <iomanip.h>
main( )
{
int m, n, i, j, a[10][10], trans[10][10];
cout << "Input order of matrix ";
cin >> m >> n;
cout << "Input matrix elements " << endl;
// c++ program to find the length of the string without using strlen( )
# include <iostream.h>
void main( )
{
char str[100];
int i, len;
cout << "Input a string ";
cin.getline(str, 100);
cout << "string is " << str << endl;
for(i = 0; str[i] != '\0'; i++); // terminate for loop by semicolon
len = i;
cout << "Length of the string is " << len;
}
// c++ program to copy one string to another without using strcpy( )
# include <iostream.h>
void main( )
{
char str[100],dstr[100];
int i;
cout << "Input a string ";
cin.getline(str, 100);
cout << "Source string is " << str << endl;
for(i = 0; str[i] != '\n'; i++)
dstr[i] = str[i];
dstr[i] = '\0';
cout << "Destination string is " << dstr;
}
/* c++ program to find the occurance of a specified character */
# include <iostream.h>
void main( )
{
int i, count;
char ch, str[100];
cout << "Input a string ";
cin.getline(str, 100);
cout << "String is " << str <<endl;
cout << "Input a character to be counted ";
cin.get(ch);
for(count = 0, i = 0;str[i] != '\0'; i++)
if(str[i] == ch)
count ++;
cout << ch << " occurs " << count << " times";
}
// C++ program to concatenate (join) two strings without using strcat( )
# include <iostream.h>
void main( )
{
char str1[50], str2[50], str3[100];
int i, j;
cout << "Input the first string ";
cin.getline(str1, 50);
cout << "Input the second string ";
cin.getline(str2, 50);
BIPU Lab Manual: Cpp programs – 72
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
prg to find the location of a character in a given string using strchr( ) function
#include<iostream.h>
#include<string.h>
void main()
{
char name[50], ch;
cout << "Enter a string \n";
cin.getline(name, 50);
cout << "Enter the character to find its position in the string\n";
cin >> ch;
char *a = strchr(name, ch);
cout << "position of character " << ch << " in given string is "
<< (a - name + 1);
}
program to illustrate difference between strcmp() and strcmpi() functions
#include<iostream.h>
#include<string.h>
void main()
{
char s1[100], s2[100];
cout << "Input string1 \n";
cin.getline(s1, 100);
cout << "Input string2 \n";
cin.getline(s2, 100);
/* if(strcmp(s1, s2) == 0)
cout << "String are equal\n";
else
cout << "string are not equal\n"; */
if(strcmpi(s1, s2) == 0)
cout << "String are equal\n";
else
cout << "String are not equal";
}
// C++ program to illustrate strcpy, strlen and strrev
#include<iostream.h>
#include<string.h>
void main()
{
char str[100], str1[100];
cout << "Input a string\n " ;
cin.getline(str, 100);
strcpy(str1, str);
cout << "No. of characters = " << strlen(str) << endl;
cout << "Reversed string = " << strrev(str) << endl;
cout << "copied string = " << str1;
}
prg to join n characters from second string to first string using strncat() fun
#include<iostream.h>
#include<string.h>
void main()
{
char s1[100], s2[100];
cout << "Input string 1\n";
BIPU Lab Manual: Cpp programs – 76
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
cin.getline(s1, 100);
cout << "Input string 2\n";
cin.getline(s2, 100);
cout << "Enter number of characters to be joined\n"
<< "to first string from second string ";
int n;
cin >> n;
cout << "String after joining : " << strncat(s1, s2, n) << endl;
}
//C++ program to compare n characters in two strings using strncmp()
# include <string.h>
# include <iostream.h>
main( )
{
char str1[50], str2[50];
int n, res;
cout << "Enter string one characters \n";
cin.getline(str1, 50);
cout << "Enter string two characters \n";
cin.getline(str2, 50);
cout << "Enter number of characters to be compraed \n";
cin >> n;
res = strncmp(str1, str2, n);
if(res == 0)
cout << "Strings are equal";
else if(res > 0)
cout << "String 1 is greater than string 2 ";
else
cout << "String 2 is greater than string 1 ";
return 0;
}
program to copy n characters from string 2 to string 1 using strncpy function
#include<iostream.h>
#include<string.h>
main()
{
char str1[50], str2[25];
int n;
cout << "Enter the first string\n";
cin.getline(str1, 25);
cout << "Enter the second string\n";
cin.getline(str2, 25);
cout << "Enter number of characters to be copied"
<<" from string 2 to string 1 \n";
cin >> n;
strncpy(str1, str2, n);
cout << "First string after copying from second string is "<< str1;
return 0; }
/* C++ program to find the square of a number using function find the value of
sum 1^2 + 2^2 + 3^2 + 4^2 +.... n^2 */
# include <iostream.h>
int sqr(int);
void main( )
{
int n, sum = 0, i;
cout << " Input a number\n";
cin >> n;
for(i = 1; i <= n; i++)
sum = sum + sqr(i);
cout << " Sum of series = " << sum;
}
int sqr(int a)
{ return (a * a);
}
/* C++ program to find the average of three numbers using functions */
# include <iostream.h>
float avg(float, float, float);
void main( )
{
float a, b, c, avg1;
cout << " Input three numbers\n";
cin >> a >> b >> c;
avg1 = avg(a, b, c);
cout << " Average of three numbers = " << avg1;
}
float avg(float x, float y, float z)
{
return((x + y + z) / 3);
}
/* C++ program to find simple interest using default arguments */
# include <iostream.h>
float simpint(float p, int t = 1, float r = 10.25);
void main( )
{
float p, r, si;
int t;
cout << " Input principal amount\n";
cin >> p;
cout << " Input time\n";
cin >> t;
if(t == 1)
si = simpint(p);
else
{
cout << " Input rate\n";
cin >> r;
si = simpint(p, t, r);
}
cout << " Simple Interest = " << si;
}
int GCD( )
{
int x, y;
cout << " Enter the numbers x and y\n";
cin >> x >> y;
while(x != y)
{
if(x > y)
x = x – y;
else
y = y – x;
}
return(x);
}
/* C++ program to find the type of a character entered using a function with
argument no return value*/
# include <iostream.h>
void chartype(char);
void main( )
{
char ch;
cout << " Enter a character\n";
cin >> ch;
chartype(ch);
}
void chartype(char c)
{
if((c >= 'a') && (c <= 'z'))
cout << c << " is lower case character ";
else if((c >= 'A') && (c <= 'Z'))
cout << c << " is upper case chracter ";
else if((c >= '0') && (c <= '9'))
cout << c << " is a number ";
else
cout << c << " is a special chracter ";
}
/* C++ program to reverse a number and check whether it is a palindrome or
not using a function with arguments and return value */
# include <iostream.h>
long reverse(long);
void main( )
{
long num, rev;
cout << " Enter a number\n";
cin >> num;
rev = reverse(num);
cout << "Reverse = " << rev << endl;
if(num == rev)
cout << num << " is a palindrome";
else
cout << num << " is not a palindrome";
}
long reverse(long n)
{
int r;
long rev=0;
while(n != 0)
{
r = n % 10;
n = n / 10;
rev = rev * 10 + r;
}
return rev;
}
/* C++ program to check whether a number is palindrome or not using function
with arguments and no return value */
# include <iostream.h>
void reverse(long);
void main( )
{
long num;
cout << " Enter a number\n";
cin >> num;
reverse(num);
}
void reverse(long n)
{
int r;
long rev = 0, temp = n;
while(n != 0)
{
r = n % 10;
n = n / 10;
rev = rev * 10 + r;
}
if(rev == temp)
cout << temp << " is a palindrome ";
else
cout << temp << " is not a palindrome";
}
/* C++ program to find whether a number is palindrome or not using function
without arguments and return value */
# include <iostream.h>
int reverse(void);
void main( )
{
int n;
n = reverse();
if(n == 1)
cout << " is a palindrome";
else
cout << " is not a palindrome";
}
int reverse(void)
{
long temp, num, rev = 0, r;
cout << " Input a number\n";
cin >> num;
temp = num;
while(num != 0)
{
r = num % 10;
num = num / 10;
rev = rev * 10 + r;
}
cout << temp;
if (rev == temp)
return 1;
else
return 0;
}
/* C++ program tocheck isprime() that returns 1 if the argument passed to it is
a prime number and 0 otherwise.Using this function generate all prime
numbers between m and n assuming m <= n */
# include <iostream.h>
# include <math.h>
# include <iomanip.h>
int isprime(int);
void main( )
{
int m, n, x;
cout << " Input the range(m <= n):";
cin >> m >> n;
cout << " list of prime numbers between " << m << " and " << n;
for(int i = m; i <= n; i++)
{
x = isprime(i);
if(x == 1)
cout << setw(5) << i;
}
}
int isprime(int num)
{
for(int i = 2; i <= sqrt(num); i++)
if(num % i == 0)
return 0;
return 1;
}
/* C++ program to find the gcd and lcm of two numbers using functions with
arguments and return value */
# include <iostream.h>
int gcd(int, int);
int lcm(int, int);
void main( )
{
int n1, n2;
BIPU Lab Manual: Cpp programs – 87
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
long sum(int n)
{
if(n == 0)
return 0;
else
return(n + sum(n – 1));
}
/* C++ program to find thex to the power of n (x ^ n) using recursive function */
#include<iostream.h>
float power(float,int);
void main( )
{ float x;
int n;
cout<<" Enter x and n values \n";
cin>>x>>n;
cout<< x <<" to the power of "<<n<<" is "<<power(x,n);
}
float power(float a,int b)
{
if(b==0)return 1;
if(b>0)
return (a*power(a,b-1));
else
return((1/a)*power(a,b+1));
}
//C++ program to illustrate the function using call by value mechanism
# include <iostream.h>
# include <iomanip.h>
void testfunc(int);
void main( )
{ int num;
num = 40;
cout << "Value of num before the function call " << num << endl;
testfunc(num);
cout << "Value of num after the function call " << num;
}
void testfunc(int x)
{
x = x + x;
}
/* C++ program to exchange the values of two numbers by passing reference to
the function */
# include <iostream.h>
void swap(int &, int &);
void main( )
{
int a, b;
cout << " Input two numbers\n";
cin >> a >> b;
cout << "Before swapping a = " << a << "and b = " << b << endl;
swap(a, b);
cout << "After swaping a = " << a << " and b = " << b << endl;
}
BIPU Lab Manual: Cpp programs – 89
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
if(i == j)
{
if(x[i][j] != scalarelement)
return 0;
}
else
{
if(x[i][j] != 0)
return 0;
}
}
}
return 1;
}
/* C++ program to find the length of a string */
# include <iostream.h>
int length(char [ ]);
void main( )
{
char str[100];
cout << " Input a string\n";
cin.getline(str, 100);
cout << " Length of string = " << length(str);
}
int length(char s[ ])
{
for(int i = 0; s[i] != '\0'; i++);
return i;
}
/* C++ program to reverse a string */
# include <iostream.h>
int length(char [ ]);
void reverse(char [ ]);
void main( )
{
char str[100];
cout << " Input a string\n";
cin.getline(str, 100);
cout << " Original string is" << str << endl;
reverse(str);
cout << " Reversed string is " << str << endl;
}
int length(char s[ ])
{
for(int i = 0; s[i] != '\0'; i++);
return i;
}
void reverse(char s[ ])
{
int n = length(s);
char temp;
/* C++ program to input user's date of birth and display the output in the date
format using structure */
# include <iostream.h>
void main( )
{
struct date
{
int day;
int month;
int year;
};
struct date dob;
cout << " Input your date ofbirth ";
cin >> dob.day >> dob.month >> dob.year;
cout << "Date of birth:" << dob.day << " - " << dob.month << " - " << dob.year ;
}
C++ program to find the distance between two points. program should define a
structure to hold information about a point in the coordinate system. The
defination should also declare two variables point1 and point2 of the same type
# include <iostream.h>
# include <math.h>
void main( )
{
struct point
{
int x, y;
} point1, point2;
float distance;
cout << " Input co-ordinate values for the first point " << endl;
cin >> point1.x >> point1.y;
cout << " Input co-ordinate values for the second point " << endl;
cin >> point2.x >> point2.y;
distance = sqrt(pow((point2.x - point1.x ),2) + pow((point2.y - point1.y), 2));
cout << " Distance between two points = " << distance << endl;
}
/* C++ program to input and display the information of a student */
#include<iostream.h>
void main( )
{
struct student
{
int regno;
char name[20];
char grade[10];
char comb[5];
float fees;
}nstud;
cout << " Enter student regno " << endl;
cin >> nstud.regno;
cout << " Enter name of the student " << endl;
cin >> nstud.name;
cout << " Enter the class student is studying " << endl;
cin >> nstud.grade;
BIPU Lab Manual: Cpp programs – 94
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
cout << " Enter the combination of the student " << endl;
cin >> nstud.comb;
cout << " Enter the fees " << endl;
cin >> nstud.fees;
cout << endl << " Student Information " << endl;
cout << " Student Register number is " << nstud.regno << endl;
cout << " Name of the student is " << nstud.name << endl;
cout << " Class studying is " << nstud.Class << endl;
cout << " Combination of the student is " << nstud.comb << endl;
cout << " Fees paid is " << nstud.fees << endl;
}
/* C++ program to illustrate the use of nested structures */
#include<iostream.h>
struct date
{
int year;
int month;
int day;
};
struct student
{
int regno;
char name[20];
struct date dob;
}std1;
void main( )
{
cout << "Enter student name ";
cin.getline(std1.name, 20);
cout << " Enter student regno \n";
cin >> std1.regno;
cout << " Enter the date of birth of student " << endl;
cin >> std1.dob.day >> std1.dob.month >> std1.dob.year;
cout << endl << " STUDENT INFORMATION " << endl;
cout << " Reg-no: " << std1.regno << endl;
cout << " Name : " << std1.name << endl;
cout << " Date of birth : ";
cout << std1.dob.day << " - " << std1.dob.month << " - " << std1.dob.year;
}
/* C++ program to accept N student information and to display all the students
information (to create a student database using structures) */
# include <iostream.h>
# include <iomanip.h>
# include <stdio.h>
struct info
{
int regno;
char name[20];
char class1[10];
char comb[5];
float fees;
};
void main( )
{
struct info std[10];
int n, i;
cout << " Enter number of students ";
cin >> n;
for(i = 0; i < n; i++)
{
cout << " Enter regno" << endl;
cin >> std[i].regno;
cout << " Enter name ";
gets(std[i].name);
cout << " Enter class ";
gets(std[i].class1);
cout << " Enter combination ";
gets(std[i].comb);
cout << " Enter fees " << endl;
cin >> std[i].fees;
}
cout << endl << " STUDENT INFORMATION " << endl << endl;
for(i = 0; i < n; i++)
{
cout << std[i].regno << '\t';
cout << std[i].name << '\t';
cout << setw(15) << std[i].class1;
cout << setw(15) << std[i].comb;
cout << setw(15) << std[i].fees;
cout << endl;
}
}
/* C++ program to accept 5 people name, address and telephone number and to
search for the information of a particular person */
#include<iostream.h>
#include<string.h>
#include<stdio.h>
struct directory
{ char name[20];
char address[20];
long telephone;
};
void main( )
{
struct directory d[3];
int i, found=1;
char customername[20];
cout << " Enter name, address and telephone number\n";
for(i = 0; i < 3; i++)
{
gets(d[i].name);
gets(d[i].address);
cin>>d[i].telephone;
}
cout << " Enter customer name to search " << endl;
gets(customername);
for(i = 0;i < 3; i++)
{
if(strcmp(d[i].name, customername) == 0)
{
cout << " Name = " << d[i].name << endl;
cout << " address = " << d[i].address << endl;
cout << " telephone = " << d[i].telephone << endl;
found = 0;
}
}
if(found)
cout << customername << " Does not have a telephone " << endl;
}
/* C++ program to illustrate the declaration and use of enumerated data type */
# include <iostream.h>
void main( )
{
enum weekdays { sunday = 2, monday, tuesday, wednesday = 7,
thursday, friday, saturday = 16};
cout << "Sunday = " << sunday << endl;
cout << " Monday = " << monday << endl;
cout << " Tuesday = " << tuesday << endl;
cout << " Wednesday = " << wednesday << endl;
cout << " Thursday = " << thursday << endl;
cout << " Friday = " << friday << endl;
cout << " Saturday = " << saturday << endl;
}
/* program to convert days into years, months and days */
#include<iostream.h>
void main( )
{
int nodays, days, years, month;
cout << " Enter the total days\n";
cin >> days;
nodays = days;
years = days / 365;
days = days % 365;
month = days / 30;
days = days % 30;
cout << nodays << " Days = " << days << "days - " << month << "months - "
<< years << " years " << endl;
}
/* program to convert seconds into hours,minutes and seconds */
#include<iostream.h>
void main( )
{
int totsec, seconds, hours, minutes;
cout << " Enter the total seconds\n";
cin >> totsec;
seconds = totsec;
hours = seconds / 3600;
BIPU Lab Manual: Cpp programs – 97
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
II PUC
Text
book
programs
Program to accept Date from the user and display date on the screen
using Object-Oriented programming technigue.
#include <iostream.h>
class Date
{
int day , month , year ;
public :
void InputDate ( )
{
cout << " Enter a Date as DD MM YY : " ;
cin >> day >> month >> year ;
}
void DisplayDate ( )
{
cout << " Entered Date is " ;
cout << day << "/" << month << "/" << year ;
}
};
void main ( )
{
Date Today ;
Today . InputDate ( ) ;
Today . DisplayDate ( ) ;
}
Program to find the area and perimeter of a Rectangle using Object -
Oriented programming technique.
#include <iostream.h>
class Rectangle
{
float length , breadth ;
public :
void InputValues ( )
{
cout << " Input the length of the rectangle : " ;
cin >> length ;
cout << " Input the breadth of the rectangle : " ;
cin >> breadth ;
}
int Area ( )
{
return ( length * breadth ) ;
}
int Perimeter ( )
{
return ( 2 * ( length + breadth ) ) ;
}
void DisplayInfo ( )
{
cout << "\n Length of the rectangle is : " << length;
cout << "\n Breadth of the rectangle is : " << breadth;
cout << "\n Area of the rectangle is : " << Area( );
cout << "\n Perimeter of the rectangle is : " << Perimeter( );
}
};
void main ( )
{
Rectangle R ;
R . InputValues ( ) ;
R . DisplayInfo ( ) ;
}
Program to read and write N numbers into one dimensional array using
object oriented technique .
#include <iostream .h>
class OneDimArray
{
int a[100] , m ;
public :
void SetNoofElements ( int n )
{
m = n ;
}
void ReadArray ( ) ;
void DisplayArray ( ) ;
};
void OneDimArray :: ReadArray ( )
{
cout << " Enter " << m << " array elements " << endl ;
for ( int i = 0 ; i < m ; i++ )
cin >> a[ i ];
}
void OneDimArray :: DisplayArray ( )
{
cout << " Array elements are : " << endl ;
for ( int i = 0 ; i < m ; i++ )
cout << a[i] << '\t' ;
}
void main ( )
{
int n ;
OneDimArray A ;
cout << " Input number of elements : " ;
cin >> n ;
A . SetNoofElements (n) ;
A . ReadArray ( ) ;
A . DisplayArray ( ) ;
}
Progarm tp display the size of the objects and a class .
#include <iostream.h>
class Student
{
long RegNo ;
char Name [20] ;
char comb [6] ;
int Marks ;
char Address
public :
void ReadStdInfo ( ) ;
void DisplayStdInfo ( ) ;
};
BIPU Lab Manual: Cpp programs – 105
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
void main ( )
{
Student S1, S2 ;
cout << "`Size of the object S1 is = " << sizeof (S1) << endl ;
cout << "`Size of the object S2 is = " << sizeof (S2) << endl ;
cout << "`Size of the class is = " << sizeof (Student) ;
}
Prg to creat a database for a college containing IdNo, Name and Marks
#include <iostream.h>
#include <iomanip.h>
class Student
{
int IdNo ;
char Name [20] ;
int Marks ;
public :
void ReadData ( )
{
cout << " Enter the following information " << endl ;
cout << " IdNo : " ; cin >> IdNo ;
cout << " Name : " ; cin >> Name;
cout << " Marks : " ; cin >> Marks ;
}
void DisplayData ( )
{
cout << setw (5) << IdNo << setw (15) << Name;
cout << setw (7) << Marks << endl ;
}
};
void main ( )
{
Student COLLEGE [100] ;
int N , i ;
cout << " Input number of student : " ;
cin >> N ;
for ( i = 0 ; i < N ; i++ )
COLLEGE [i] . ReadData ( ) ;
cout << " --------------------------------------------" << endl ;
cout << " LIST OF STUDENTS IN ABC COLLEGE " << endl ;
cout << " ---------------------------------------------"<< endl ;
cout << " IdNo " << setw (15) << " Name " << setw (9)
<< " Marks " << endl ;
for ( i=0 ; i < N ; i++ )
COLLEGE [i] . DisplayData ( ) ;
cout << " --------------------------------------------" << endl ;
}
Program to find the total marks of PUC and CET examinations in each
subject.
#include <iostream.h>
class Exam
{
float Physics , Chemistry , Maths ;
public :
void ReadMarks ( )
{
cout << " Input Physics marks : " ; cin >> Physics ;
cout << " Input Chemistry marks : " ; cin >> Chemistry ;
cout << " Input Maths marks : " ; cin >> Maths ;
}
void DisplayInfo ( )
{
cout << " Physics : " << Physics << endl ;
cout << " Chemistry : " << Chemistry << endl ;
cout << " Maths : " << Maths << endl ;
}
void Total ( Exam PU , Exam CT )
{
Physics = PU . Physics + CT . Physics ;
Chemistry = PU . Chemistry + CT . Chemistry ;
Maths = PU . Maths + CT . Maths ;
}
};
void main ( )
{
Exam PUC , CET , PUCplusCET ;
cout << " Enter PUC marks " << endl << endl ;
PUC . ReadMarks ( ) ; // read PUC marks
cout << endl << " Enter Common Entrance test marks " << endl ;
CET . ReadMarks ( ) ;
PUCplusCET . Total ( PUC , CET ) ;
cout << endl << " Total marks of PUC and CET is : " << endl ;
PUCplusCET . DisplayInfo ( );
}
Program to return objects from functions.
#include <iostream.h>
class Exam
{
float Physics , Chemistry , Maths ;
public :
void ReadMarks ( )
{
cout << " Input Physics marks : " ; cin >> Physics ;
cout << " Input Chemistry marks : " ; cin >> Chemistry ;
cout << " Input Maths marks : " ; cin >> Maths ;
}
void DisplayInfo ( )
{
cout << " Physics : " << Physics << endl ;
cout << " Chemistry : " << Chemistry << endl ;
cout << " Maths : " << Maths << endl ;
}
BIPU Lab Manual: Cpp programs – 107
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
cout << " Value of a = " << a << " and b = " << b
<< " after the swap "<< endl ;
char c1 = 'A' , c2 = 'B' ;
cout << " \nValue of c1 = " << c1 << " and c2 = " << c2
<< " before the swap " << endl ;
SWAP ( c1 , c2 ) ;
cout << " Value of c1 = " << c1 << " and c2 = " << c2
<< " after the swap "<< endl ;
}
void SWAP ( int &a , int &b )
{
int temp = a ;
a = b ;
b = temp ;
}
void SWAP ( char &a , char &b )
{
char temp = a ;
a = b ;
b = temp ;
}
void SWAP ( float &a , float &b )
{
float temp = a ;
a = b ;
b = temp ;
}
Program to find the cube of a number using inline function .
#include <iostream.h>
inline int CUBE ( int a)
{
return a * a * a ;
}
void main ( )
{
int n ;
cout << " Input a number : " ;
cin >> n ;
cout << " Cube of " << n << " = " << CUBE ( n) ;
}
Program to check a number is even or odd using a friend function.
#include <iostream.h>
class Number
{
int a ;
public :
void ReadData ( )
{
cout << " Input a number " ;
cin >> a ;
}
friend int IsEven ( Number ) ;
};
void ReadData ( )
{
cout << " Input husband name " ;
cin >> name ;
cout << " Input salary " ;
cin >> salary ;
}
friend int TotalSalary ( Husband , Wife );
};
class Wife
{
char name [20] ;
int salary ;
public :
void ReadData ( )
{
cout << " Input wife name " ;
cin >> name ;
cout << " Input salary " ;
cin >> salary ;
}
friend int TotalSalary ( Husband , Wife );
};
int TotalSalary ( Husband H , Wife W )
{
return ( H . salary + W. salary) ;
};
void main ( )
{
Husband H ;
Wife W ;
H . ReadData ( ) ;
W . ReadData ( ) ;
cout << "Total salary of the family is " << TotalSalary (H, W);
}
Program to show how to declare a constructor inside class definition.
#include <iostream.h>
class ABC
{
public :
ABC ( ) // Constructor
{
cout << " This is a class constructor " ;
}
};
void main ( )
{
ABC ConObj ; // object creation
}
int CalculateAndDisplay ( )
{
for ( int i=1 ; i <= n ; i++ ) S+=i ;
return S ;
}
};
void main ( )
{
Sum SumOfN ;
SumOfN . ReadData ( ) ;
cout << " Sum of natural numbers = "
<< SumOfN . CalculateAndDisplay ( ) ;
}
Prg for default constructors
#include <iostream.h>
class Point
{
int x , y ;
public :
Point ( )
{
x = 0 ;
y = 0 ;
}
void DisplayCoordinates ( )
{
cout << " X - coordinate = " << x << endl ;
cout << " Y - coordinate = " << y << endl ;
}
};
void main ()
{
Point P ;
P . DisplayCoordinates ( ) ;
}
Program to illustrate the passing of arguments to the constructor
using implicit call .
#include <iostream.h>
class Sum
{
int total ;
public :
Sum ( int n )
{
total = 0 ;
for ( int i = 1 ; i <= n ; i++ )
total+=i ;
}
void DisplaySum ( )
{
cout << " Total = " << total ;
}
};
void main ( )
{
Sum S ( 100 ) ;
S . DisplaySum ( ) ;
}
Program to find the largest of two numbers using parameterized
constructor using explict call .
#include <iostream.h>
class Max
{
int big ;
public :
Max ( int n , int m )
{
if ( n > m )
big = n ;
else
big = m;
}
void DisplayBig ( )
{
cout << " Big = " << big << endl ;
}
};
void main ( )
{
Max N = Max ( 50 , 78 ) ;
Max M = Max ( -123 , -345 ) ;
N . DisplayBig ( ) ;
M . DisplayBig ( ) ;
}
Program to find the area of a circle calling a parameterized
constructor using operator.
#include <iostream.h>
class Area
{
float A , R ;
public :
Area ( float r )
{
R = r ;
}
void DisplayArea ( )
{
A = 3.142 * R * R ;
cout << " Area = " << A << endl ;
}
};
void main ( )
{
Area N = 5 ;
Area M = 10 ;
N . DisplayArea ( ) ;
M . DisplayArea ( ) ;
}
BIPU Lab Manual: Cpp programs – 115
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
void main ( )
{
Area A1 ;
Area A2 ( 3) ;
Area A3 ( 4 ,5) ;
Area A4 ( 5 , 12 , 13) ;
}
Constructors with default arguments
#include <iostream.h>
class Point
{
int X , Y ;
public :
Point ( ) { }
Point ( int a , int b = 0 )
{
X = a ;
Y = b ;
}
void GetPoint ( )
{
cout << " Enter X - coordinates : " ; cin >> X ;
cout << " Enetr Y - coordinates : " ; cin >> Y ;
}
void DisplayPoint ( )
{
cout << "Point is ( " << X << " , " << Y << " ) " << endl;
}
} ;
void main ( )
{
Point P1 , P2 ( 3) , P3( 5 ,6) ;
cout << " Input coordinates of P1 point " << endl ;
P1 . GetPoint( );
P1 . DisplayPoint ( ) ;
P2 . DisplayPoint ( ) ;
P3 . DisplayPoint ( ) ;
}
Program to illustrate how a copy constructor can be overloaded .
#include <iostream.h>
class Number
{
int a ;
public :
Number ( ) { }
Number ( int N )
{
a = N ;
}
Number ( Number &X )
{
a = X . a;
cout << " Copy constructor is invoked " ;
}
void Display ( )
{
cout << a << endl ;
}
};
void main ( )
{
Number N1 ( 345) ;
Number N2 ( N1) ;
N1 . Display ( ) ;
N2 . Display ( ) ;
}
Program to illustrate the use of destructor in C++ .
#include <iostream.h>
class Number
{
int data ;
public :
Number ( )
{
cout << " Constructor invoked " << endl ;
data = 80 ;
}
~ Number ( )
{
cout << " Destructor " << endl ;
}
void DisplayData ( )
{
cout << " Data is = " << data << endl ;
}
};
void main ( )
{
Number N ;
N . DisplayData ( ) ;
Number a ;
}
Program to illustrate public inheritance .
#include<iostream.h>
class Shape
{
public :
int side1 , side2 ;
};
class Rectangle : public Shape
{
public :
int area ;
void ComputeArea ( )
{
area = side1 * side2 ;
}
};
void main ( )
{
Rectangle R ;
R . side1 = 5 ;
R . side2 = 6 ;
R . ComputeArea ( ) ;
cout << " Area of rectangle = " << R . area ;
}
Program to illustrate private inheritance .
#include <iostream.h>
class Shape
{
protected :
int side1 , side2 ;
public :
int area ;
void ComputeArea ( )
{
area = side1 * side2 ;
}
};
class Rectangle : private Shape
{
public :
void ReadData ( )
{
cout << " Input first side : " ; cin >> side1 ;
cout << " Input second side : " ; cin >> side2 ;
}
void DisplayOutput ( )
{
ComputeArea ( ) ;
cout << " Area of the Rectangle = " <<area ;
}
};
void main ( )
{
Rectangle R ;
R . ReadData ( ) ;
R . DisplayOutput ( ) ;
}
Program to illustrate protected inheritance with the base class
having protected and public members .
#include <iostream.h>
class Shape
{
protected :
int side1 , side2 ;
public :
int ComputeArea ( )
{
return (side1 * side2) ;
}
};
Hierarchical Inheritance
#include <iostream.h>
class Company
{
protected :
char Name [ 30] ;
char Address [ 50] ;
public :
void Input ( )
{
cout << " Enter the name of the company : " ;
cin >> Name ;
cout << " Enter the address of the company : " ;
cin >> Address ;
}
void Output ( )
{
cout << " Company Name : " << Name << endl ;
cout << " Company Address : " << Address << endl ;
}
};
class Item : public Company
{
char ItemName[ 30] ;
float Price ;
public :
void Input ( )
{
Company :: Input ( ) ;
cout << " Enter the name of the item : " ;
cin >> ItemName ;
cout << " Enter the cost of the item : " ;
cin >> Price ;
}
void Output ( )
{
Company :: Output ( ) ;
cout<< " Item Name : " << ItemName << endl ;
cout<< " Item Cost : " << Price << endl ;
}
};
class Electronic : public Company
{
char ItemName[ 30] , Capacity [ 20] ;
float Price ;
public : void Input ( )
{
Company :: Input ( ) ;
cout << " Enter the name of the item : " ;
cin >> ItemName ;
cout << " Enter the capacity of the system : " ;
cin >> Capacity ;
cout << " Enter the cost of the item : " ;
cin >> Price ;
}
BIPU Lab Manual: Cpp programs – 123
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
void Output ( )
{
Company :: Output ( ) ;
cout<< " Item Name : " << ItemName << endl ;
cout<< " Output capacity : "<<Capacity << endl ;
cout<< " Item Cost : " << Price << endl ;
}
};
void main ( )
{
Item I ;
Electronic E ;
cout << " Input Item information " << endl ;
I . Input ( ) ;
cout << " Input Electronic component information " << endl ;
E . Input ( ) ;
cout << endl << " ITEM INFORMATION " << endl << endl ;
I . Output ( ) ;
cout << endl << "ELECTRONIC COMPONENT INFORMATION " << endl ;
E . Output ( ) ;
}
Program to illustrate the technique of hierarchial inheritance .
#include <iostream.h>
class Employee
{
protected :
char Name [30 ] ;
char Address [50 ] ;
public :
void Input ( )
{
cout << "Enter the name of the employee : " ;
cin >> Name ;
cout << " Enter the address of the employee : " ;
cin >> Address ;
}
void Output ( )
{
cout << " Employee Name : " << Name << endl ;
cout << " Employee Address : " << Address << endl ;
}
};
class WorkDetails : public Employee
{
protected :
char Designation [ 30] ;
float Salary ;
public : void Input ( )
{
Employee :: Input ( );
cout << "Enter the designation of the employee:";
cin >> Designation ;
cout << " Enter the salary of the employee : " ;
cin >> Salary ;
}
BIPU Lab Manual: Cpp programs – 124
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
void Output ( )
{
Employee :: Output ( ) ;
cout << " Employee designation : " << Designation << endl ;
cout << " Employee salary : " << Salary << endl ;
}
};
class Sports
{
protected :
char GameName [ 20] ;
float Incentive ;
public :
void Input ( )
{
cout << "Enter name of the game : "; cin >> GameName;
cout << " Enter incentive amount: "; cin >> Incentive;
}
void Output ( )
{
cout << "Name of the game : " << GameName << endl ;
cout << " Incentive : " << Incentive << endl ;
}
};
class EmployeeDetails : public WorkDetails , public Sports
{
float TotalSalary ;
public :
void Input ( )
{
WorkDetails :: Input ( ) ;
Sports :: Input ( ) ;
}
void ComputeNetSalary ( )
{
TotalSalary = Salary + Incentive ;
}
void Output ( )
{
WorkDetails ::Output ( ) ;
Sports :: Output ( ) ;
ComputeNetSalary ( ) ;
cout << " Total Salary of the employee : "
<< TotalSalary ;
}
};
void main ( )
{
EmployeeDetails E ;
cout << " Input employee information " << endl ;
E . Input ( ) ;
cout << endl << " Employee details " << endl << endl ;
E . Output ( ) ;
}
#include <iostream.h>
void main ( )
{
int num ;
int *pInt ;
num = 468 ;
pInt = &num ;
cout << " Value of num is : " << num << endl ;
cout << " Address of num is : " << pInt << endl ;
}
num = 468 ;
pInt = &num ;
cout << " Value of num is : " << *pInt << endl ;
cout << " Address of num is : " << pInt << endl ;
}
Program to illustrate pointer initialization .
#include <iostream.h>
void main ( )
{
int *pInt ;
int num ;
num = 45 ;
pInt = &num ;
cout << " Value of num is : " << num << endl ;
cout << " Address of num is : " << &num << endl ;
cout << " The contents of ptr is " << pInt << endl ;
cout << " Value of num is " << *( &num) << endl ;
cout << " Value pointed by ptr is " << *pInt << endl ;
cout << " The address of pointer is " << &pInt << endl ;
}
#include <iostream.h>
void main ( )
{
int iVar , *pInt ;
float fVar , *pFloat ;
char cVar , *pChar ;
iVar = 123 ;
fVar = 12.34 ;
cVar = 'A' ;
pInt = &iVar ;
pFloat = &fVar ;
pChar = &cVar ;
*ptr1 = *ptr1 + 70 ;
*ptr2 = *ptr2 * 2 ;
cout << " a = " << a << " b = " << b << endl ;
}
Program to print an array of elements .
#include <iostream.h>
void main ( )
{
int A[5] = {15, 25, 67, 83, 12 };
for ( int i = 0 ; i < 5 ; i++ )
cout << A[i] << " \t " ;
}
Program to print an array array elements using constant pointer .
#include <iostream.h>
void main ( )
{
int A[ 5] = { 15 , 25 , 67 , 83 , 12 } ;
cout << * ( A ) << " \t " ;
cout << * ( A +1) << " \t " ;
cout << * ( A +2) << " \t " ;
cout << * ( A +3) << " \t " ;
cout << * ( A +4) << " \t " ;
}
Program to read and write array elements using a pointer variable .
#include <iostream.h>
void main ( )
{ int A [10] , n ;
int *ptr ;
cout << " Input number of elements in the array : " ;
cin >> n ;
cout << " Input Array elements : " << endl ;
for ( ptr = A ; ptr < A+n ; ptr++ )
cin >> *ptr ;
cout << " Array elements are : " << endl ;
for ( ptr =A ; ptr<A+n ; ptr ++)
cout << *ptr << " \t " ;
}
BIPU Lab Manual: Cpp programs – 128
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.
DataDouble ( number );
cout << " New value of number is " << number ;
}
void DataDouble ( int &num )
{
num = num + num ;
return ;
}
Program to exchange the values of two numbers by passing reference to
the function .
#include <iostream.h>
void SWAP ( int &, int &) ;
void main ( )
{
int a , b ;
cout << " Input values for a and b : " ;
cin >> a >> b ;
cout << " Before swapping " << endl ;
cout << " a = " << a << " and b = " << b << endl ;
SWAP ( a , b ) ;
public :
void ReadData ( )
{
cout << "input register number : " ; cin >> RegNo ;
cout << "input name of the student :" ; cin >> Name ;
cout << " input marks : " ; cin >> Marks ;
}
void Display( )
{
cout << "Register number : " << RegNo << endl;
cout << "Name of the student : " << Name << endl;
cout << "Marks : " << Marks;
}
};
void main ( )
{
Student *pStdObj ;
cout << " Enter the following information " << endl ;
pStdObj -> ReadData ( ) ;
pStdObj -> Display ( ) ;
}
Program to access members of a class using ‘this’ pointer .
#include <iostream.h>
class Time
{
int hh , mm , ss ;
public :
void InputTime ( )
{
cout << " Input hours : " ; cin >> hh ;
cout << " Input minutes : " ; cin >> this -> mm ;
cout << " Input seconds : " ; cin >> this -> ss ;
}
void DisplayTime ( )
{
cout << "Time : " ;
cout << hh << " : " ;
cout << " : " << ( *this) . mm ;
cout << " : " << this -> ss ;
}
void DisplayAddress ( )
{
cout << " Address of the object = " << this ;
}
};
void main ( )
{
Time T ;
cout << " Input time : " << endl ;
T . InputTime ( ) ;
T . DisplayTime ( ) ;
cout << endl << " Address of the object = " << &T << endl ;
T . DisplayAddress ( ) ;
}
delete [ ] pnArray ;
}
C++ file handling program.
# include <fstream.h>
void main ( )
{
ofstream myfile ;
myfile . open ( " example.txt ") ;
myfile << " Second Year PUC \n " ;
myfile . close ( ) ;
}
Program to store three names into a file called " NAMELIST.DAT " .
# include <fstream.h>
void main ( )
{
ofstream names ;
names . open ( "NAMELIST.DAT ") ;
names << " S . I . SANIYA \n " ;
names << " H . R . MANIK \n " ;
names << " Y . A . MALHOTRA \N " ;
names . close ( ) ;
}
Program to create a text file. (Note: Press ctrl + z to stop
inputting of characters)
# include <fstream.h>
void main ( )
{
char ch ;
ofstream TextFile ( "Text.Dat") ;
while (cin)
{
cin.get(ch ) ;
TextFile.put(ch) ;
}
TextFile.close ( ) ;
}
BIPU Lab Manual: Cpp programs – 133
// Use clrscr( ) and getch( ) functions along with #include<conio.h> file wherever necessary.