0% found this document useful (0 votes)
125 views

2nd PUC Labmanual - Final

The document contains C++ programs for array operations like finding frequency of an element, inserting and deleting elements, sorting in ascending order using insertion sort, searching using binary search, calculating simple interest, and finding roots of a quadratic equation by overloading functions to calculate area of different shapes. The programs take input, perform the relevant operations, and display output.

Uploaded by

bhuvanalmath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

2nd PUC Labmanual - Final

The document contains C++ programs for array operations like finding frequency of an element, inserting and deleting elements, sorting in ascending order using insertion sort, searching using binary search, calculating simple interest, and finding roots of a quadratic equation by overloading functions to calculate area of different shapes. The programs take input, perform the relevant operations, and display output.

Uploaded by

bhuvanalmath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Q1.

Write a C++ program to find the frequency presence of an element in


an array.

#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:

Enter the number of elements: 5


Enter array elements: 10 20 30 40 50
Enter the element to be searched: 55
55 does not exist
Q2. Write a C++ program to insert an element into an array at a given
position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class insertion
{
private:
int a[20],i,n,ele,pos;

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 :

Enter the total number of elements:5


Enter array elements:10 20 30 40 50
Enter the position of element to be deleted:2
30 is deleted
Array elements after deletion
10 20 40 50

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

9. Write a C++ program to find cube of a number using inline function.


Program:
#include<iostream.h>
#include<conio.h>
class findcube
{
public:
inline int cube(int x)
{
return x*x*x;
}
};
void main()
{
int n;
findcube C;
clrscr();
cout<<"Enter a number:";
cin>>n;
cout<<"Cube of "<<n<<" ="<<C.cube(n);
getch();
}
Output:
Enter a number:5
Cube of 5 =125
10. Write a C++ program to find sum of the series 1 + x + x2 + x3 + ….xn
using constructors.

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

Student details are...


Register number=1234
Name=Rajesh
Fees=5000

13. Write a program to perform push items into the stack.


Program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<iomanip.h>
#define max 3
class stack
{
private:
int a[max],top,i;
public:
stack()
{
top=-1;
}
void push(int ele)
{
if(top==max-1)
{
cout<<"stack is full"<<endl;
return;
}
top++;
a[top]=ele;
cout<<ele<<"Is pushed"<<endl;
}
void print();
};
void stack::print()
{
if(top!=-1)
{
cout<<"Stack contains:"<<endl;
for(i=0;i<=top;i++)
cout<<setw(5)<<a[i]<<endl;
}
else
cout<<"Stack is empty"<<endl;
}
void main()
{
clrscr();
stack s;
int ele;
cout<<"Initial status is"<<endl;
s.print();
s.push(10);
s.print();
s.push(20);
s.print();
s.push(30);
s.print();
cout<<"\nPush operation is completed.."<<endl;
getch() ;
}
Output:
Initial status is:
Stack is empty
10 Is pushed
Stack contains:
10
20Is pushed
Stack contains:
10 20
30Is pushed
Stack contains:
10 20 30
Push operation is completed..
14. Write a program to pop elements from the stack.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#define max 3
class stack
{
private:
int a[max],top,i;
public:
stack()
{
top=-1;
}
void push(int ele)
{
if(top==max-1)
{
cout<<"stack is full"<<endl;
return;
}
top++;
a[top]=ele;
cout<<endl<<ele<<"Is pushed"<<endl;
}
void pop()
{
if(top==-1)
{
cout<<"Stack is empty"<<endl;
return;
}
else
{
int temp =a[top];
top--;
cout<<endl<<temp<<"is popped"<<endl;
}
}
void print();
};
void stack::print()
{
if(top!=-1)
{
cout<<"Stack contains: "<<endl;
for(i=0;i<=top;i++)
cout<<setw(5)<<a[i];
}
else
cout<<"Stack is empty"<<endl;
}
void main()
{
stack s;
clrscr();
cout<<"Initial status is:"<<endl;
s.print();
s.push(10);
s.print();
s.push(20);
s.print();
s.push(30);
s.print();
cout<<"\nPush operation is completed.."<<endl;
cout<<endl;
cout<<"Result of pop operation is.."<<endl;
s.print();
s.pop();
s.print();
s.pop();
s.print();
s.pop();
s.print();
getch();
}
Output:
Initial status is:
Stack is empty
10 Is pushed
Stack contains:
10
20Is pushed
Stack contains:
10 20
30Is pushed
Stack contains:
10 20 30
Push operation is completed..
Result of pop operation is..
Stack contains:
10 20 30
30is popped
Stack contains:
10 20
20is popped
Stack contains:
10
10is popped
Stack is empty
15. Write a program to perform enqueue and dequeue operation.
Program:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 3
class queue
{
private:
int Q[MAX],front,rear;
public:
queue()
{
front=-1;
rear=-1;
}
void enqueue(int item);
void dequeue();
void display();
};
void queue::enqueue(int item)
{
if(rear==MAX-1)
{
cout<<"\n Queue is full"<<endl;
return;
}
else if(rear==-1)
{
front=0; rear=0;
}
else
rear++;
Q[rear]=item;
cout<<endl;
cout<<item<<" \t is inserted"<<endl;
}
void queue::dequeue()
{
if(front==-1)
{
cout<<"\n Queue is empty"<<endl;
return;
}
int item=Q[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else
front++;
cout<<endl<<item<<"\t is removed successfully"<<endl;
}
void queue::display()
{
if(front==-1)
cout<<"\nQueue is empty"<<endl;
else
{
cout<<"Queue contains:";
for(int i=front;i<=rear;i++)
cout<<Q[i]<<"\t";
}
}
void main()
{
queue q;
clrscr();
cout<<"Elements inserted into the queue are:"<<endl;
q.display();
q.enqueue(10);
q.display();
q.enqueue(20);
q.display();
q.enqueue(30);
q.display();
cout<<"\nElements deleted from the queue are:"<<endl;
q.dequeue();
q.display();
q.dequeue();
q.display();
q.dequeue();
q.display();
getch();
}
Output:

Elements inserted into the queue are:


Queue is empty
10 is inserted
Queue contains:10
20 is inserted
Queue contains:10 20
30 is inserted
Queue contains:10 20 30
Elements deleted from the queue are:
10 is removed successfully
Queue contains:20 30
20 is removed successfully
Queue contains:30
30 is removed successfully
Queue is empty
16. Write a program to create a linked list and appending nodes.
#include<iostream.h>
#include<conio.h>
class linklist
{
private:
struct node
{
int data;
node *link;
}*start;
public:
linklist();
void print();
void append(int n);
void count();
};
linklist::linklist()
{
start=NULL;
}
void linklist::print()
{
if(start==NULL)
{
cout<<"Linked list is empty"<<endl;
return;
}
cout<<"Linked list contains:";
node *t=start;
while(t!=NULL)
{
cout<<t->data<<" ";
t=t->link;
}
}
void linklist::append(int num)
{
node *n;
n=new node;
n->data=num;
n->link=NULL;
if(start==NULL)
{
start=n;
cout<<endl<<num<<"\tis inserted as first node"<<endl;
}
else
{
node *t=start;
while(t->link!=NULL)
t=t->link;
t->link=n;
cout<<endl<<num<<"\t is inserted"<<endl;
}
}
void linklist::count()
{
node *t;
int c=0;
for(t=start;t!=NULL;t=t->link)
c++;
cout<<endl<<" No of nodes in the linked list="<<c<<endl;
}
void main()
{
linklist *ob=new linklist();
clrscr();
ob->print();
ob->append(10);
ob->print();
ob->count();
ob->append(20);
ob->print();
ob->count();
ob->append(30);
ob->print();
ob->count();
getch();
}
Output:
Linked list is empty
10 is inserted as first node
Linked list contains:10
No of nodes in the linked list=1
20 is inserted
Linked list contains:10 20
No of nodes in the linked list=2
30 is inserted
Linked list contains:10 20 30
No of nodes in the linked list=3
SQL PROGRAM
PROGRAM 1:

1 Generate the electricity bill for one customer.


Create a table for house hold Electricity bill with the following fields.

Field name Type


RRno Varchar(10)
Name Varchar(25)
Billdate Date
Units Int(4)

2 Insert 10 records into the table.


3 Check the structure of table and note your observation.
4. Add two fields to the table.
a. BILL_AMT FLOAT(6,2)
b. DUE_DATE DATE
5. Compute the bill amount for each customer as per the following rules.
a. MIN_AMT Rs. 50
b. First 100 units Rs 4.50/Unit
c. >100 units Rs. 5.50/Unit
6. Compute due date as BILLING_DATE + 15 Days
7. List all the bills generated.

Solution:

1) mysql> create table ebill(RRno varchar(10),name varchar(25),billdate date,units int(4));

2) mysql> insert into ebill values('e001','ajay','2022-01-01',96);

