XII CS1 Journal 2024 25
XII CS1 Journal 2024 25
C++ program with class ratio and assign(), convert(), invert(), print()
5
functions.
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";
}
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: