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

26461621ii Puc Computer Science Lab Manual

The document outlines 14 computer science lab programs to be written in C++ and SQL. The C++ programs cover topics like arrays, classes, functions, inheritance and data structures. The SQL programs generate electricity bills, student results, employee details, bank transactions and perform operations like insert, update, delete on the tables.

Uploaded by

Nayana GS
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)
151 views

26461621ii Puc Computer Science Lab Manual

The document outlines 14 computer science lab programs to be written in C++ and SQL. The C++ programs cover topics like arrays, classes, functions, inheritance and data structures. The SQL programs generate electricity bills, student results, employee details, bank transactions and perform operations like insert, update, delete on the tables.

Uploaded by

Nayana GS
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/ 61

II PUC COMPUTER SCIENCE LAB MANUAL

CONTENTS
Program Page
Program Name
No No
SECTION- A (C++ AND DATA STRUCTURES)
01 Write a C++ program to find the frequency presence of an element in an array. 06
02 Write a C++ program to insert an element into an array at a given position. 08
03 Write a C++ program to delete an element from an array from a given position. 10
Write a C++ program to sort the element of an array in ascending order using
04 12
insertion sort.
Write a C++ program to search for a given element in an array using binary search
05 14
method.
Write a C++ program to create a class with data members principal, time and rate.
06 Create a member function to accept data values, to compute simple interest and to 16
display the result.
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.
07 18
➢ 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.
Write a C++ program to find the area of square/ rectangle/ triangle using function
08 20
overloading.

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


Write a C++ program to find sum of the series 1 + x + x + x + ….x using
2 3 n

10 23
constructors.
Create a base class containing the data member roll number and name. Also create a
member function to read and display the data using the concept of single level
11 25
inheritance. Create a derived class that contains marks of two subjects and total marks
as the data members.
Create a class containing the following data members Register No, Name and Fees.
Also create a member function to read and display the data using the concept of
12 pointers to objects. 27
13 Write a C++ program to perform push items into the stack. 29
14 Write a C++ program to perform pop items into the stack. 32
15 Write a C++ program to perform Enqueue and Dequeue. 35
16 Write a program to create a linked List and appending nodes 38

1
Program Page
Program Name
No No
SECTION – B (SQL)
Generate the electricity bill for one customer
Create a table for house hold Electricity bill with the following fields.
Field Name Type
RR_NO VARCHAR(3)
CUS_NAME VARCHAR(35)
DATE_BILLING DATE
UNITS NUMBERIC(6,2)

01 Insert 10 records into the table. 42


1. Check the structure of table and note your observation.
2. Add two fields to the table.
a. BILL_AMT NUMBERIC(6,2)
b. DUE_DATE DATE
3. Compute the bill amount for each customer as per the following rules.
a. Minimum Amount Rs. 50
b. First 100 units Rs 4.50/Unit
c. >100 units Rs. 5.50/Unit
4. Compute due date as BILLING_DATE + 15 Days
5. List all the bills generated.
Create a student database and compute the results.
Create a table for class of students with the following fields.
Field Name Type
ID_NO VARCHAR(7)
S_NAME VARCHAR(25)
SUB1 INT
SUB2 INT
SUB3 INT
SUB4 INT
SUB5 INT
SUB6 INT

1. Add records into the table for 10 students for Student ID, Student Name and
02 marks in 6 subjects using INSERT command. 44
2. Display the description of the fields in the table 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 the table.
7. Retrieve only ID_NO and S_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_NO.
2
Generate the Employee details and compute the salary based on the department.
Create the following table EMPLOYEE
Field Name Type
EMP_ID INT
DEPT_ID INT
EMP_NAME VARCHAR(10)
EMP_SALARY FLOAT

Create another table DEPARTMENT

Field Name Type


DEPT_ID INT
DEPT_NAME VARCHAR(10)
SUPERVISOR VARCHAR(10)
Assume the DEPARTMENT names as Purchase (Id-01), Accounts (Id-02), Sales (Id-
03 03), and Apprentice (Id-04) 47
Enter 10 rows of data for table EMPLOYEE and 4 rows of data for DEPARTMENT
table.
Write the SQL statements for the following:
1. Find the names of all employees who work for the Accounts department.
2. How many employees work for Accounts department?
3. What are the Minimum, Maximum and Average salary of employees working for
Accounts department?
4. List the employees working for 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 Colum to the table EMPLOYEE called BONUS NUMBER (5) and
compute 5% of the salary to the said field.
8. Delete all the rows for the employee in the Apprentice department.

3
Create database for the Bank transaction

Create following table customer

fieldname datatype description


C_NO INT Customer id number
NAME VARCHAR(10) Customer Name
ADDRESS VARCHAR(100) Customer Address
PHONE BIGINT Customer phone

Create another table Bank with following structure

fieldname datatype description


AC_NO INT Customer Account No
04 TRANS_NO INT Customer Name
TRANS_DATE DATE Transaction date 51
TRANS_TYPE CHAR Transaction type (C/D)
CUST_NO INT Customer No

1. Enter 5 Records to Customer and 5 records to Bank table


2. Display structure and records of both the table
3. Command to display the transaction between two dates
4. Command to display the transaction greater than a specific date
5. Command to Display Account No, Customer No, Name where Customer No equal
to Customer No from Bank Table
6. Command to delete a record having a specific phone number
7. Command to display all the records that have transaction as credit
8. Command to create a new table with account no and transaction amount
9. Command to list all the names starting from ‘A’
10. Command to display system date

SECTION- C HTML

01 Write a HTML program to create a study time-table 56

02 Create an HTML program with table and Form. 58

4
SECTION – A
C++ AND DATA STRUCTURES

5
PROGRAM 1:

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


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

class Frequency
{
private:
int m[10], n, ele, freq; //Data member
public:
void getdata( );
void findfreq( ); //Member functions declaration
void display( );
};

void Frequency::getdata( ) //Member function definition


{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter “<<n<<” the array elements:"<<endl;
for(int i=0; i<n; i++)
cin>>m[i];
cout<<"Enter the search element "<<endl;
cin>>ele;
}

void Frequency::findfreq( ) //Member function definition


{
freq=0;
for(int i=0; i<n; i++)
if (ele = = m[i]) //Traversing Operation
freq++;
}

void Frequency::display( ) //Member function definition


{
if(freq > 0)
cout<<” Frequency of “ <<ele<<” is “<<freq;
else
cout<<ele<<" does not exist";
}

void main( ) //Main function


{
Frequency F;
clrscr( );
F.readdata( );
F.findfreq( );
F.display( );
getch( );
}

6
OUTPUT 1:

OUTPUT 2:

7
PROGRAM 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 <process.h>

class Insertion
{
private:
int m[10], n, p, ele; //Data Members

public:
void getdata( );
void insert( ); // Member Function Declaration
void display( );
};

void Insertion::getdata( )
{
cout<<"Enter the size of the array"<<endl;
cin>>n;
cout<<"Enter the elements for the array"<<endl;
for(int i=0; i<n; i++)
cin>>m[i];
cout<<"Enter the element to be inserted"<<endl;
cin>>ele;
cout<<"Enter the position of the element in the array"<<endl;
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]; // Shift array elements
m[p] = ele; // Insert the given element
cout<< ele << “ successfully inserted “ << endl;
n = n+1; // Size of the array is incremented by 1
}

void Insertion::display( )
{
cout<<"Array elements after insertion are:"<<endl;
for(int i=0; i<n; i++)
cout<<setw(4)<<m[i];
}
8
void main( )
{
Insertion I;
clrscr( );
I.getdata( );
I.insert( );
I.display( );
getch( );
}

OUTPUT 1:

OUTPUT 2:

9
PROGRAM 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 <process.h>

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

void deletion::getdata( )
{
cout<<"Enter the size of the array"<<endl;
cin>>n;
cout<<"Enter the elements for the array:"<<endl;
for (int i=0; i<n; i++)
cin>>m[i];
cout<<"Enter the position to an delete an element:\n";
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 = n-1; // Reduce size of the array by 1
cout<< ele << “ is successfully removed “;
}

void deletion::display( )
{
cout<<"After deletion the array elements are"<<endl;
for(int i=0; i<n; i++)
cout<<setw(4)<<m[i];
}

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

OUTPUT 1:

OUTPUT 2:

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

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

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

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

void sorting::sort( )
{
int j, temp;
for(int i=1; i<n; i++)
{
j = i;
while(j >= 1)
{
if(m[j] < m[j-1])
{
temp = m[j];
m[j] = m[j-1];
m[j-1] = temp;
}
j = j-1;
}
}
}

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

OUTPUT 1:

OUTPUT 2:

13
PROGRAM 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 binarysearch
{
private:
int m[10], n, ele, loc ;
public:
void getdata( );
void search( );
void display( );
};

void binarysearch::getdata( )
{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter the array elements in sorted order:"<<endl;
for(int i=0;i<n;i++)
cin>>m[i];
cout<<"Enter the element to search:"<<endl;
cin>>ele;
}

void binarysearch::display( )
{
if(loc >=0)
cout<<ele" Found at location = "<<loc;
else
cout<< ele " Element does not exist “;
}

void binarysearch::search( )
{
loc = -1; // Assume that element does not exist
beg = 0; // First element of the array
end = n-1;
while (beg<=end)
{
mid = (beg+end)/2;
if (ele = = m[mid]) // Element found at mid
{
loc = mid;
break;
}
else
if (ele < m[mid])
end = mid-1;
else
beg = mid+1;
14
}
}

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

OUTPUT 1:

OUTPUT 2:

15
PROGRAM 6:

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

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

class interest
{
private:
double p,r,t,si; //Data Members
public:
void getdata( );
void compute( ); //Member Functions Declaration
void putdata( );
};

void interest::getdata( ) //Member Function Definition


{
cout<<"Enter the Principal amout , Rate and Time"<<endl;
cin>>p>>t>>r;
}

void interest::putdata( ) //Member Function Definition


{
cout<<"Principal = "<<p<<endl;
cout<<"Time = "<<t<<endl;
cout<<"Rate = "<<r<<endl;
cout<<"Simple Interest = "<<si<<endl;
}

void interest::compute( ) //Member Function Definition


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

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

16
OUTPUT 1:

OUTPUT 2:

17
PROGRAM 7:

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

#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 values for a, b, c (Co-efficient)"<<endl;
cin>>a>>b>>c;
}

void quadratic::roots( )
{
double d = b*b-4*a*c;

if (d = = 0)
{
cout<<"Equal Roots..."<<endl;
r1= -b/(2*a);
r2=r1;
}

else if(d>0)
{
cout<<"Real and Distinct Roots..."<<endl;
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
}
else
{
cout<<"Imaginary Roots..."<<endl;
getch();
exit(0);
}

18
void quadratic::putdata( )
{
cout<<"Root 1 is "<<r1<<endl;
cout<<"Root 2 is "<<r2<<endl;
}

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

OUTPUT 1:

OUTPUT 2:

OUTPUT 3:

19
PROGRAM 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 Funcoverload
{
float s;
public:
float area(float a) //To compute area of square
{
return a*a;
}

float area(float a,float b) //To compute area of rectangle


{
return a*b;
}

float area(float a,float b,float c) //To compute area of triangle


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

void main()
{
float x,y,z;
int ans;
Funcoverload F;
clrscr( );

cout<<"Enter the number of sides (1 ,2 and 3 ) "<<endl;


cin>>ans;

if (ans= = 1)
{
cout<<"Enter the side "<<endl;
cin>>x;
cout<<"Area of Square= "<<F.area(x)<<endl;
}
else if (ans= = 2)
{
cout<<"Enter the two sides "<<endl;
cin>>x>>y;
cout<<"Area of Rectangle= "<<F.area(x,y)<<endl;
}

20
else if (ans = = 3)
{
cout<<"Enter the three sides"<<endl;
cin>>x>>y>>z;
cout<<"Area of Triangle= "<<F.area(x,y,z)<<endl;
}
else
cout<<"Invalid input !!!"<<endl;

getch( );
}

OUTPUT 1:

OUTPUT 2

OUTPUT 3

21
PROGRAM 9:

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

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

class assign
{
private:
int n;
public:
assign (int nn) // parameterized constructor with only one parameter
{
n=nn;
}
int cube();
};
inline int assign :: cube()
{
return (n*n*n);
}

void main() //Main Function


{
int n;
clrscr( );
cout<<"Enter the input number"<<endl;
cin>>n;
assign N=n; // invoking through = for only one parameter
cout<<"Cube of"<<n<<" = "<<N.cube(); // Inline function call
getch( );
}

OUTPUT 1:

OUTPUT 2:

22
PROGRAM 10:

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

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

class Series
{
private:
int bas,power,term,sum;

public:
Series(int b,int p); //Parameterized constructor
float calculate();
};

Series::Series(int b,int p)
{
bas=b;
power=p;
}

float Series::calculate()
{
sum=1;
term=bas;

for(int i=1;i<=power;i++)
{
sum=sum+term;
term=term*bas;
}

return sum;
}

void main()
{
clrscr();
int b,p;

cout<<"Enter the value for base =";


cin>>b;
cout<<"Enter the value for power =";
cin>>p;

Series S1(b,p); // Parameterized constructor is implicit call


Series S2=S1; // Copy constructor is called

cout<<endl<<"The sum of series using Parameterized constructor ="<<S1.calculate();


cout<<endl<<"The sum of series using copy constructor ="<<S2.calculate();

getch();

23
OUTPUT 1:

Enter the value of base = 2


Enter the value of power = 3
Sum of Series using Parameterized Constructor =15
Sum of Series using Copy Constructor = 15

OUTPUT 2:

Enter the value for base = 3


Enter the value for power = 5
Sum of Series using Parameterized Constructor =364
Sum of Series using Copy Constructor = 364

24
PROGRAM 11:

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

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

class student // Base Class


{
private:
long rollno;
char name[20];
public:
void read( )
{
cout<<"Enter the Roll Number: ";
cin>>rollno;
cout<<"Enter the Student Name:";
cin.getline(name,20);
}

void display( )
{
cout<<"\nRoll Number :"<<rollno<<endl;
cout<<"Student Name:"<<name<<endl;
}
};

class marks : public student // Derived class


{
private:
int m1, m2, total;
public:
void read1( )
{
cout<<"\nEnter Subject 1 Marks: ";
cin>>m1;
cout<<"Enter Subject 2 Marks: ";
cin>>m2;
total= m1+m2;
}
void display1( )
{
cout<<’ Mark1 “ <<m1<<endl;
cout<<” Mark2 “ <<m2<<endl;
cout<<"Total Marks : "<<total<<endl;
}
};

25
void main( )
{
marks obj; // Create an object obj to process Student data
clrscr( );
obi.read( );
obj.read1( );
obj.display( );
obj.display1( );
getch( );
}

OUTPUT 1:

OUTPUT 2:

26
PROGRAM 12:

Create a class containing the following data members Register_No, Name and Fees. Also create a
member function to read and display the data using the concept of pointers to objects.

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

class student
{
private:
long regno;
char name[20];
float fees;

public:
void get( );
void display( );
};

void student::get( )
{
cout<<"Enter the Register Number:"<<endl;
cin>>regno;
cout<<"Enter the Student Name:"<<endl;
cin.getline(name,20);
cout<<"Enter the Fees:"<<endl;
cin>>fees;
}

void student::display( )
{
cout<<"Register Number : "<<regno<<endl;
cout<<"Student Name : "<<name<<endl;
cout<<"Fees : "<<fees<<endl;
}

void main( )
{
Student s,*sp; // Create a pointer to point Student object
clrscr( );
sp=&s;
sp->get( ); // Access Student data member using a pointer
sp->display( ); // Display data using a pointer
getch( );
}

OUTPUT 1:

27
OUTPUT 2:

28
PROGRAM 13:

Write a C++ program to perform push items into the stack.

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

class Stack
{
private:
int A[MAX], top;

public:
Stack( ) // Constructor to initialize TOP pointer
{
top = -1;
}
void Push(int item); // Member Function Declaration
void print( );
};

void Stack::Push(int item)


{
if(top == MAX-1)
{
cout<<"Stack is Full Overflow!!!"<<endl;
getch();
exit(0);
}

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

void Stack::print( )
{
if(top != -1)
{
cout<<"The Stack elements are:"<<endl;
for(int i=0; i<=top; i++)
cout<<setw(4)<<A[i];
cout<<endl;
}

else
cout<<"Empty Stack!!!"<<endl;
}

void main( )
{
Stack S;
29
int choice, itm;
clrscr( );
while(1)
{
cout<<"Stack Push Operation Menu"<<endl;
cout<<"1. PUSH"<<endl;
cout<<"2. DISPLAY"<<endl;
cout<<"3. EXIT"<<endl;

cout<<"Enter your Choice"<<endl;


cin>>choice;

switch(choice)
{
case 1: {
cout<<"Push Operation"<<endl;
cout<<"Enter the value of element:"<<endl;
cin>>itm;
S.Push(itm); break;
}
case 2: {
S.print( );
break;
}
case 3: {
cout<<"End of Stack Operation"<<endl;
getch( );
exit(0);
}

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


}
getch();
}
}

30
OUTPUT:

31
PROGRAM 14:

Write a C++ program to perform pop items into the stack.

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

class Stack
{
private:
int A[MAX], top;
public:
Stack() // Constructor to initialize TOP pointer
{
top = -1;
}
void push(int);
void pop( ); // Member Functions Declaration
void display( );
};

void Stack::push(int item)


{
if(top == MAX-1)
{
cout<<"Stack is Full Overflow!!!"<<endl;
}
else
{
top++;
A[top]=item;
cout<<item<<" is successfully pushed"<<endl;
}
}

void Stack::pop()
{
int item;
if(top == -1)
{
cout<<"Stack Empty!!!...Can't POP"<<endl;
}
else
{
item = A[top];
top--;
cout<<item<<"is successfully popped"<<endl;
}
}

32
void Stack::display( )
{
if(top == -1)
cout<<"Stack Empty!!!"<<endl;

else
{
cout<<"The Stack elements are:"<<endl;
for(int i=0; i<=top; i++)
cout<<setw(4)<<A[i];
cout<<endl;
}
}

void main( )
{
Stack S;
int choice, itm;
clrscr( );
while(1)
{
cout<<"\n Stack Push & Pop Operation Menu"<<endl;
cout<<"1.PUSH"<<endl;
cout<<"2.POP"<<endl;
cout<<"3.DISPLAY"<<endl;
cout<<"4.EXIT"<<endl;
cout<<"Enter your Choice"<<endl;
cin>>choice;

switch(choice)
{
case 1: cout<<"Push Operation"<<endl;
cout<<"enter the value of an element"<<endl;
cin>>itm;
S.push(itm);
break;
case 2: cout<<"Pop Operation"<<endl;
S.pop();
break;
case 3:
S.display();
break;
case 4: cout<<"End of the Stack Operetion"<<endl;
getch( );
exit(0);
default:cout<<"Invalid Choice...!!!"<<endl;
}
getch();
}
}

33
OUTPUT:

34
PROGRAM 15:

Write a C++ program to perform Enqueue and Dequeue.

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 3

class Queue
{
private:
int q[MAX],front,rear,count;
public:
Queue() // Constructor to initialize FRONT and REAR pointer
{
front = -1;
rear = -1;
}
void enqueue(int x);
int dequeue(); // Member Functions Declaration void display();
void display();
};

void Queue::enqueue(int x)
{
if(rear == MAX-1)
{
cout<<"Queue is full Overflow!!!"<<endl;
getch( );
exit(0);
}
if(front == -1)
{
front = 0;
rear = 0;
}
else
rear++;
q[rear] = x;
count++;
cout<<"Item Inserted: "<<x<<endl;
}

int Queue::dequeue()
{
int x;
if(front == -1)
{
cout<<"Queue is Empty Underflow!!!"<<endl;
getch();
exit(0);
}

35
x = q[front];
if(front == rear)
{
front = -1;
rear = -1;
}
else
front++;
count--;
return x;
}

void Queue::display()
{
if (count>0)
for(int i=front; i<=rear; i++)
cout<<q[i]<<endl;

else
cout<<"Queue is Empty!!!"<<endl;
}

void main()
{
int item, choice;
Queue Q;
clrscr( );
while(1)
{
cout<<"\nQueue Operation Menu"<<endl;
cout<<"1.Adding Element"<<endl;
cout<<"2.Deleting Element"<<endl;
cout<<"3.Display"<<endl; cout<<"4.Exit"<<endl;
cout<<"Enter your Choice"<<endl;
cin>>choice;

switch(choice)
{
case 1: cout<<"Enter the element to be inserted"<<endl;
cin>>item;
Q.enqueue(item);
break;
case 2: Q.dequeue( );
break;
case 3: cout<<"The Queue Contents:"<<endl;
Q.display( );
break;
case 4: cout<<"End of Queue Operation"<<endl;
getch();
exit(0);
default:cout<<"Invalid Choice...!!!"<<endl;
}
getch();
}
}
36
OUTPUT:

37
16. Write a program to create a linked list and appending nodes.

#include<iostream.h>
#include<conio.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<<"linked list is empty\n";
return;
}
cout<<"\nlinked list contains";
Node*p=START;
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->link;
38
}
}
void linklist::Append(int num)
{
Node *newNode;
newNode=new Node;
newNode->data=num;
newNode->link=NULL;

if(START==NULL)
{
START=newNode;
cout<<num<<"is inserted as the first node";
}
else
{
Node *p=START;
while(p->link!=NULL)
p=p->link;
p->link=newNode;
cout<<endl<<num<<"is inserted"<<endl;
}
}
void linklist::count()
{
Node*p;
int c=0;
for(p=START;p!=NULL;p=p->link)
c++;
cout<<endl<<"number of elements 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();
obj->count();
getch();
}

39
OUPUT :
SECTION – B
STRUCTURED QUERY LANGUAGE (SQL)
PROGRAM 1:

Generate the electricity bill for one customer.


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

Field Name Type


RR_NUMBER VARCHAR(3)
CONSUMER_NAME VARCHAR(35)
DATE_BILLING DATE
UNITS NUMERIC(6,2)
Insert 10 records into the table.
1. Check the structure of table and note your observation.
2. Add two fields to the table.
a. AMOUNT NUMERIC(6,2)
b. DUE_DATE DATE
3. Compute the bill amount for each customer as per the following rules.
a. Minimum amount Rs. 50
b. First 100 units Rs 4.50/Unit
c. >100 units Rs. 5.50/Unit
4. Compute due date as BILLING_DATE + 15 Days
5. List all the bills generated.

Solution:

1) Creating a table
create table elec_bill(
rr_number varchar(3),
consumer_name varchar(35),
date_billing date,
units numeric(6,2));

2) Command to insert 5 records into the table


insert into elec_bill values('a01','arvi','2000/02/09',49);
insert into elec_bill values('a02','bhim','2001/07/07',90);
insert into elec_bill values('a03','chetan','2002/09/05',100);
insert into elec_bill values('a04','chotu','2001/07/07',150);
insert into elec_bill values('a05','druv','2002/06/05',600);

3) Command to add two new fields to the table


alter table elec_bill add(amount numeric(6,2),due_date date);

4) command to check the structure of the table


desc elec_bill;

42
5) Command to compute bill amount
update elec_bill set amount =50;
update elec_bill set amount=amount+100*4.50 where units<=100;
update elec_bill set amount=amount+100*4.50+(units-100)*5.50 where units>100;

update elec_bill set due_date=date_billing+15;

6) Command to view the bill statement


select * from elec_bill;

43
PROGRAM 2:

Create a student database and compute the results.


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

Field Name Type


Student_id varchar(7)
student_name char(25)
marks1 int
marks2 int
marks3 int
marks4 int
marks5 int
marks6 int

1. Add records into the table for 10 students for Student ID, Student Name and marks in 6
subjects using INSERT command.
2. Display the description of the fields in the table using DESC command.
3. Alter the table and calculate TOTAL and PERC_MARKS.
4. Compute the RESULT as “PASSP 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 the table.
7. Retrieve only ID_NO and S_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_NO.

Solution:

Command to create table


create table student_master(
student_id varchar(7),
student_name char(25),
marks1 int,
marks2 int,
marks3 int,
marks4 int,
marks5 int,
marks6 int);

1) Command to add records into the table


insert into student_master values('010','rohini',29,98,88,18,67,89);
insert into student_master values('012','Meena',66,78,78,27,99,88);
44
insert into student_master values ('013','chetan',30,98,78,66,55,89);
insert into student_master values('004','hari',45,77,67,88,56,87);
insert into student_master values ('005','deva',96,88,88,87,89,98);
insert into student_master values('006','giri',85,97,77,98,66,77);

2) Command to Display the description of the fields in the table


desc student_master;

3) Command to alter the table


alter table student_master add(total int,perc_marks int,result varchar(4));

Command to calculate total


Update student_master set total=marks1+marks2+marks3+marks4+marks5+marks6;

Command to calculate percentage


update student_master set perc_marks=total/6 where student_id>0;

4) Command to calculate result as pass


update student_master set result='pass' where marks1>=35 and marks2>=35 and marks3>35
and marks4>=35 and marks5>=35 and marks6>35;

Command to calculate result as fail


update student_master set result='fail' where marks1<35 or marks2<35 or marks3<35 or
marks4<35 or marks5<35 or marks6<35;

