CS1
CS1
Program:
#include <iostream.h>
#include <conio.h>
void main ()
{
clrscr() ;
int a[10],i,j,t ;
cout<<"enter ten numbers to sort "<<endl ;
for (i=0 ; i<10 ; i++)
{
cout<<"element no "<<i+1<<": ";
cin>>a[i];
}
for (i=0 ; i<10 ; i++)
for (j=0 ; j<9 -i ; j++)
{
if (a [j] <=a [j+1])
{
t = a[j] ;
a [j] = a [j+1] ;
a [j + 1] = t;
}
}
cout<<endl<<"the sorted list is : "<<endl;
for (i=0 ; i<10 ; i++)
{
cout<<"element no"<<i+1<<" : "<<a [i] <<endl ;
}
getch () ;
}
Experiment No. 2
a) Write a program in C++ with ratio class using member
AIM:
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)
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();
}
Experiment No. 3
AIM: 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.
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();
}
Experiment No. 4
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();
}
Experiment No. 5
AIM: 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.
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";
}
};
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<<"\nSecond Object :";
c2.display();
cout<<"\n---------------------------------------------";
cout<<"\nResult :";
c3.display();
getch();
}
Experiment No. 6
AIM: 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.
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.
#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();
}
Experiment No. 7
AIM: 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.
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();
}
Experiment No. 8
AIM: 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.
Program:
<html>
<head>
<title>INFOSYS</title>
</head>
<body bgcolor="yellow">
<marquee><font color="blue" size="8"> Welcome To
INFOSYS</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>
Experiment No. 9
AIM: 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.
<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/wi
pro.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>
Experiment No. 10
AIM: Write a program in Visual Basic that calculates area and
selections of two shapes, Circle and Rectangle.
Enter radius
Area of circle is
Length
Breadth
Experiment No. 11
a) Write a program in Visual Basic to create a Text Editor, which
has the following menu options
File Edit
New Cut
Open Copy
Save Paste
Close
Program:
Private Sub Form_Load()
WindowState = 2
End Sub
Program:
Private Sub Command1_Click()
Dim a As Integer
L = Len(Text1.Text)
a=0
If L = 0 Then
MsgBox ("Name cannot be blank")
a=a+1
End If
If IsDate(Text2.Text) <> True Then
MsgBox ("Enter Valid Date Of Birth")
a=a+1
End If
If IsNumeric(Text3.Text) <> True Then
MsgBox ("Enter Valid Telephone Number")
a=a+1
End If
If a = 0 Then
MsgBox ("entered is correct")
End If
End Sub
Program:
Private Sub Command1_Click()
Dim n As Integer
Dim s As Integer
n=1
Do While (n <= 100)
s=s+n
n=n+1
Loop
Label1.Caption = s
End Sub
Program:
Private Sub Form_Load()
Form1.WindowState = 2
End Sub
Private Sub Command1_Click()
MsgBox ("Welcome" & Text1.Text)
End Sub
End Sub
Experiment No. 15
AIM: Create a graphic editor using Visual Basic which has the
following functions: change color line width, fill color, change
border color etc. (Select any three properties to change).
Program:
Private Sub Combo1_CLick()
If Combo1.Text = "Red" Then Shape1.FillColor = vbRed
If Combo1.Text = "Green" Then Shape1.FillColor = vbGreen
If Combo1.Text = "Blue" Then Shape1.FillColor = vbBlue
End Sub
End Sub
Combo1.AddItem "Red"
Combo1.AddItem "Green"
Combo1.AddItem "Blue"
Combo2.AddItem "10"
Combo2.AddItem "20"
Combo2.AddItem "30"
Combo3.AddItem "Red"
Combo3.AddItem "Green"
Combo3.AddItem "Blue"
End Sub