Вы находитесь на странице: 1из 56

CS LAB MANUAL

SIMS, HOSAKOTE
Computer Science Lab Manual For Second PUC
Karnataka Board.

Abstract
PART- A: C++ Programs(1-16)
PART- B:SQL Experiments(17-19)
PART- C:HTML Programs(21-22)

Irshad Pasha
9591730046
II PUC CS LAB MANUAL SIMS, HOSAKOTE

PART – A : C++

1. Write a program to find the frequency of presence of an element in an array.


2. Write a program to insert an element into an array at a given position.
3. Write a program to delete an element from an array from a given position.
4. Write a program to sort the elements of an array in ascending order using insertion
sort.
5. Write a program to search for a given element in an array using binary search
method.
6. Write a program to create a class with data membersprinciple, time and rate.
Create member function to accept data values to compute simple interest and to
display the result.
7. Write a program to create a class with data members a,b,c and member function to
input data, compute and print the roots of quadratic equation.
8. Write a program to find the area of square,rectangle and triangle using function
overloading.
9. Write a program to find the the cube of a number using inline function.
10. Write a program to find the sum of the series 1+X+X2+……+Xn using constructors.
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 concept of single level
inheritance. Create a derived class that contains marks of two subjects and total
marks as the data members.
12. Create a class containing the following data members register number, name and
fees. Also create a member function to read and display the data using the concept
of pointers to objects.
13. Write a program to perform push operation on stack.
14. Write a program to perform pop operation on stack.
15. Write a program to perform enqueue and dequeue operations on a queue.
16. Write a program to create a linked list and appending nodes.

PART – B : SQL

17. Generate the electricity bill for one consumer.


18. Create a student database and compute the result.
19. Generate the employee details and compute the salary based on the department.

PART – C : HTML

20. Write a HTML program to create a study time-table.


21. Write a HTML program with table and form.

Page |1 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

Page |2 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

PART-A: C++

1.Program to find the frequency of presence of an element in an array

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

class frequency
{
private:
int n, m[100], ele, freq;
public:
void getdata();
void findfreq();
void display();
};

void frequency::getdata()
{
cout<<"Enter the size of array: ";
cin>>n;
cout<<"Enter "<<n<<" elements into the array: ";
for(int i = 0 ; i < n ; i++)
cin>>m[i];
cout<<"Enter the search element: ";
cin>>ele;
}
void frequency::findfreq()
{
freq = 0;
for(int i = 0; i < n ; i++)
if(ele==m[i])
freq++;
}

Page |3 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

void frequency::display()
{
if(freq>0)
cout<<"Frequency of "<<ele<<" is "<<freq;
else
cout<<ele<<" does not exist";
}

void main()
{
frequency F;
clrscr();
F.getdata();
F.findfreq();
F.display();
getch();
}

Output:

2.Program to insert an element into an array at a given position

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

class insertion
{
private:
int n, m[100], ele, p;
public:
void getdata();
void insert();
Page |4 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

void display();
};

void insertion::getdata()
{
cout<<"How many elements?";
cin>>n;
cout<<"Enter the elements: ";
for(int i=0; i<n; i++)
cin>>m[i];
cout<<"Enter the element to be inserted: ";
cin>>ele;
cout<<"Enter the position(0 to "<<n<<"): ";
cin>>p;
}
void insertion::insert()
{
if(p>n)
{
cout<<p<<" is an invalid position";
getch();
exit(0);
}
for(int i=n-1; i>=p; i--)
m[i+1] = m[i];
m[p]=ele;
n++;

cout<<ele<<" is successfully inserted"<<endl;


}

void insertion::display()
{
cout<<"The array after the insertion is ";

for(int i=0; i<n; i++)


cout<<setw(4)<<m[i];
}

void main()

Page |5 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

{
insertion I;
clrscr();
I.getdata();
I.insert();
I.display();
getch();
}
Output:

3.Program to delete an element from an array from a given position

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

class deletion
{
private:
int m[50], n, ele, p;
public:
void getdata();
void remove();
void display();
};

void deletion::getdata()
{
cout<<"How many elements: ";
cin>>n;
cout<<"Enter the elements: ";
for(int i=0; i<n; i++)
cin>>m[i];

Page |6 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

cout<<"Enter the position: ";


cin>>p;
}

void deletion::remove()
{
if(p>n-1)
{
cout<<p<<" is an invalid position";
getch();
exit(0);
}
ele=m[p];
for(int i=p+1; i<n; i++)
m[i-1]=m[i];
n--;
cout<<ele<<" is successfully removed"<<endl;
}

void deletion::display()
{
cout<<"The array after deletion is ";
for(int i=0; i<n; i++)
cout<<setw(4)<<m[i];
}

void main()
{
deletion D;
clrscr();
D.getdata();
D.remove();
D.display();
getch();
}

Page |7 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

Output:

4.Program to sort the elements of an array in ascending order using insertion


sort

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

class sorting
{
private:
int m[50], n;
public:
void getdata();
void sort();
void display();
};

void sorting::getdata()
{
cout<<"How many elements : ";
cin>>n;
cout<<"Enter the elements : ";
for(int i=0; i<n; i++)
cin>>m[i];
}

void sorting::sort()
{
int temp, j;
for(int i=1; i<n; i++)
{
j=i;
while(j>=1)

Page |8 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

{
if(m[j]<m[j-1])
{
temp = m[j];
m[j] = m[j-1];
m[j-1] = temp;
}
j--;
}
}
}

void sorting::display()
{
cout<<"The sorted elements are :";
for(int i=0; i<n; i++)
cout<<"\t"<<m[i];
}

void main()
{
sorting S;
clrscr();
S.getdata();
S.sort();
S.display();
getch();
}

Output:

5.Program to search for a given element in an array using binary search


method

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

Page |9 Irshad Pasha


II PUC CS LAB MANUAL SIMS, HOSAKOTE

#include<conio.h>

class binary
{
private:
int m[50], n, ele, loc;
public:
void getdata();
void search();
void display();
};

void binary::getdata()
{
cout<<"How many elements: ";
cin>>n;
cout<<"Enter the elements: ";
for(int i=0; i<n; i++)
cin>>m[i];
cout<<"Enter the search element: ";
cin>>ele;
}

void binary::display()
{
if(loc>=0)
cout<<"Position = "<<loc;
else
cout<<"Search is unsuccessful";
}

void binary::search()
{
int beg,end,mid;
loc=-1;
beg=0;
end=n-1;
while(beg<=end)
{
mid=(beg+end)/2;

P a g e | 10 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

if(ele==m[mid])
{
loc=mid;
break;
}
else
if(ele<m[mid])
end=mid-1;
else
beg=mid+1;
}
}

void main()
{
binary B;
clrscr();
B.getdata();
B.search();
B.display();
getch();
}

Output:

6.Program to compute simple interest and display the result

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

class interest
{
private:
double p, t, r, si;

P a g e | 11 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

public:
void getdata();
void compute();
void putdata();
};

void interest::getdata()
{
cout<<"Enter principle amount, time and rate: "<<endl;
cin>>p>>t>>r;
}

void interest::compute()
{
si = (p*t*r)/100;
}

void interest::putdata()
{
cout<<"Principle : "<<p<<endl;
cout<<"Time : "<<t<<endl;
cout<<"Rate : "<<r<<endl;
cout<<"Simple interest: "<<si<<endl;
}

void main()
{
interest I;
clrscr();
I.getdata();
I.compute();
I.putdata();
getch();
}

P a g e | 12 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

Output:

7.Program to display the roots of Quadratic equation.

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>

class quadratic
{
private:
double a, b, c, r1, r2;
public:
void getdata();
void roots();
void putdata();
};

void quadratic::getdata()
{
cout<<"Enter the co-efficients: ";
cin>>a>>b>>c;
}

void quadratic::roots()
{
double d=b*b-4*a*c;
if(d==0)
{
cout<<"Roots are equal"<<endl;
r1=-b/(2*a);
P a g e | 13 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

r2=r1;
}
else
if(d>0)
{
cout<<"Roots are positive and different:"<<endl;
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
}
else
{
cout<<"Roots are imaginary";
getch();
exit(0);
}
}

void quadratic::putdata()
{
cout<<"First root = "<<r1<<endl;
cout<<"Second root = "<<r2;
}

void main()
{
quadratic Q;
clrscr();
Q.getdata();
Q.roots();
Q.putdata();
getch();
}

P a g e | 14 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

Output:

8.Program to find the area of a square/rectangle/triangle using function


overloading

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

class function
{
private:
float s;
public:
double area(double a)
{
return a*a;
}
double area(double l, double b)
{
return l*b;
}
double area(double a, double b, double c)
{
s=(a+b+c)/2.0;
return(sqrt(s*(s-a)*(s-b)*(s-c)));
}
};
P a g e | 15 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

void main()
{
function f;
double x, y, z;
int ans;
clrscr();
cout<<"Enter the number of sides(1,2 or 3): ";
cin>>ans;
if(ans==1)
{
cout<<"Enter the side: ";
cin>>x;
cout<<"Area of the square ="<<f.area(x)<<endl;
}
else
if(ans==2)
{
cout<<"Enter two sides: ";
cin>>x>>y;
cout<<"Area of the rectangle = "<<f.area(x,y)<<endl;
}
else
if(ans==3)
{
cout<<"Enter three sides: ";
cin>>x>>y>>z;
cout<<setprecision(8);
cout<<"Area of triangle = "<<f.area(x,y,z)<<endl;
}
else
cout<<"Invalid input";
getch();
}

P a g e | 16 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

Output:

9.Program to find the cube of a number using inline function

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

class assign
{
private:
int n;
public:
assign(int nn)
{
n=nn;
}
int cube();
};

inline int assign::cube()


{
return(n*n*n);
}

void main()
{
int n;
clrscr();

P a g e | 17 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

cout<<"Enter the number: ";


cin>>n;
assign N=n;
cout<<"Cube of "<<n<<" = "<<N.cube();
getch();
}

Output:

10.Program to find sum of series 1+x+x2+…..+xn using constructors.

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

class copy
{
private:
int var, sum, term;
public:
double calculate();
copy(int temp, int x)
{
var = temp;
term = x;
}
};

double copy::calculate()
{
int p;
sum=1;
p=term;
for(int i=1; i<=var; i++)
{
sum = sum + p;

P a g e | 18 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

p = p * term;
}
return sum;
}

void main()
{
int n, t;
clrscr();
cout<<"Enter the base and the power(x and n): ";
cin>>t>>n;
copy obj(n,t);
copy cpy = obj;
cout<<"Sum of the series is "<<obj.calculate();
getch();
}

Output:

11.Program to demonstrate concept of single level inheritance

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

class student
{
private:
int rollno;
char name[20];
public:
void read()
{
cout<<"Enter the name: ";
cin.getline(name,20);
cout<<"Enter Roll No: ";
cin>>rollno;
}
P a g e | 19 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

void display()
{
cout<<"Roll no: "<<rollno<<endl;
cout<<"Name: "<<name<<endl;
}
};

class marks:public student


{
private:
int m1;
int m2;
int total;
public:
void read1()
{
cout<<"Enter two subject marks: ";
cin>>m1>>m2;
total = m1 + m2;
}

void display1()
{
cout<<"Subject1 = "<<m1<<endl;
cout<<"Subject2 = "<<m2<<endl;
cout<<"Total marks = "<<total<<endl;
}
};

void main()
{
marks ob;
clrscr( );
ob.read();
ob.read1();
ob.display();
ob.display1();
getch();
}

P a g e | 20 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

Output:

12.Program to demonstrate the concept of pointers and objects

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

class student
{
private:
int regno;
char name[20];
float fees;
public:
void get();
void display();
};

void student::get()
{
cout<<"Enter student name: ";
cin.getline(name, 20);
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;

P a g e | 21 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

cout<<"Student fees: "<<fees;


}

void main()
{
student s, *sp;
clrscr();
sp = &s;
sp->get();
sp->display();
getch();
}

Output:

13.Program to push items into the stack.

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
#define MAX 3

class stackpush
{
private:
int A[MAX], top;
public:
stackpush()
{
top = -1;
}
void push(int item);
void print();
P a g e | 22 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

};

void stackpush::push(int item)


{
if(top == MAX-1)
{
cout<<"sorry.. stack is full"<<endl;
return;
}
top++;
A[top] = item;
cout<<item<<" is successfully pushed"<<endl;
}

void stackpush::print()
{
if(top != -1)
{
cout<<"stack contains: ";
for(int i=0; i<=top; i++)
cout<<setw(4)<<A[i];
cout<<endl;
}
else
cout<<"stack is empty"<<endl;
}

void main()
{
stackpush S;
int choice, item;
clrscr();
while(1)
{
cout<<endl<<"1. Push"<<endl<<"2. Print"<<endl<<"3. Exit"<<endl;
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1: cout<<"Enter the item: ";

P a g e | 23 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

cin>>item;
S.push(item);
break;

case 2: S.print();
break;

case 3: cout<<"Thank you.. Visit again";

getch();
exit(0);

default: cout<<"Invalid choice"<<endl;


}
}
}

Output:

P a g e | 24 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

14.Program to pop elements from the stack.

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
#define MAX 3

class stackpop
{
private:
int A[MAX], top;
public:
stackpop()
{
top = -1;
}
void push(int item);
void print();
void pop();
};

void stackpop::push(int item)


{
if(top == MAX-1)
{
cout<<"Sorry.. Stack is full"<<endl;
return;
}

P a g e | 25 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

top++;
A[top] = item;
cout<<item<<" is successfully pushed"<<endl;
}

void stackpop::print()
{
if(top != -1)
{
cout<<"stack contains: ";
for(int i=0; i<=top; i++)
cout<<setw(4)<<A[i];
cout<<endl;
}
else
cout<<"stack is empty"<<endl;
}

void stackpop::pop()
{
if(top == -1)
{
cout<<endl<<"Sorry, stack is empty"<<endl;
return;

}
else
{
int ele = A[top];
top--;
cout<<ele<<" is successfully popped"<<endl;
}
}

void main()
{
stackpop S;
int choice, item;
clrscr();
while(1)

P a g e | 26 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

{
cout<<endl<<"1. push"<<endl<<"2. pop"<<endl<<"3.
print"<<endl<<"4. exit"<<endl;
cout<<"Enter your choice: ";
cin>>choice;

switch(choice)
{
case 1: cout<<"Enter the item: ";
cin>>item;
S.push(item);
break;

case 2: S.pop();
break;

case 3: S.print();
break;

case 4: cout<<"Thank you.. Visit again";


getch();
exit(0);

default: cout<<"Invalid choice"<<endl;


}
}
}

Output:

P a g e | 27 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

15.Program to perform enqueue and dequeue operations.

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
P a g e | 28 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

#include<stdlib.h>
#define SIZE 3

class queue
{
private:
int q[SIZE];
int front, rear;
int count;
public:
queue();
void enqueue(int x);
void dequeue();
void display();
};

queue::queue()
{
front = -1;
rear = -1;
count = 0;
}

void queue::enqueue(int x)
{
if(rear == SIZE - 1)
{
cout<<"Sorry.. queue is full."<<endl;
return;
}
if(front == -1)
{
front = 0;
rear = 0;
}
else
rear++;
q[rear] = x;
count++;
cout<<x<<" is successfully inserted"<<endl;

P a g e | 29 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

void queue::dequeue()
{
if(front == -1)
{
cout<<"queue is empty"<<endl;
return;
}
int x = q[front];
if(front == rear)
{
front = -1;
rear = -1;
}
else
front++;
count--;
cout<<x<<" is successfully deleted"<<endl;
}

void queue::display()
{
if(count > 0)
{
cout<<"queue contains: ";
for(int i=front; i<=rear; i++)
cout<<q[i]<<setw(4);
cout<<endl;
}
else
cout<<"Sorry... queue is empty"<<endl;
}

void main()
{
queue Q;
int choice;
int item;
clrscr();

P a g e | 30 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

while(1)
{
cout<<"1. Enqueue"<<endl<<"2. Dequeue"<<endl<<"3. Print
Queue"<<endl<<"4. Exit"<<endl;
cout<<"Enter your choice: ";
cin>>choice;

switch(choice)
{
case 1: cout<<"Enter the item: ";
cin>>item;
Q.enqueue(item);
break;

case 2: Q.dequeue();
break;

case 3: Q.display();
break;

case 4: cout<<"Thank you... Visit again";


getch();
exit(1);

default: cout<<"Invalid choice..."<<endl;


}
}
}

P a g e | 31 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

Output:

16.Program to create linked list and append nodes.

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

class linklist
{
private:

P a g e | 32 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

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<<"link list is empty"<<endl;
return;

}
cout<<"link list contains: ";
Node *tmp = START;
while(tmp != NULL)
{
cout<<tmp->data<<" ";
tmp=tmp->link;
}
}

void linklist::Append(int num)


{
Node *newNode;
newNode=new Node;
newNode->data=num;
newNode->link=NULL;

P a g e | 33 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

if(START==NULL)
{
START=newNode;
cout<<endl<<num<<" is inserted at 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();
clrscr();
obj->print();
obj->Append(100);
obj->print();
obj->count();

obj->Append(200);
obj->print();
obj->count();

obj->Append(300);
obj->print();

P a g e | 34 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

obj->count();
getch();
}

Output:

P a g e | 35 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

P a g e | 36 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

PART –B : SQL

GENERATE ELECTRICITY BILL FOR ONE CONSUMER


1. Command to create table
create table electric(RR_number varchar2(10),
consumer_name varchar2(25),
date_billing date,
units number(4));
2.Commands to add records into the table
insert into electric values('A1001','Manjunath','12-FEB-2014',34);
insert into electric values('A1098','Reeta','14-FEB-2014',128);
insert into electric values('B1190','Nithin','9-FEB-2014',234);
insert into electric values('B1234','Vikas','14-FEB-2014',256);
insert into electric values('B2345','Parinitha','13-FEB-2014',277);
insert into electric values('A1987','Tarun Vohra','23-FEB-2014',289);
insert into electric values('A2456','Solanki','12-FEB-2014',178);
insert into electric values('C3459','Patil SS','15-FEB-2014',176);
insert into electric values('B3765','Yashaswini','13-FEB-2014',160);
insert into electric values('A4790','Lashman JS','16-FEB-2014',299);
3.Command to view the description of a table
desc electric;
4.Command to add two new fields to the table
alter table electric add(amount number(6,2), due_date date);
5..Command to calculate amount and date due date
update electric set amount=50;

P a g e | 37 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

update electric set amount=amount+100*4.50+(units-100)*5.50 where


units>100;
update electric set amount=amount+units*4.50 where units<=100;
update electric set due_date=date_billing+15;
6.Command to view the bill statement
select * from electric;

Output for desc command:

Output for select command:

P a g e | 38 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

CREATE A STUDENT DATABASE AND COMPUTE THE RESULT


1.Command to create a table
create table student(student_id number(4),student_name
varchar2(25),sub1_marks number(2),sub2_marks number(2),sub3_marks
number(2),sub4_marks number(2),sub5_marks number(2),sub6_marks
number(2));
2.Command to add records into table
insert into student values(1124,'Kiran',67,82,86,90,56,78);
insert into student values(1127,'Sandeep',56,69,78,34,52,59);
insert into student values(1123,'Vinodh',51,40,50,51,55,58);
insert into student values(1121,'Bhavani',28,36,45,34,37,39);
insert into student values(1122,'Preetham',34,56,68,79,80,96);
insert into student values(1125,'Khushbu',78,89,90,96,95,92);
insert into student values(1129,'Kishan',68,77,84,69,70,79);
insert into student values(1126,'Kalpana',78,89,86,88,96,95);
insert into student values(1120,'Varun',56,30,35,47,55,54);
insert into student values(1119,'Joseph',66,69,60,70,81,59);
3.Command to view the structure of the table
desc student;
4.Command to add the new fields to the existing table
alter table student add(total number(3),perc_marks number(2),result
varchar2(10));
5.Command to calculate total
update student set
total=sub1_marks+sub2_marks+sub3_marks+sub4_marks+sub5_marks+sub6
_marks;

P a g e | 39 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

6.Command to calculate percentage


update student set perc_marks=total/6.0;
7.Command to calculate result as pass
update student set result='pass' where sub1_marks>=35 and sub2_marks>=35
and sub3_marks>=35 and sub4_marks>=35 and sub5_marks>=35 and
sub6_marks>=35;

8.Command to calculate result as fail


update student set result='fail' where sub1_marks<35 or sub2_marks<35 or
sub3_marks<35 or sub4_marks<35 or sub5_marks<35 or sub6_marks<35;

9.Command to view the contents of the table


select * from student;

10. Command to retrieve all the records of the table

select * from student;

11.Command to retrieve only student id and student name of all the students

select student_id,student_name from student;

12. Command to list the students who have result as pass

select * from student where result=’pass’;

13. Command to list the students who have as fail

select * from student where result=’fail’;

14. Command to count the number of students who have passed

select count(*) from student where result=’pass’;

P a g e | 40 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

15. Command to count the number of students who have failed

select count(*) from student where result=’fail’;

16. Command to count the number of students who have percentage more
than 60

select * from student where perc_marks>=60;

17. Command to sort the students list according to student id

select * from student order by student_id;

Output for desc command:

Output for select command:

P a g e | 41 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

GENERATE THE EMPLOYEE DETAILS AND COMPUTE THE


SALARY BASED ON THE DEPARTMENT
1.Commands to create the tables:
create table employee(emp_id number(4),dept_id number(4), emp_name
varchar2(25),emp_salary number(5));
create table department(dept_id number(4), dept_name varchar2(20),
supervisor varchar2(20));
2.Commands to insert the data in department table:
insert into department values(1, 'purchase','Ameen');
insert into department values(2, 'accounts','Krishna Reddy');
insert into department values(3, 'sales','Tanveer');
insert into department values(4, 'apprentice','AshishMehra');
3.Commands to insert the data in employee table:
insert into employee values(1009,1,'Arun Gupta',25000);
insert into employee values(1045,2,'Priya Rao',27500);
insert into employee values(1067,3,'Anup Kaul',27500);
insert into employee values(1034,2,'Vanshidhar',23700);
insert into employee values(1058,4,'Hari Prasad',29000);
insert into employee values(1029,3,'Anil Goel',19350);
insert into employee values(1044,2,'Harsha Shenoy',52000);
insert into employee values(1030,3,'Surya',14500);
insert into employee values(1022,4,'Keerthi',37900);
insert into employee values(1088,2,'Arun Jaitley',27500);
4.Command to find the names of all the employees who work for the
accounts department
select * from employee where dept_id=(select dept_id from department
where dept_name='accounts');

P a g e | 42 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

5.Command to find the number of employees who work for the accounts
department
select count(*) from employee where dept_id=(select dept_id from
department where dept_name='accounts');
6. Command to find the minimum,maximum and average salary of
employees who work for the accounts department
select min(emp_salary) from employee where dept_id=(select dept_id from
department where dept_name='accounts');
select max(emp_salary) from employee where dept_id=(select dept_id from
department where dept_name='accounts');
select avg(emp_salary) from employee where dept_id=(select dept_id from
department where dept_name='accounts');
7. Command to list the employees working for a particular supervisor
select * from employee where dept_id=(select dept_id from department
where supervisor='Tanveer');
8. Command to retrieve the department names for each department where
only one employee works
select dept_name from department where dept_id in(select dept_id from
employee group by dept_id having count(*)=1);
9. Command to increase the salary of all employees in the sales department
by 15%
update employee set emp_salary=emp_salary+emp_salary*0.15 where
dept_id=(select dept_id from department where dept_name='sales');
10.Command to add a new column to the table employee, called Bonus
number(5) and compute 5% of the salary to the said field
alter table employee add bonus number(5);
update employee set bonus=emp_salary*0.05;

P a g e | 43 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

11.Command to delete all the rows for employees in the apprentice


department
delete from employee where dept_id=(select dept_id from department where
dept_name='apprentice');

P a g e | 44 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

P a g e | 45 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

PART-C: HTML
1.Write a html program to create a study time table
<html>
<head>
<title>Study time table</title>
<style>
td,th,table
{
border:1px solid black;
}
</style>
</head>
<body>
<h1><center>MY STUDY TIME-TABLE FOR THE WEEK</center></h1>
<h2><center>Beautiful Sunrise</center></h2>
<img border="0" src="C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg"
width="900" height=300">
<table style="width:900px">
<tr>
<th>Days</th>
<th>Subjects</th>
<th>Morning study time</th>
<th>College study time</th>
<th>Evening study time</th>
<th>Question papers solution time</th>

P a g e | 46 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

</tr>
<tr>
<td>Monday</td>
<td>Kannada</td>
<td>5:00 - 6:30 A.M</td>
<td>8:30 - 4:00 P.M</td>
<td>6:00 - 8:30 P.M</td>
<td>9:00 - 11:00 P.M</td>
</tr>

<tr>
<td>Tuesday</td>
<td>English</td>
<td>5:00 - 6:30 A.M</td>
<td>8:30 - 4:00 P.M</td>
<td>6:00 - 8:30 P.M</td>
<td>9:00 - 11:00 P.M</td>
</tr>

<tr>
<td>Wednesday</td>
<td>Economics</td>
<td>5:00 - 6:30 A.M</td>
<td>8:30 - 4:00 P.M</td>
<td>6:00 - 8:30 P.M</td>

P a g e | 47 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

<td>9:00 - 11:00 P.M</td>


</tr>

<tr>
<td>Thursday</td>
<td>Business Studies</td>
<td>5:00 - 6:30 A.M</td>
<td>8:30 - 4:00 P.M</td>
<td>6:00 - 8:30 P.M</td>
<td>9:00 - 11:00 P.M</td>
</tr>

<tr>
<td>Friday</td>
<td>Accounts</td>
<td>5:00 - 6:30 A.M</td>
<td>8:30 - 4:00 P.M</td>
<td>6:00 - 8:30 P.M</td>
<td>9:00 - 11:00 P.M</td>
</tr>

<tr>
<td>Saturday</td>
<td>Computer Science</td>
<td>5:00 - 6:30 A.M</td>

P a g e | 48 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

<td>8:30 - 4:00 P.M</td>


<td>6:00 - 8:30 P.M</td>
<td>9:00 - 11:00 P.M</td>
</tr>
</table>
<marquee direction="right">Enjoy life as a student!!</marquee>
</body>
</html>

Output:

P a g e | 49 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

2.Create an html program with table and form


<html>
<head>
<title>Student registration form</title>
<style>
td,th,table
{
border:1px solid black;
}
</style>
</head>
<body>
<h1>ATTENDENCE DETAILS:</h1>
<h3>SUBJECT:COMPUTER SCIENCE</h3>
<table style="width:300px">
<tr>
<th>Month</th>
<th>No of classes held</th>
<th>No of classes attended</th>
</tr>
<tr>
<td>JUNE</td>
<td>08</td>
<td>08</td>
</tr>

P a g e | 50 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

<tr>
<td>JULY</td>
<td>16</td>
<td>16</td>
</tr>
<tr>
<td>AUGUST</td>
<td>16</td>
<td>16</td>
</tr>
<tr>
<td>SEPTEMBER</td>
<td>16</td>
<td>16</td>
</tr>
<tr>
<td>OCTOBER</td>
<td>16</td>
<td>16</td>
</tr>
<tr>
<td>NOVEMBER</td>
<td>16</td>
<td>16</td>
</tr>

P a g e | 51 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

<tr>
<td>DECEMBER</td>
<td>16</td>
<td>16</td>
</tr>
<tr>
<td>Total No of days</td>
<td>120</td>
<td>120</td>
</tr>
<tr>
<td>PERCENTAGE</td>
<td>100</td>
<td>100</td>
</tr>
</table>
<br><br>
<h3>STUDENT REGISTRATION FORM</h3>
<form name="registrationform">
<table style="width:100px">
<tr>
<td>Student Name:</td>
<td>
<input type="text" name="SName" maxlength="50" size="30">
</td>

P a g e | 52 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

</tr>
<tr>
<td>Student ID:</td>
<td>
<input type="text" name="SID" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>Father Name:</td>
<td>
<input type="text" name="FName" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio" name="gender" value="male" >Male
<input type="radio" name="gender" value="female">Female
</td>
</tr>
<tr>
<td>Course:</td>
<td>
<select name="Course">
<option value="-1" selected>select..</option>

P a g e | 53 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

<option value="PCMB">PCMB</option>
<option value="EBACs">EBACs</option>
<option value="PCMCs">PCMCs</option>
</select>
</td>
</tr>
<tr>
<td>Mobile Number:</td>
<td>
<input type="text" name="telephone" maxlength="12" size="30">
</td>
</tr>
<tr>
<td><input type="reset" value="Reset"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>

P a g e | 54 Irshad Pasha
II PUC CS LAB MANUAL SIMS, HOSAKOTE

Output:

********************************************************

P a g e | 55 Irshad Pasha