mysql> insert into ebill values('e002','vijay','2022-02-02',85);

..

..

..

3) mysql> desc ebill;

M mysql> select * from ebill;

4) mysql> alter table ebill add(billamt float(6,2),duedate date);

mysql> desc ebill; (Note down the output)

5) mysql> update ebill set billamt=50;


mysql> update ebill set billamt=billamt+units*4.50 where units<=100;
mysql> update ebill set billamt=billamt+100*4.50+(units-100)*5.50 where units>100;
6) mysql> update ebill set duedate=billdate+15;
mysql> select * from ebill; (Note down the output)

****************************************
PROGRAM 2:
Create a student database and compute the results.

1) Create a table for class of students with the following fields.

Field name Type


Sid Int(4)
Name Varchar(25)
Sub1 Int(3)
Sub2 Int(3)
Sub3 Int(3)
Sub4 Int(3)
Sub5 Int(3)
Sub6 Int(3)

2) Add 10 students records into the table.


3) Display the description of the fields in the table using DESC command.
4) Alter the table and calculate TOTAL and PERC_MARKS.
5) Compute the RESULT as “PASS or “FAIL” by checking if the student has scored more
than 35 marks in each subject.
6) List the contents of the table.
7) Retrieve all the records of the table.
8) Retrieve only sid and NAME of all the students.
9) List the students who have result as “PASS”.
10) List the students who have result as “FAIL”.
11) Count the number of students who have passed.
12) Count the number of students who have failed.
13) List the students who have percentage greater than 60.
14) Sort the table according to the order of sid

Solutions:

1) mysql> create table student(sid int(4),name varchar(25),sub1 int(3),sub2 int(3),sub3


int(3),sub4 int(3),sub5 int(3),sub6 int(3));

2) mysql> insert into student values(01,'arjun',65,45,85,62,73,68);

mysql> insert into student values(01,'bhargav',25,16,45,62,53,68);


.
.
.
.
3) mysql> desc student;
4) mysql> alter table student add(total int(3),pmark float(6,2));
mysql> select * from student;
mysql> desc student; (Note down the output)

mysql> update student set total=sub1+sub2+sub3+sub4+sub5+sub6;

mysql> update student set pmark=(total*100)/600;


mysql> alter table student add(result varchar(5));

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);

6) mysql> select * from student;


7) mysql> select * from student;
8) mysql> select sid,name from student
9) mysql> select * from student where result='pass'; (Note down the output)
10) mysql> select * from student where result='fail'; (Note down the output)
11) mysql> select count(*) from student where result='pass';
12) mysql> select count(*) from student where result='fail';
13) mysql> select * from student where pmark>=60;
14) mysql> select * from student order by sid; (Note down the output)

*************************************
PROGRAM 3

Generate the Employee details and compute the salary based on the department.

1. Create the following table EMPLOYEE.

Field name Data type


Emp_id Int(4)
Dept_id Int(4)
Emp_name Varchar(25)
Emp_salary Int(5)

2. Create the following table department.

Field name Data type


Dept_id Int(2)
Dept_name Varchar(25)
Supervisor Varchar(20)

(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.

5. How many employees work for Accounts department?

6. What is the Minimum, Maximum and Average salary of employees working for Accounts
department?

7. List the employees working for particular supervisor.

8. Retrieve the department names for each department where only one employee works.

9. Increase the salary of all employees in the sales department by 15%.

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));

2. mysql> create table department(did int(2),dname varchar(20),supervisor varchar(20));

mysql>desc employee; (Note down the output)

mysql>desc department; (Note down the output)


3. mysql> insert into employee values(001,01,'arjun',25000);

mysql> insert into employee values(002,02,'amith',35000);

mysql> insert into employee values(003,03,'bhavya',40000);

mysql> insert into employee values(004,04,'rakesh',42000);

mysql> insert into employee values(005,01,'swathi',45000);

...

..

..

mysql> insert into department values(01,'purchase','Ramesh');


mysql> insert into department values(02,'accounts','deep singh');
mysql> insert into department values(03,'sales','joseph');
mysql> insert into department values(04,'apprentice','alex');

mysql> select * from department; (Note down the output)


mysql> select * from employee; (Note down the output)

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));

mysql> update employee set bonus=salary*0.05;

mysql> select * from employee;

(Note down the output)

11. mysql> delete from employee where did=(select did from department where dname='apprentice');

mysql> select * from employee;

mysql> select * from department;

***************************************************
Program 4:
4. Create database for bank transaction

Create the bank database for ABC Bank with following structure.

Field Name Data Type

Acc No INT(10)

Cust Name VARCHAR(25)

Acc type Char(2)

Balance Int(10)

DOT date

Tamt Int(6)

Ttype Char(2)

2. Insert 10 records into the table.

3. List the details of customer whose balance is more than 30000.

4. How many customer whose balance amount is less than minimum in the account.

(assume the minimum balance is 1000)

5. Perform the transaction on ttype deposit or withdrawal.

6. Display the transaction amount on a particular day.

7. Display all the records of a CA account.

Solution:

1. mysql> create table bank(accno int(10),custname varchar(25),acctype char(2),

balance float(8,2),dot date,tamt int(6),ttype char(2));

mysql> desc bank; (Note down the output)

2. mysql> insert into bank values(001,'Bharath','SB',35000,'2021-01-01',3000,'d');


mysql> insert into bank values(002,'chaitra','SB',45000,'2022-02-02',2000,'w');

mysql> insert into bank values(003,'Dhanush','CA',5000,'2022-03-03',20000,'d');

..

..

...

mysql> select * from bank;

3. mysql> select * from bank where balance>30000;

4. mysql> select * from bank where balance<1000;

5. mysql> update bank set balance=balance+tamt where ttype='d';

mysql>select * from bank;

mysql> update bank set balance=balance-tamt where ttype='w';

mysql>select * from bank; (Note down the output)

6. mysql> select * from bank where dot='2022-02-02';

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>

<body bgcolor="yellow" text="black"><b>


<font size = "14">
<form></b>
<h3 align="center"><U>PUC Application form</u></h3>
<br>

<table border = "3" align="center">


<font size = "14">
<tr>
<td><b> Student name:</b>
<td><input type="text" name="std"></td>
</tr>

<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>

<select name="drop down">


<option value="PCMC">PCMC</option>
<option value="PCMB">PCMB</option>
<option value="PCME">PCME</option>
</tr>

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

You might also like