0% found this document useful (0 votes)
43 views80 pages

Lab Manual 2nd Year 2022

Here is a C++ program to find the roots of a quadratic equation based on the discriminant: #include <iostream> #include <math.h> using namespace std; class QuadraticEquation { private: double a, b, c; double discriminant, root1, root2; public: void input() { cout << "Enter coefficients a, b and c: "; cin >> a >> b >> c; } void calculateDiscriminant() { discriminant = b*b - 4*a*c; } void findRoots() { calculateDiscriminant(); if(discriminant == 0) { root
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)
43 views80 pages

Lab Manual 2nd Year 2022

Here is a C++ program to find the roots of a quadratic equation based on the discriminant: #include <iostream> #include <math.h> using namespace std; class QuadraticEquation { private: double a, b, c; double discriminant, root1, root2; public: void input() { cout << "Enter coefficients a, b and c: "; cin >> a >> b >> c; } void calculateDiscriminant() { discriminant = b*b - 4*a*c; } void findRoots() { calculateDiscriminant(); if(discriminant == 0) { root
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/ 80

Computer science

Practical manual

2nd year
PUC

pg. 1
Table of contents

C++

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


2. program to insert an element into an array at a given position
3. program to delete an element from an array from a given position
4. program to sort the elements of an array in ascending order using
insertion sort
5. program to search for a given element in an array using Binary search
method.
6. program to calculate simple interest
7. program to calculate roots of quadratic equations
8. program to find the area of a square / rectangle/ triangle using function
overloading
9. program to find the cube of a number using inline functions.
10. program to find the sum of the series 1+ x + ×2 + . + xn using
constructors.
11. program to implement single level inheritance
12. program to implement concept of pointers to object
13. program to perform PUSH operations
14. program to perform POP operations
15. program to perform enqueue and dequeue.
16. program to create a linked list and appending nodes

Sql
17. Generate electricity bill
18. Generate student database
19. Generate employee details
20. Generate bank database

Html

21. To create study timetable


22. To display table of attendance details and application form

pg. 2
Instructions

1. To open a new file File->New


2. To open an existing file F3
3.To save the program F2
4.To run the program ctrl+F9
5.To compile alt+F9
6.To close the application alt+X
7.For full screen F5

Procedure to execute html program


Step 1 : Open a notepad document
Step 2 : Write the code
Step 3 : To save the program -file-save-give the file name with the
extension .html and then click on "save as type" as All files(from drop
down list)
Step 4 : click on save the respective file will be converted to .html file
To execute the program , double click on the html file.
To open the existing code, right click on the html file- click on the option '
open with ' and then choose notepad to retrieve the code.

NOTE:
If we get an error like statement missing, we have to look for the previous
line.
If we get an error like prototype missing, we have to include the respective
header file.
All the keywords,cout,cin,void has to be written only in lower case with
respect to answer script and system.

pg. 3
NOTES FOR EACH PROGRAM:

Program 2) whenever we are using exit(0), we have to use


#include<stdlib.h>

Program 3) -whenever we are using exit(0), we have to use


#include<stdlib.h>
-delete is a keyword

Program 5) in binary search, elements should always be entered in ascending


order

Program 6) declare the data members as double data type only

Program 7) -whenever we are using sqrt( ), we have to use


#include<math.h>
When discriminant=0, put = = (equals operator)

Program10) whenever we are using pow( ), we have to use


#include<math.h>

Program 11) - whenever we are using gets( ) and puts( ), we have to use
#include<stdio.h>
-in inheritance, we should always create object for derived class.

Program 12) whenever we are using gets( ) and puts( ), we have to use
#include<stdio.h>

pg. 4
C++

1: Write a C++ program to find the frequency presence of an


element in an array.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class frequency
{
private:
int a[100], i , n , ele , tally;
public:
void accept( );
void calculate( );
void display( );
};

void frequency :: accept( )


{
cout<<"Enter the number of elements"<<endl;
cin>>n;
cout<<"Enter the array elements"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to find the frequency"<<endl;
cin>>ele;
}

void frequency :: calculate( )


{
tally=0;
for(i=0;i<n;i++)
if(ele == a[i])
tally++;
}

pg. 5
void frequency :: display( )
{
if(tally>0)
cout<<ele<<" occurs "<<tally<<" time/s";
else
cout<<ele<<" does not exist"<<endl;
}

void main( )
{
frequency obj;
clrscr();
obj.accept();
obj.calculate();
obj.display( );
getch( );
}

Output 1:

pg. 6
Output 2:

pg. 7
2: Write a C++ program to insert an element into an array at a
given position.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class insert
{
private:
int a[100],i,j,n,ele,pos;
public:
void accept();
void calculate();
void display();
};

void insert :: accept()


{
cout<<"Enter the no. of elements in the array"<<endl;
cin>>n;
cout<<"Enter the array elements"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the element to be inserted"<<endl;
cin>>ele;
cout<<"Enter the position"<<endl;
cin>>pos;
}

pg. 8
void insert :: calculate( )
{
if(pos>n)
{
cout<<"position is out of array limits"<<endl;
getch( );
exit(0);
}
else
{
for(j=n-1;j>=pos;j--)
a[j+1]=a[j];
a[pos]=ele;
n=n+1;
}
}

void insert :: display( )


{
cout<<"array elements after inserting"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}
void main( )
{
insert obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display( );
getch( );
}

pg. 9
Output 1:

Output 2:

pg. 10
3: Write a C++ program to delete an element from an array from
a given position.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class deletion
{
private:
int a[100],n,pos,ele,i,j;
public:
void accept( );
void calculate( );
void display( );
};

void deletion :: accept( )


{
cout<<"Enter the number of elements in the array."<<endl;
cin>>n;
cout<<"Enter the array elements."<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the position of the element to be deleted."<<endl;
cin>>pos;
}

pg. 11
void deletion :: calculate( )
{
if(pos>n-1)
{
cout<<"Invalid position."<<endl;
getch();
exit(0);
}
else
{
ele=a[pos];
for(j=pos+1;j<n;j++)
a[j-1]=a[j];
n=n-1;
}

void deletion :: display( )


{
cout<<"Array elements after deletion are "<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}

void main( )
{
deletion obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display( );
getch( );
}

pg. 12
Output 1:

Output 2:

pg. 13
4: Write a C++ program to sort the element of an array in
ascending order using insertion sort.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class sorting
{
private:
int a[100],n,i,j,temp;
public:
void accept( );
void calculate( );
void display( );

};

void sorting :: accept( )


{
cout<<"Enter the number of elements in the array."<<endl;
cin>>n;
cout<<"Enter the array elements."<<endl;
for(i=0;i<n;i++)
cin>>a[i];
}

pg. 14
void sorting :: calculate( )
{
for(i=1;i<n;i++)
{
j=i;
while(j>=1)
{
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
j=j-1;
}
}
}

void sorting :: display( )


{
cout<<"The array elements after sorting are"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<"\t";
}

void main( )
{
sorting obj;
clrscr ( );
obj.accept( );
obj.calculate( );
obj.display( );
getch( );
}

pg. 15
Output 1:

pg. 16
5: Write a C++ program to search for a given element in an array
using binary search method.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class binary
{
private: int a[100],n,ele,loc,i;
public:
void accept( );
void calculate( );
void display( );
};
void binary :: accept( )
{
cout<<"enter the number of array elements"<<endl;
cin>>n;
cout<<"enter the array elements in ascending order"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
cout<<"enter the element to search"<<endl;
cin>>ele;
}
void binary:: calculate( )
{
int beg,end,mid;
beg= 0;
end = n-1;
loc = -1;
while( beg <= end)
{
mid=(beg+end)/2;

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

void binary :: display( )


{
if(loc >=0)
cout<<"element found at position "<<loc<<endl;
else
cout<<"element not found"<<endl;
}

void main( )
{
binary obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display( );
getch();
}

pg. 18
Output 1:

Output 2:

pg. 19
6: Write a C++ program to create a class with data members
principal, time and rate. Create a member function to accept data
values, to compute simple interest and to display the result.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class simple
{
private :
double si,p,t,r;
public :
void accept( )
{
cout<<"Enter the principle amount, time and rate"<<endl;
cin>>p>>t>>r;
}

void calculate( )
{
si=(p*t*r)/100;
}

void display( )
{
cout<<"Simple Interest is "<<si<<endl;
}
};

pg. 20
void main( )
{
simple obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display( );
getch();
}

Output 1:

pg. 21
7: Write a C++ program to create a class with data members a, b, c and
member functions to input data, compute the discriminates based on the
following conditions and print the roots.
 If discriminates = 0, print the roots are equal and their value.
 If discriminates > 0, print the real roots and their values.
 If discriminates < 0, print the roots are imaginary and exit the
program

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class quad
{
private:
int a,b,c;
float disc,x,x1,x2;
public:
void accept( )
{
cout<<"Enter the values for a,b,c"<<endl; cin>>a>>b>>c;
}

void calculate( )
{
disc=b*b-4*a*c;
}

pg. 22
void display( )
{
if(disc==0)
{
cout<<"Equal roots"<<endl; x=-b/(2*a);
cout<<"Root is="<<x;
}

else if(disc>0)
{
cout<<"Real & distinct roots"<<endl;
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
cout<<"Root 1 is="<<x1<<endl;
cout<<"Root 2 is="<<x2<<endl;
}

else
cout<<"Imaginary roots"<<endl;
}
};

void main( )
{
quad obj;
clrscr( );
obj.accept( );
obj.calculate();
obj.display();
getch( );
}

pg. 23
Output 1:

Output 2:

Output 3:

pg. 24
8: Write a C++ program to find the area of square/ rectangle/
triangle using function overloading

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class function_overload
{
private:
float s;
public:
float area(float a)
{
return a*a;
}

float area(float L , float b)


{
return L*b;
}

float area(float a,float b,float c)


{
s=(a+b+c)/2;
return (sqrt(s*(s-a)*(s-b)*(s-c)));
}
};

pg. 25
void main( )
{
int choice;
float x,y,z;
clrscr();
function_overload obj;
cout<<"Enter the choice 1 or 2 or 3."<<endl;
cin>>choice;
if(choice==1)
{
cout<<"Enter the side of square."<<endl;
cin>>x;
cout<<"Area of the square is "<<obj.area(x)<<endl;
}

else if(choice==2)
{
cout<<"Enter the sides of the rectangle."<<endl;
cin>>x>>y;
cout<<"Area of the rectangle is "<<obj.area(x,y)<<endl;
}

else if(choice==3)
{
cout<<"Enter the sides of triangle."<<endl;
cin>>x>>y>>z;
cout<<"Area of the triangle is "<<obj.area(x,y,z)<<endl;
}

else
cout<<"Invalid input."<<endl;
getch( );

pg. 26
Output 1:

Output 2:

Output 3:

pg. 27
Output 4:

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

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

class number
{
public :
inline int cube(int a)
{
return(a*a*a);
}
};

void main()
{
number obj;
int x;
clrscr();
cout<<"enter a number"<<endl;
cin>>x;
cout<<"cube of given number is : "<<obj.cube(x);
getch();
}

pg. 29
Output 1:

pg. 30
10: Write a C++ program to find sum of the series 1 + x + x2 + x3
+ ….xn using constructors.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class series
{
private:
int sum,x,n,i;

public:
series( )
{
sum=1;
}
void accept();
void calculate();
void display();
};

void series::accept( )
{
cout<<"Input the value of X"<<endl;
cin>>x;
cout<<"Input the value of n"<<endl;
cin>>n;
}

pg. 31
void series::calculate( )
{
for(i=1;i<=n;i++)
sum=sum+pow(x,i);
}

void series:: display( )


{
cout<<"sum= "<<sum<<endl;
}

void main( )
{
series obj;
clrscr( );
obj.accept( );
obj.calculate( );
obj.display();
getch();
}

Output 1:

pg. 32
11: Create a base class containing the data member roll number and name.
Also create a member function to read and display the data using the
concept of single level inheritance. Create a derived class that contains
marks of two subjects and total marks as the data members.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
class student
{
private:
int id;
char name[20];
public:
void accept( )
{
cout<<"Input Roll No."<<endl;
cin>>id;
cout<<"Input name of student."<<endl;
gets(name);
}

void display( )
{
cout<<"Roll Number : "<<id<<endl;
cout<<"Name : "<<name<<endl;
}
};

pg. 33
class report : public student
{
private:
int m1,m2,total;
public:

void input( )
{
cout<<"Enter the subject1 marks : "<<endl;
cin>>m1;
cout<<"Enter the subject2 marks : "<<endl;
cin>>m2;
}

void calculate( )
{
total=m1+m2;
cout<<"Total : "<<total<<endl;
}

};

void main( )
{
report obj;
clrscr( );
obj.accept( );
obj.display( );
obj.input( );
obj.calculate( );
getch( );
}

pg. 34
Output 1:

pg. 35
12: Create a class containing the following data members Register No,
Name and Fees. Also create a member function to read and display the
data using the concept of pointers to objects.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
class student
{
private:
int id;
char name[20];
float fees;
public:
void accept( );
void display( );
};

void student::accept( )
{
cout<<"enter register number"<<endl;
cin>>id;
cout<<"enter the name of the student"<<endl;
gets(name);
cout<<"enter the fees"<<endl;
cin>>fees;
}
void student::display( )
{
cout<<"register number:"<<id<<endl;
cout<<"name of the student:"<<name<<endl;
cout<<"fees: "<<fees<<endl;
}

pg. 36
void main( )
{
student obj,*p;
p=&obj;
clrscr( );
p-> accept( );
p-> display( );
getch( );
}

Output 1:

pg. 37
13. Write a program to perform push operation

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
#define max 2

class stack
{
private:
int a[max], top;
public: stack()
{
top=-1;
}
void push(int item);
void print();
};

void stack :: push(int item)


{
if(top == max -1)
{
cout<<endl<<"sorry, stack is full"<<endl;
return;
}

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

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

void main ()
{
stack s;
int choice, itm;
clrscr();
while(1)
{
cout<<endl<<"1.PUSH"<<endl<<"2.PRINT"<<endl<<"3.EXIT"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1 :
{
cout<<"Enter the item"<<endl;
cin>>itm;
s.push(itm);
break;
}

pg. 39
case 2 :
{
s.print();
break;
}

case 3 :
{
cout<<"Thankyou for visiting"<<endl;
exit(0);
}
default : cout<<"Invalid choice";
}
}
}

Output :

pg. 40
3
Thank you for visiting

pg. 41
14. Write a program to perform pop operation

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

#define max 2
class stack
{
private:
int a[max], top;
public:
stack()
{
top = -1;
}
void push(int item);
void print();
void pop();
};

void stack :: push(int item)


{
if(top == max-1)
{
cout<<endl<<"\t sorry stack is full"<<endl;
return;
}
top++;
a[top]=item;
cout<<"\t"<<item<<" is successfully pushed"<<endl;
}

void stack :: print()


{
if(top!=-1)
{
cout<<"stack contains ";
for(int i=0; i<=top; i++)
cout<<a[i]<<setw(4);
cout<<endl;
}
else
cout<<"\t the stack is empty"<<endl;
pg. 42
}

void stack :: pop()


{
if(top == -1)
{
cout<<endl<<"\t sorry stack is empty"<<endl;
return;
}
else
{
int ele = a[top];
top--;
cout<<"\t"<<ele<<" is successfully popped"<<endl;
}
}

void main ()
{
stack s;
int choice, itm;
clrscr();
while(1)
{
cout<<"1.PUSH"<<endl<<"2.POP"<<endl<<"3.PRINT"<<endl<<"4.EXIT"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter the item : "<<endl;
cin>>itm;
s.push(itm);
break;
}

case 2 :
{
s.pop();
break;
}

case 3:
{
s.print();
break;
pg. 43
}

case 4:
{
cout<<"Thank you, visit again";
getch();
exit(1);
}

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


}
}
}

Output:

pg. 44
2
sorry stack is empty

4
Thank you, visit again

pg. 45
15. Write a program to perform enqueue and dequeue operations

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#define max 2
class queue
{
private:
int item, i, q[max], rear, front;
public:
queue()
{
rear=0;
front=0;
}

void insert()
{
if(rear == max)
cout<<"\n queue reached max!"<<endl;
else
{
cout<<"\n Enter the value to be inserted"<<endl;
cin>>item;
q[rear++] = item;
}
}

void remove()
{
if(front == rear)
cout<<"\n queue is empty"<<endl;
else
{
cout<<q[front]<<" Element successfully removed"<<endl;
front++;
}
}

pg. 46
void display()
{

for(i=front; i<rear; i++)


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

void main ()
{
int choice, exit_p = 1;
queue obj;
clrscr();
do
{
cout<<"\n 1.Insert \n 2.Remove \n 3.Display \n 4.Exit"<<endl;
cout<<"\n Enter your choice "<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
obj.insert();
break;
}
case 2:
{
obj.remove();
break;
}
case 3:
{
obj.display();
break;
}
default :
{
exit_p=0;
break;
}
}
}while(exit_p);
}

pg. 47
Output:

pg. 48
4

pg. 49
16. Write a program to insert and display elements using single linked list

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
struct node
{
int value;
struct node*next;
};
void insert();
void display();

typedef struct node DATA_NODE;

DATA_NODE * head_node, *first_node, *temp_node = 0, *prev_node, next_node;


int data;

void main ()
{
clrscr();
int option = 0;
cout<<"singly linked list \n"<<endl;
while(option<3)
{
cout<<"\n options \n";
cout<<"1.Insert into linked list \n";
cout<<"2.Display linked list \n";
cout<<"3.Exit \n";
cout<<"Enter your option"<<endl;
cin>>option;
switch(option)
{
case 1:
{
insert ();
break;
}

pg. 50
case 2:
{
display();
break;
}

default : exit (0);


}
}
getch();
}

void insert ()
{
cout<<"\n Enter element for inserting in linked list"<<endl;
cin>>data;
temp_node = (DATA_NODE*)malloc(sizeof(DATA_NODE));
temp_node -> value = data;
if(first_node == 0)
{
first_node = temp_node;
}
else
{
head_node -> next = temp_node;
}
temp_node -> next=0;
head_node = temp_node;
}

void display()
{
int count = 0;
temp_node = first_node;
cout<<"\n Display linked list :"<<endl;
while(temp_node!=0)
{
cout<<"\t"<<temp_node -> value;
count++;
temp_node = temp_node -> next;
}
cout<<"\n No. of items in linked list : "<<count;
}

pg. 51
Output:

pg. 52
SQL
17. Generate the electricity bill for one consumer.
Create a table for house hold electricity bill with the following fields.
FIELD NAME TYPE
RR_number Varchar2(10)
Consumer_name Varchar2(25)
Date_billing date
units Number(4)

1. Insert 10 records into the table.


2. Check the structure of table and note your observation
3. Add two new fields to the table
 Bill_amt number(6,2)
 Due_date date
4. Compute the bill amount for each customer as per the following rules
Min_amt Rs.50
First 100 units Rs.4.50 /unit
>100 units Rs.5.50 /unit
5. Compute due date as billing date+15 days
6. List all the bills generated

Solution:

create table ebill(rr_number varchar2(10),consumer_name varchar2(25),date_billing


date,units number(4));

1. insert into ebill values('e1','a','01-aug-2022',60);

insert into ebill values('e2','b','02-aug-2022',70);

insert into ebill values('e3','c','03-aug-2022',80);

insert into ebill values('e4','d','04-aug-2022',90);

insert into ebill values('e5','e','05-aug-2022',100);

insert into ebill values('e6','f','06-aug-2022',110);

insert into ebill values('e7','g','07-aug-2022',120);

insert into ebill values('e8','h','08-aug-2022',130);

insert into ebill values('e9','i','09-aug-2022',140);

pg. 53
insert into ebill values('e10','j','10-aug-2022',150);

2. desc ebill;

3. alter table ebill add(bill_amt number(6,2),due_date date);

4 i) update ebill set bill_amt=50;

ii) update ebill set bill_amt=bill_amt+units*4.50 where units<=100;

iii) update ebill set bill_amt=bill_amt+100*4.50+(units-100)*5.50 where units>100;

5. update ebill set due_date = date_billing + 15;

6. select *from ebill;

Output:

2. Name Null? Type


----------------------------------------- -------- ----------------------------
RR_NUMBER. VARCHAR2(10)
CONSUMER_NAME VARCHAR2(25)
DATE_BILLING DATE
UNITS. NUMBER(4)

6.

RR_NUMBER CONSUMER_NAME DATE_BILL UNITS BILL_AMT DUE_DATE


---------- ------------------------- --------- ---------- ---------- ---------
e1 a 01-AUG-22 60 320 16-AUG-22
e2 b 02-AUG-22 70 365 17-AUG-22
e3. c 03-AUG-22 80 410 18-AUG-22
e4 d 04-AUG-22 90 455 19-AUG-22
e5 e 05-AUG-22 100 500 20-AUG-22
e6 f 06-AUG-22 110 555 21-AUG-22
e7 g 07-AUG-22 120 610 22-AUG-22
e8 h 08-AUG-22 130 665 23-AUG-22
e9 i 09-AUG-22 140 720 24-AUG-22
e10 j 10-AUG-22 150 775 25-AUG-22

pg. 54
18

Create a student database and compute the result.


Create a table for a class of students with the following details
FIELD NAME TYPE
id number(4)
name Varchar2(25)
Sub1 number(3)
Sub2 number(3)
Sub3 number(3)
Sub4 number(3)
Sub5 number(3)
Sub6 number(3)
1. Add records into the table for 10 students for name ,id,and marks of six subjects
using insert command.
2. Display the description of the fields using desc command
3. Alter the table and calculate total and perc_marks.
4. Compute the result as pass or fail by checking if the student has scored
more than 35 marks in each subject.
5. List the contents of the table.
6. retrieve all the records of table
7. Retrieve id,name of all the students
8. List the students who have result as pass
9. List the students who have result as fail
10. Count the number of students who have passed
11. Count the number of students who have failed.
12. List the students who have percentage greater than 60
13. Sort the table according to the order of id.

Solution:

create table student(id number(3), name varchar2(5), sub1 number(3),sub2


number(3),sub3 number(3),sub4 number(3),sub5 number(3),sub6 number(3));

1.
insert into student values(1,'a',90,90,90,90,90,90);

insert into student values(2,'b',80,80,80,80,80,80);

insert into student values(3,'c',70,70,70,70,70,70);

insert into student values(4,'d',60,60,60,60,60,60);

insert into student values(5,'e',50,50,50,50,50,50);

pg. 55
insert into student values(6,'f',40,40,40,40,40,40);

insert into student values(7,'g',30,30,30,30,30,30);

insert into student values(8,'h',20,20,20,20,20,20);

insert into student values(9,'i',10,10,10,10,10,10);

insert into student values(10,'j',5,10,15,20,25,30);

2.desc student;

3. alter table student add(total number(3), perc_marks number(6,2), result varchar2(5));

4 i) update student set total=sub1 + sub2 + sub3 + sub4 + sub5 + sub6;

ii)update student set perc_marks= total/6;

iii)update student set result='pass' where sub1>=35 and sub2>=35 and sub3>=35 and
sub4>=35 and sub5>=35 and sub6>=35 ;

iv) update student set result='fail' where sub1<35 or sub2<35 or sub3<35 or sub4<35 or
sub5<35 or sub6<35 ;

5 & 6. select * from student;

7. select id, name from student;

8 .select * from student where result ='pass';

9. select * from student where result ='fail';

10. select count (*) from student where result ='pass';

11. select count (*) from student where result ='fail';

12. select * from student where perc_marks >60;

13. select * from student order by id;

pg. 56
Output

2.

Name Null? Type


----------------------------------------- -------- ----------------------------
ID NUMBER(3)
NAME VARCHAR2(5)
SUB1 NUMBER(3)
SUB2 NUMBER(3)
SUB3 NUMBER(3)
SUB4 NUMBER(3)
SUB5 NUMBER(3)
SUB6 NUMBER(3)

