You are on page 1of 25

Expt. No. 1: Exchanging data of two numbers using pointers.

Aim:Write a function in C++ that exchanges data (passing by reference)


using swap function to interchange the given two numbers.
#include<iostream.h>
#include<conio.h>
void swap(double &x,double &y);
void main()
{
double a,b;
clrscr();
cout<<"enter two nos.:";
cin>>a>>b;
cout<<"\nbefore swapping:";
cout<<"\n a="<<a<<"\t"<<"b="<<b;
swap(a,b);
cout<<"\nafter swapping:";
cout<<"\n a="<<a<<"\t"<<"b="<<b;
getch();
}
void swap(double &x,double &y)
{
double temp;
temp=x;
x=y;
y=temp;
}
Expt. No. 2: Sorting an array of integers using Bubble Sort method.
Aim: Write a program in C++ that first initializes an array of given 10 real
numbers. The program must sort numbers in ascending order using Bubble
Sort method. It should print the given list of numbers as well as the sorted
list
#include<iostream>
#include<conio.h>
void main()
{
int n, i, arr[50], j, temp;
cout<<"Enter the Size (max. 50): ";
cin>>n;
cout<<"Enter "<<n<<" Numbers: ";
for(i=0; i<n; i++)
cin>>arr[i];
cout<<"\nSorting the Array using Bubble Sort Technique..\n";
for(i=0; i<(n-1); i++)
{
for(j=0; j<(n-i-1); j++)
{
if(arr[j]>arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
cout<<"\nArray Sorted Successfully!\n";
cout<<"\nThe New Array is: \n";
for(i=0; i<n; i++)
cout<<arr[i]<<" ";
cout<<endl;

}
Expt. No. 3: Searching a number in an array using Binary Search technique.
Aim: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 to
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”.
#include <iostream.h>
#include <conio.h>
void main()
{
int n,i,beg,end,mid,flag;
n=10;flag=0;
double a[10],x;
clrscr();
cout<<"Enter sorted array:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\nEnter the no. that is to be searched:";
cin>>x;
beg=0;
end=n-1;
while(beg<=end)
{
mid=(beg+end)/2;
if(x==a[mid])
{
flag=1;
break;
}
if(x<a[mid])
end=mid-1;
else
beg=mid+1;
}
if(flag==1)
cout<<"\nThe no. is found at location: "<<mid+1;
else
cout<<"\nThe no. is not found";
getch();
}
Expt. No. 4: Printing start & end address of elements of array along with
sum.
Aim: Write a program in C++ that first initializes an array of five given
numbers (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 size of the number to which it points. The
program must also print the sum and pointer address with the addition of
every number as well as the ending address.
# include <iostream.h>
# include <conio.h>
void main()
{
float a[]={10.2,3.9,4.6,5.5,6.9};
float *ptr, sum=0;
ptr=a;
clrscr();
cout<<"\nStarting address \tSize \t\tEnding address \t\tValue of sum";
for(int i=0;i<5;i++)
{
sum=sum+*ptr;
cout<<"\n"<<ptr<<"\t\t"<<sizeof(*ptr)<<"\t\t";
ptr=ptr+1;
cout<<ptr<<"\t\t"<<sum;
}
getch();
}
Expt. No. 5: Reversing a string.

Aim: Write a program in C++ to input the given string (including spaces)
and reverse it using function which locates the end of the string and swaps
the first character with the last character, the second character with second
last character and so on.

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
void swap(int length,char s[]);
void main()
{
int len;
char str[100];
clrscr();
cout<<"Enter the string:";
gets(str);
len=strlen(str);
swap(len,str);
cout<<"\nReverse of the given string is:"<<str;
getch();
}
void swap(int length,char s[])
{char temp;
int l=length-1;
for(int i=0;i<length/2;i++)
{
temp=s[i];
s[i]=s[l];
s[l]=temp;
l--;
}
}
Expt. No. 6: Implementing class Ratio with member functions like assign,
convert & invert.
Aim:Write a program in C++ with a Ratio class using member functions like
assign() function to initialize its member data (integer numerator and
denominator), convert() function to convert the ratio into double, invert()
function to get the reverse of the ratio and print() function to print the ratio
and its reciprocal.
#include<iostream.h>
#include<conio.h>
class Ratio
{
private:
int numerator,denominator;
public:
void assign(int n,int d);
double convert();
void invert();
void print();
};
void Ratio::assign(int n,int d)
{numerator=n,denominator=d;}
double Ratio::convert()
{return(double)numerator/denominator;}
void Ratio::invert()
{
int temp;
temp=numerator;
numerator=denominator;
denominator=temp;
}
void Ratio::print()
{cout<<numerator<<"/"<<denominator;}
void main()
{
int x,y;Ratio r;
clrscr();
cout<<"Enter numerator and denominator:";
cin>>x>>y;
r.assign(x,y);
cout<<"\nThe Ratio is";
r.print();
cout<<"="<<r.convert();
cout<<"\nThe reciprocal is";
r.invert();
r.print();
cout<<"="<<r.convert();
getch();
}
Expt. No. 7: Implementing class Circle with default constructor & accessing
functions like area and circumference.
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 and a
circumference() function. The program must print the co-ordinates with
radius, area and circumference of the circle.
Program:
include<iostream.h>
#include<conio.h>
class circle
{
private: float x,y,radius;
public: circle();
void getdata();
void area();
void circumference();
void print();
};
circle::circle()
{
x= 0.0;
y=0.0;
radius=0.0;
}
void circle::getdata()
{
cout<<”\n Enter the coordinates:”;
cin>>x>>y;
cout<<”\n Enter radius:”;
cin>>radius;
}
void circle::area()
{
cout<<”\nArea=”<<(3.14*radius*radius);
}

void circle::circumference()
{
cout<<”\nCircumference=”<<(2*3.14*radius);
}
void circle::print()
{
cout<<”\nCircle details are as follows:”;
cout<<”\nX=”<<x<<”\nY=”<<y;
cout<<”\nRadius=”<<radius;
area();
circumference();
}

void main()
{
circle c;
clrscr();
c.getdata();
c.print();
getch();
}
Expt. No. 8: Implementing class Ratio with three constructors.

Aim: Write a program in C++ that initializes a Ratio class with no


parameters as a default constructor. Add a constructor having no
parameters that initializes the declared object with the default integer
values 0 and 1. Add another constructor that has one integer parameter.
This constructor must initialize the object to be the fractional equivalent of
that integer. The output should print the ratio as per the constructors.

#include<iostream.h>
#include<conio.h>
class Ratio
{
private:
int num,den;
public:
Ratio()
{
num=0;
den=1;
}
Ratio(int n)
{
num=n;
den=1;
}
Ratio(int n,int d)
{num=n;
den=d;
}
void print()
{
cout<<num<<"/"<<den<<endl;
}
};
void main()
{
clrscr();
Ratio x,y(5),z(23,8);
cout<<"x=";
x.print();
cout<<"y=";
y.print();
cout<<"\z=";
z.print();
getch();
}
Expt. No. 9: Study scope of an object using constructor & destructor.

Aim: 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.

#include<iostream.h>
#include<conio.h>
class Ratio
{
public:

Ratio()
{ cout<<”OBJECT IS BORN”<<endl; }

~Ratio()
{ cout<<”OBJECT DIES”<<endl; }

void x()
{ cout<<”NOW X IS ALIVE”<<endl;}
};

void main()
{
clrscr();
Ratio r;
r.x();
}
Expt. No. 10: Implementing inheritance.
Aim: Write a program in C++ to implement the following class hierarchy.
Class Student to obtain Roll no., Class Test to obtain marks in two different
subjects, Class Sports to obtain weightage in sports, and class Result to
calculate total marks. The program must print the roll no., individual marks
obtained in two subjects, sports and total marks.

Student

Test Sports

Result

Program:

# include<iostream.h>
# include<conio.h>

class student
{
private: int rollno;
public:
void setno(int a)
{ rollno=a; }

void putno()
{ cout<<"\n roll no:"<<rollno; }
};

class test:public student


{
protected:float sub1,sub2;
public:
void setmarks(float x,float y)
{ sub1=x; sub2=y; }
void putmarks()
{
cout<<"\n marks in sub 1:"<<sub1;
cout<<"\n marks in sub 2:"<<sub2;
}
};

class sports
{
protected:float score;
public:
void setscore(float s)
{ score=s; }
void putscore()
{ cout<<"\n sports score weightage:"<<score; }
};

class result:public test,public sports


{
private:float total;
public:
void display()
{
total=sub1+sub2+score;
putno();
putmarks();
putscore();
cout<<"\n total marks:"<<total<<endl;
}
};

void main()
{
int rn;
float s1,s2,sc;
result r;
cout<<"\n Enter students info";
cout<<"\n roll no:";
cin>>rn;
r.setno(rn);
cout<<"\n enter marks 1:";
cin>>s1;
cout<<"\n enter marks 2:";
cin>>s2;
r.setmarks(s1,s2);
cout<<"\n weightage in sports: ";
cin>>sc;
r.setscore(sc);
cout<<"\n The students details are as follows :";
r.display();
}
Expt. No. 11: Using Virtual function.
Aim: Write a program in C++ using virtual function. The program must
declare P to be a pointer to object of the base class Person. First, the
program must assign P to point to an instance x (name of the person for eg.
BOB) of class Person. The program must then assign P to point to an
instance y (name of the Student eg. TOM) of the derived class Student.
Define a print function in the base class to print the name of the Person.
The second call to the print function must print the name of the Student
using derived class’s print function.

#include<iostream.h>
#include<conio.h>
class Person
{
public:
virtual void print()
{cout<<"\n THe name of the person is BOB";
}
};
class Student:public Person
{
public:
void print()
{
cout<<"\n The name of the student is TOM";
}
};
void main()
{
clrscr();
Person *P;
Person p1;
P=&p1;
P->print();
Student s1;
P=&s1;
P->print();
getch();
}
Expt. No. 12: To find sum of first 10 numbers using Do Loop.
Aim:
a) Write a program in Visual Basic to find the sum of first 10 nos. using Do
loop.
Program:
Sr. No. Control type Property Value
Name cmdAdd
1 Command Button
Caption Add
Name CmdExit
2 Command Button
Caption Exit
Name txtResult
3 Text Box
Visible False
Private Sub Command1_Click()
Dim a, i, sum As Integer
i=0
sum = 0
a=0
Do While i < 10
a = InputBox("Enter Numbeer", "Sumof 10 Numbers")
sum = sum + a
i=i+1
Loop
txtresult.Text = sum
End Sub

Private Sub Command2_Click()


End
End Sub
Expt. No. 13: Calculating area of circle and rectangle based on selection.
Aim: Write a program in Visual Basic that calculates area on selection of
two shapes-circle & rectangle.
Program:
Sr. No. Control type Property Value
Name cmbShape
1 ComboBox
Text Shape
Name Shape1
2 Shape
Visible False
Name lblRadius
3 Label
Caption Radius
Name lblLength
4 Label
Caption Length
Name lblBreadth
5 Label
Caption Breadth
Name txtRadius
6 TextBox
Text
Name txtLength
7 TextBox
Text
Name txtBreadth
8 TextBox
Text

Form1 code
Private Sub Command1_Click()
Form2.Show
End Sub
Private Sub Command2_Click()
Form3.Show
End Sub
Form2 code
Private Sub Command1_Click()
Dim r As Integer
r = Val(txtrad.Text)
txtres.Text = r * r * 3.14
End Sub
Form 3 code
Private Sub Command1_Click()
Dim l, b As Integer
l = Val(txtlen.Text)
b = Val(txtbre.Text)
txtres.Text = l * b
End Sub
Expt. No. 14: Creating Web Page with background color and hyperlink.
Aim: 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 appropriate title, background color or background image, and
hyperlinks to other pages. The paragraphs must have text consisting of
different colors and styles in terms of alignment and font size.

<html>
<head><title>FRIENDS JR COLLEGE</title></head>
<body bgcolor="yellow" text="black">
<h1 align="center"><font color="Maroon" face="broadway"><u> FRIENDS
Junior College
</u></font></h1>
<p align="center"><font color="fushia" size="6">
FRIENDS Junior College was established in 1947 with pure science and
commerce.<br>
Bifocal subjects were introduced in 2009and I.T. started in 1998.
</font></p>

<p align="left"><font color="blue" size="5">


Labs:There are 5 laboratories of each department.The science department
of the college have spacious
laboratories which are equipped with excellent apparatus and other
accesories required for smooth
conduction of practical.
</font></p>

<p align="right"><font color="red" siize="4">


Gymkhana:
The Gymkhana concentrates on a number of Indoor games such as
carom,chess,table-
tennis, etc. and Outdoor games such as volley ball, cricket, football etc.
</font></p><br>
<a href="Features.html">FRIENDS</a>
</body>
</html>

<html>
<head><title>Features of FRIENDS. Junior College</title></head>
<body>
<h1>---Features of FRIENDS. Junior College---</h1>
<ol type="1">
<li> A peaceful location </li>
<li> Up-to-date library </li>
<li> Well equipped laboratories </li>
<li> Sports ground </li>
<br>
<hr>
<br>
<a href="FRIENDS.html">Back</a>
</body>
</html>
Expt. No. 15: Working with tables and images in HTML.

Aim: Create a simple HTML page on any of the following topics: College
Profile, Computer Manufacturer, or Software Development CompanyThe
page must consist of a scrolling marquee displaying an appropriate
message. The page must include table with at least five rows and 3 columns
having merged cells at least at one 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 hyperlink to
another page

<html>
<head><title>FRIENDS.jr.collage of science</title></head>
<body bgcolor="pink">
<center><h1>Friends jr.collage of science</h1>
<a href="features1.html"><img src="logo.png"
alt="Friends.collage"height="100"
width="120"</a></center>
<marquee><h3>Updated on 1.10.2012</marquee>
<table align="center"border="1"bordercolor="black">
</tr>
<th>Department</th>
<th> colspan="3">Staff</th>
</tr>
<tr>
<td>Physic</td><td>MrHarshada</td></tr>
<tr>
<td>
Biology</td><td>Caroline Dency</td>
</tr>
<tr>
<td>Chemistry</td><td>Regina </td>
</tr>
<tr>
<td>Computer science & IT</td><td>Mrs. Anita Jeba</td>
</tr>
</table>
</body>
</html>

features.html
<html>
<head><title>Features of FRIENDS.junior College___</title>
</head>
<body>
<h1> ... Features of FRIENDS.junior College..</h1>
<ol type="1">
<li>A peaceful location</li>
<li>UP-to-date library</li>
<li>Well equipped laboratories</li>
<li>sport graound</li>
</ol>
<br>
<hr>
<br>
<a href="Friends.html">Back</a>
</body>
</html>

You might also like