II PUC Labprograms NEW
II PUC Labprograms NEW
Practical Manual
Second Year PUC
Computer Science
REVISED EDITION
CONTENTS
Program PageNo
Program
No
Name
SECTION- A (C++ AND DATA STRUCTURES)
01 Write a C++ program to find the frequency presence of an element in an array. 1-2
02 Write a C++ program to insert an element into an array at a given position. 3-4
03 Write a C++ program to delete an element from an array from a given position. 5-6
Write a C++ program to sort the element of an array in ascending order using
04
insertion sort. 7-8
Write a C++ program to search for a given element in an array using binary 9-10
05 search method.
Write a C++ program to create a class with data members principal, time and
06 rate.Create a member function to accept data values, to compute simple interest
and to 11-12
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
11
inheritance. Create a derived class that contains marks of two subjects and total marks 20-21
as the data members.
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
12 concept ofpointers to objects. 22-23
13 Write a C++ program to perform push items into the stack. 24-26
14 Write a C++ program to perform pop items into the stack. 27-29
15 Write a C++ program to perform Enqueue and Dequeue. 30-32
16 Write a program to create a linked list and appending nodes. 33-35
Program Page
Program
No No
Name
SECTION – B (SQL)
Generate the electricity bill for one customer
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
1. Insert 10 records into the table
2. Describe the structure of table
3. Alter the table by adding two fields to the table
Field Name Type
17
bill_amt number(6,2)
due_date date
4.Compute the bill amount for each customer as per the following rules. 36-37
a. MIN_AMT Rs. 50
b. First 100 units Rs 4.50/Unit
c. >100 units Rs. 5.50/Unit
5.Compute due date as Date_billing + 15 Days
6.List all the bills generated.
1. Generate the Employee details and compute the salary based on the
department.Create the following table employee.
Field Name Type
Emp_id Number(4)
Dept_id Number(4)
Emp_name Varchar2(25)
Emp_salary Number(5)
SECTION- C HTML
III. Viva-voce
1. Four questions must be asked and each question carries 1 mark(external examiner two question and
internal examiner two questions)
2. The questions in the viva-voce should be simple, direct and related to the experiments to be
performed by the student.
NOTE : Laboratory rules to be followed
1. Conduct 22 experiments(16 from c++, 4 from SQL and 2 from HTML)experiments have to be
conducted in the practical classes.
2. Maintain one Observation note book and lab record.
3. Come prepared to the lab
4. Follow the lab programs as instructed by the PU Board
5. Strictly observe the instructions given by the teacher/Lab instructor.
6. Use the computers for academic purpose only.
7. Keep your lab clean
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
SECTION – A (C++)
PROGRAM 1:
Write a C++ program to find the frequency presence of an element in an array.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class Frequency
{
private: int a[50], n, ele, count;
public: void readdata( );
void findfreq( );
void display( );
};
void Frequency::readdata( )
{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter the array elements:"<<endl;
for(int i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to find the frequency"<<endl;
cin>>ele;
}
void Frequency::findfreq( )
{
count=0;
for(int i=0; i<n; i++)
if(ele == a[i])
count++;
}
void Frequency::display( )
{
if(count > 0)
cout<<ele<<" Occurs"<<count<<" Time";
else
cout<<ele<<" Does Not Exists";
}
void main( )
MES PU COLLEGES 1
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
{
Frequency f;
clrscr( );
f.readdata( );
f.findfreq( );
f.display( );
getch( );
}
OUTPUT 1:
OUTPUT 2:
*****
2 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 2:
Write a C++ program to insert an element into an array at a given position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
class Insertion
{
private: int a[50], n, pos, ele, i;
public: void readdata( );
void insert( );
void display( );
};
void Insertion::readdata( )
{
cout<<"Enter the size of the array"<<endl;
cin>>n;
cout<<"Enter the elements for the array"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the position of the element in the array"<<endl;
cin>>pos;
cout<<"Enter the element to be inserted"<<endl;
cin>>ele;
}
void Insertion::insert( )
{
if(pos>n)
{
cout<<"Out of array limits!!!";
getch( );
exit(0);
}
else
{
for(i=n; i>=pos; i--)
a[i+1] = a[i];
a[pos] = ele;
n = n+1;
}
MES PU COLLEGES 3
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
}
void Insertion::display( )
{
cout<<"Array elements after insertion are:"<<endl;
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
void main( )
{
Insertion I;
clrscr( );
I.readdata( );
I.insert( );
I.display( );
getch( );
}
OUTPUT 1:
OUTPUT 2:
*****
4 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 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>
#include<iomanip.h>
class Deletion
{
private:
int a[50], n, pos, i;
public:
void readdata( );
void delet( );
void display( );
};
void Deletion::readdata( )
{
cout<<"Enter the size of the array"<<endl;
cin>>n;
cout<<"Enter the elements for the array:"<<endl;
for (i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the position to an delete an element:\n";
cin>>pos;
}
void Deletion::delet( )
{
if(pos>n)
{
cout<<"Out of array limits...!!!";
getch( );
exit(0);
}
else
{
for(i=pos; i<n; i++)
a[i] = a[i+1];
n = n-1;
}
}
MES PU COLLEGES 5
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
void Deletion::display( )
{
cout<<"After deletion the array elements are"<<endl;
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
void main( )
{
Deletion d;
clrscr();
d.readdata( );
d.delet( );
d.display( );
getch( );
}
OUTPUT 1:
OUTPUT 2:
*****
6 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 4:
Write a C++ program to sort the element of an array in ascending order using
insertion sort method.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
class Sort
{
private: int a[50], n, i;
public: void readdata( );
void insertionsort( );
void display( );
};
void Sort::readdata( )
{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter the elements for the array:"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
}
void Sort::insertionsort( )
{
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 = j-1;
}
}
}
void Sort::display( )
{
for(i=0; i<n; i++)
MES PU COLLEGES 7
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
cout<<a[i]<<"\t";
cout<<endl;
}
void main( )
{
Sort s;
clrscr();
s.readdata( );
cout<<"Unsorted List......"<<endl;
cout<<"*******************"<<endl;
s.display( );
s.insertionsort( );
cout<<"Sorted List........"<<endl;
cout<<"*******************"<<endl;
s.display( );
getch( );
}
OUTPUT 1:
OUTPUT 2:
*****
8 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 05:
Write a program to search for a given element in an array using Binary search
method
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class search
{
private: int a[100],n,ele,i,loc;
public: void input();
void binary_search();
void display();
};
void search::input()
{
cout<<"\n Enter the size of the array";
cin>>n;
cout<<"\n Enter the array elements";
for(i=0; i<n;i++)
cin>>a[i];
cout<<"\n Enter the search element";
cin>>ele;
}
void search::binary_search()
{
int b=0, e=n-1,mid;
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;
}
MES PU COLLEGES 9
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
}
void search::display()
{
if(loc>=0)
cout<<ele<<" is found at location "<<loc<<endl<<"\n BINARY
SEARCH IS
SUCCESSFULL";
else
cout<<ele<<"element does not exists"<<endl<<"BINARY SEARCH IS
UNSUCCESSFULL";
}
void main()
{
search S;
clrscr();
S.input();
S.binary_search();
S.display();
getch();
}
OUTPUT 1
OUTPUT 2
*****
10 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 06:
Write a program to create a class with data members principle amount, time and
rate of interest. Create a member function to accept data values to compute simple
interest and to display the result.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class simple_intrest
{
private: double p,t,r,si;
public: void input();
void compute();
void display();
};
void simple_intrest::input()
{
cout<<"Enter the principal amount"<<endl;
cin>>p;
cout<<"Enter the time period "<<endl;
cin>>t;
cout<<"Enter the Rate of Intrest"<<endl;
cin>>r;
}
void simple_intrest::compute()
{
si=(p*t*r)/100;
}
MES PU COLLEGES 11
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
void main()
{
simple_intrest I;
clrscr();
I.input();
I.compute();
I.display();
getch();
}
OUTPUT 1
OUTPUT 2
*****
12 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 07:
Write a program to create a class with data members a,b,c and member function to
input data, compute the discriminant based on the following conditions and print the
roots.
1. If discriminant =0 , print the roots that are equal.
2. If the discriminant is >0 , print the real and distinct roots
3. If the discriminant is < 0 , print that the roots are imaginary.
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
#include<process.h>
#include<conio.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;
}
MES PU COLLEGES 13
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
}
else
{
cout<<" Roots are imaginary";
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:
OUTPUT 2:
*****
14 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 08:
Write a program to find the area of a square/rectangle/triangle using function
overloading.
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
#include<conio.h>
class fun_overload
{
private: float s;
public: float area(float a)
{
return(a*a);
}
void main()
{
fun_overload O;
clrscr();
float x,y,z;
int n;
cout<<"Enter the number of inputs:"; cin>>n;
if(n==1)
{
cout<<"Enter side of square"<<endl; cin>>x;
cout<<"Area of the square="<<O.area(x)<<endl;
}
else if(n==2)
MES PU COLLEGES 15
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
{
cout<<"Enter the length and breadth of a rectangle:";
cin>>x>>y;
cout<<"Area of the rectangle="<<O.area(x,y)<<endl;
}
else if(n==3)
{
cout<<"Enter three sides of a triangle"<<endl; cin>>x>>y>>z;
cout<<"Area of triangle="<<O.area(x,y,z)<<endl;
}
else
{
cout<<"Invalid input";
}
getch();
}
OUTPUT 1:
OUTPUT 2:
*****
16 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 9:
Write a C++ program to find cube of a number using inline function.
#include<iostream.h>
#include<conio.h>
OUTPUT 1:
OUTPUT 2:
*****
MES PU COLLEGES 17
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 10:
Write a program to find the sum of series 1+x+x2+x3+.........xn using constructors.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class power
{
private : int x,i,sum,n;
public: power()
{
sum=1;
}
void getdata()
{
cout<<”enter the values for x and n”;
cin>>x>>n;
}
void calculate()
{
for(i=1;i<=n;i++)
sum=sum+pow(x,i);
}
void display()
{
cout<<”sum of the series=”<<sum;
}
};
void main()
{
power p;
clrscr();
p.getdata();
p.calculate()
p.display();
getch();
}
18 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
OUTPUT 1:
OUTPUT 2:
*****
MES PU COLLEGES 19
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 11 :
Create a base class containing the data members 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<iomanip.h>
#include<conio.h>
class student
{
};
class marks: public student
{
void display1()
20 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
cout<<"Subject1="<<ml<<endl;
cout<<"Subject2 ="<<m2<<endl;
cout<<"Total marks= "<<total<<endl;
}
};
int main ()
{
marks ob; clrscr();
ob.read();
ob.read1();
ob.display(); ob.display1();
getch();
return 0;
}
OUTPUT 1:
OUTPUT 2:
*****
MES PU COLLEGES 21
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM 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>
class student
{
private:
int regno;
char name[20];
float fees;
public:
void get ();
void display();
};
void student: :get ()
{
cout<<"Enter student name:";
cin>>name;
cout<<" Enter student register number:”;
cin>>regno;
cout<<"Enter student fees:";
cin>>fees;
}
void student::display()
{
cout<<" Student register number"<<regno<<endl; cout<<"Student
name :"<<name<<endl; cout<<"Student fees:"<<fees;
}
int main ()
{
student s , *sp;
clrscr();
sp=&s;
sp->get();
sp->display(); getch();
return 0;
22 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
OUTPUT 1:
OUTPUT 2:
*****
MES PU COLLEGES 23
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM: 13
Write a C++ program to push an element into the stack.
#include<iostream.h>
#include<ctype.h>
#include<iomanip.h>
#include<stdlib.h>
#define MAX 3
class Stack
{
private :
int A[MAX], top;
public :
Stack()
{
top=-1;
}
void Push(int item);
void print();
};
void Stack :: Push(int item)
{
if(top == MAX-1)
{
cout<<endl<<”Sorry… Stack is full”<<endl;
return;
}
top++;
A[top]=item;
cout<<item<<”is successfully pushed”<<endl;
}
void Stack :: print()
{
if(top !=-1)
{
cout <<”Stack contains “;
for(int i=0;i<=top;i++)
cout<<setw(4)<<A[i];
cout<<endl;
}
else
24 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
cout<<”Stack is empty”<<endl;
}
void main()
{
Stack S;
int choice, itm;
while(1)
{
cout<<endl<<”1.Push”<<endl<<”2.Print
“<<endl<<”3.Exit”<<endl;
cout<<Ënter your choice : “;
cin>>choice;
switch(choice)
{
case 1: {
cout<<”Enter the item : “;
cin>>itm;
S.Push(itm);
break;
}
case 2: {
S.print();
break;
}
case 3: {
cout<<”Thank you … Visit again “;
exit(0);
}
default : cout << “Invalid choice “<<endl;
}
}
}
MES PU COLLEGES 25
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
OUTPUT:
*****
26 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM : 14
Write a program to pop elements from the stack.
#include<iostream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 3
class Stack
{
private :
int A[MAX], top;
public :
Stack()
{
top=-1;
}
void Push(int item);
void Pop();
void Print();
};
void Stack :: Push(int item)
{
if(top == MAX-1)
{
cout<<endl<<”Sorry… Stack is full”<<endl;
return;
}
top++;
A[top]=item;
cout<<item<<”is successfully pushed”<<endl;
}
void Stack :: Print()
{
if(top !=-1)
{
cout <<”Stack contains “;
for(int i=0;i<=top;i++)
cout<<A[i]<<setw(4);
cout<<endl;
MES PU COLLEGES 27
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
}
else
cout<<”Stack is empty”<<endl;
}
void Stack :: Pop()
{
if(top == -1)
{
cout <<endl<<”Sorry, Stack is empty”<<endl;
return;
}
else
{
int ele = A[top];
top --;
cout<<”\t”<<ele<<” is successfully popped “<<endl;
}
}
void main()
{
Stack S;
int choice, itm;
while(1)
{
cout<<endl<<”1.Push”<<endl<<”2.Pop<<endl<<”3.Print Stack
“<<endl<<”4.Exit”<<endl;
cout<<Ënter your choice : “;
cin>>choice;
switch(choice)
{
case 1: {
cout<<”Enter the item : “;
cin>>itm;
S.Push(itm);
break;
}
case 2: {
S.pop();
break;
}
case 3: {
28 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
S.print();
break;
}
case 4: {
cout<<”Thank you … Visit again “;
exit(0);
}
default : cout << “Invalid choice “<<endl;
}
}
}
OUTPUT 1:
*****
MES PU COLLEGES 29
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM :15
Write a program to perform enqueue and dequeue.
#include<iostream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#define QUEUE_SIZE 3
class Queue
{
private :
int q[QUEUE_SIZE];
int front,rear;
int count;
public :
Queue();
void enqueue(int x);
void dequeue();
void getsize();
};
Queue :: Queue()
{
front = -1;
rear = -1;
count=0;
}
void Queue :: enqueue(int X)
{
if(rear == QUEUE_SIZE -1)
{
cout<<endl<<”Sorry… Queue is full”<<endl;
return;
}
if(front = -1)
{
front = 0;
rear = 0;
}
else
rear++;
Q[rear] = x;
30 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
count++;
cout<<endl<<x<<”is successfully inserted “<<endl;
}
void Queue :: dequeue()
{
if(front == -1)
{
cout <<”\t Queue is empty “<<endl;
return;
}
int x = q[front];
if(front == rear)
{
front =-1;
rear =-1;
}
else
front++;
count--;
cout<<”\t”<<x<<”is successfully deleted “ <<endl;
}
void Queue :: getsize()
{
if(count > 0)
{
cout<<”\tQueue contains “ ;
for(int i=front;i<=rear ;i++)
cout<<q[i]<<setw(4);
cout<<endl;
}
else
cout<<”\t Sorry… Queue is empty”<<endl;
}
void main()
{
Queue Q;
int choice, item;
while(1)
{
cout<<endl<<”1.Enqueue”<<endl<<”2.Dequeue
“<<endl<<”3.Print Queue”<<”4.Exit”<<endl;
MES PU COLLEGES 31
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
OUTPUT 1:
*****
32 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
PROGRAM : 16
Write a program to create a linked list and appending nodes.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class LinkList
{
private :
struct Node
{
int data;
Node* link;
}*START;
public :
LinkList();
void Print();
void Append(int num);
void Count();
};
LinkList :: LinkList()
{
START = NULL;
}
Void LinkList :: Print()
{
if (START == NULL)
{
cout<<endl<<”Sorry… Linked List is empty”<<endl;
return;
}
cout<<”Linked list contains “;
Node* tmp = START;
while(tmp != NULL)
{
cout<<tmp->data<<” “;
tmp = tmp ->Link;
}
}
void LinkList :: Append (int num)
{
MES PU COLLEGES 33
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
Node *newNode;
newNode = new Node;
newNode –>data = num;
newNode ->Link = NULL;
if(START == NULL)
{
START = newNode;
cout <<endl<<num<<” is inserted as the first node”<<endl;
}
else
{
Node *tmp = START;
while(tmp->link != NULL)
tmp = tmp->link;
tmp->link = newNode;
cout<<endl<<num<<”is inserted “<<endl;
}
}
void LinkList ::Count()
{
Node *tmp;
int c = 0;
for (tmp = START; tmp != NULL; tmp = tmp->link)
c++;
cout<<endl<<”No. of nodes in the linked list =”<<c<<endl;
}
void main()
{
LinkList* Obj = new LinkList();
Obj -> Print();
Obj -> Append(100);
Obj -> Print();
Obj ->Count();
Obj-> Append(200);
Obj->Print();
Obj->Count();
Obj-> Append(300);
Obj->Print();
Obj->Count();
34 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
OUTPUT 1:
*****
MES PU COLLEGES 35
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
SECTION – B (SQL)
SQL PROGRAM-17
1. Generate the Electricity bill for one consumer.
5. Compute the bill amount for each customer as per the following rules:
36 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
min_amt Rs. 50
first 100 units Rs. 4.50/unit
>100 units Rs. 5.50/unit
➢ Solution: update EB set amount=50;
update EB set amount=amount +100*4.50+(units-100)*5.50
where units>100;
update EB set due_date=date_billing+15;
*****
MES PU COLLEGES 37
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
38 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
MES PU COLLEGES 39
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
12. List the students who have percentage greater than 60:
➢ Solution: select * from STD where percentage>=60;
OUTPUT:
Student Student Sub1 Sub2 Sub3 Sub4 Sub5 Sub6 Total Per Result
id name marks marks marks marks marks marks cen
tag
e
1124 Anuthara 67 82 86 90 56 78 459 77 Pass
1127 Bhargavi 56 69 78 34 52 59 348 58 Fail
1113 Manjunath 45 47 51 40 50 51 284 47 Pass
1121 Bhavani 28 36 45 34 37 39 219 37 Fail
1123 Vijetha 90 91 95 96 92 89 553 92 Pass
1125 Nisarga 78 79 80 90 88 85 500 83 Pass
*****
40 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
3. Enter 5 rows of data for employee table and 4 rows of data for
department table:
➢ Solution: insert into EMPY values(1000, 11, ‘Arun’, 30000);
insert into EMPY values(1001, 13, ‘Priya’, 57500);
insert into EMPY values(1002, 12, ‘Anup’, 20000);
insert into EMPY values(1003, 14, ‘Surya’, 40000);
insert into EMPY values(1004, 12, ‘Keerthi’, 50000);
MES PU COLLEGES 41
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
4. Find the names of all employees who work for accounts department:
➢ Solution: select * from EMPY where dept_id=(select dept_id from
DEPI where dept_name=’Accounts’);
42 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
10. Add a new column to table employee called bonus number(5) and
compute 5% of salary to said field:
OUTPUT:
emp_id dept_id emp_name emp_salary bonus
1000 11 Arun 30000 1500
1001 13 Priya 57500 2875
1002 15 Anup 20000 1000
1003 14 Surya 40000 2000
*****
MES PU COLLEGES 43
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
SQL PROGRAM - 20
4. Create a database for bank transaction.
1. Create a customer table having following fields:
44 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
7. Display all records from bank table transaction data is greater than or
equal to a particular data:
➢ Solution: select * from bank where trdate>=’10-Dec-2022’;
MES PU COLLEGES 45
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
13. Select one record from customer table where names is starting with a
particular letter:
➢ Solution: select* from customer where cname like ‘A%’;
17. Select unique customer number from bank table using district
command:
➢ Solution: select distinct (cno) from bank;
18. Display accno, count(*) from bnkapr group by accno having count (*) >1;
➢ Solution: select * from customer where cphone = ‘98765439’;
46 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
OUTPUT:
Cno Cname Caddress Cphone
1123 Roy MG Road, Bangalore 123456789
1345 Vijetha Vijayanagar, Bangalore 98765439
1678 Khushi Rajajinagar, Bangalore 78456785
2333 Rohith Shivanagar, Bangalore 98746574
2345 Ketan Shreenagar, Delhi 94567346
*****
MES PU COLLEGES 47
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
SECTION – C (HTML)
Experiment No - 21
Write a HTML program to create a study time table
<!doctype html>
<html>
<head>
<style> th,td,table
{
border:1px solid black;
}
</style>
</head>
<body bgcolor="lightgreen">
<h1> <center> <Color="red"> MY STUDY TIME TABLE FOR THE WEEK
</color> </center> <h1>
<h2> <center> Beautiful sunrise </center> </h2>
<img border="0" src="web.jpg" width="304" height="228">
<table align=”center” “ width=”900px” >
<tr>
<th>Days</th>
<th>Subject</th>
<th>Morning study time only reading</th>
<th>College study time</th>
<th>Evening study time</th>
<th>Question Paper Solution Time only writing</th>
</tr>
<tr>
<th>Monday</th>
<th>Lang I </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th>Tuesday</th>
<th>Lang II </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th> Wednesday</th>
48 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
<th>Optional I</th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th>Thursday</th>
<th>Optional II </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th> Friday</th>
<th>Optional III </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th>Saturday</th>
<th>Optional Lang I </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
</table>
<marquee direction="right">Enjoy life as a student !!</marquee>
</body>
</html>
OUTPUT
*****
MES PU COLLEGES 49
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
Experiment No- 22
Create an HTML Program with table and Form
<html>
<form name="htmlform" method="post" action="html_form_send.php">
<head>
<table width="450px">
<style>
td, th, table
{
border : 1px solid red; color : blue ;
}
</style>
</table>
</head>
<body bgcolor="lightblue" >
<h1> ATTENDANCE DETAILS : </h1>
<h3> SUBJECT : COMPUTER SCIENCE </h2>
<table style = "WIDHT:300 px">
<tr>
<th> Month</th>
<th> No of classes held </th>
<th> No of classes attended </th>
</tr>
<tr>
<th> JUNE </th>
<th> 10</th>
<th> 10 </th>
</tr>
<tr>
<th> JULY</th>
<th> 20 </th>
<th> 15 </th>
</tr>
<tr>
<th> AUGUST </th>
<th> 20 </th>
<th> 18 </th>
</tr>
<tr>
<th> SEPTEMBER </th>
<th> 20 </th>
<th> 12 </th>
</tr>
<tr>
<th> OCTOBER </th>
50 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
<th> 10 </th>
<th> 04 </th>
</tr>
<tr>
<th> NOVEMBER </th>
<th> 10 </th>
<th> 14 </th>
</tr>
<tr>
<th> DECEMBER </th>
<th> 10 </th>
<th> 04 </th>
</tr>
<tr>
<th> JANUARY </th>
<th> 10</th>
<th> 10</th>
</tr>
<tr>
<th> FEBRUARY </th>
<th> 10 </th>
<th> 10 </th>
</tr>
<tr>
<th> Total No of Days </th>
<th> 120 </th>
<th> 97</th>
</tr>
<tr>
<th> PERCENTAGE </th>
<th> </th>
<th> </th>
</tr>
</table>
<br>
<br>
<table WIDTH=200px>
<tr>
<th> <label for ="Student_ID"> Student ID*
</label> </th>
<td> <input type = "text" name= " Student_ID" maxlength="50" size="30"> </td>
</tr>
<tr>
MES PU COLLEGES 51
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪
*****
52 MES PU COLLEGES