5,6)View or select contents from the table


select *from student_master;

45
7) Command to retrieve only student_id and Student_name of all the students
select student_id,student_name from student_master;

8) Command to list the students who have result as ‘pass’


select * from student_master where result=’pass’;

9) Command to list the students who have result as ‘fail’


select *from student_master where result=’fail’;

10) Command to count the number of students who have passed


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

11) Command to count the number of students who have failed


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

12) Command to count the number of students who have percentage more than 60
select count(*) from student_master where perc_marks>=60;

13) Command to sort student list according to student_id


select from student_master ORDER BY student_id;

46
PROGRAM 3:

Generate the Employee details and compute the salary based on the department. Create the
following table EMPLOYEE.
Field Name Type
EMP_ID INT
DEPT_ID INT
EMP_NAME VARCHAR(10)
EMP_SALARY FLOAT

Create another table DEPARTMENT.


Field Name Type
DEPT_ID INT
DEPT_NAME VARCHAR(10)
SUPERVISOR VARCHAR(10)

Assume the DEPARTMENT names 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 DEPARTMENT table.
Write the SQL statements for the following:

1. Find the names of all employees who work for the Accounts department.
2. How many employees work for Accounts department?
3. What are the Minimum, Maximum and Average salary of employees working for
Accounts department?
4. List the employees working for 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 the employee in the Apprentice department.

Solution:

To create two tables, EMPLOYEE and DEPARTMENT.

MYSQL> CREATE TABLE EMPLOYEE (


EMP_ID INT,
DEPT_ID INT,
EMP_NAME VARCHAR(10),
EMP_SALARY FLOAT);

MYSQL> CREATE TABLE DEPARTMENT (DEPT_ID INT, DEPT_NAME


VARCHAR(10), SUPERVISOR VARCHAR(10));
To Insert 10 records into the table EMPLOYEE using INSERT INTO command.

SQL> INSERT INTO EMPLOYEE VALUES (101, 01, 'ARUN', 15000);


SQL> INSERT INTO EMPLOYEE VALUES (104, 02, 'MOHAN', 20000);
SQL> INSERT INTO EMPLOYEE VALUES (105, 03, 'SUMAN', 22000);
SQL> INSERT INTO EMPLOYEE VALUES (106, 02, 'SUSHMA', 18000);
SQL> INSERT INTO EMPLOYEE VALUES (109, 01, 'KUSHI', 22300);
SQL> INSERT INTO EMPLOYEE VALUES (110, 02, 'VIDHYA', 15000);
SQL> INSERT INTO EMPLOYEE VALUES (102, 02, 'KAVYA', 21300);
SQL> INSERT INTO EMPLOYEE VALUES (107, 03, 'AKASH', 18200);
SQL> INSERT INTO EMPLOYEE VALUES (108, 04, 'NAWAZ', 12000);
SQL> INSERT INTO EMPLOYEE VALUES (103, 02, 'DEEPAK', 24000);

To insert 4 records into the table DEPARTMENT using the INSERT INTO command.

SQL>INSERT INTO DEPARTMENT VALUES (01, 'PURCHASE', 'KRISHNA');


SQL>INSERT INTO DEPARTMENT VALUES (02, 'ACCOUNTS', 'TANVEER');
SQL>INSERT INTO DEPARTMENT VALUES (03, 'SALES', 'SURYA');
SQL>INSERT INTO DEPARTMENT VALUES (04, 'APPRENTICE', 'HARSHA');

1. Find the names of all employees who work for the Accounts department

2. How many employees work for Accounts department?


3) What are the Minimum, Maximum and Average salary of employees working for Accounts
department?

4) List the employees working for 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 the employee in the Apprentice department.
PROGRAM 4:
Create database for the Bank transaction

Create following table customer

fieldname datatype description


C_NO INT Customer id number
NAME VARCHAR(25) Customer Name
ADDRESS VARCHAR(100) Customer Address
PHONE BIGINT Customer phone

Create another table Bank with following structure

fieldname datatype description


AC_NO INT Customer Account
No
TRANS_NO INT Transaction Number
TRANS_DATE DATE Transaction date
TRANS_TYPE CHAR Transaction type
(C/D)
CUST_NO INT Customer No

1. Enter 5 Records to Customer and 5 records to Bank table


2. Display structure and records of both the table
3. Command to display the transaction between two dates
4. Command to display the transaction greater than a specific date
5. Command to Display Account No, Customer No, Name where Customer No equal to
Customer No from Bank Table
6. Command to delete a record having a specific phone number
7. Command to display all the records that have transaction as credit
8. Command to create a new table with account no and transaction amount
9. Command to list all the names starting from ‘A’
10. Command to display system date

mysql> CREATE TABLE CUST(


C_NO INT,
NAME VARCHAR(25),
ADDRESS VARCHAR(100),
PHONE BIGINT);
1) Command to describe the Customer

mysql> DESC CUST;

2) Command to add Records to Customer

INSERT INTO CUST VALUES(0001,'ANIL','E302,R R ROAD,MYSORE ',914253627);


INSERT INTO CUST VALUES(0001,'ANIL','E302,R R ROAD,MYSORE ',9142536276);
INSERT INTO CUST VALUES(0002,'AJAY','A302,MG ROAD,MYSORE ',9142532566);
INSERT INTO CUST VALUES(0003,'VIJAY','A305,MGR ROAD,MYSORE ',9188832566);
INSERT INTO CUST VALUES(0003,'ABHAY','B205,DRR ROAD,BANGLORE
',9234832566);
INSERT INTO CUST VALUES(0004,'RAMESH','Q4205,MLR ROAD,MANGLORE
',9234456566);

3) Command to display all the records from Customer

SELECT * FROM CUST;

4) Command to create another table bank

mysql> CREATE TABLE BANK(


AC_NO INT,
TRANS_NO INT,
TRANS_DATE DATE,
TRANS_TYPE CHAR,
CUST_NO INT);
5) Command to describe the Customer

mysql> DESC BANK;

6) Command to Add records to Bank

INSERT INTO BANK VALUES(1112,123112,'2022-11-01','C',2);


INSERT INTO BANK VALUES(1111,123111,'2022-01-01','C',1);
INSERT INTO BANK VALUES(1113,123113,'2022-11-01','D',3);
INSERT INTO BANK VALUES(1114,123114,'2022-09-01','C',4);

7) Command to display all the records from Bank

SELECT *FROM BANK;

8) Command to display the transaction between two dates

SELECT *FROM BANK WHERE TRANS_DATE >'2022-01-02' AND TRANS_DATE


<'2022-12-23';

9) Command to display the transaction greater than a specific date

SELECT *FROM BANK WHERE TRANS_DATE >'2022-01-02';

10) Command to Display Account No, Customer No, Name where Customer No equal to
Customer No from Bank Table
SELECT AC_NO,CUST.C_NO,NAME FROM CUST,BANK WHERE
C_NO=BANK.CUST_NO;
11) Command to delete a record having a specific phone number

DELETE FROM CUST WHERE PHONE=9164253627;

12) Command to display all the records that have transaction as credit

SELECT * FROM BANK WHERE TRANS_TYPE='C';

13) Command to create a new table with account no and transaction amount

CREATE VIEW TEMP AS SELECT AC_NO,TRANS_AMT FROM BANK;

14) Command to list all the names starting from ‘A’

SELECT *FROM CUST WHERE NAME LIKE 'A%';

15) Command to display system date

SELECT SYSDATE() FROM DUAL;


SECTION – C
ADVANCED HTML
PROGRAM 1:

Write a HTML program to create a CLASS Timetable.

<<html>

<head>

<title> Study Timetable </title>

</head>

<body bgcolor=gold text=navy>

<img src=Internet.jpg width=200 height=150>

<table border=3 width=900 height=400>

<caption> <b> <font size=7> My Study Timetable for a week </font> <b> </caption>

<tr>
<th> Day </th>
<th> Subject </th>
<th> Morning Session </th>
<th> College Time </th>
<th> Evening Session </th>
<th> QP Solving Time </th>
</tr>

<tr>
<td> Monday </td>
<td> Lang 1 </td>
<td> 5.00am - 7.00am </td>
<td> 8.30am - 4.30pm </td>
<td> 7.00pm - 9.00pm </td>
<td> 10.00pm - 11.00pm </td>
</tr>

<tr>
<td> Tuesday </td>
<td> Lang 2 </td>
<td> 5.00am - 7.00am </td>
<td> 8.30am - 4.30pm </td>
<td> 7.00pm - 9.00pm </td>
<td> 10.00pm - 11.00pm </td>
</tr>

56
<tr>
<td> Wednesday </td>
<td> Physcics </td>
<td> 5.00am - 7.00am </td>
<td> 8.30am - 4.30pm </td>
<td> 7.00pm - 9.00pm </td>
<td> 10.00pm - 11.00pm </td>
</tr>

<tr>
<td> Thursday </td>
<td> Chemistry </td>
<td> 5.00am - 7.00am </td>
<td> 8.30am - 4.30pm </td>
<td> 7.00pm - 9.00pm </td>
<td> 10.00pm - 11.00pm </td>
</tr>

<tr>
<td> Friday </td>
<td> Maths </td>
<td> 5.00am - 7.00am </td>
<td> 8.30am - 4.30pm </td>
<td> 7.00pm - 9.00pm </td>
<td> 10.00pm - 11.00pm </td>
</tr>

<tr>
<td> Saturday </td>
<td> Computer Science </td>
<td> 5.00am - 7.00am </td>
<td> 8.30am - 4.30pm </td>
<td> 7.00pm - 9.00pm </td>
<td> 10.00pm - 11.00pm </td>
</tr>

</table>

<marquee direction=right> Study well!!!</marquee>

</body>
</html>

57
OUTPUT

PROGRAM 2:

2. Write a HTML program with table and form

<html>

<head>

<title> Online application </title>

</head>

<body>

<form>

<h3> First PUC Application Form </h3>

<table>

<tr>
<td> Student Name: </td>
<td> <input type=text name=stuname> </td>
</tr>

58
<tr>
<td> Father Name: </td>
<td> <input type=text name=fatname> </td>
</tr>

<tr>
<td> Address </td>
<td> <textarea rows=5 cols=20 name=add> </textarea> </td>
</tr>

<tr>
<td> Date of Birth </td>
<td> <input type=date name=dob> </td>
</tr>

<tr>
<td> Email ID </td>
<td> <input type=text name=eid>
Password:<input type=password name=pwd> </td>
</tr>

<tr>
<td> Gender:</td>
<td> <input type=radio name=gen value=m> Male
<input type=radio name=gen value=f> Female
</td>
</tr>

<tr>
<td> Subject Choosen: </td>
<td> <input type=checkbox name=sub value=kan> Kannada
<input type=checkbox name=sub value=eng> English
<input type=checkbox name=sub value=phy> Physics
<input type=checkbox name=sub value=che> Chemistry
<input type=checkbox name=sub value=mat> Maths
<input type=checkbox name=sub value=cs> Computer Science
<input type=checkbox name=sub value=bio> Biology
</td>
</tr>

<tr>
<td> <input type=submit value="Submit the form"> </td>
<td> <input type=reset value="Reset the form"> </td>
</tr>

<table>
<form>
59
<br>
<br>
<br>

<h3> Attendance Report </h3>

<table border=1 width=100>


<tr>
<th> Month </th>
<th> No of classes held </th>
<th> No of classes attended </th>
</tr>

<tr>
<td> June </td>
<td> 18 </td>
<td> <input type=text size=2 maxlength=2> </td>
</tr>

<tr>
<td> July </td>
<td> 25 </td>
<td> <input type=text size=2 maxlength=2> </td>
</tr>

<tr>
<td> August </td>
<td> 22 </td>
<td> <input type=text size=2 maxlength=2> </td>
</tr>

<tr>
<td> September </td>
<td> 20 </td>
<td> <input type=text size=2 maxlength=2> </td>
</tr>

<tr>
<td> October </td>
<td> 23 </td>
<td> <input type=text size=2 maxlength=2> </td>
</tr>

</table>

</body>
60
</html>

OUTPUT

61

You might also like