0% found this document useful (0 votes)
34 views28 pages

XII CS1 Journal 2024 25

Uploaded by

chitrodakrisshiv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views28 pages

XII CS1 Journal 2024 25

Uploaded by

chitrodakrisshiv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Computer Science 1

H.S.C Board Practical fair Journal


INDEX
Sr.
Practical Title
No.
1 C++ program to perform bubble sort.

2 C++ program to swap two values.

3 C++ program to perform binary search.

4 C++ program to reverse a string.

C++ program with class ratio and assign(), convert(), invert(), print()
5
functions.

6 C++ program with circle class using default constructor.

7 C++ program using constructor and destructor function.

C++ program to add two complex numbers using binary operator


8
overloading.

9 C++ program using virtual function.

10 C++ program to perform file handling.

11 HTML program to create simple webpage.

12 HTML program to create web page consisting table.


Experiment No. 1
a) Write a program in C++ that first initializes an array off given 10 real
numbers. The program must sort numbers in ascending/descending order
using BUBBLE-SORT method. It should print given list of numbers as well
as the sorted list.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a[ ]={10.1,8.1,7.1,6.4,1.1,4.5,2.1,3.2,6.7,4.9};
cout<<"The original list of element is\n";
for(int i=0;i<10;i++)
{
cout<<a[i]<<"\n";
}
cout<<"\n The sorted list in Ascending order\n";
for(i=0;i<10;i++)
{
for(int j=0;j<9-i;j++)
{
if(a[j]>=a[j+1])
{
float s=a[j];
a[j]=a[j+1];
a[j+1]=s;
}
}
}
for(i=0;i<10;i++)
{
cout<<a[i]<<"\n";
}
getch();
}
Output:
Experiment No. 2
a) Write a function in C++ that exchanges data (passing) by reference using
swap function to interchange the given two numbers.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
void swap(int*x, int*y);
void main()
{
clrscr();
int a,b;
cout<<"\n Enter two integer numbers";
cin>>a>>b;
cout<<"\n Before swapping";
cout<<" a="<<a<<"b="<<b;
swap(&a,&b);
cout<<"\n After swapping";
cout<<" a="<<a<<"b="<<b;
getch();
}
void swap(int*x,int*y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Output:
Experiment No. 3
a) Write a program in C++ that first initializes an array of given10 sorted real
numbers. The program must is to verify whether the given element belongs
this array or not, using binary search technique. The element to be searched
is to enter at the time of execution. If number is found then program should
print its position in the array otherwise it should print the number is not
found.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a[10],p;
int i, top, bot, mid;
cout<<"Type 10 real numbers in ascending order \n";
for(i=0;i<10;i++)
{
cin>>a[i];
}
top=0;
bot=9;
cout<<"\n Type the no you want to search \n";
cin>>p;
mid=(top+bot)/2;
while((top<=bot)&&(a[mid]!=p))
{
if(p<a[mid])
bot=mid-1;
else
top=mid+1;
mid=(top+bot)/2;
}
if(a[mid]==p)
{
cout<<"The no is at position="<<(mid+1)<<"\n";
cout<<"\n The binary search is successful";
}
else
{
cout<<"\n Oh the search is unsuccessful";
cout<<"\n The no is not found in entire list \n";
}
getch();
}

Output:
Experiment No. 4
a) Write a function in C++ to i/p the given string (including spaces) and
reverses it using function which locates the end of the string and swap the
first character with the last character, the second character with the second
last character and so on.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void swap(char *rev);
void main()
{
clrscr();
char str[80];
cout<<"\n Enter string= \n";
cin.getline(str,80);
cout<<"\n The original string is="<<str;
swap(str);
cout<<"\n After swapping string is="<<str;
getch();
}
void swap(char *rev)
{
strrev(rev);
}
Output:
Experiment No. 5
a) Write a program in C++ with ratio class using member functions like assign
() function to initialise its member data (integer numerator and
denominator), convert () function to convert the ratio into double, invert ()
function to get the inverse of the ratio and print () function to print the ratio
and reciprocal.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
class ratio
{
private:
int num,den;
float f,ref;
double n;
public:
void assign();
void convert();
void invert();
void print();
};
void ratio::assign()
{
cout<<" Enter the numerator of the ratio\n";
cin>>num;
cout<<"Enter the denominator of the ratio\n";
cin>>den;
f=(float)num/den;
}
void ratio::convert()
{
n=f;
}
void ratio::invert()
{
ref=1/f;
}
void ratio::print()
{
cout<<"\n The original ratio is=\n"<<f;
cout<<"\n The reciprocal of the ratio is=\n"<<ref;
}
void main()
{
clrscr();
ratio obj;
obj.assign();
obj.convert();
obj.invert();
obj.print();
getch();
}

Output:

Experiment No. 6
a) Implement a circle class in C++ Each object of this class will represent a
circle, storing its radius and x and y co-ordinates of its centre as floats.
Include a default constructor, access functions, an area () function on and
a circumference() function. The program must print the co-ordinates with
radius, area and circumference of the circle.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<conio.h>
#include<iostream.h>
class circle
{
private :
float x,y,pi,rad;
public:
circle()
{
pi=3.14;
}
void accept()
{
cout<<”enter x co-ordinates \n”;
cin>>x;
cout<<”enter y co-ordinates \n”;
cin>>y;
cout<<”enter radius \n”;
cin>>rad;
}
void display()
{
cout<<"X-co-ordinate of circle is:"<<x<<endl;
cout<<"Y-co-ordinate of circle is:"<<y<<endl;
}
void area()
{
float ar= pi*rad*rad;
cout<<"\n area of the circle is = "<<ar;
}
void circum()
{
float cr= 2*pi*rad;
cout<<"\n Circumference of the circle is "<<cr;
}
};
void main()
{
clrscr();
circle c;
c.accept();
c.display();
c.area();
c.circum();
getch();
}

Output:

Experiment No. 7
a) Write a program in C++ that initialises a Static 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.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
class ratio
{
public:
ratio()
{
cout<<"Object is BORN"<<endl;
}
~ratio()
{
cout<<"Object DIES"<<endl;
}
};
void main()
{
clrscr();

{
ratio x;
cout<<"Now X is alive"<<endl;
}
getch();
}
Output:

Experiment No. 8
a) Write a program in C++ with a complex constructor to add the given two
complex numbers A =______ and B = ______. The program should print
the given complex number and their sum.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
class complex
{
private:
float x; //real
float y; //imaginary
public:
complex() { }
complex(float real, float imag)
{ x=real;
y=imag;
}
void display()
{
cout<<x<<"+"<<y<<"i \n";
}

complex operator + (complex c)


{
complex temp;
temp.x = x + c.x;
temp.y = y + c.y;
return ( temp );
}
};
void main()
{
clrscr();
complex c1, c2, c3;
c1 = complex (3.2,2.5);
c2 = complex (4.5,2.5);
c3 = c1 + c2 ;
cout<<"First Object :";
c1.display();
cout<<"\n Second Object :";
c2.display();
cout<<"\n---------------------------------------------";
cout<<"\n Result:";
c3.display();
getch();
}
Output:

Experiment No. 9
a) Write a program in C++ 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 e.g. “BOB”) of class
person. The program must then assign p to point at an instance y (name of
student, e.g. “TOM”) of the derived class student.
b) Define a print () function in the base class such that it invokes the same
base class function to print the name of the name of the student.
c) Enter the program and verify proper execution on the same Computer.
d) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
class person
{
public :
virtual void print()
{
cout<<"\nName of the person assigned through base object is BOB”<<endl;
}
};
class student:public person
{
public:
void print()
{
cout<<"\nName of the person assign through derived class is
TOM"<<endl;
}
};
void main()
{
clrscr();
person *p,x;
student y;
p=&x;
p->print();
p=&y;
p->print();
getch();
}
Output:

Experiment No. 10
a) Write a program in C++ to read the name of country from one text file and
name of its corresponding capital city from another text file. The program
must display the country name and indicate its corresponding capital (for
at least five countries) in the output.
b) Enter the program and verify proper execution on the same Computer.
c) Obtain a hardcopy of the program listing as well as output.
Program:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();
ofstream fout;
fout.open("Country");
fout<<"USA\n";
fout<<"UK\n";
fout<<"SA\n";
fout<<”India\n”;
fout<<”Srilanka\n “;
fout.close();
fout.open("Capital");
fout<<"Washington\n";
fout<<"London\n";
fout<<"Seol\n";
fout<<”Delhi\n “;
fout<<”Colombo\n”;
fout.close();
const int n=80;
char line [n];
ifstream fin;
fin.open("Country");
cout<<"\n Contents of Country file\n";
while(fin.eof()==0)
{
fin.getline(line,n);
cout<<line<<endl;
}
fin.close();
fin.open("Capital");
cout<<"\n Contents of Capital file\n";
while(fin.eof()==0)
{
fin.getline(line,n);
cout<<line<<endl;
}
fin.close();
getch();
}
Output:

Experiment No. 11
a) Create a simple HTML page on 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 hyperlink
to other pages. The paragraphs must have text consisting of different colors
and styles in terms of alignment and Font Size.
b) Save the file and view the same using any HTML Browser. Verify
functioning of the hyperlink.
c) Obtain a hardcopy of the HTML code only.
Program:
<html>
<head>
<title>INFOSYS</title>
</head>

<body bgcolor="yellow">
<marquee><font color="blue" size="8"> Welcome
ToINFOSYS</font></marquee>
<hr>
<h2><center>ABOUT</center></h2>
<font color="red" size="5"><p>
Infosys is a global leader in consulting, technology, outsourcing and next-
generation services. We enable clients in more than 50 countries to outperform
the competition and stay ahead of the innovation curve. US$ 9.5 billion in LTM
revenues and 194,000+ employees, we are helping enterprises renew themselves
while also creating new avenues to generate value.
</font></p>
<hr>
<h2><center>CAREER</center></h2>
<font color="green" size="5"><p>
You will take bottom-line responsibility for the project. You will build the
project team, review progress, mitigate risk, ensure successful delivery and
implementation. You will take ownership of your team and their performance.
</font></p>
<hr>
<h2><center>CONTACT US</center></h2>
<font color="aqua" size="5"><p>
India
HRD - Recruitment<br>
Infosys Limited<br>
No. 44, Electronics City<br>
Bangalore - 560 100<br>
Fax: +91 80 2852 0851<br>
Website:-
<a href="www.infosys.com">INFOSYS</a>
</font></p>

</body>
</html>

Output:
Experiment No. 12
a) Create a simple HTML page on 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 last 5 rows and 3 columns
having merged cells at least at 1 place. The page must also display an
image, 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 hyperlink to
another page.
b) Save the file and view the same using any HTML Browser offline. Verify
functioning of the hyperlinks.
c) Obtain a hardcopy of the HTML code only.
Program:
<html>
<head>
<title>WIPRO</title>
</head>
<body bgcolor="aqua">
<marquee><font color="black" size="8"> Welcome To
Wipro</font></marquee>
<a href="www.wirpo.com"><img
src="file:///C:/Documents%20and%20Settings/admin/Desktop/wipro.png"
width=40% height=200 alt="WIPRO">
</img></a>
<hr>
<h2><center>ABOUT</center></h2>
<font color="red" size="5"><p>
Wipro Ltd (NYSE:WIT) is a global information technology, consulting and
outsourcing company with 170,000+ workforce serving clients in 175+ cities
across 6 continents. The company posted revenues of $7.7 Billion for the
financial year ended Mar 31, 2016.
</font></p>
<hr>
<h2><center>CAREER</center></h2>
<font color="green" size="5"><p>
<table border="2">
<tr>
<th>Campus</th>
<th> Work with Us</th>
<th colspan="2"> staffing partners </th>
</tr>
<tr>
<td> Engineering</td>
<td> Job Search </td>
<td>Permanant Staffing </td>
<td> Contractual Staffing </td>
</tr>
<tr>
<td> MBA</td>
<td> Hiring Process </td>
<td> ABC </td>
<td> XYZ </td>
</tr>
<tr>
<td> Science Graduates </td>
<td> Wipro Americas </td>
<td> DEF </td>
<td> UVW</td>
</tr>
</table>
</font></p>
<hr>
<h2><center>CONTACT US</center></h2>
<font color="orange" size="5"><p>
Wipro Limited<br>
Doddakannelli, Sarjapur Road, <br>
Bangalore - 560035<br>
Phone: +91 80 28440011 <br>
Fax No: +91 80 28440256
Website:-
<a href="www.wipro.com">WIPRO</a>
</font></p>
</body>
</html>

Output:

You might also like