CS 1 Practical Handbook
CS 1 Practical Handbook
1
COMPUTER SCIENCE I (D93)
INDEX
SR EXPERIMENT NAME
NO.
C++
01 Write a program in C++ that first initializes an array of given 10 real numbers.
The program must sort numbers in ascending/descending order using Bubble –
Sort method. It should print the given list of numbers as well as the sorted list.
02 Write a function in C++ that exchanges data (passing by reference)
using swap function to interchange the given two numbers.
03 Write a program in C++ that first initializes an array of given 10 sorted real
numbers. The program must verify whether a given element belongs this array or
not, using Binary – Search technique. The element (to be searched) is to be
entered at the time of execution. If the number is found, the program should print
its position in the array otherwise it should print “The number is not found.”
04 Write a program in C++ that first initializes an array of five given numbers
(short /float/ double). The program must add these numbers by traversing this
array with a pointer. The output should print the starting address of the array with
the size of the number (in bytes) to which it points. The program must also print
the sum and pointer address with addition of every number as well as the ending
address.
05 Write a program in C++ that initializes a Ratio class with no parameters as a
default constructor. The program must print the message “OBJECT IS BORN”
during initialization. It should display the message “NOW X IS ALIVE’’, when
the first member function Ratio x is called. The program must display “OBJECT
DIES” when the class destructor is called for the object when it reaches the end of
its scope.
06 Implement a Circle class in C++. Each object of this class will represent a circle,
storing its radius and X & Y coordinates of its center as floats. Include a default
constructor, access functions an area() and circumference() of circle. The program
must print coordinates with radius, area and circumference of the circle.
07 Write a C++ program using virtual function. The program must declare p to be a
pointer to objects of the base
class Person. First, the program must assign p to point an instance X (name of the
person eg. “BOB”)
of class
person. The program must then assign p to point at an instance y( name of the stu
dent, eg. ”Tom”) of the derived class Student.
Define a print () in the base class such that it invokes the same base class function
to print
the name of the person by default. The second call for the same should evoke the
derived class function to print the name of the student.
08 Write a program in C++ to read the name of a country from one text file and nam
e of its corresponding capital
2
COMPUTER SCIENCE I (D93)
city from another text file. The program must display the country name and indica
te its corresponding capital (for at least five countries) in the output
09 Write a C++ program that first initializes an array of given 10 sorted real number
s. The program must verify
whether a given element belongs this array or not, using linear search technique.
The element (to be searched)
is to be entered at the time of execution if the number is found, the
program should print its position in the
array otherwise it should print” The number is not found”.
10 Write a C++ program to implement the concept of friend function
11 Write a C++ program to implement the concept of single inheritance
12 Write a C++ program to implement the concept of function overloading
HTML
13 Create a simple HTML page on any of the following topics: College Profile,
Computer Manufacturer or Software Development Company.The page must
consist of at least 3 paragraphs of text. The page must have an appropriate title,
background color or background image, and hyper-links to other pages. The
paragraphs must have text consisting of different colors and styles in terms of
alignment and Font Size.
14 Create a simple HTML page on any of the following topics: College Profile,
Computer Manufacturer or Software Development Company.The page must
consist of a scrolling marquee displaying an appropriate Message. The page must
include a table with at least 5 rows and 3 columns having merged cells at least at
1 place. The page must also display an image, such that when the same is viewed
through a browser and the mouse is placed (hovered) on the Image, an
appropriate text message should be displayed. The image itself should also act as
a hyper-link to another page.
15 Create a simple HTML page on any of the following topics: College Profile,
Computer Manufacturer or Software Development Company.The page must
consist of at least 3 paragraphs of text. The page must have an appropriate title,
background color or background image, and hyper-links to other pages. The
paragraphs must have text consisting of different colors and styles in terms of
alignment and Font Size.
16 Create simple HTML page which should contain scrolling marquee
displaying appropriate message. Include different
list tag in it
17 CreatesimpleHTMLpagewhichconsistatleast1paragraph,backgroundcolour
,textconsistingofdifferentcoloursandstyleintermsofalignmentandfontsize.
18 CreatesimpleHTMLpagewhichshouldcontainsimpletablewithatleast5rowsand
3columns.Createtablehavingmergedcellsatleast at1place.
19 CreatesimpleHTMLpagewhichshouldcontainsimpletable tags and also use
marquee tag.
3
COMPUTER SCIENCE I (D93)
PROGRAMMING IN C++
EXPERIMENT NO. 1
Write a program in C++ that first initializes an array of given 10 real numbers. The program
must sort numbers in ascending/descending order using Bubble – Sort method. It should
print the given list of numbers as well as the sorted list.
SOLUTION
#include<iostream>
int main()
inti,j,size;
cin>>size;
for(i=0;i<size;i++)
cin>>array[i];
for(i=0;i<size;i++)
cout<<array[i]<<"\t";
array[j+1]= array[i];
array[i]=temp;
} //end of if
cout<<endl;
for(i=0;i<size;i++)
cout<<array[i]<<endl;
return 0;
5
COMPUTER SCIENCE I (D93)
OUTPUT:
6
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 2
Write a function in C++ that exchanges data (passing by reference) using swap function to
interchange the given two numbers.
SOLUTION
#include<iostream>
floattmp=*f1;
*f1=*f2;
*f2=tmp;
int main()
float num1,num2;
cin>>num1;
cin>>num2;
cout<<num1<<endl;
cout<<num2<<endl;
return 0;
7
COMPUTER SCIENCE I (D93)
OUTPUT
8
COMPUTER SCIENCE I (D93)
EXPERIMENT 3
Write a program in C++ that first initializes an array of given 10 sorted real numbers. The
program must verify whether a given element belongs this array or not, using Binary –
Search technique. The element (to be searched) is to be entered at the time of execution. If
the number is found, the program should print its position in the array otherwise it should
print “The number is not found.”
SOLUTION
#include<iostream>
int main()
intbeg,end,mid,check,search;
beg=0;
end=9;
for(int i=0;i<10;i++)
cout<<array[i]<<"\t";
cout<<endl;
cin>>search;
while(beg<=end)
9
COMPUTER SCIENCE I (D93)
{
mid=(beg+end)/2;
if(array[mid] == search)
check=1;
break;
else if(array[mid]>search)
end=mid-1;
else
beg=mid+1;
if(check==1)
else
return 0;
10
COMPUTER SCIENCE I (D93)
OUTPUT
11
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 4
Write a program in C++ that first initializes an array of five given numbers (short /float/
double). The program must add these numbers by traversing this array with a pointer. The
output should print the starting address of the array with the size of the number (in bytes) to
which it points. The program must also print the sum and pointer address with addition of
every number as well as the ending address.
SOLUTION
#include<iostream>
int main()
int i;
cout<<"\n The size of the element to which the pointer is pointing : "<<sizeof(*a)<<" bytes";
cout<<"\n The "<<(i+1)<<" element in the array is : "<<*(a+i)<<" and its address is :
"<<(a+i);
12
COMPUTER SCIENCE I (D93)
return 0; }
OUTPUT
13
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 5
Write a program in C++ that initializes a Ratio class with no parameters as a default
constructor. The program must print the message “OBJECT IS BORN” during initialization.
It should display the message “NOW X IS ALIVE’’, when the first member function Ratio x
is called. The program must display “OBJECT DIES” when the class destructor is called for
the object when it reaches the end of its scope.
SOLUTION
#include<iostream>
class Ratio
private:
floatnum, deno;
public:
};
int main()
Ratio r1;
14
COMPUTER SCIENCE I (D93)
cout<< "Now object r1 is alive \n";
return 0;
OUTPUT
15
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 6
Implement a Circle class in C++. Each object of this class will represent a circle, storing its
radius and X & Y coordinates of its center as floats. Include a default constructor, access
functions an area() and circumference() of circle. The program must print coordinates with
radius, area and circumference of the circle.
SOLUTION
#include <iostream>
using namespace std;
class Circle
{
private:
floatx,y,r;
float area, circum;
public:
void assign();
void area1();
voidcircumf();
void print();
void circle();
};
void Circle::circle()
{}
void Circle::assign()
{
cout<<"enter x y co-ordinates\n";
cin>>x>>y;
cout<<"enter radius\n";
cin>>r;
}
void Circle::area1()
{
area=3.14*r*r;
}
void Circle::circumf()
{
circum=2*3.14*r;
16
COMPUTER SCIENCE I (D93)
}
void Circle::print()
{
cout<<"x and y coordinates are: "<<x<<" and "<<y<<endl;
cout<<"The radius is: "<<r<<endl;
cout<<"The area is: "<<area<<endl;
cout<<"The circumference is: "<<circum<<endl;
}
int main()
{
Circle c1;
c1.assign();
c1.area1();
c1.circumf();
c1.print();
c1.circle();
return 0;
}
OUTPUT
17
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 7
Write a C++ program using virtual function. The program must declare p to be a
pointer to objects of the base class Person. First, the program must assign p to
point an instance X (name of the person eg. “BOB”) of class person.
The progra must then assign p to point at an instance y( name of the student, eg. ”Tom”) of
the derived class Student.
Define a print () in the base class such that it invokes
the same base class function to print the name of the person by default.
The second call for the same should evoke the derived class function to print the name
of the student.
SOLUTION
#include<iostream>
using namespace std;
class Person
{
public:
virtual void print()
{
cout<< "My name is BOB" <<endl;
}
};
class Student : public Person
{
public:
void print()
{
cout<< "My name is TOM" <<endl;
}
};
int main()
{
OUTPUT
19
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 8
Write a program in C++ to read the name of a country from one text file and name of its corr
esponding capital
city from another text file. The program must display the country name and indicate its corres
ponding capital (for at least five countries) in the output.
SOLUTION
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
charcname[80],cap[80];
ifstream ifile1,ifile2;
ofstreamofile;
ofile.open("country.dat");
ofile<<"India\nUSA\nUK\nJapan\nFrance";
ofile.close();
ofile.open("capital.dat");
ofile<<"New Delhi\nWashisngton dc\nLondon\nTokyo\nParis";
ofile.close();
ifile1.open("country.dat");
ifile2.open("capital.dat");
cout<<"\ncountry\tcapital\n";
cout<<"===============";
while(!ifile1.eof()&&!ifile2.eof())
{
ifile1.getline(cname,80);
ifile2.getline(cap,80);
cout<<endl<<cname<<"\t"<<cap<<"\n";
}
ifile1.close();
ifile2.close();
return 0;
}
20
COMPUTER SCIENCE I (D93)
OUTPUT
21
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 9
Write a C++ program that first initializes an array of given 10 sorted real numbers.
The program must verify whether a given element belongs to this array or not, using linear
search technique.The element (to be searched) is to be entered at the time of execution if the
number is found, the program should print its position in the array otherwise it should print
“ The number is not found”
SOLUTION
#include<iostream>
using namespace std;
int main()
{
22
COMPUTER SCIENCE I (D93)
OUTPUT
23
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 10
SOLUTION
#include <iostream>
using namespace std;
class Box
{
private:
int length;
public:
Box (): length (0) {}
friend intprintLength (Box); //friend function
};
intprintLength (Box b)
{
b. length +=10;
return b. length;
}
int main ()
{
Box b;
cout<<"Length of box:"<<printLength (b)<<endl;
return 0;
}
OUTPUT
24
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 11
SOLUTION
#include <iostream>
using namespace std;
class Account {
public:
float salary = 60000;
};
class Programmer: public Account {
public:
float bonus = 5000;
};
int main(void) {
Programmer p1;
cout<<"Salary: "<<p1.salary<<endl;
cout<<"Bonus: "<<p1.bonus<<endl;
return 0;
}
OUTPUT
25
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 12
SOLUTION
#include <iostream>
using namespace std;
void add(int a, int b)
{
cout<< "sum = " << (a + b);
}
void add(double a, double b)
{
cout<<endl<< "sum = " << (a + b);
}
// Driver code
int main()
{
add(10, 2);
add(5.3, 6.2);
return 0;
}
OUTPUT
26
COMPUTER SCIENCE I (D93)
HTML
EXPERIMENT NO.13
Create a simple HTML page on any of the following topics: College Profile, Computer
Manufacturer or Software Development Company.The page must consist of at least 3
paragraphs of text. The page must have an appropriate title, background color or background
image, and hyper-links to other pages. The paragraphs must have text consisting of different
colors and styles in terms of alignment and Font Size.
SOLUTION
FIRST.HTML
<html>
<head><title> International Business Machines Corporation</title></head>
<body bgcolor="white">
<H1 align="center"> International Business Machines Corporation(IBMC)</H1>
<p align="left"><font size="+1" color="blue" > International Business Machines
Corporation (commonly referred to as IBM) is an American multinational technology
company headquartered in Armonk, New York, United States, with operations in over 170
countries. The company originated in 1911 as the Computing-Tabulating-Recording
Company (CTR) and was renamed “International Business Machines” in 1924.</font></p>
<p align="right"><font size="+2" color="green"> IBM has continually shifted its business
mix by exiting commoditizing markets and focusing on higher-value, more profitable
markets. This includes spinning off printer manufacturer Lexmark in 1991 and selling off its
personal computer (ThinkPad) and x86-based server businesses to Lenovo (2005 and 2014,
respectively), and acquiring companies such as PwC Consulting ,SPSS, and The Weather
Company (2016).</font></p>
</body>
</html>
27
COMPUTER SCIENCE I (D93)
SECOND.HTML
<html>
<head><title> International Business Machines Corporation</title></head>
<body>
<H3> International Business Machines Corporation(IBMC)</H3>
<p> To know more about International Business Machines Corporation(IBM) product,
services and career you can visit original website.
</p>
</body>
</html>
OUTPUT:
FIRST.HTML
SECOND.HTML
28
COMPUTER SCIENCE I (D93)
EXPERIMENT NO.14
Create a simple HTML page on any of the following topics: College Profile, Computer
Manufacturer or Software Development Company.The page must consist of a scrolling
marquee displaying an appropriate Message. The page must include a table with at least 5
rows and 3 columns having merged cells at least at 1 place. The page must also display an
image, such that when the same is viewed through a browser and the mouse is placed
(hovered) on the Image, an appropriate text message should be displayed. The image itself
should also act as a hyper-link to another page.
SOLUTION
TABLE.HTML
<html>
<head><title> International Business Machines Corporation</title></head>
<body>
<marquee><H3> International Business Machines Corporation(IBMC)</H3></marquee>
<p> How your business can get smarter,To know more about International Business
Machines Corporation(IBM) product, services and career you can see our table and can refer
original website.
</p>
<table border="2″ cellpadding="20″ cellspacing="2″ align="center">
<tr>
<thcolspan="3"> OUR SERVICES </th>
<tr>
<th> Product </th>
<th> Services</th>
<th> Prices</th>
</tr>
<tr>
<td> Cloud Computing</td>
<td> PC cloud </td>
29
COMPUTER SCIENCE I (D93)
<td> 9000</td>
</tr>
<tr>
<td> Mobile cloud </td>
<td>software</td>
<td> 1000</td>
</tr>
<tr>
<td> Security </td>
<td> Hardware </td>
<td> 9000</td>
</tr>
<tr>
<td> Storage </td>
<td> File Storage </td>
<td> 8000</td>
</tr>
</table>
<a href="next.html"><imgsrc="cloud.png" title="cloud Picture" align="center" width="500″
height="500″ ></a>
</body></html>
NEXT.HTML
<html>
<head><title> International Business Machines Corporation</title></head>
<body>
<H3> International Business Machines Corporation(IBMC)</H3>
<p> To know more about International Business Machines Corporation(IBM) product,
services and career you can visit original website.
</p>
</body>
</html>
OUTPUT:
TABLE.HTML
30
COMPUTER SCIENCE I (D93)
OUTPUT:
NEXT.HTML
31
COMPUTER SCIENCE I (D93)
EXPERIMENT NO.15
Create a simple HTML page on any of the following topics: College Profile, Computer
Manufacturer or Software Development Company.The page must consist of at least 3
paragraphs of text. The page must have an appropriate title, background color or background
image, and hyper-links to other pages. The paragraphs must have text consisting of different
colors and styles in terms of alignment and Font Size.
SOLUTION
FIRST.HTML
<html>
<head><title>MUMBAI UNIVERSITY</title></head>
<body bgcolor="white">
<H1 align="center"> MUMBAI UNIVERSITY</H1>
<p align="left"><font size="+1" color="blue" > The University of Mumbai (known earlier as
University of Bombay) is one of the oldest and premier Universities in India.
It was established in 1857 consequent upon “Wood’s Education Dispatch”, and it is one
amongst the first three Universities in India. As a sequel to the change in the name of the city
from Bombay to Mumbai, the name of the University has been changed from “University of
Bombay” to “University of Mumbai”, vide notification issued by the Government of
Maharashtra and published in the Government Gazette dated 4th September, 1996.The
University was accorded 5 star status in 2001 & ‘A’ grade status in April 2012 by the
National Assessment and Accreditation Council (NAAC).</font></p>
</body>
</html>
SECOND.HTML
<html>
<head><title> MUMBAI UNIVERSITY</title></head>
<body>
<H3>Facilities</H3>
<p> Knowledge Resource Centre</p>
<p>Gym Khana</p>
<p> Virtual Classrooms</p>
<p> University Health Care Centre</p>
33
COMPUTER SCIENCE I (D93)
</body>
</html>
OUTPUT
FIRST.HTML
OUTPUT
SECOND.HTML
34
COMPUTER SCIENCE I (D93)
EXPERIMENT NO.16
Create simple HTML page which should contain scrolling marquee displaying appropriate m
essage. Include different
list tag in it
SOLUTION
<html>
<head>
<title>List</title>
</head>
<bodybgcolor="lime">
<marquee><H3> COMPUTER SCIENCE</H3></marquee>
<b><u>OrderListtagexampleisbelow:‐</u></b>
<ol>
<li>Operatingsystem</li>
<li>DataStructure</li>
<li>HTML</li>
<li>c++programming</li>
</ol>
<b><u>OrderListtagexamplewithattributesisbelow:‐</u></b>
35
COMPUTER SCIENCE I (D93)
<olstart=”25”type=”A”>
<li>Operatingsystem</li>
<li>DataStructure</li>
<li>HTML</li>
<litype=”I”>C++programming</li>
</ol>
<hr>
<b><u>UnorderListtagexampleisbelow:‐</u></b>
<ultype="square">
<li>IntroductionofMicroprocessor</li>
<li>InstructionSetandprogramming</li>
<litype="circle">IntroductiontoMicrocontroller</li>
<litype="disc">NetworkTechnology</li>
</ul>
<hr>
<b><u>DefinitionListtagexampleisbelow:‐</u></b>
<dl>
<dt>Software</dt>
<dd><strong>Software</
strong>isasetofprogramwhichisrequiredtorunthesystem.</dd>
<dt>Hardware</dt>
<dd><strong>Hardware</
strong>areelectroniccomponentsusedinthecomputersystem.</dd>
</dl>
</body>
</html>
OUTPUT
36
COMPUTER SCIENCE I (D93)
EXPERIMENT NO.17
CreatesimpleHTMLpagewhichconsistatleast1paragraph,backgroundcolour,textconsist
ingofdifferentcoloursandstyleintermsofalignmentandfontsize.
SOLUTION
<html>
<head>
<title> College profile </title>
</head>
<body bgcolor="skyblue">
OUTPUT
EXPERIMENT NO.18
CreatesimpleHTMLpagewhichshouldcontainsimpletablewithatleast5rowsand3columns.C
reatetablehavingmergedcellsatleast at1place.
SOLUTION
<html>
<head>
<title> table </title>
</head>
<body bgcolor="orange">
<caption>Wind </caption>
<table border="2" cellpadding="10" cellsapcing="50">
<tr>
<th> City</th>
<th> High</th>
<th> Low</th>
</tr>
38
COMPUTER SCIENCE I (D93)
<tr>
<td>Mumbai</td>
<td> 33</td>
<td> 24</td>
</tr>
</table>
<br><hr>
<center>TABLE 2</center>
<br>
<caption> Result</caption>
<table border="2">
<tr>
<throwspan="2">Sr.No. </th>
<throwspan="2">Student<br> Name</th>
<thcolspan="3">Marks Obtained </th>
<throwspan="2">Total <br></th>
</tr>
<tr>
<td> Test1 </td>
<td>Test2 </td>
<td> Test3 </td>
</tr>
<td align="center">1</td>
<td>Maheshwari</td>
<td>150</td>
<td>100</td>
<td>100</td>
<td>350</td>
</tr>
<tr>
<td align="center">2</td>
<td>Ravi</td>
<td>120</td>
<td>100</td>
<td>100</td>
<td>320</td>
</tr>
</table>
</body>
</html>
OUTPUT
39
COMPUTER SCIENCE I (D93)
EXPERIMENT NO. 19
SOLUTION
<!DOCTYPE html>
<html>
<style>
table, th, td {
border:1px solid black;
}
</style>
<body>
<h1><marquee>STUDENT DATA</marquee></h1>
<h3>A basic HTML table</h3>
<table style="width:100%">
40
COMPUTER SCIENCE I (D93)
<tr>
<th>NAME</th>
<th>SUBJECT</th>
<th>MARKS</th>
</tr>
<tr>
<td>ABC</td>
<td>PHYSICS</td>
<td>20</td>
</tr>
<tr>
<td>PQR</td>
<td>CHEMISTRY</td>
<td>35</td>
</tr>
</table>
</body>
</html>
OUTPUT:
41