2nd PUC Labmanual - Final
2nd PUC Labmanual - Final
#include<iostream.h>
#include<conio.h>
class frequency
{
private:
int a[20],i,n,ele,freq;
public:
void input();
void find();
void display();
};
void frequency::input()
{
cout<<"Enter the number of elements:";
cin>>n;
cout<<"Enter array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to be searched:";
cin>>ele;
}
void frequency::find()
{
freq=0;
for(i=0;i<n;i++)
if(ele==a[i])
freq++;
}
void frequency::display()
{
if(freq>0)
cout<<ele<<" is present "<<freq<<"\t times";
else
cout<<ele<<"\t does not exist";
}
void main()
{
frequency F;
clrscr();
F.input();
F.find();
F.display();
getch();
}
Output 1:
Enter the number of elements: 5
Enter array elements: 10 20 30 30 40
Enter the element to be searched: 30
30 is present 2 times
Output 2:
public:
void input();
void process();
void display();
};
void insertion::input()
{
cout<<"Enter the number of elements:";
cin>>n;
cout<<"Enter array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to be inserted:";
cin>>ele;
cout<<"Enter the position of element to be inserted:";
cin>>pos;
}
void insertion::process()
{
if(pos>n)
{
cout<<"Invalid position";
getch();
exit(0);
}
else
{
for(i=n-1;i>=pos;i--)
a[i+1]=a[i];
a[pos]=ele;
n++;
}
}
void insertion::display()
{
cout<<"Array elements after insertion: ";
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
void main()
{
insertion I;
clrscr();
I.input();
I.process();
I.display();
getch();
}
Output 1:
Enter the number of elements: 5
Enter array elements: 2 3 5 6 7
Enter the element to be inserted: 4
Enter the position of element to be inserted: 2
Array elements after insertion: 2 3 4 5 6 7
Output 2
Enter the number of elements: 5
Enter array elements: 10 20 30 40 50
Enter the element to be inserted: 70
Enter the position of element to be inserted: 8
Invalid position
3.Write a C++ program to delete an element from an array from a given
position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Deletion
{
private:
int a[20],i,n,ele,pos;
public:
void input();
void remove();
void display();
};
void Deletion::input()
{
cout<<"Enter the total number of elements:";
cin>>n;
cout<<"Enter array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the position of element to be deleted:";
cin>>pos;
}
void Deletion::remove()
{
if(pos<n)
{
ele=a[pos];
for(i=pos;i<n-1;i++)
a[i]=a[i+1];
n--;
cout<<ele<<" is deleted"<<endl;
}
else
{
cout<<"Invalid position";
getch();
exit(0);
}
}
void Deletion::display()
{
cout<<"Array elements after deletion"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
void main()
{
Deletion D;
clrscr();
D.input();
D.remove();
D.display();
getch();
}
Output 1 :
Output 2:
Enter the total number of elements:5
Enter array elements: 5 10 15 20 25
Enter the position of element to be deleted:8
Invalid position
4. Write a C++ program to sort the element of an array in ascending order
using insertion sort.
#include<iostream.h>
#include<conio.h>
class sort
{
private:
int a[20],i,n;
public:
void input();
void process();
void display();
};
void sort::input()
{
cout<<"Enter the number of elements:";
cin>>n;
cout<<"Enter array elements:";
for(i=0;i<n;i++)
cin>>a[i];
}
void sort::process()
{
int j,temp;
for(i=1;i<n;i++)
{
j=i;
while(j>=1)
{
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
j--;
}
}
}
void sort::display()
{
cout<<"Array elements after sorting"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
void main()
{
sort S;
clrscr();
S.input();
S.process();
S.display();
getch();
}
Output 1:
Enter the number of elements: 5
Enter array elements:5 2 8 3 1
Array elements after sorting1 2 3 5 8
5. Write a C++ program to search for a given element in an array using
binary search method.
#include<iostream.h>
#include<conio.h>
class Search
{
private:
int a[20],i,n,ele,mid,loc,b,e;
public:
void input();
void binarysearch();
void display();
};
void Search::input()
{
cout<<"Enter the number of elements:";
cin>>n;
cout<<"Enter array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to be searched:";
cin>>ele;
}
void Search::binarysearch()
{
b=0,e=n-1,loc=-1;
while(b<=e)
{
mid=(b+e)/2;
if(ele==a[mid])
{
loc=mid;
break;
}
else if(ele<a[mid])
e=mid-1;
else
b=mid+1;
}
}
void Search::display()
{
if(loc>=0)
cout<<ele<<" is present at"<<loc<<endl;
else
cout<<ele<<" does not exist";
}
void main()
{
Search S;
clrscr();
S.input();
S.binarysearch();
S.display();
getch();
}
Output 1:
Enter the number of elements:5
Enter array elements:5 6 7 9 10
Enter the element to be searched:7
7 is present at2
Output 2:
Enter the number of elements:5
Enter array elements:3 4 5 6 7
Enter the element to be searched:9
9 does not exist
6. Write a C++ program to create a class with data members principal,
time and rate. Create a member function to accept data values, to compute
simple interest and to display the result.
#include<iostream.h>
#include<conio.h>
class Simple
{
private:
float p,t,r,si;
public:
void input();
void calculate();
void display();
};
void Simple::input()
{
cout<<"Enter principal amount,time and rate of interest:";
cin>>p>>t>>r;
}
void Simple::calculate()
{
si=(p*t*r)/100;
}
void Simple::display()
{
cout<<"Principal amount:"<<p<<endl;
cout<<"Time:"<<t<<endl;
cout<<"Rate of interest:"<<r<<endl;
cout<<"Simple Interest:"<<si;
}
void main()
{
Simple S;
clrscr();
S.input();
S.calculate();
S.display();
getch();
}
Output:
Enter principal amount,time and rate of interest:1000 2 1.5
Principal amount:1000
Time:2
Rate of interest:1.5
Simple Interest:30
7. Write a C++ program to create a class with data members a, b, c and
member functions to input data, compute the discriminates based on the
following conditions and print the roots.
1) If discriminates = 0, print the roots are equal and their value.
2) If discriminates > 0, print the real roots and their values.
3) If discriminates < 0, print the roots are imaginary and exit the program.
#include<conio.h>
#include<math.h>
#include<process.h>
class quadratic
{
private:
double a,b,c,r1,r2,d;
public:
void getdata();
void compute();
void display();
};
void quadratic:: getdata()
{
cout<<"Enter the co-efficients:"<<endl;
cin>>a>>b>>c;
}
void quadratic::compute()
{
d=b*b-4*a*c;
if(d==0)
{
cout<<"Roots are equal"<<endl;
r1=(-b-sqrt(d))/(2*a);
r2=r1;
}
else if(d>0)
{
cout<<"Roots are different"<<endl;
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
}
else
{
cout<<"roots are imaginary"<<endl;
getch();
exit(0);
}
}
void quadratic::display()
{
cout<<"first root="<<r1<<endl;
cout<<"Second root="<<r2;
}
void main()
{
quadratic q;
clrscr();
q.getdata();
q.compute();
q.display();
getch();
}
Output 1
Enter the co-efficients:
242
Roots are equal
first root=-1
Second root=-1
Output 2:
Enter the co-efficients:
1 3 -4
Roots are different
first root=1
Second root=-4
Output 3:
Enter the co-efficients:
325
roots are imaginary
8. Write a C++ program to find the area of square/ rectangle/ triangle
using function overloading.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class funoverload
{
public:
float area(float a)
{
return a*a;
}
float area(float l, float b)
{
return l*b;
}
float area(float a, float b, float c)
{
float s;
s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
};
void main()
{
funoverload F;
clrscr();
cout<<"\nArea of square="<<F.area(2.5);
cout<<"\nArea of rectangle="<<F.area(10.5,20.5);
cout<<"\nArea of triangle="<<F.area(3.5,4.5,5.0);
getch();
}
Output:
Area of square=6.25
Area of rectangle=215.25
Area of triangle=7.64853
Program
#include<iostream.h>
#include<conio.h>
#include<math.h>
class series
{
private:
int sum,x,i,n;
public:
series()
{
sum=1;
}
void getdata()
{
cout<<"Enter the value for X and N"<<endl;
cin>>x>>n;
}
void display()
{
cout<<"sum of series is:"<<sum;
}
void calculate();
};
void series::calculate()
{
for(int i=1;i<=n;i++)
sum=sum+pow(x,i);
}
void main()
{
series s;
clrscr();
s.getdata();
s.calculate();
s.display();
getch();
}
Output:
Enter the value for X and N
2 3
sum of series is:15
11. Create a base class containing the data member roll number and
name. Also create a member function to read and display the data using
the concept of single level inheritance. Create a derived class that contains
marks of two subjects and total marks as the data members.
#include<iostream.h>
#include<conio.h>
class Student
{
private:
int rollno;
char name[20];
public:
void input1()
{
cout<<"Enter roll number"<<endl;
cin>>rollno;
cout<<"Enter the name:";
cin>>name;
}
void display1()
{
cout<<"\nRoll Number:"<<rollno;
cout<<"\nStudent details are:"<<endl;
cout<<"\nStudent Name:"<<name;
}
};
class mark: public Student
{
private:
int m1,m2,total;
public:
void input2()
{
cout<<"\nEnter marks in two subjects:"<<endl;
cin>>m1>>m2;
}
void display2()
{
total=m1+m2;
cout<<"\nSubject Mark1:"<<m1;
cout<<"\nsubject Mark2:"<<m2;
cout<<"\nTotal Marks:"<<total;
}
};
void main()
{
mark R;
clrscr();
R.input1();
R.input2();
R.display1();
R.display2();
getch();
}
Output:
Enter roll number
123
Enter the name: Ajay
Enter marks in two subjects:
45 78
Roll Number:123
Student details are:
Student Name: Ajay
Subject Mark1:45
subject Mark2:78
Total Marks:123
12. Create a class containing the following data members Register No,
Name and Fees. Also create a member function to read and display the
data using the concept of pointers to objects.
Program:
#include<iostream.h>
#include<conio.h>
class Student
{
private:
int regno;
char name[20];
float fees;
public:
void input()
{
cout<<"Enter register number:";
cin>>regno;
cout<<"Enter the name:";
cin>>name;
cout<<"Enter the fees:";
cin>>fees;
}
void display()
{
cout<<endl<<"Student details are..."<<endl;
cout<<"Register number="<<regno<<endl;
cout<<"Name="<<name<<endl;
cout<<"Fees="<<fees<<endl;
}
};
void main()
{
Student s,*sp;
clrscr();
sp=&s;
sp->input();
sp->display();
getch();
}
Output:
Enter register number:1234
Enter the name:Rajesh
Enter the fees:5000
Solution:
..
..
..
****************************************
PROGRAM 2:
Create a student database and compute the results.
Solutions:
5) mysql> update student set result='pass' where (sub1>34 and sub2>34 and sub3>34 and
sub4>34 and sub5>34 and sub6>34);
mysql> update student set result='fail' where (sub1<35 or sub2<35 or sub3<35 or sub4<35 or
sub5<35 or sub6<35);
*************************************
PROGRAM 3
Generate the Employee details and compute the salary based on the department.
(Assume the DEPARTMENT names as Purchase (Id-01), Accounts (Id-02), Sales (Id-03),and
Apprentice (Id-04))
3. Enter 10 rows of data for table EMPLOYEE and 4 rows of data for DEPARTMENT table.
4. Find the names of all employees who work for the Accounts department.
6. What is the Minimum, Maximum and Average salary of employees working for Accounts
department?
8. Retrieve the department names for each department where only one employee works.
10. Add a new Colum to the table EMPLOYEE called BONUS NUMBER (5) and compute 5%of the
salary to the said field.
11. Delete all the rows for the employee in the Apprentice department.
Solution:
1. mysql> create table employee(eid int(4),did int(2),ename varchar(25),salary int(5));
...
..
..
4. mysql> select * from employee where did=(select did from department where dname='accounts');
5. mysql> select count(*) from employee where did=(select did from department where dame='accounts');
6. mysql> select count(*) from employee where did=(select did from department where dname='accounts');
mysql> select max(salary) from employee where did=(select did from department where
dname='accounts');
mysql> select avg(salary) from employee where did=(select did from department where
dname='account');
7. mysql> select * from employee where did=(select did from department where supervisor='deep singh');
8. mysql> select dname from department where did in(select did from employee group by did having
count(*)=1);
9. mysql> update employee set salary=salary+salary*0.15 where did=(select did from department where
dname='sales');
10. mysql> alter table employee add (bonus float(6,2));
11. mysql> delete from employee where did=(select did from department where dname='apprentice');
***************************************************
Program 4:
4. Create database for bank transaction
Create the bank database for ABC Bank with following structure.
Acc No INT(10)
Balance Int(10)
DOT date
Tamt Int(6)
Ttype Char(2)
4. How many customer whose balance amount is less than minimum in the account.
Solution:
..
..
...
7. mysql> select * from bank where acctype='CA'; (Note down the output)
21. Write an HTML program to create study time table.
<html>
<head>
<title>study time table</title>
</head>
<body bgcolor="yellow"text="black"><B>
<center><h2>SOUNDARAYA PU COLLEGE</h2>
<h3>STUDY TIME TABLE</h3>
<table border="8" bgcolor="red">
<tr>
<th>DAYS</th>
<th>10:00 -11:00</th>
<th>11:00-12:00</th>
<th rowspan="7" > Break </th>
<th>12:30-1:30</TH>
<th>1:30-2:30</th>
</th>
<tr>
<th>MONDAY</th>
<th>Lan-1</th>
<th>comp.sc</th>
<th>Acc</th>
<th> Eco</th>
</tr>
<tr>
<th>TUESDAY</th>
<th>Lan-2</th>
<th>Bus</th>
<th>Com.Sc</th>
<th> B/S </th>
</tr>
<tr>
<th>WEDNESDAY</th>
<th>Acc</th>
<th>B/S</th>
<th>Bus</th>
<th>Lan-1</th>
</tr>
<tr>
<th>THURSDAY</th>
<th>B/S</th>
<th>Comp.Sc</th>
<th>Eco</th>
<th>Lan-2</th>
</tr>
<tr>
<th>FRIDAY</th>
<th>Acc</th>
<th>Eco</th>
<th>Comp.Sc</th>
<th>Lan-1</th>
</tr>
<tr>
<th>SATURDAY</th>
<th>Lan-2</th>
<th>Eco</th>
<th>B/s</th>
<th>Comp.Sc</th>
</tr>
</table>
</body>
</html>
Output:
22. Create an HTML program with table and form.
<html>
<head>
<title>Application Form</title>
</head>
<tr>
<td align="left"><b>Father name:</b></td>
<td><input type="text" name="Father name:">
</tr>
</td>
<tr>
<td align="left"><b>Mother name:</B></td>
<td><input type="text" name="Mother name">
</tr>
</td>
<tr>
<td align="left"><b>Sex</b> </td>
<td><input type="radio" name="Sex" value =
"Male">Male
<input type="radio" name="Sex" value =
"Female">Female</td>
</tr>
<tr>
<td><b>Address:</b></td>
<td><input type="text" name="Add":></td>
</tr>
<tr>
<td><b>Contact number</b>:</td>
<td><input type="text" ></td>
</tr>
<tr>
<td><b>Select Course:</b></td>
<td align="left" name="course">
<br>
<tr>
<td align="left"><b>Languages known:</b> </td>
<td><input type="checkbox" name="Subject" value
=" Kan">Kannada
<input type="checkbox" name="Subject" value
="Hin">Hindi
<input type="checkbox" name="Subject" value
="Eng">English
</tr>
<tr>
<td align="right"><input type="button"
value="Submit" align="right"></td>
<td align="left"><input type="reset" value="Reset"
align="center"></td>
</tr>
</table>
</form>
</body>
</html>
OUTPUT: