Lab Manual 2nd Year 2022
Lab Manual 2nd Year 2022
Practical manual
2nd year
PUC
pg. 1
Table of contents
C++
Sql
17. Generate electricity bill
18. Generate student database
19. Generate employee details
20. Generate bank database
Html
pg. 2
Instructions
NOTE:
If we get an error like statement missing, we have to look for the previous
line.
If we get an error like prototype missing, we have to include the respective
header file.
All the keywords,cout,cin,void has to be written only in lower case with
respect to answer script and system.
pg. 3
NOTES FOR EACH PROGRAM:
Program 11) - whenever we are using gets( ) and puts( ), we have to use
#include<stdio.h>
-in inheritance, we should always create object for derived class.
Program 12) whenever we are using gets( ) and puts( ), we have to use
#include<stdio.h>
pg. 4
C++
pg. 5
void frequency :: display( )
{
if(tally>0)
cout<<ele<<" occurs "<<tally<<" time/s";
else
cout<<ele<<" does not exist"<<endl;
}
void main( )
{
frequency obj;
clrscr();
obj.accept();
obj.calculate();
obj.display( );
getch( );
}
Output 1:
pg. 6
Output 2:
pg. 7
2: Write a C++ program to insert an element into an array at a
given position.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class insert
{
private:
int a[100],i,j,n,ele,pos;
public:
void accept();
void calculate();
void display();
};
pg. 8
void insert :: calculate( )
{
if(pos>n)
{
cout<<"position is out of array limits"<<endl;
getch( );
exit(0);
}
else
{
for(j=n-1;j>=pos;j--)
a[j+1]=a[j];
a[pos]=ele;
n=n+1;
}
}
pg. 9
Output 1:
Output 2:
pg. 10
3: Write a C++ program to delete an element from an array from
a given position.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class deletion
{
private:
int a[100],n,pos,ele,i,j;
public:
void accept( );
void calculate( );
void display( );
};
pg. 11
void deletion :: calculate( )
{
if(pos>n-1)
{
cout<<"Invalid position."<<endl;
getch();
exit(0);
}
else
{
ele=a[pos];
for(j=pos+1;j<n;j++)
a[j-1]=a[j];
n=n-1;
}
void main( )
{
deletion obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display( );
getch( );
}
pg. 12
Output 1:
Output 2:
pg. 13
4: Write a C++ program to sort the element of an array in
ascending order using insertion sort.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class sorting
{
private:
int a[100],n,i,j,temp;
public:
void accept( );
void calculate( );
void display( );
};
pg. 14
void sorting :: calculate( )
{
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=j-1;
}
}
}
void main( )
{
sorting obj;
clrscr ( );
obj.accept( );
obj.calculate( );
obj.display( );
getch( );
}
pg. 15
Output 1:
pg. 16
5: Write a C++ program to search for a given element in an array
using binary search method.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class binary
{
private: int a[100],n,ele,loc,i;
public:
void accept( );
void calculate( );
void display( );
};
void binary :: accept( )
{
cout<<"enter the number of array elements"<<endl;
cin>>n;
cout<<"enter the array elements in ascending order"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
cout<<"enter the element to search"<<endl;
cin>>ele;
}
void binary:: calculate( )
{
int beg,end,mid;
beg= 0;
end = n-1;
loc = -1;
while( beg <= end)
{
mid=(beg+end)/2;
pg. 17
if(ele == a[mid])
{
loc = mid;
break;
}
else if(ele< a[mid])
end = mid-1;
else
beg = mid+1;
}
}
void main( )
{
binary obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display( );
getch();
}
pg. 18
Output 1:
Output 2:
pg. 19
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>
#include<iomanip.h>
class simple
{
private :
double si,p,t,r;
public :
void accept( )
{
cout<<"Enter the principle amount, time and rate"<<endl;
cin>>p>>t>>r;
}
void calculate( )
{
si=(p*t*r)/100;
}
void display( )
{
cout<<"Simple Interest is "<<si<<endl;
}
};
pg. 20
void main( )
{
simple obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display( );
getch();
}
Output 1:
pg. 21
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.
If discriminates = 0, print the roots are equal and their value.
If discriminates > 0, print the real roots and their values.
If discriminates < 0, print the roots are imaginary and exit the
program
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class quad
{
private:
int a,b,c;
float disc,x,x1,x2;
public:
void accept( )
{
cout<<"Enter the values for a,b,c"<<endl; cin>>a>>b>>c;
}
void calculate( )
{
disc=b*b-4*a*c;
}
pg. 22
void display( )
{
if(disc==0)
{
cout<<"Equal roots"<<endl; x=-b/(2*a);
cout<<"Root is="<<x;
}
else if(disc>0)
{
cout<<"Real & distinct roots"<<endl;
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
cout<<"Root 1 is="<<x1<<endl;
cout<<"Root 2 is="<<x2<<endl;
}
else
cout<<"Imaginary roots"<<endl;
}
};
void main( )
{
quad obj;
clrscr( );
obj.accept( );
obj.calculate();
obj.display();
getch( );
}
pg. 23
Output 1:
Output 2:
Output 3:
pg. 24
8: Write a C++ program to find the area of square/ rectangle/
triangle using function overloading
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class function_overload
{
private:
float s;
public:
float area(float a)
{
return a*a;
}
pg. 25
void main( )
{
int choice;
float x,y,z;
clrscr();
function_overload obj;
cout<<"Enter the choice 1 or 2 or 3."<<endl;
cin>>choice;
if(choice==1)
{
cout<<"Enter the side of square."<<endl;
cin>>x;
cout<<"Area of the square is "<<obj.area(x)<<endl;
}
else if(choice==2)
{
cout<<"Enter the sides of the rectangle."<<endl;
cin>>x>>y;
cout<<"Area of the rectangle is "<<obj.area(x,y)<<endl;
}
else if(choice==3)
{
cout<<"Enter the sides of triangle."<<endl;
cin>>x>>y>>z;
cout<<"Area of the triangle is "<<obj.area(x,y,z)<<endl;
}
else
cout<<"Invalid input."<<endl;
getch( );
pg. 26
Output 1:
Output 2:
Output 3:
pg. 27
Output 4:
pg. 28
9: Write a C++ program to find cube of a number using inline
function.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class number
{
public :
inline int cube(int a)
{
return(a*a*a);
}
};
void main()
{
number obj;
int x;
clrscr();
cout<<"enter a number"<<endl;
cin>>x;
cout<<"cube of given number is : "<<obj.cube(x);
getch();
}
pg. 29
Output 1:
pg. 30
10: Write a C++ program to find sum of the series 1 + x + x2 + x3
+ ….xn using constructors.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class series
{
private:
int sum,x,n,i;
public:
series( )
{
sum=1;
}
void accept();
void calculate();
void display();
};
void series::accept( )
{
cout<<"Input the value of X"<<endl;
cin>>x;
cout<<"Input the value of n"<<endl;
cin>>n;
}
pg. 31
void series::calculate( )
{
for(i=1;i<=n;i++)
sum=sum+pow(x,i);
}
void main( )
{
series obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display();
getch();
}
Output 1:
pg. 32
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>
#include<iomanip.h>
#include<stdio.h>
class student
{
private:
int id;
char name[20];
public:
void accept( )
{
cout<<"Input Roll No."<<endl;
cin>>id;
cout<<"Input name of student."<<endl;
gets(name);
}
void display( )
{
cout<<"Roll Number : "<<id<<endl;
cout<<"Name : "<<name<<endl;
}
};
pg. 33
class report : public student
{
private:
int m1,m2,total;
public:
void input( )
{
cout<<"Enter the subject1 marks : "<<endl;
cin>>m1;
cout<<"Enter the subject2 marks : "<<endl;
cin>>m2;
}
void calculate( )
{
total=m1+m2;
cout<<"Total : "<<total<<endl;
}
};
void main( )
{
report obj;
clrscr( );
obj.accept( );
obj.display( );
obj.input( );
obj.calculate( );
getch( );
}
pg. 34
Output 1:
pg. 35
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.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
class student
{
private:
int id;
char name[20];
float fees;
public:
void accept( );
void display( );
};
void student::accept( )
{
cout<<"enter register number"<<endl;
cin>>id;
cout<<"enter the name of the student"<<endl;
gets(name);
cout<<"enter the fees"<<endl;
cin>>fees;
}
void student::display( )
{
cout<<"register number:"<<id<<endl;
cout<<"name of the student:"<<name<<endl;
cout<<"fees: "<<fees<<endl;
}
pg. 36
void main( )
{
student obj,*p;
p=&obj;
clrscr( );
p-> accept( );
p-> display( );
getch( );
}
Output 1:
pg. 37
13. Write a program to perform push operation
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
#define max 2
class stack
{
private:
int a[max], top;
public: stack()
{
top=-1;
}
void push(int item);
void print();
};
top++;
a[top]=item;
cout<<item<<"is successfully pushed"<<endl;
}
pg. 38
void stack :: print()
{
if(top != -1)
{
cout<<"Stack contains "<<endl;
for(int i=0; i<=top; i++)
cout<<setw(4)<<a[i];
cout<<endl;
}
else
cout<<"stack is empty"<<endl;
}
void main ()
{
stack s;
int choice, itm;
clrscr();
while(1)
{
cout<<endl<<"1.PUSH"<<endl<<"2.PRINT"<<endl<<"3.EXIT"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1 :
{
cout<<"Enter the item"<<endl;
cin>>itm;
s.push(itm);
break;
}
pg. 39
case 2 :
{
s.print();
break;
}
case 3 :
{
cout<<"Thankyou for visiting"<<endl;
exit(0);
}
default : cout<<"Invalid choice";
}
}
}
Output :
pg. 40
3
Thank you for visiting
pg. 41
14. Write a program to perform pop operation
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
#define max 2
class stack
{
private:
int a[max], top;
public:
stack()
{
top = -1;
}
void push(int item);
void print();
void pop();
};
void main ()
{
stack s;
int choice, itm;
clrscr();
while(1)
{
cout<<"1.PUSH"<<endl<<"2.POP"<<endl<<"3.PRINT"<<endl<<"4.EXIT"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter the item : "<<endl;
cin>>itm;
s.push(itm);
break;
}
case 2 :
{
s.pop();
break;
}
case 3:
{
s.print();
break;
pg. 43
}
case 4:
{
cout<<"Thank you, visit again";
getch();
exit(1);
}
Output:
pg. 44
2
sorry stack is empty
4
Thank you, visit again
pg. 45
15. Write a program to perform enqueue and dequeue operations
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#define max 2
class queue
{
private:
int item, i, q[max], rear, front;
public:
queue()
{
rear=0;
front=0;
}
void insert()
{
if(rear == max)
cout<<"\n queue reached max!"<<endl;
else
{
cout<<"\n Enter the value to be inserted"<<endl;
cin>>item;
q[rear++] = item;
}
}
void remove()
{
if(front == rear)
cout<<"\n queue is empty"<<endl;
else
{
cout<<q[front]<<" Element successfully removed"<<endl;
front++;
}
}
pg. 46
void display()
{
void main ()
{
int choice, exit_p = 1;
queue obj;
clrscr();
do
{
cout<<"\n 1.Insert \n 2.Remove \n 3.Display \n 4.Exit"<<endl;
cout<<"\n Enter your choice "<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
obj.insert();
break;
}
case 2:
{
obj.remove();
break;
}
case 3:
{
obj.display();
break;
}
default :
{
exit_p=0;
break;
}
}
}while(exit_p);
}
pg. 47
Output:
pg. 48
4
pg. 49
16. Write a program to insert and display elements using single linked list
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
struct node
{
int value;
struct node*next;
};
void insert();
void display();
void main ()
{
clrscr();
int option = 0;
cout<<"singly linked list \n"<<endl;
while(option<3)
{
cout<<"\n options \n";
cout<<"1.Insert into linked list \n";
cout<<"2.Display linked list \n";
cout<<"3.Exit \n";
cout<<"Enter your option"<<endl;
cin>>option;
switch(option)
{
case 1:
{
insert ();
break;
}
pg. 50
case 2:
{
display();
break;
}
void insert ()
{
cout<<"\n Enter element for inserting in linked list"<<endl;
cin>>data;
temp_node = (DATA_NODE*)malloc(sizeof(DATA_NODE));
temp_node -> value = data;
if(first_node == 0)
{
first_node = temp_node;
}
else
{
head_node -> next = temp_node;
}
temp_node -> next=0;
head_node = temp_node;
}
void display()
{
int count = 0;
temp_node = first_node;
cout<<"\n Display linked list :"<<endl;
while(temp_node!=0)
{
cout<<"\t"<<temp_node -> value;
count++;
temp_node = temp_node -> next;
}
cout<<"\n No. of items in linked list : "<<count;
}
pg. 51
Output:
pg. 52
SQL
17. Generate the electricity bill for one consumer.
Create a table for house hold electricity bill with the following fields.
FIELD NAME TYPE
RR_number Varchar2(10)
Consumer_name Varchar2(25)
Date_billing date
units Number(4)
Solution:
pg. 53
insert into ebill values('e10','j','10-aug-2022',150);
2. desc ebill;
Output:
6.
pg. 54
18
Solution:
1.
insert into student values(1,'a',90,90,90,90,90,90);
pg. 55
insert into student values(6,'f',40,40,40,40,40,40);
2.desc student;
iii)update student set result='pass' where sub1>=35 and sub2>=35 and sub3>=35 and
sub4>=35 and sub5>=35 and sub6>=35 ;
iv) update student set result='fail' where sub1<35 or sub2<35 or sub3<35 or sub4<35 or
sub5<35 or sub6<35 ;
pg. 56
Output
2.
5,6 &13
ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT
---------- ---------- ---------- -----
1 a 90 90 90 90 90 90 540 90 pass
2 b 80 80 80 80 80 80 480 80 pass
3 c 70 70 70 70 70 70 420 70 pass
4 d 60 60 60 60 60 60 360 60 pass
5 e 50 50 50 50 50 50 300 50 pass
6 f 40 40 40 40 40 40 240 40 pass
7 g 30 30 30 30 30 30 180 30 fail
8 h 20 20 20 20 20 20 120 20 fail
9 i 10 10 10 10 10 10 60 10 fail
pg. 57
7.
ID NAME
---------- -----
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
10 j
8.
ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT
---------- ---------- ---------- -----
1 a 90 90 90 90 90 90 540 90 pass
2 b 80 80 80 80 80 80 480 80 pass
3 c 70 70 70 70 70 70 420 70 pass
4 d 60 60 60 60 60 60 360 60 pass
5 e 50 50 50 50 50 50 300 50 pass
6 f 40 40 40 40 40 40 240 40 pass
pg. 58
9.
ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT
7 g 30 30 30 30 30 30 180 30 fail
8 h 20 20 20 20 20 20 120 20 fail
9 i 10 10 10 10 10 10 60 10 fail
10.
COUNT(*)
----------
6
11.
COUNT(*)
----------
4
12.
ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT
---------- ---------- ---------- -----
1 a 90 90 90 90 90 90 540 90 pass
2 b 80 80 80 80 80 80 480 80 pass
3 c 70 70 70 70 70 70 420 70 pass
pg. 59
19.
Generate the employee details and compute the salary based on the department.
Create the following employee table
Enter 10 rows of data for table employee and 4 rows of data for department table
Solution:
pg. 60
insert into employee values(1,1,'a',20000);
1.
select employee.emp_name,department.dept_name from employee,department where
employee.dept_id=department.dept_id and department.dept_name='accounts';
2.
select count(*) from employee,department where
employee.dept_id=department.dept_id and department.dept_name='accounts';
3.
select min(employee.emp_salary), max(employee.emp_salary),
avg(employee.emp_salary) from employee,department where
employee.dept_id=department.dept_id and department.dept_name='accounts';
pg. 61
4.
select * from employee where dept_id=(select dept_id from department where
supervisor='b');
5.
select dept_name from department where dept_id in(select dept_id from employee
group by dept_id having count(*)=1);
6.
update employee set emp_salary=emp_salary+emp_salary*0.15 where dept_id=(select
dept_id from department where dept_name='sales');
7.
i.alter table employee add bonus number(10,2);
8.
delete from employee where dept_id=(select dept_id from department where
dept_name='apprentice');
Output:
pg. 62
select * from department; [sample data]
1.
EMP_NAME DEPT_NAME
--------------- ---------------
b accounts
e accounts
h accounts
2.
COUNT(*)
----------
3
3.
MIN(employee.EMP_SALARY) MAX(employee.EMP_SALARY)
AVG(employee.EMP_SALARY)
----------------------- ----------------------- -----------------------
30000 90000 60000
4.
pg. 63
5.
DEPT_NAME
---------------
purchase
6.
select * from employee;
7.
select * from employee;
pg. 64
8.
pg. 65
20.
Solution:
insert into bank values(01, 'a', 'sb', 85000, '01-aug-22', 5000, 'd');
insert into bank values(02, 'b', 'sb', 80000, '02-aug-22', 5500, 'd');
insert into bank values(03, 'c', 'sb', 75000, '03-aug-22', 4000, 'd');
insert into bank values(04, 'd', 'sb', 70000, '04-aug-22', 1200, 'd');
insert into bank values(05, 'e', 'sb', 50000, '05-aug-22', 1500, 'd');
insert into bank values(06, 'f', 'ca', 999, '06-aug-22', 500, 'w');
insert into bank values(07, 'g', 'ca', 900, '07-aug-22', 200, 'w');
insert into bank values(08, 'h', 'ca', 950, '08-aug-22', 450, 'w');
insert into bank values(09, 'i', 'ca', 800, '09-aug-22', 410, 'w');
insert into bank values(10, 'j', 'ca', 700, '10-aug-22', 400, 'w');
pg. 66
1.
select cust_name from bank where balance>30000;
2.
select count(*) from bank where balance<1000;
3.
update bank set balance = balance + t_amount where t_type = 'd';
4.
select * from bank where dot = '01-aug-22';
5.
select * from bank where acc_type = 'ca';
Output:
1.
CUST_NAME
----------
a
b
c
d
e
pg. 67
2.
COUNT(*)
----------
5
3.
4.
pg. 68
5.
pg. 69
Html
<table border=20>
<tr>
<th>DAYS</th>
<th>SUBJECT</th>
<th>MORNING STUDY TIME</th>
<th>COLLEGE TIME</th>
<th>EVENING STUDY TIME</th>
<th>SOLVING QUESTION PAPER</th>
</tr>
<tr>
<td>MONDAY</td>
<td>PHYSICS</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>
<tr>
<td>TUESDAY</td>
<td>CHEMISTRY</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>
pg. 70
<tr>
<td>WEDNESDAY</td>
<td>MATH</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>
<tr>
<td>THURSDAY</td>
<td>COMPUTER</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>
<tr>
<td>FRIDAY</td>
<td>LANGUAGE</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>
</table>
<marquee>ALL THE BEST</marquee>
</body>
</html>
Output
pg. 71
22. To display table of attendance details and application form
<html>
<head>
<center><Attendance details</center>
</head>
<title>2nd Program</title>
<body>
<center><h2>Subject: Computer Science</h2></center>
<table border=10>
<tr>
<th>Months</th>
<th>No. of classes held</th>
<th>No. of classes attended</th>
</tr>
<tr>
<td>June</td>
<td>16</td>
<td>16</td>
</tr>
</table>
<table border=10>
<tr>
<center><h2>Application form</h2></center>
</tr>
<form method=get action=targetfile.html>
<tr>
<td>Student Name: </td>
<td><input type=text name= ></td>
</tr>
<tr>
<td>Gender: </td>
<td>
<input type=radio name=gender>Male
<input type=radio name=gender>Female
</td>
</tr>
pg. 72
<tr>
<td>Subject: </td>
<td>
<input type=checkbox>phy
<input type=checkbox>chem
<input type=checkbox>maths
<input type=checkbox>computer
</td>
</tr>
<tr>
<td align=right><input type=submit value=submit></td>
<td align=left><input type=reset value=reset></td>
</tr>
</form>
</table>
</body>
</html>
targetfile.html
<html>
<head>
<title></title>
</head>
<body>
Hello your file is successfully submitted
</body>
<html>
pg. 73
Output:
pg. 74
pg. 75
pg. 76
pg. 77
pg. 78
pg. 79
pg. 80