5,6 &13

ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT
---------- ---------- ---------- -----
1 a 90 90 90 90 90 90 540 90 pass

2 b 80 80 80 80 80 80 480 80 pass

3 c 70 70 70 70 70 70 420 70 pass

4 d 60 60 60 60 60 60 360 60 pass

5 e 50 50 50 50 50 50 300 50 pass

6 f 40 40 40 40 40 40 240 40 pass

7 g 30 30 30 30 30 30 180 30 fail

8 h 20 20 20 20 20 20 120 20 fail

9 i 10 10 10 10 10 10 60 10 fail

10 j 5 10 15 20 25 30 105 17.5 fail

pg. 57
7.

ID NAME
---------- -----
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
10 j

8.
ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT
---------- ---------- ---------- -----
1 a 90 90 90 90 90 90 540 90 pass

2 b 80 80 80 80 80 80 480 80 pass

3 c 70 70 70 70 70 70 420 70 pass

4 d 60 60 60 60 60 60 360 60 pass

5 e 50 50 50 50 50 50 300 50 pass

6 f 40 40 40 40 40 40 240 40 pass

pg. 58
9.

ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT

7 g 30 30 30 30 30 30 180 30 fail

8 h 20 20 20 20 20 20 120 20 fail

9 i 10 10 10 10 10 10 60 10 fail

10 j 5 10 15 20 25 30 105 17.5 fail

10.

COUNT(*)
----------
6

11.

COUNT(*)
----------
4

12.

ID NAME SUB1 SUB2 SUB3 SUB4 SUB5 SUB6 TOTAL PERC_MARKS RESULT
---------- ---------- ---------- -----
1 a 90 90 90 90 90 90 540 90 pass

2 b 80 80 80 80 80 80 480 80 pass

3 c 70 70 70 70 70 70 420 70 pass

pg. 59
19.

Generate the employee details and compute the salary based on the department.
Create the following employee table

FIELD NAME DATA TYPE DESCRIPTION


Emp_id number(4) Employee’s id number
Dept_id number(4) Department’s id
number
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’s head’s
name

Assume the department names as purchase(id-1),accounts(id-2),sales(id-3) and


apprentice(id-4).

Enter 10 rows of data for table employee and 4 rows of data for department table

Write SQL statements for the following.


1. find the names of all employees who works for accounts department.
2. How many employees work for accounts department.
3. What is the minimum, maximum and average salary of employees working for
accounts department.
4. List the employees working for a particular supervisor.
5. Retrieve the department names for each department where only one employee
works
6. Increase the salary of all employees in the sales department by 15%
7. Add a new column to the table employee called bonus number(5) and compute 5%
of the salary to the said field.
8. Delete all the rows for employees in the apprentice department.

Solution:

create table employee(emp_id number(4),dept_id number(2),emp_name


varchar2(15),emp_salary number(5));

pg. 60
insert into employee values(1,1,'a',20000);

insert into employee values(2,2,'b',30000);

insert into employee values(3,3,'c',40000);

insert into employee values(4,4,'d',50000);

insert into employee values(5,2,'e',60000);

insert into employee values(6,3,'f',70000);

insert into employee values(7,4,'g',80000);

insert into employee values(8,2,'h',90000);

insert into employee values(9,3,'i',10000);

insert into employee values(10,4,'j',25000);

create table department(dept_id number(2),dept_name varchar2(15),supervisor


varchar2(10));

insert into department values(1,'purchase','a');

insert into department values(2,'accounts','b');

insert into department values(3,'sales','c');

insert into department values(4,'apprentice','d');

1.
select employee.emp_name,department.dept_name from employee,department where
employee.dept_id=department.dept_id and department.dept_name='accounts';

2.
select count(*) from employee,department where
employee.dept_id=department.dept_id and department.dept_name='accounts';

