0% found this document useful (0 votes)
4 views59 pages

Oxford

The document is a lab manual for II PUC Computer Science, containing multiple C++ programs that demonstrate various concepts such as finding frequency of an element in an array, insertion, deletion, sorting using insertion sort, binary search, calculating simple interest, and more. Each program includes class definitions, member functions for input, computation, and output, along with example usage in the main function. The manual serves as a practical guide for students to understand and implement fundamental programming techniques in C++.

Uploaded by

aryavsta3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views59 pages

Oxford

The document is a lab manual for II PUC Computer Science, containing multiple C++ programs that demonstrate various concepts such as finding frequency of an element in an array, insertion, deletion, sorting using insertion sort, binary search, calculating simple interest, and more. Each program includes class definitions, member functions for input, computation, and output, along with example usage in the main function. The manual serves as a practical guide for students to understand and implement fundamental programming techniques in C++.

Uploaded by

aryavsta3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

OXFORD INDEPENDENT

PU COLLEGE
#68,

DEPARTMENT OF COMPUTER SCIENCE


II PUC LAB MANUAL
Unruled side Ruled side

OUTPUT 1 :
PROGRAM – 01

/*write a C++ program to find the frequency of an element in an


array */

#include<iostream.h>
#include<conio.h>
class frequency
{
private:
int a[100];
int n,ele,f,i;
public:
OUTPUT 2 : void input( );
void compute( );
void output( );
};

void frequency::input( )
{
cout<<"Enter thenumber ofelements in the array : ";
cin>>n;
cout<<"Enter the array elements : ";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Input the element to find the frequency :";
cin>>ele;
}
void frequency::compute( )
{
f=0;
Unruled side Ruled side

for( i=0;i<n;i++)
if(ele==a[i])
f++;
}
void frequency::output( )
{
if(f>0)
cout<<ele<<" occurs "<<f<<" times ";
else
cout<<ele<<" does not exist ";
}

void main( )
{
frequency obj;
clrscr( );
obj.input( );
obj.compute( );
obj.output( );
getch( );
}
Unruled side Ruled side

PROGRAM – 02
Output 1:
/* Write a C++ program to insert an element into an array ata
given position */

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

class insertion
{
private :
int a[100],element,pos,n,i;

Output 2:
public:
void input( );
void compute( );
void output( );
};

void insertion::input( )
{
cout<<"Inputnoofelements:"<<endl;
cin>>n;
cout<<"Input array elements : "<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to be inserted : ";
cin>>element;
cout<<"Input position of the element in the array : ";
cin>>pos;
}
Unruled side Ruled side

void insertion::compute( )
{
if(pos>=n)
{
cout<<"Position isout ofarray limits ";
getch();
exit(0);
}
else
{
for(i=n;i>pos;i--)
a[i]=a[i-1];
a[pos]=element;
n=n+1;
}
}

void insertion::output( )
{
cout<<"Array elements after insertion : "<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}

void main()
{
insertion obj;
clrscr( );
obj.input ();
obj.compute( );
obj.output( );
getch( );
}
Unruled side Ruled side

PROGRAM – 03
OUTPUT 1 :
/* write a program to delete an element from an array at a given
position */

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class deletion
{
private : int a[100],element,pos,n,i;

public:
OUTPUT 2 : void input ( );
void compute( );
void output ( );
};
void deletion :: input( )
{
cout<<" Input number of elements : "<<endl;
cin>>n;
cout<<"Input array elements : "<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter theposition of the element to be deleted : ";
cin>>pos;
}

void deletion :: compute( )


{
if(pos>=n)
{
cout<<"Position is out of array limits ";
Unruled side Ruled side

getch( );
exit(0);
}
else
{

element=a[pos];
for(i=pos;i<n-1;i++)
a[i]=a[i+1];
n=n-1;
}
}

void deletion :: output( )


{
cout<<"Deleted element is " << element;
cout<<"\nArray after deletion : "<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}

void main( )
{
deletion obj;
clrscr( );
obj.input ( );
obj. compute ( );
obj.output( );
getch( );
}
Unruled side Ruled side

OUTPUT 1 : PROGRAM – 04

/*Write a c++ program to sort anelement in the array using


insertion sort*/

#include<iostream.h>
#include<conio.h>
class sort
{
private:
int a[100],i,n;
public
void input( );
void compute( );
void output( );
};
void sort :: input( )
{
cout<<"Enterthenumberofelements:";
cin>>n;
cout<<"Enter array elements : ";
for(i=0;i<n;i++)
cin>>a[i];
}
void sort :: compute( )
{
int temp,j;
for(i=0;i<n;i++)
{
j=i;
while(j>=1)
{
Unruled side Ruled side

if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
j=j-1;
}
}
}
void sort :: output( )
{

for(i=0;i<n;i++)
cout<<a[i]<<"\t"<<"\n";
}

void main( )
{
sorrt s;
clrscr( );
s.input( );
cout<<"Unsorted list is : "<<endl;
s.output( );
s. compute();
cout<<"Sorted list is : "<<endl;
s.output( );
getch( );
}
Unruled side Ruled side

OUTPUT 1 : PROGRAM – 05

/* Write a C++program to searchforan element in an array usingbinary


search*/

#include<iostream.h>
#include<conio.h>
class search
{
private:
int a[100],ele,loc,n,i;
public:
void input( );
void compute( );
OUTPUT 2 :
void output( );
};
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 search element";
cin>>ele;
}

void search :: compute( )


{
int low,high,mid;
loc=-1;
low=0;
Unruled side Ruled side

high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(ele==a[mid])
{
loc=mid;
break;
}
else
if(ele<a[mid])
high=mid-1;
else
low=mid+1;
}
}

void search :: output( )


{
if(loc==-1)
cout<<"Element does not exist, unsucessful search";
else
cout<<"Searching element is present in the location "<<loc;
}
void main( )
{
search s;
clrscr( );
s.input( );
s. compute( );
s.output( );
getch();
}
Unruled side Ruled side

OUTPUT 1 : PROGRAM – 06

/* Write a C++ Program to find the Simple Interest*/

#include<iostream.h>
#include<conio.h>
class simpleinterest
{
private:
double principle,rate,time,si;
public:
void input()
{
cout<<" Input principle amount:";
cin>>principle;
cout<<" Input number of years : ";
cin>>time;
cout<<"Input rate of interest:";
cin>>rate;
}
void compute ( )
{
si=principle*rate*time/100;
}
void output ( )
{
cout<<"Simple interest = "<<si;
}
};
Unruled side Ruled side

void main( )
{
simpleinterest s;
clrscr( );
s.input( );
s.compute( );
s.output( );
getch( );
}
Unruled side Ruled side

OUTPUT 1 : PROGRAM – 07

/*Write a C++ program tocreate a class with data members a, b, c


and member functions to input data, and to compute the
discriminant based on the following conditions and to print the
roots.
a. If discriminant = 0, print the roots are equal and their value
b. If the discriminant is > 0, print the real roots and their value.
c. If the discriminant < 0, print the roots are imaginary and exit
OUTPUT 2 : the program.*/

#include<iostream.h>
#include<conio.h>
#include<math.h>
class quadratic
{
private :
int a, b, c;
OUTPUT 3 : float disc, x1, x2 ;
public :
void input ( )
{
cout<< "Input values for a,b, and c:";
cin>> a >> b >> c ;
}
void compute ( )
{
disc = b * b - 4 * a * c;
if (disc==0 )
{
cout<< "Roots are equal " <<endl ;
x1 = - b / (2*a);
Unruled side Ruled side

x2 = x1;
}
else
if(disc > 0)
{
cout<<"Real & Distinct roots"<<endl;
x1=(- b + sqrt (disc) ) / (2 * a);
x2=(- b - sqrt (disc) ) / (2 * a);
}
else
cout<<"Roots are imaginary"<<endl;
}

void output ( )
{
cout<< "Root 1 is " << x1 <<endl;
cout<< "Root 2 is " << x2 <<endl;
}

};

void main()
{
quadratic q;
clrscr();
q.input();
q.compute();
q.output();
getch();
}
Unruled side Ruled side

PROGRAM – 08
OUTPUT 1 :
/* Program to find the area of square/rectangle/triangle using
function overloading concept */

#include<iostream.h>
#include<conio.h>
#include<math.h>
class fun
{
private:
float s;
OUTPUT 2 : public:
int area (int a)
{
return (a *a);
}
int area(int l, int b)
{
return (l *b);
}
float area(float a, float b, float c)
{
OUTPUT 3 : s=(a+b+c)/2;
return(sqrt(s* (s-a) * (s-b) * (s-c) ));
}
};

void main()
{
fun f;
clrscr();
int num;
Unruled side Ruled side

OUTPUT 4 : cout<<" Enter the no of sides : "<<endl;


cin>>num;
if (num == 1)
{
int a;
cout<<"Enter the side of a square : "<<endl;
cin>>a;
cout<<"Area of a square is : "<<f.area(a)<<endl;
}
else
if (num == 2)
{
int l , b;
cout<<" Enter the length and breadth : "<<endl;
cin>>l>>b;
cout<<" Area of rectangle is : "<<f.area(l , b);
}
else
if (num == 3)
{
float a, b, c;
cout<<" Enter the three sides : "<<endl;
cin>>a>>b>>c;
cout<<"Area of triangle is :"<<f.area(a,b,c);
}
else
cout<<"Invalid option."<<endl;
getch();
}
Unruled side Ruled side

PROGRAM – 09
OUTPUT 1 :
/* Program to find the cube of a number using inline function */

#include<iostream.h>
#include<conio.h>
class assign
{
private :
int n;
public :
OUTPUT 2 :
assign(int num)
{
n = num;
}
int cube();
};

inline int assign :: cube()


{
return (n * n * n);
}

void main()
{
clrscr();
int number;
cout<<"Enter a num : "<<endl;
cin>>number;
assign f=number;
cout<<"Cube of a number is : "<< f.cube();
getch();
}
Unruled side Ruled side

PROGRAM – 10
OUTPUT 1 :
/*Write a program to find the sum of the series 1 + x + x2 + x3+. .
. . + xn using constructor*/

# include <iostream.h>
# include <math.h>
# include <conio.h>
class series
{
OUTPUT 2 :
private:
int sum, n, x;
public:
series ( )
{
sum =1 ;
}
void input( )
{
cout<<"InputN(numberofterms)value:";
cin>> n ;
cout<< "Input X value " ;
cin>> x;
}
void compute( )
{
int i;
for (i=1;i<=n;i++)
sum = sum + pow (x,i) ;
}
Unruled side Ruled side

void output( )
{
cout<<"Sum = "<< sum;
}
};

void main ( )
{
series p;
clrscr();
p.input ();
p. compute( );
p. output( );
getch( );
}
Unruled side Ruled side

PROGRAM – 11
OUTPUT 1 :
/* Create a base class containing the data members roll No. and
name. Also create a member function to read and output the
data using single level inheritance. Create a derived class that
contains marks of 2 subjects and total marks as the data
members*/

#include<iostream.h>
#include<conio.h>
class student
{
private:
int rno;
char name[20];
OUTPUT 2 :
public :
void input()
{
cout<<"Input roll number:";
cin>>rno;
cout<<"Input name of the student:";
cin>> name ;
}
};
class report : public student
{
private :
int marks1,marks2,total ;
public :
void inputmarks()
{
cout<<"Enter Subject1 marks:";
cin>>marks1;
cout<<"Enter Subject 2 marks:";
Unruled side Ruled side

cin>>marks2;
}
void compute()
{
total=marks1+marks2;
cout<<endl<<"Total Marks = "<<total;
}
};

void main()
{
report r;
clrscr();
r.input();
r.inputmarks();
r.compute();
getch();
}
Unruled side Ruled side

PROGRAM – 12
OUTPUT 1:
/* Create a class containing the following data members
Enter regno,name,fee register no,name and fees. Create a member function to read
101 and output the data using the concept of pointers to objects*/
Chandana
20000 #include<iostream.h>
#include<conio.h>
Register no: 101
Name : Chandana class student
Fees :20000 {
private :
int regno, fees;
OUTPUT 2: char name[15];

Enter regno,name,fee public :


102 void input( )
Reena {
40000 cout<<"Enter regno,name,fee"<<endl;
cin>>regno>>name>>fees;
Register no : 102 }
Name : Reena
Fees : 40000 void output( )
{
cout<<" Register no :"<<regno<<endl;
cout<<" Name :"<<name<<endl;
cout<<" Fees :"<<fees<<endl;
}
};

void main( )
{
student s,*sp;
Unruled side Ruled side

clrscr( );
sp=&s;
sp->input();
sp->output();
getch( );

}
Unruled side Ruled side

PROGRAM – 13

OUTPUT :
Stack operations /* Program to push the element into the stack */
1. Push operation
2. display stack elements # include <iostream.h>
3. Exit # include <conio.h>
Enter your choice # include <stdlib.h>
1 # define max 10
Input element to insert
25 class stack
{
Stack operations protected : int s[max] ;
1. Push operation int top ;
2. display stack elements public :stack( )
3. Exit {
Enter your choice top= -1 ;
1 }
Input element to insert void push (int ele)
36 {
if (top == max-1)
Stack operations cout << "Stack is is full”<<endl;
1. Push operation else
2. display stack elements top++ ;
3. Exit s[top] = ele ;
Enter your choice
1
Input element to insert }
10 void display ( )
{
int i;
cout << "Stack elements"<<endl;
for(i=top;i>=0;i--)
Unruled side Ruled side

cout<<s[i]<<endl;
Stack operations
1. Push operation }
2. display stack elements };
3. Exit
Enter your choice void main ( )
2 {
Stack elements stack s;
10 clrscr();
36 int choice, element ;
25 while (1)
{
Stack operations cout << "Stack operations"<<endl;
1. Push operation cout << "1. Push operation"<<endl ;
2. display stack elements cout << "2. display stack elements" <<endl;
3. Exit cout << "3. Exit" <<endl;
Enter your choice cout<<endl;
3 cout << "Enter your choice" ;
End of Stack operations cin >> choice ;
switch (choice)
{
case 1: cout << "Input element to insert ";
cin >>element ;
s.push(element) ;
break;
case 2: s.display( );
break ;
case 3: cout<<"End of Stack operations" ;
exit (1);
}
}
getch();
}
Unruled side Ruled side

OUTPUT: Program No 14

Stack operations /* Program to pop the element from the stack */


1. Push operation # include <iostream.h>
2. Pop operation # include <conio.h>
3. Display stack elements # include <stdlib.h>
4. Exit #define max 10
Enter your choice class stack
1 {
Insert new element protected : int s[5] ;
12 int top ;
public : stack( )
Stack operations {
1. Push operation top= -1 ;
2. Pop operation }
3. Display stack elements void push (int ele)
4. Exit {
Enter your choice if (top == max-1)
1 cout<<"Stack is full”<< endl;
Insert new element else
5 top++ ;
s[top] = ele ;
Stack operations }
1. Push operation void pop ()
2. Pop operation {
3. Display stack elements if (top == -1)
4. Exit {
Enter your choice cout << "Stack is empty”<< endl;
3 }
Stack elements else
5
12
Unruled side Ruled side

Stack operations {
1. Push operation int ele=s[top];
2. Pop operation top--;
3. Display stack elements cout<<"Popped element is"<< ele;
4. Exit }
Enter your choice }
2 void display ( )
Popped element is 5 {
int i;
Stack operations cout << "Stack elements"<<endl;
1. Push operation for(i=top;i>=0;i--)
2. Pop operation cout<<s[i]<<endl;
3. Display stack elements }
4. Exit };
Enter your choice
2 void main ( )
Popped element is 12 {
stack s;
Stack operations clrscr();
1. Push operation int choice, element ;
2. Pop operation while (1)
3. Display stack elements {
4. Exit cout << "Stack operations"<<endl;
Enter your choice cout << "1. Push operation"<<endl ;
2 cout << "2. Pop operation" <<endl;
Stack is empty cout << "3. Display stack elements" <<endl;
cout << "4. Exit" <<endl;
Stack operations cout<<endl;
1. Push operation cout << "Enter your choice" ;
2. Pop operation cin >> choice ;
3. Display stack elements switch (choice)
4. Exit {
Enter your choice
Unruled side Ruled side

4 case 1 : cout << "Insert new element " ;


End of Stack operations cin >>element ;
s.push(element) ;
break;
case 2 : s.pop( );
break ;
case 3 : s.display( );
break ;
case 4 : cout << "End of Stack operations" ;
exit (1);
}
}
getch( );
}
Unruled side Ruled side

OUTPUT Program 15
/*Program to perform enqueue and dequeue */
Queue Operations:
1. Add Item # include <iostream.h>
2. Delete Item # include <conio.h>
3. Display Contents # include<stdlib.h>
4. Exit # define n 5
Enter your choice:1 class queue
Input an element to insert {
protected : int q[n] ;
35
int front, rear;
public: queue( )
Queue Operations:
{
1. Add Item
front = -1;
2. Delete Item rear = -1;
3. Display Contents }
4. Exit void qinsert (int item)
Enter your choice:1 {
Input element to insert if (rear==n-1)
45 {
cout << "Queue is full"<<endl;
Queue Operations: }
1. Add Item else if(rear==-1)
2. Delete Item {
front=0 ;
3. Display Contents
rear=0;
4. Exit
q[rear]=item;
Enter your choice:3 }
The Queue contents is: else
q[0]=35 {
q[1]=45 rear ++;
Unruled side Ruled side

Queue Operations: q[rear]=item;


1. Add Item }
2. Delete Item }
3. Display Contents int qdelete ( )
4. Exit {
Enter your choice:2 int item;
if (front == -1)
cout <<"Underflow"<<endl;
Queue Operations:
else
1. Add Item
item = q[front];
2. Delete Item if(front == rear||front==n-1)
3. Display Contents {
4. Exit front = -1;
Enter your choice:3 rear = -1;
The Queue contents is: }
q[1]=45 else
front ++;
Queue Operations: return item ;
1. Add Item }
2. Delete Item void display ( )
3. Display Contents {
4. Exit if (front == -1)
Enter your choice:2 cout <<"Empty queue "<<endl;
else
for(int i=front;i<=rear;i++)
Queue Operations:
cout <<”q[“<<i<<”]=”<<q[i] <<endl;
1. Add Item
}
2. Delete Item
3. Display Contents };
4. Exit
Enter your choice:3 void main ( )
Empty queue {
queue q;
Unruled side Ruled side

Queue Operations: clrscr( );


1. Add Item int item,choice =1;
2. Delete Item while (choice)
3. Display Contents {
4. Exit cout << "Queue Operations: " <<endl;
Enter your choice:2 cout << "1. Add Item"<endl;
cout << "2. Delete Item"<<endl;
Underflow
cout << "3. Display Contents"<<endl;
cout << "4. Exit "<<endl;
Queue Operations:
cout << "Enter your choice: " ;
1. Add Item
cin >>choice;
2. Delete Item switch (choice)
3. Display Contents {
4. Exit case 1 : cout<<"Input an item to insert : " ;
Enter your choice:4 cin>> item;
q.qinsert(item);
break;
case 2 : q.qdelete( );
break;
case 3 : cout << "The Queue contents is: "<<endl ;
q.display( );
break;
case 4 : exit(0);
default : cout<<"Enter the correct choice"<<endl;
}
}
}
Unruled side Ruled side

OUTPUT Program No 16

/* Write a program to create a linked list and appending the


nodes*/

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

class linklist
{
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<<"Linklist is empty"<<endl;
}
else
{
Unruled side Ruled side

node *temp;
temp = start;
while(temp!=NULL)
{
cout<<temp->data<<endl;
temp=temp->link;
}
}
}
void linklist::append(int num)
{
node *newnode;
newnode = new node;
newnode -> data=num;
newnode->link=NULL;
if(start==NULL)
{
start=newnode;
}
else
{
node *temp;
temp=start;
while(temp->link!= NULL)
{
temp=temp->link;
}
temp->link=newnode;
cout<<num<<"is inserted"<<endl;
}
}
void linklist::count( )
{
Unruled side Ruled side

node *temp;
int c=0;
for(temp=start;temp!=NULL;temp=temp->link)
c++;
cout<<"Linklist contains "<<c<<"elements"<<endl;
}
void main( )
{
linklist *li = new linklist();
clrscr( );
li->append(100);
li->print( );
li->count( );
li->append(200);
li->print( );
li->count( );
li->append(300);
li->print( );
li->count( );
getch( );
}
STRUCTURED QUERY LANGUAGE

PROBLEM 1

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

Field Name Type Description


RR_NO VARCHAR2(10) Electric Meter Number
CUS_NAME VARCHAR2(25) Customer Name
BILLING_DATE DATE Billing Date
UNITS NUMBER(4) Units consumed

Insert 10 records into the Table

i. Check the structure of table and note your observation.


ii. Add two new fields to the table
BILL_AMT NUMBER (6,2)
DUE_DATE Date

iii. Compute the Bill amount for each customer as per the following rules
MIN_AMOUNT Rs.100/-
First 100 Units Rs.4.25/- per Unit
> 100 Units Rs.5/- per Unit

iv. Compute due date as billing date + 15 days.


v. List all the bills generated.
Solution: First we have to create the table EBILL using CREATE TABLE command

SQL> CREATE TABLE EBILL


(
RR_NO VARCHAR2(10) ,
CUS_NAME VARCHAR2(25) ,
BILLING_DATE DATE ,
UNITS NUMBER(4)
);

To insert 10 records into the table EBILL use the following INSERT INTO
commands

SQL > INSERT INTO EBILL VALUES (‘EH 1003’, ‘ARUN KUMAR’, ’12-MAR-14’, 98) ;
SQL > INSERT INTO EBILL VALUES (‘EH 2005’, ‘NAVEEN’, ’18-FEB-14’, 108) ;
SQL > INSERT INTO EBILL VALUES (‘EH 2007’, ‘VARUN’, ’28-APR-14’, 157) ;
SQL > INSERT INTO EBILL VALUES (‘EH 3009’, ‘PINKY’, ’28-APR-14’, 77) ;
SQL > INSERT INTO EBILL VALUES (‘EH 3010’, ‘SOORI’, ’08-APR-14’, 198) ;
SQL > INSERT INTO EBILL VALUES (‘EH 3013’, ‘MD ALI’, ’23-MAR-14’, 68) ;
SQL > INSERT INTO EBILL VALUES (‘EH 3017’, ‘JACOB’, ’03-MAR-14’, 132) ;
SQL > INSERT INTO EBILL VALUES (‘EH 3033’, ‘DRUVA’, ’28-APR-14’, 127) ;
SQL > INSERT INTO EBILL VALUES (‘EH 3037’, ‘KUMAD’, ’08-APR-14’, 87) ;
SQL > INSERT INTO EBILL VALUES (‘EH 3041’, ‘DRUTHI’, ’05-APR-14’, 137) ;

To store all the records permanently in the EBILL table use the following COMMIT
command:

SQL >COMMIT ;

To show the contents of the table EBILL use the following SELECT command:

SQL >SELECT * FROM EBILL ;


i. Check the structure of table and note your observation.

SQL > DESCRIBE EBILL ;

OR

SQL > DESC EBILL ;

ii. Add two new fields to the table.

SQL >ALTER TABLE EBILL ADD (BILL_AMT NUMBER (9, 5) ) ;

SQL > ALTER TABLE EBILL ADD (DUE_DATE DATE) ;

iii. Compute the bill amount for each customer as per the rules.

SQL > UPDATE EBILL


SET BILL_AMT = 100 + UNITS * 4.25
WHERE UNITS <= 100 ;

SQL > UPDATE EBILL


SET BILL_AMT = 100 + 100*4.25 + (UNITS – 100) * 5
WHERE UNITS >100 ;
iv. Compute due date as billing date + 15 days.

SQL > UPDATE EBILL


SET DUE_DATE = BILLING_DATE + 15 ;

v. List all the bills generated.

SQL >SELECT * FROM EBILL ;


PROBLEM 2

Create a table for a CLASS of students with the following details.

Field Name Type Description


ID_NO NUMBER (4) Student ID Number
S_NAME VARCHAR2(25) Student name
SUB1 NUMBER (3) Subject 1 marks
SUB2 NUMBER (3) Subject 2 marks
SUB3 NUMBER (3) Subject 3 marks
SUB4 NUMBER (3) Subject 4 marks
SUB5 NUMBER (3) Subject 5 marks
SUB6 NUMBER (3) Subject 6 marks

i. Add records into the table CLASS for 10 students for ID_NO, S_NAME and marks in 6
subjects using INSERT command
ii. Display the description of the fileds in the table using DESC command.
iii. Calculate TOTAL and PERC_MARKS
iv. Compute the RESULT as “PASS” or “FAIL” by checking if the student has scored more
than 35 marks in each subject
v. List the contents of the table.
vi. Retrieve all the records of the table.
vii. Retrieve only ID_NO and S_NAME of all the students.
viii. List the students who have result as “PASS”.
ix. List the students who have result as “FAIL”.
x. Count the number of students who have passed.
xi. Count the number of students who have failed.
xii. List the students who have percentage greater than 60.
xiii. Sort the table according to the order of ID_NO
Solution: First we have to create the table TABLE CLASS using CREATE TABLE
command

SQL> CREATE TABLE CLASS


(
ID_NO NUMBER (4),
S_NAME VARCHAR2(25),
SUB1 NUMBER(3),
SUB2 NUMBER(3),
SUB3 NUMBER(3),
SUB4 NUMBER(3),
SUB5 NUMBER(3),
SUB6 NUMBER(3)
);

i. Add records into the table CLASS for 10 students for ID_NO, S_NAME and
marks in 6 subjects using INSERT command

SQL> INSERT INTO CLASS VALUES (1401, ‘PAWAN’ , 56, 36, 56, 78, 44, 67) ;
SQL> INSERT INTO CLASS VALUES (1411, ‘RAJESH’, 100, 100, 96, 100, 100, 100) ;
SQL> INSERT INTO CLASS VALUES (1412, ‘KARAN’, 60, 30, 45, 45, 36, 49);
SQL> INSERT INTO CLASS VALUES (1403, ‘MAYA’, 56, 60, 72, 57, 78, 67);
SQL> INSERT INTO CLASS VALUES (1410, ‘GUNA’, 96, 99, 97, 9, 78, 100);
SQL> INSERT INTO CLASS VALUES (1401, ‘MANISHA’, 30, 45, 39, 20, 33, 56);
SQL> INSERT INTO CLASS VALUES (1406, ‘MARTIN’, 79., 65, 79, 79, 89, 88);
SQL> INSERT INTO CLASS VALUES (1405, ‘SATHYA’, 100, 90, 100, 89, 90, 100);
SQL> INSERT INTO CLASS VALUES (1404, ‘ULLAS’, 35, 30, 78, 23, 44, 70);
SQL> INSERT INTO CLASS VALUES (1407, ‘SOORI’, 100, 100, 100, 99, 98, 100);
i.Display the description of the fields in the table using DESC command.

SQL >DESCRIBE CLASS ;

OR

SQL >DESC CLASS ;

iii. Calculate TOTAL and PERC_MARKS

SQL > ALTER TABLE CLASS


ADD (
TOTAL NUMBER(8) ,
PERC_MARKS NUMBER (9,5) ,
RESULT VARCHAR2(10)
);

SQL > UPDATE CLASS


SET TOTAL = SUB1 + SUB2 + SUB3 + SUB4 + SUB5 + SUB6 ;

SQL > UPDATE CLASS


SET PERC_MARKS = TOTAL / 6 ;

iv. Compute the RESULT as “PASS” or “FAIL” by checking if the student has scored more
than 35 marks in each subject.

SQL> UPDATE CLASS


SET RESULT = ‘PASS’
WHERE (SUB1 >=35 AND SUB2 >= 35 AND SUB3 >=35 AND
SUB4 >=35 AND SUB5 >= 35 AND SUB6 >=35) ;
SQL> UPDATE CLASS
SET RESULT = ‘FAIL’
WHERE (SUB1 < 35 OR SUB2 < 35 OR SUB3 < 35 OR
SUB4 < 35 OR SUB5 < 35 OR SUB6 < 35) ;

v . List the contents of the table.

SQL >SELECT * FROM CLASS ;

vii. Retrieve only ID_NO and S_NAME of all the students

SQL >SELECT ID_NO , S_NAME FROM CLASS ;

viii. List the students who have result as “PASS”.

SQL > SELECT * FROM CLASS


WHERE RESULT = ‘PASS’ ;

ix. List the students who have result as “FAIL”.

SQL > SELECT * FROM CLASS


WHERE RESULT = ‘FAIL’ ;

x. Count the number of students who have passed.

SQL > SELECT COUNT ( * ) FROM CLASS


WHERE RESULT = ‘PASS’ ;
xi. Count the number of students who have failed.

SQL > SELECT COUNT ( * ) FROM CLASS


WHERE RESULT = ‘FAIL’ ;

xii. List the students who have percentage greater than 60.

SQL >SELECT * FROM CLASS


WHERE PERC_MARKS > 60 ;

xii. Sort the table according to the order of ID_NO

SQL >SELECT * FROM CLASS ORDER BY ID_NO ;


PROBLEM 3

Create the following table EMPLOYEE for the ABC Ltd. With the following structure:

Field Name Data type Description


EMP_ID NUMBER(4) Employee’s Id number
DEPT_ID NUMBER(2) Name of the department
EMP_NAME VARCHAR2(25) Employee name
EMP_SALARY NUMBER(5) Salary of the employee

Create another table DEPARTMENT with the following structure :

Field Name Data type Description


DEPT_ID NUMBER(2) Department’s Id number
DEPT_NAME VARCHAR2(20) Department name
SUPERVISOR VARCHAR2(20) Department head’s name

Assume the department name as PURCHASE(ID_01), ACCOUNTS(ID_02), SALES(ID_03) and APPRENTICE(ID_04). Enter 10 rows
of data for table EMPLOYEE and 4 rows of data for DEPARMTMENT table.

Write SQL statements for the following:

i. Find the names of the employees who work for the accounts department?
ii. How many employees work for accounts department?
iii. What are the minimum, maximum and average salary of employees working for accounts department?
iv. List the employees working for a particular supervisor.
v. Retrieve the department names for each department where only one employee works.
vi. Increase the salary of all employees in the sales department by 15%.
vii. Add a new columns to the table employee called Bonus number(5) and compute 5% of the salary to the said field.
viii. Delete all the news for employees in the apprentice department.
SOLUTION: First we have to create two tables EMPLOYEE and DEPARTMENT

SQL> CREATE TABLE EMPLOYEE


(
EMP_ID NUMBER(4),
DEPT_ID NUMBER(2),
EMP_NAME VARCHAR2(25),
EMP_SALARY NUMBER(5)
);

SQL> CREATE TABLE DEPARTMENT


(
DEPT_ID NUMBER(2),
DEPT_NAME VARCHAR2(20),
SUPERVISOR VARCHAR2(20)
);

To insert 10 records into the table EMPLOYEE use the following INSERT INTO commands:

SQL > INSERT INTO EMPLOYEE VALUES (101, 01, ‘ARUN’, 15000);
SQL > INSERT INTO EMPLOYEE VALUES (104, 02, ‘SUMAN’, 20000);
SQL > INSERT INTO EMPLOYEE VALUES (105, 03, ‘ANURAG’, 22000);
SQL > INSERT INTO EMPLOYEE VALUES (106, 04, ‘KOUSHIK’, 18000);
SQL > INSERT INTO EMPLOYEE VALUES (109, 01, ‘MARRY’, 22300);
SQL > INSERT INTO EMPLOYEE VALUES (110, 02, ‘AKASH’, 15000);
SQL > INSERT INTO EMPLOYEE VALUES (107, 03, ‘VARUN’, 21300);
SQL > INSERT INTO EMPLOYEE VALUES (102, 04, ‘KOMAL’, 18200);
SQL > INSERT INTO EMPLOYEE VALUES (103, 02, ‘RAM’, 24000);
SQL > INSERT INTO EMPLOYEE VALUES (108, 02, ‘USHA’, 12000);
To insert 4 records into the table DEPARTMENT use the following INSERT INTO
commands :

SQL > INSERT INTO DEPARTMENT VALUES (01, ‘PURCHASE’, ‘MARRY’);


SQL > INSERT INTO DEPARTMENT VALUES (02, ‘ACCOUNTS’, ‘SUMAN’);
SQL > INSERT INTO DEPARTMENT VALUES (03, ‘SALES’, ‘ANURAG’);
SQL > INSERT INTO DEPARTMENT VALUES (04, ‘APPRENTICE’, ‘KOUSHIK’);

Use the following SELECT command to list all the records of the table EMPLOYEE :

SQL > SELECT * FROM EMPLOYEE;

Use the following SELECT command to list all the records of the table DEPARTMENT :

SQL > SELECT * FROM DEPARTMENT;

i. Find the names of all employees who work for the ACCOUNTS
department

SQL > SELECT EMPLOYEE . EMP_NAME , DEPARTMENT. DEPT_NAME


FROM EMPLOYEE, DEPARTMENT
WHERE EMPLOYEE . DEPT_ID = DEPARTMENT . DEPT_ID
AND
DEPARTMENT . DEPT_NAME = ‘ACCOUNTS’ ;
ii. How many Employees work for ACCOUNTS Department?

SQL> SELECT COUNT(*)


FROM EMPLOYEE , DEPARTMENT
WHERE EMPLOYEE . DEPT_ID = DEPARTMENT . DEPT_ID
AND
DEPARTMENT . DEPT_NAME = ‘ACCOUNTS’ ;

iii. What are the minimum maximum and average salary of employees working for
ACCOUNTS department?

SQL > 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’ ;

iv. List the employees working for a particular supervisor .

SQL> SELECT FROM EMPLOYEE . EMP_NAME


EMPLOYEE , DEPARTMENT
WHERE EMPLOYEE . DEPT_ID = DEPARTMENT . DEPT_ID
AND
DEPARTMENT . SUPERVISOR = ‘ ARUN ’
AND
EMPLOYEE . EMP_NAME < > ‘ MARRY ‘ ;
v. Retrieve the department names for each department where only one employee works.

SQL> SELECT DEPT_NAME FROM DEPARTMENT


WHERE DEPT_IN IN (SELECT DEPT_ID FROM EMPLOYEE
GROUP BY DEPT_ID HAVING COUNT(*) =1 ) ;

vi. Increase the salary of all employees in the ‘SALES’ department by 15%.

SQL > UPDATE EMPLOYEE


SET EMP_SALARY= EMP_SALARY + 15 * EMP_SALARY/100
WHERE DEPT_ID = (SELECT DEPT_ID FROM DEPARTMENT
WHERE DEPT_NAME = ‘SALES’) ;

vii. Add a new column to the table employee called BOUNS of type NUMBER(5) and compute
5% of the salary to the said field.

SQL > ALTER TABLE EMPLOYEE ADD (BONUS NUMBER(5) );

To compute 5% BONUS for each employee on the EMP_SALARY we use the following UPDATE
command :

SQL> UPDATE EMPLOYEE


SET BONUS = 5 * EMPL_SALARY /100 ;

SQL > SELECT * FROM EMPLOYEE ;

ix.Delete all the rows for employees in the APPRENTICE department

SQL> DELETE FROM EMPLOYEE


WHERE DEPT_ID= (SELECT DEPT_ID FROM DEPARTMENT
WHERE DEPT_NAME = ‘ACCOUNTS’) ;
PROBLEM 4

Create the following table BANK DATABASE for the ABC bank with the following structure

Field Name Data type Description


ACC_NUMBER NUMBER(12) Customer account Number
CUST_NAME VARCHAR2(25) Customer name
ACC_TYPE CHAR(2) Nature of account
BALANCE NUMBER(12) Balance amount in the account
DOT DATE Date of transaction
T_AMOUNT NUMBER(12) Transaction amount
T_TYPE CHAR(1) D for deposit W for withdrawal

Write SQL statements for the following:

i. Find the names of all customer whose balance amount is more than Rs.30000/-
ii. How many customer whose balance amount is less than the minimum in the account (assume that minimum balance is Rs.1000/ -?
iii. Perform the transaction on T_TYPE (Deposit or withdrawal).
iv. Display the transaction on a particular day.
v. Display all the records of CA account.

Solution: First we have to create the table BANK_DATABASE using CREATE TABLE
command :

SQL > CREATE TABLE BANK_DATABASE


(
ACC_NUMBER NUMBER(12),
CUST_NAME VARCHAR2(25),
ACC_TYPE CHAR(2),
BALANCE NUMBER(12),
DOT DATE,
T_AMOUNT NUMBER(12),
T_TYPE CHAR(1)
);
Insert 8 records into the table BANL_DATABASE use the following INSERT INTO
commands.

SQL > INSERT INTO BANK_DATABASE


VALUES (1230033, ‘ARJUN’, ‘SB’, 34500, ’12-APR-14’, 30000, ‘D’);
SQL > INSERT INTO BANK_DATABASE
VALUES (1230013, ‘KARAN’, ‘SB’, 5000, ’10-APR-14’, 40000, ‘D’);
SQL > INSERT INTO BANK_DATABASE
VALUES (1230345, ‘SUMUKHA’, ‘CA’, 30450, ’1-APR-14’, 45000, ‘D’);

SQL > INSERT INTO BANK_DATABASE


VALUES (1230123, ‘ANAND’, ‘SB’, 13950, ’10-APR-14’, 2500, ‘D’);
SQL > INSERT INTO BANK_DATABASE
VALUES (1230321, ‘MAYA’, ‘SB’, 24500, ’12-APR-14’, 2000, ‘D’);
SQL > INSERT INTO BANK_DATABASE
VALUES (1233345, ‘SHREYA’, ‘CA’, 39400, ’10-APR-14’, 12000, ‘W’);
SQL > INSERT INTO BANK_DATABASE
VALUES (1334563, ‘HEMA’, ‘SB’, 50000, ’12-APR-14’, 30000, ‘W’);
SQL > INSERT INTO BANK_DATABASE
VALUES (1233300, ‘VANI’, ‘SB’, 700, ’10-APR-14’, 500, ‘W’);

i.Find the names of all customer whose balance amount is more than Rs.30000?

SQL > SELECT * FROM BANK_DATABASE WHERE BALANCE > 30000 ;

ii. How many customers whose balance amount is less than the minimum in the account?
(assume that minimum balance is Rs.1000/)

SQL>SELECT COUNT (*) FROM BANK_DATABASE WHERE BALANCE <1000 ;


iii. Perform the transaction on T_TYPE (Deposit or withdrawal).

SQL > UPDATE BANK_DATABASE


SET BALANCE = BALANCE + T_AMOUNT WHERE T_TYPE = ‘D’;

SQL > UPDATE BANK_DATABASE


SET BALANCE = BALANCE - T_AMOUNT WHERE T_TYPE = ‘W’ ;

iv. Display transaction amount on a particular day.

SQL > SELECT * FROM BANK_DATABASE WHERE DOT = ’10-APR-14’ ;

v.Display all the records of CA account.

SQL > SELECT * FROM BANK_DATABASE WHERE ACC_TYPE = ‘CA’ ;


HTML

1. Write a HTML program to create a study time table.

<HTML>
<BODY>
<CENTER><H4>MIPUC</H4>
<TABLE BORDER = 2 BORDERCOLOR="RED">
<CAPTION>IIPUC TIME TABLE</CAPTION>
<TD ROWSPAN= 2>DAY</TD>
<TD ALIGN = "CENTER" COLSPAN =7>TIME</TD>
</TR>

<TR>
<TH>9-10</TH>
<TH>10-11</TH>
<TH>11-12</TH>
<TH>12-1</TH>
<TH>1-1:30</TH>
<TH>1:30-2:30</TH>
<TH>2:30-3:30</TH>
</TR>

<TR>
<TD>MON</TD>
<TD>BS</TD>
<TD>MATH</TD>
<TD>CS</TD>
<TD>LANG</TD>
<TD ROWSPAN=6> LUNCH BREAK</TD>
<TD>LAB</TD>
<TD>ECO</TD>
</TR>

<TR>
<TD>TUE</TD>
<TD>CS</TD>
<TD>LANG</TD>
<TD>BS</TD>
<TD>MATH</TD>
<TD>ECO</TD>
<TD>CS</TD>
</TD>

<TR>
<TD>WED</TD>
<TD>LANG</TD>
<TD>CS</TD>
<TD>LAB</TD>
<TD>BS</TD>
<TD>ECO</TD>
<TD>ACC</TD>
</TR>

<TR>
<TD>THUR</TD>
<TD>ACC</TD>
<TD>ECO</TD>
<TD>CS</TD>
<TD>LANG</TD>
<TD>LAB</TD>
<TD>BS</TD>
</TR>
<TR>
<TD>FRI</TD>
<TD>BS</TD>
<TD>ACC</TD>
<TD>ENG</TD>
<TD>CS</TD>
<TD>LAB</TD>
<TD>ECO</TD>
</TR>

<TR>
<TD>SAT</TD>
<TD>ACC</TD>
<TD>MATH</TD>
<TD>CS</TD>
<TD>K/H/S</TD>
<TD>BS</TD>
<TD>ECO</TD>

</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
2. Create an HTML program with table and form.

<HTML>
<BODY>
<CENTER>
<FORM NAME ="FORM" METHOD ="POST" ACTION ="1PUCSEND.APP">
<H4> FIRST PUC APPLICATION FORM </H4>
<TABLE >

<TR>
<TD>STUDENT NAME :</TD>
<TD ><INPUT TYPE ="TEXT"></TD>
</TR>

<TR>
<TD> FATHERS NAME :</TD>
<TD><INPUT TYPE ="TEXT"></TD>
</TR>

<TR>
<TD> CONTACT NUMBER :</TD>
<TD><INPUT TYPE ="TEXT"></TD>
</TR>

<TR>
<TD> STUDENT ADDRESS </TD>
<TD><TEXTAREA ROWS="2" COLS="15" NAME="DESCRIPTION"></TEXTAREA></TD>
</TR>

<TR >
<TD> GENDER :</TD>
<TD><INPUT TYPE="RADIO" NAME="GENDER" VALUE ="MALE" >MALE</INPUT>
<TD><INPUT TYPE="RADIO" NAME="GENDER" VALUE ="FEMALE" >FEMALE</INPUT>
</TR>
<TR >
<TD> SYLLABUS STREAM:</TD>
<TD ><INPUT TYPE="CHECKBOX" NAME="CBSE" VALUE ="CBSE" >CBSE</INPUT>
<TD ><INPUT TYPE="CHECKBOX" NAME="ICSE" VALUE ="ICSE" >ICSE</INPUT>
<TD ><INPUT TYPE="CHECKBOX" NAME="STATE" VALUE ="STATE" >STATE</INPUT>
</TR>

<TR>
<TD> SELECT THE COURSE:</TD>
<TD><SELECT NAME="DROPDOWN">
<OPTION VALUE="PCMB">PCMB</OPTION>
<OPTION VALUE="PCMCS">PCMCS</OPTION>
<OPTION VALUE="EBACS">EBACS</OPTION>
<OPTION VALUE="EBAS">EBAS</OPTION></TD>
</TR>

<TR>
<TD><INPUT TYPE="BUTTON" VALUE ="SUBMIT" ></TD>
<TD><INPUT TYPE="RESET" VALUE ="RESET" ></TD>
</TR>

</TABLE>
</FORM>
</CENTER>
</BODY>
</HTML>

You might also like