3.
select min(employee.emp_salary), max(employee.emp_salary),
avg(employee.emp_salary) from employee,department where
employee.dept_id=department.dept_id and department.dept_name='accounts';
pg. 61
4.
select * from employee where dept_id=(select dept_id from department where
supervisor='b');

5.
select dept_name from department where dept_id in(select dept_id from employee
group by dept_id having count(*)=1);

6.
update employee set emp_salary=emp_salary+emp_salary*0.15 where dept_id=(select
dept_id from department where dept_name='sales');

7.
i.alter table employee add bonus number(10,2);

ii.update employee set bonus=emp_salary*0.05;

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

Output:

select * from employee; [sample data]

EMP_ID DEPT_ID EMP_NAME EMP_SALARY


---------- ---------- --------------- ----------
1 1 a 20000
2 2 b 30000
3 3 c 40000
4 4 d 50000
5 2 e 60000
6 3 f 70000
7 4 g 80000
8 2 h 90000
9 3 i 10000
10 4 j 25000

pg. 62
select * from department; [sample data]

DEPT_ID DEPT_NAME SUPERVISOR


---------- --------------- ----------
1 purchase a
2 accounts b
3 sales c
4 apprentice d

1.

EMP_NAME DEPT_NAME
--------------- ---------------
b accounts
e accounts
h accounts

2.

COUNT(*)
----------
3

3.

MIN(employee.EMP_SALARY) MAX(employee.EMP_SALARY)
AVG(employee.EMP_SALARY)
----------------------- ----------------------- -----------------------
30000 90000 60000

4.

EMP_ID DEPT_ID EMP_NAME EMP_SALARY


---------- ---------- --------------- ----------
2 2 b 30000
5 2 e 60000
8 2 h 90000

pg. 63
5.

DEPT_NAME
---------------
purchase

6.
select * from employee;

EMP_ID DEPT_ID EMP_NAME EMP_SALARY


---------- ---------- --------------- ----------
1 1 a 20000
2 2 b 30000
3 3 c 46000
4 4 d 50000
5 2 e 60000
6 3 f 80500
7 4 g 80000
8 2 h 90000
9 3 i 11500
10 4 j 25000

7.
select * from employee;

EMP_ID DEPT_ID EMP_NAME EMP_SALARY BONUS


---------- ---------- --------------- ---------- ----------
1 1 a 20000 1000
2 2 b 30000 1500
3 3 c 46000 2300
4 4 d 50000 2500
5 2 e 60000 3000
6 3 f 80500 4025
7 4 g 80000 4000
8 2 h 90000 4500
9 3 i 11500 575
10 4 j 25000 1250

pg. 64
8.

select * from employee;

EMP_ID DEPT_ID EMP_NAME EMP_SALARY BONUS


---------- ---------- --------------- ---------- ----------
1 1 a 20000 1000
2 2 b 30000 1500
3 3 c 46000 2300
5 2 e 60000 3000
6 3 f 80500 4025
8 2 h 90000 4500
9 3 i 11500 575

pg. 65
20.

Solution:

create table bank(acc_number number(12), cust_name varchar2(10), acc_type char(2),


balance number(12), dot date, t_amount number(12), t_type char(1));

insert into bank values(01, 'a', 'sb', 85000, '01-aug-22', 5000, 'd');

insert into bank values(02, 'b', 'sb', 80000, '02-aug-22', 5500, 'd');

insert into bank values(03, 'c', 'sb', 75000, '03-aug-22', 4000, 'd');

insert into bank values(04, 'd', 'sb', 70000, '04-aug-22', 1200, 'd');

insert into bank values(05, 'e', 'sb', 50000, '05-aug-22', 1500, 'd');

insert into bank values(06, 'f', 'ca', 999, '06-aug-22', 500, 'w');

insert into bank values(07, 'g', 'ca', 900, '07-aug-22', 200, 'w');

insert into bank values(08, 'h', 'ca', 950, '08-aug-22', 450, 'w');

insert into bank values(09, 'i', 'ca', 800, '09-aug-22', 410, 'w');

insert into bank values(10, 'j', 'ca', 700, '10-aug-22', 400, 'w');
pg. 66
1.
select cust_name from bank where balance>30000;

2.
select count(*) from bank where balance<1000;

3.
update bank set balance = balance + t_amount where t_type = 'd';

update bank set balance = balance - t_amount where t_type = 'w';

4.
select * from bank where dot = '01-aug-22';

5.
select * from bank where acc_type = 'ca';

Output:

select * from bank; [sample data]

ACC_NUMBER CUST_NAME AC BALANCE DOT T_AMOUNT T_TYPE


---------- ---------- -- ---------- --------- ---------- -
1 a sb 85000 01-AUG-22 5000 d
2 b sb 80000 02-AUG-22 5500 d
3 c sb 75000 03-AUG-22 4000 d
4 d sb 70000 04-AUG-22 1200 d
5 e sb 50000 05-AUG-22 1500 d
6 f ca 999 06-AUG-22 500 w
7 g ca 900 07-AUG-22 200 w
8 h ca 950 08-AUG-22 450 w
9 i ca 800 09-AUG-22 410 w
10 j ca 700 10-AUG-22 400 w

1.

CUST_NAME
----------
a
b
c
d
e

pg. 67
2.

COUNT(*)
----------
5

3.

select * from bank where t_type = ‘d’;

ACC_NUMBER CUST_NAME AC BALANCE DOT T_AMOUNT T_TYPE


---------- ---------- -- ---------- --------- ---------- -
1 a sb 90000 01-AUG-22 5000 d
2 b sb 85500 02-AUG-22 5500 d
3 c sb 79000 03-AUG-22 4000 d
4 d sb 71200 04-AUG-22 1200 d
5 e sb 51500 05-AUG-22 1500 d

select * from bank where t_type = ‘w’;

ACC_NUMBER CUST_NAME AC BALANCE DOT T_AMOUNT T_TYPE


---------- ---------- -- ---------- --------- ---------- -
6 f ca 499 06-AUG-22 500 w
7 g ca 700 07-AUG-22 200 w
8 h ca 500 08-AUG-22 450 w
9 i ca 390 09-AUG-22 410 w
10 j ca 300 10-AUG-22 400 w

4.

ACC_NUMBER CUST_NAME AC BALANCE DOT T_AMOUNT T_TYPE


---------- ---------- -- ---------- --------- ---------- -
1 a sb 90000 01-AUG-22 5000 d

pg. 68
5.

ACC_NUMBER CUST_NAME AC BALANCE DOT T_AMOUNT T_TYPE


---------- ---------- -- ---------- --------- ---------- -
6 f ca 499 06-AUG-22 500 w
7 g ca 700 07-AUG-22 200 w
8 h ca 500 08-AUG-22 450 w
9 i ca 390 09-AUG-22 410 w
10 j ca 300 10-AUG-22 400 w

pg. 69
Html

21. To create study timetable


<html>
<head>
<b><u>STUDY TIME TABLE</u></b>
</head>
<title>Lab program</title>

<table border=20>
<tr>
<th>DAYS</th>
<th>SUBJECT</th>
<th>MORNING STUDY TIME</th>
<th>COLLEGE TIME</th>
<th>EVENING STUDY TIME</th>
<th>SOLVING QUESTION PAPER</th>
</tr>

<tr>
<td>MONDAY</td>
<td>PHYSICS</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>

<tr>
<td>TUESDAY</td>
<td>CHEMISTRY</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>

pg. 70
<tr>
<td>WEDNESDAY</td>
<td>MATH</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>

<tr>
<td>THURSDAY</td>
<td>COMPUTER</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>

<tr>
<td>FRIDAY</td>
<td>LANGUAGE</td>
<td>5:30-7:00</td>
<td>8:30-4:00</td>
<td>6:00-8:30</td>
<td>10:30-11:30</td>
</tr>

</table>
<marquee>ALL THE BEST</marquee>
</body>
</html>

Output

pg. 71
22. To display table of attendance details and application form

<html>
<head>
<center><Attendance details</center>
</head>
<title>2nd Program</title>
<body>
<center><h2>Subject: Computer Science</h2></center>
<table border=10>
<tr>
<th>Months</th>
<th>No. of classes held</th>
<th>No. of classes attended</th>
</tr>
<tr>
<td>June</td>
<td>16</td>
<td>16</td>
</tr>
</table>

<table border=10>
<tr>
<center><h2>Application form</h2></center>
</tr>
<form method=get action=targetfile.html>
<tr>
<td>Student Name: </td>
<td><input type=text name= ></td>
</tr>

<tr>
<td>Gender: </td>
<td>
<input type=radio name=gender>Male
<input type=radio name=gender>Female
</td>
</tr>

pg. 72
<tr>
<td>Subject: </td>
<td>
<input type=checkbox>phy
<input type=checkbox>chem
<input type=checkbox>maths
<input type=checkbox>computer
</td>
</tr>

<tr>
<td align=right><input type=submit value=submit></td>
<td align=left><input type=reset value=reset></td>
</tr>
</form>
</table>
</body>
</html>

targetfile.html

<html>
<head>
<title></title>
</head>
<body>
Hello your file is successfully submitted
</body>
<html>

pg. 73
Output:

pg. 74
pg. 75
pg. 76
pg. 77
pg. 78
pg. 79
pg. 80

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy