0% found this document useful (0 votes)
25 views61 pages

II PUC Labprograms NEW

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)
25 views61 pages

II PUC Labprograms NEW

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

Department of Computer Science

Practical Manual
Second Year PUC
Computer Science
REVISED EDITION
CONTENTS
Program PageNo
Program
No
Name
SECTION- A (C++ AND DATA STRUCTURES)
01 Write a C++ program to find the frequency presence of an element in an array. 1-2
02 Write a C++ program to insert an element into an array at a given position. 3-4
03 Write a C++ program to delete an element from an array from a given position. 5-6
Write a C++ program to sort the element of an array in ascending order using
04
insertion sort. 7-8
Write a C++ program to search for a given element in an array using binary 9-10
05 search method.
Write a C++ program to create a class with data members principal, time and
06 rate.Create a member function to accept data values, to compute simple interest
and to 11-12

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
➢ If discriminates = 0, print the roots are equal and their value. 13-14
➢ 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
08 function overloading. 15-16
09 Write a C++ program to find cube of a number using inline function. 17
Write a C++ program to find sum of the series 1 + x + x + x + ….x2 3 n

10 using constructors. 18-19

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
inheritance. Create a derived class that contains marks of two subjects and total marks 20-21
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
12 concept ofpointers to objects. 22-23

13 Write a C++ program to perform push items into the stack. 24-26
14 Write a C++ program to perform pop items into the stack. 27-29
15 Write a C++ program to perform Enqueue and Dequeue. 30-32
16 Write a program to create a linked list and appending nodes. 33-35
Program Page
Program
No No
Name
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_number Varchar2(10)
Consumer_name Varchar2(25)
Date_billing Date
Units number
1. Insert 10 records into the table
2. Describe the structure of table
3. Alter the table by adding two fields to the table
Field Name Type
17
bill_amt number(6,2)
due_date date

4.Compute the bill amount for each customer as per the following rules. 36-37
a. MIN_AMT Rs. 50
b. First 100 units Rs 4.50/Unit
c. >100 units Rs. 5.50/Unit
5.Compute due date as Date_billing + 15 Days
6.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 Data type


Student_id Number(4)
Student name Varchar2(25)
Sub1_marks Number(3)
Sub2_marks Number(3)
Sub3_marks Number(3)
Sub4_marks Number(3)
Sub5_marks Number(3)
Sub6_marks Number(3)
38-40
18 1. Insert 10 records in the table using insert5 command
2. Display the description of the fields in the table using desc command
3. Alter the table by adding fields
Field name Data type
Total Number(4)
Per number(5)
Result varchar2(10)
4. compute total and percentage
5. Computer the result “ pass” or “fail” by checking if the students has scored
more than 35 marks in each subject.
6. List the contents of the table.
7. Retrieve only student_id and student_name of all the students
8. List the student who have result as “PASS”
9. List the student 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 student_id.

1. Generate the Employee details and compute the salary based on the
department.Create the following table employee.
Field Name Type
Emp_id Number(4)
Dept_id Number(4)
Emp_name Varchar2(25)
Emp_salary Number(5)

2. Create another table department with the following structure


Field Name Type
Dept_id Number(4)
dept_name Varchar2(25)
19 Supervisor Varchar2(20)
3. Enter 10 Records for table employee and 4 records for table Department 41-43
4. Find the names of all employees who work for the accounts department
5. What is the minimum, maximum and average salary of employees working
for accounts department?
6. List the employees working for a particular supervisor.
7. Retrieve the department names for each department where only one
employee works
8. Increase the salary of all the employees in the sales department by 15%
9. Add a new column to the table employee called Bonus number(5) and
compute 5% of the salary to the said field
10. Delete all the rows for employees in the apprentice department

1. Create a database for the bank transaction.


1. Create a table for customer
2. Create a table bank
3. Insert data values into customer table
4. Insert data values for bank table
5. Display all records from bank table
6. Display all records from customer table
7. To display all records from bank whose transaction date
44-47
20 8. To join tables
9. Display count of all records and their corresponding transaction group by
transaction type
10. Display all records from customer order by customer name in descending
order
11. Change the transaction amount
12. Alter the customer to change the size of customer address
13. Delete records from customer account number*
14. Create a table containing customer account number range
15. Display records from customers whose name start with ‘G’
16. Display today’s date
17. Display total transaction amount from bank table.
18. Create a view on customer showing customers no and customers phone
number
19. Display distinct customers numbers from bank
20. Display account number from bank who have more than one transaction
21. Display all records from customers whose phone number is NULL
22. Delete all records from customers tables
23. Drop table bank
24. Drop table customer.

SECTION- C HTML

21 Write a HTML program to create a study time-table 48-49

22 Create an HTML program with table and Form. 50-52


SECOND PUC PRACTICALEXAMINATION
SUBJECT- COMPUTER SCIENCE (41)
General Instructions:
• Duration of Practical examination 2 hours.
• Maximum marks allotted: 30 marks:
• The Practical examination question paper should consist of two questions for writing (One program
from C++ and one program from either SQL or HTML)
• Each question carries 6 marks of writing i.e. 2X6=12 marks
• Only one experiment to be executed
• Execution process carries 6 marks
• Generating the correct output for the executed problem carries two marks.
Scheme of Valuation
A. Weightage of marks
Sl.No Particulars Marks
01 Writing one Program from PART A and one Program PART B (six marks each) 12 marks

02 Execution of any one program (Examiners Choice) 06 marks


03 Formatting the output 02 marks
04 Viva voce 04 marks
05 Record writing 06 marks
TOTAL LAB MARKS 30 marks
B. Distribution of marks
I. Performing the experiment
a) Programs on C++ and Data structure
Sl.No Particulars Marks
01 Including the necessary header 1
02 Declaration of correct object 1
03 Input/output commands 1
04 Logic 2
05 Output commands 1
TOTAL 6
b) Problems on SQL
Sl.No Particulars Marks
01 Creating table including the necessary attributes in SQL 2
02 Inserting data for the table (data entry) 1
03 Using the correct SQL query 1
04 Generating the correct output 2
TOTAL 6
c) Problems on Advanced HTML
Sl.No Particulars Marks

01 Including the necessary basic tags of the HTML 1

Including the necessary basic tags of the Header and Title 1


02

03 Including any advanced HTML tags like forms/tables 2

Generating the correct output. 2


04
TOTAL 6

II. Practical Record


Sl.No Particulars Marks
If the student has performed and recorded 27 programs or more(91- 100 % of the 6
01 prescribed for the practical examination or more)
If the student has performed and recorded 24 programs and below 27 programs ( 5
02 81- 90 % of the prescribed for the practical examination )
If the student has performed and recorded 21 programs and below 24 programs ( 4
03 71- 80% of the prescribed for the practical examination )
If the student has performed and recorded below 21 programs and above 11 3
04 programs(41- 70 % of the prescribed for the practical examination )
If the student has performed and recorded below 10 programs ( 40% and below 40 0
05 % of the prescribed for the practical examination )

III. Viva-voce
1. Four questions must be asked and each question carries 1 mark(external examiner two question and
internal examiner two questions)
2. The questions in the viva-voce should be simple, direct and related to the experiments to be
performed by the student.
NOTE : Laboratory rules to be followed
1. Conduct 22 experiments(16 from c++, 4 from SQL and 2 from HTML)experiments have to be
conducted in the practical classes.
2. Maintain one Observation note book and lab record.
3. Come prepared to the lab
4. Follow the lab programs as instructed by the PU Board
5. Strictly observe the instructions given by the teacher/Lab instructor.
6. Use the computers for academic purpose only.
7. Keep your lab clean
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

SECTION – A (C++)
PROGRAM 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[50], n, ele, count;
public: void readdata( );
void findfreq( );
void display( );
};
void Frequency::readdata( )
{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter the array elements:"<<endl;
for(int i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to find the frequency"<<endl;
cin>>ele;
}
void Frequency::findfreq( )
{
count=0;
for(int i=0; i<n; i++)
if(ele == a[i])
count++;
}
void Frequency::display( )
{
if(count > 0)
cout<<ele<<" Occurs"<<count<<" Time";
else
cout<<ele<<" Does Not Exists";
}

void main( )

MES PU COLLEGES 1
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

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

OUTPUT 1:

OUTPUT 2:

*****

2 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 2:
Write a C++ program to insert an element into an array at a given position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
class Insertion
{
private: int a[50], n, pos, ele, i;
public: void readdata( );
void insert( );
void display( );
};
void Insertion::readdata( )
{
cout<<"Enter the size of the array"<<endl;
cin>>n;
cout<<"Enter the elements for the array"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the position of the element in the array"<<endl;
cin>>pos;
cout<<"Enter the element to be inserted"<<endl;
cin>>ele;
}
void Insertion::insert( )
{
if(pos>n)
{
cout<<"Out of array limits!!!";
getch( );
exit(0);
}
else
{
for(i=n; i>=pos; i--)
a[i+1] = a[i];
a[pos] = ele;
n = n+1;
}

MES PU COLLEGES 3
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

}
void Insertion::display( )
{
cout<<"Array elements after insertion are:"<<endl;
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
void main( )
{
Insertion I;
clrscr( );
I.readdata( );
I.insert( );
I.display( );
getch( );
}
OUTPUT 1:

OUTPUT 2:

*****

4 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 3:
Write a C++ program to delete an element from an array from a given position.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
class Deletion
{
private:
int a[50], n, pos, i;
public:
void readdata( );
void delet( );
void display( );
};
void Deletion::readdata( )
{
cout<<"Enter the size of the array"<<endl;
cin>>n;
cout<<"Enter the elements for the array:"<<endl;
for (i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the position to an delete an element:\n";
cin>>pos;
}
void Deletion::delet( )
{
if(pos>n)
{
cout<<"Out of array limits...!!!";
getch( );
exit(0);
}
else
{
for(i=pos; i<n; i++)
a[i] = a[i+1];
n = n-1;
}
}

MES PU COLLEGES 5
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

void Deletion::display( )
{
cout<<"After deletion the array elements are"<<endl;
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
void main( )
{
Deletion d;
clrscr();
d.readdata( );
d.delet( );
d.display( );
getch( );
}

OUTPUT 1:

OUTPUT 2:

*****

6 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 4:
Write a C++ program to sort the element of an array in ascending order using
insertion sort method.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
class Sort
{
private: int a[50], n, i;
public: void readdata( );
void insertionsort( );
void display( );
};
void Sort::readdata( )
{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter the elements for the array:"<<endl;
for(i=0; i<n; i++)
cin>>a[i];
}
void Sort::insertionsort( )
{
int j, temp;
for(i=1; i<n; i++)
{
j = i;
while(j >= 1)
{
if(a[j] < a[j-1])
{
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
j = j-1;
}
}
}
void Sort::display( )
{
for(i=0; i<n; i++)

MES PU COLLEGES 7
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

cout<<a[i]<<"\t";
cout<<endl;
}
void main( )
{
Sort s;
clrscr();
s.readdata( );
cout<<"Unsorted List......"<<endl;
cout<<"*******************"<<endl;
s.display( );
s.insertionsort( );
cout<<"Sorted List........"<<endl;
cout<<"*******************"<<endl;
s.display( );
getch( );
}

OUTPUT 1:

OUTPUT 2:

*****

8 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 05:
Write a program to search for a given element in an array using Binary search
method
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class search
{
private: int a[100],n,ele,i,loc;
public: void input();
void binary_search();
void display();
};

void search::input()
{
cout<<"\n Enter the size of the array";
cin>>n;
cout<<"\n Enter the array elements";
for(i=0; i<n;i++)
cin>>a[i];
cout<<"\n Enter the search element";
cin>>ele;
}
void search::binary_search()
{
int b=0, e=n-1,mid;
loc=-1;
while(b<=e)
{
mid=(b+e)/2;
if(ele==a[mid])
{
loc=mid; break;
}
else if(ele<a[mid])
e=mid-1;
else
b=mid+1;
}
MES PU COLLEGES 9
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

}
void search::display()
{
if(loc>=0)
cout<<ele<<" is found at location "<<loc<<endl<<"\n BINARY
SEARCH IS
SUCCESSFULL";
else
cout<<ele<<"element does not exists"<<endl<<"BINARY SEARCH IS
UNSUCCESSFULL";
}
void main()
{
search S;
clrscr();
S.input();
S.binary_search();
S.display();
getch();
}
OUTPUT 1

OUTPUT 2

*****

10 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 06:
Write a program to create a class with data members principle amount, time and
rate of interest. Create a member function to accept data values to compute simple
interest and to display the result.

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class simple_intrest
{
private: double p,t,r,si;
public: void input();
void compute();
void display();
};
void simple_intrest::input()
{
cout<<"Enter the principal amount"<<endl;
cin>>p;
cout<<"Enter the time period "<<endl;
cin>>t;
cout<<"Enter the Rate of Intrest"<<endl;
cin>>r;
}
void simple_intrest::compute()
{
si=(p*t*r)/100;
}

void simple_intrest:: display()


{
cout<<" The given principal amount is= "<<p<<endl; cout<<" The
given time period = "<<t<<endl; cout<<" The given Rate of Intrest
="<<r<<endl;
cout<<"=======================================
==="<<endl;
cout<<" The simple intrest = "<<si<<endl;
cout<<"=======================================
==="<<endl;
}

MES PU COLLEGES 11
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

void main()
{
simple_intrest I;
clrscr();
I.input();
I.compute();
I.display();
getch();
}

OUTPUT 1

OUTPUT 2

*****

12 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 07:
Write a program to create a class with data members a,b,c and member function to
input data, compute the discriminant based on the following conditions and print the
roots.
1. If discriminant =0 , print the roots that are equal.
2. If the discriminant is >0 , print the real and distinct roots
3. If the discriminant is < 0 , print that the roots are imaginary.

#include<iostream.h>
#include<iomanip.h>
#include<math.h>
#include<process.h>
#include<conio.h>
class quadratic
{
private:double a,b,c,r1,r2,d;
public:void getdata();
void compute();
void display();
};

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

void quadratic:: compute()


{
d=b*b-4*a*c;
if(d==0)
{
cout<<"Roots are equal "<<endl; r1=(-b-sqrt(d))/(2*a);
r2=r1;
}
else if(d>0)
{
cout<<" Roots are different"<<endl; r1=(-b + sqrt(d))/(2*a);
r2=(-b - sqrt(d))/(2*a);

MES PU COLLEGES 13
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

}
else
{
cout<<" Roots are imaginary";
exit(0);
}
}
void quadratic :: display()
{
cout<<" First root="<<r1<<endl; cout<<" Second root ="<<r2;
}
void main()
{
quadratic Q;
clrscr();
Q.getdata();
Q.compute();
Q.display();
getch();
}
OUTPUT 1:

OUTPUT 2:

*****
14 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 08:
Write a program to find the area of a square/rectangle/triangle using function
overloading.
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
#include<conio.h>
class fun_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.0;
return(sqrt(s*(s-a)*(s-b)*(s-c)));
}
};

void main()
{
fun_overload O;
clrscr();
float x,y,z;
int n;
cout<<"Enter the number of inputs:"; cin>>n;
if(n==1)
{
cout<<"Enter side of square"<<endl; cin>>x;
cout<<"Area of the square="<<O.area(x)<<endl;
}
else if(n==2)

MES PU COLLEGES 15
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

{
cout<<"Enter the length and breadth of a rectangle:";
cin>>x>>y;
cout<<"Area of the rectangle="<<O.area(x,y)<<endl;
}
else if(n==3)
{
cout<<"Enter three sides of a triangle"<<endl; cin>>x>>y>>z;
cout<<"Area of triangle="<<O.area(x,y,z)<<endl;

}
else
{
cout<<"Invalid input";
}
getch();
}

OUTPUT 1:

OUTPUT 2:

*****

16 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

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

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

inline int cube(int a)


{
return (a*a*a);
}
void main()
{
int n;
clrscr( );
cout<<"Enter the input number"<<endl;
cin>>n;
cout<<"Cube of"<<" = "<<cube(n);
getch( );
}

OUTPUT 1:

OUTPUT 2:

*****

MES PU COLLEGES 17
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

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

#include<iostream.h>
#include<conio.h>
#include<math.h>
class power
{
private : int x,i,sum,n;
public: power()
{
sum=1;
}

void getdata()
{
cout<<”enter the values for x and n”;
cin>>x>>n;
}
void calculate()
{
for(i=1;i<=n;i++)
sum=sum+pow(x,i);
}
void display()
{
cout<<”sum of the series=”<<sum;
}
};
void main()
{
power p;
clrscr();
p.getdata();
p.calculate()
p.display();
getch();
}

18 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

OUTPUT 1:

OUTPUT 2:

*****

MES PU COLLEGES 19
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM 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 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<iomanip.h>
#include<conio.h>
class student
{

private: int rollno;


char name[20];
public: void read ()
{
cout<<"Enter the name:”
cin>>name;
cout<<"Enter Roll No:";
cin>>rollno;
}
void display()
{
cout<<"Roll no:"<<rollno <<endl;
cout<<"Name:"<<name <<endl;
}

};
class marks: public student
{

private: int ml,m2, total;

public: void read1 ()


{
cout<<"Enter two subject marks:”
cin>>ml>>m2;
total= ml+ m2;
}

void display1()
20 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

cout<<"Subject1="<<ml<<endl;
cout<<"Subject2 ="<<m2<<endl;
cout<<"Total marks= "<<total<<endl;
}
};
int main ()
{
marks ob; clrscr();
ob.read();
ob.read1();
ob.display(); ob.display1();
getch();
return 0;
}
OUTPUT 1:

OUTPUT 2:

*****

MES PU COLLEGES 21
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

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>
#include<iomanip.h>
class student
{
private:
int regno;
char name[20];
float fees;
public:
void get ();
void display();
};
void student: :get ()
{
cout<<"Enter student name:";
cin>>name;
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; cout<<"Student fees:"<<fees;
}
int main ()
{
student s , *sp;
clrscr();
sp=&s;
sp->get();
sp->display(); getch();
return 0;

22 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

OUTPUT 1:

OUTPUT 2:

*****

MES PU COLLEGES 23
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM: 13
Write a C++ program to push an element into the stack.
#include<iostream.h>
#include<ctype.h>
#include<iomanip.h>
#include<stdlib.h>
#define MAX 3
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;
}
void Stack :: print()
{
if(top !=-1)
{
cout <<”Stack contains “;
for(int i=0;i<=top;i++)
cout<<setw(4)<<A[i];
cout<<endl;
}
else

24 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

cout<<”Stack is empty”<<endl;
}
void main()
{
Stack S;
int choice, itm;
while(1)
{
cout<<endl<<”1.Push”<<endl<<”2.Print
“<<endl<<”3.Exit”<<endl;
cout<<Ënter your choice : “;
cin>>choice;
switch(choice)
{
case 1: {
cout<<”Enter the item : “;
cin>>itm;
S.Push(itm);
break;
}
case 2: {
S.print();
break;
}
case 3: {
cout<<”Thank you … Visit again “;
exit(0);
}
default : cout << “Invalid choice “<<endl;
}
}
}

MES PU COLLEGES 25
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

OUTPUT:

*****

26 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM : 14
Write a program to pop elements from the stack.
#include<iostream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 3
class Stack
{
private :
int A[MAX], top;
public :
Stack()
{
top=-1;
}
void Push(int item);
void Pop();
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;
}
void Stack :: Print()
{
if(top !=-1)
{
cout <<”Stack contains “;
for(int i=0;i<=top;i++)
cout<<A[i]<<setw(4);
cout<<endl;

MES PU COLLEGES 27
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

}
else
cout<<”Stack is empty”<<endl;
}
void Stack :: Pop()
{
if(top == -1)
{
cout <<endl<<”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;
while(1)
{
cout<<endl<<”1.Push”<<endl<<”2.Pop<<endl<<”3.Print Stack
“<<endl<<”4.Exit”<<endl;
cout<<Ënter your choice : “;
cin>>choice;
switch(choice)
{
case 1: {
cout<<”Enter the item : “;
cin>>itm;
S.Push(itm);
break;
}
case 2: {
S.pop();
break;
}
case 3: {
28 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

S.print();
break;
}
case 4: {
cout<<”Thank you … Visit again “;
exit(0);
}
default : cout << “Invalid choice “<<endl;
}
}
}

OUTPUT 1:

*****

MES PU COLLEGES 29
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM :15
Write a program to perform enqueue and dequeue.
#include<iostream.h>
#include<ctype.h>
#include<iomanip.h>
#include<conio.h>
#define QUEUE_SIZE 3
class Queue
{
private :
int q[QUEUE_SIZE];
int front,rear;
int count;
public :
Queue();
void enqueue(int x);
void dequeue();
void getsize();
};
Queue :: Queue()
{
front = -1;
rear = -1;
count=0;
}
void Queue :: enqueue(int X)
{
if(rear == QUEUE_SIZE -1)
{
cout<<endl<<”Sorry… Queue is full”<<endl;
return;
}
if(front = -1)
{
front = 0;
rear = 0;
}
else
rear++;
Q[rear] = x;

30 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

count++;
cout<<endl<<x<<”is successfully inserted “<<endl;
}
void Queue :: dequeue()
{
if(front == -1)
{
cout <<”\t Queue is empty “<<endl;
return;
}
int x = q[front];
if(front == rear)
{
front =-1;
rear =-1;
}
else
front++;
count--;
cout<<”\t”<<x<<”is successfully deleted “ <<endl;
}
void Queue :: getsize()
{
if(count > 0)
{
cout<<”\tQueue contains “ ;
for(int i=front;i<=rear ;i++)
cout<<q[i]<<setw(4);
cout<<endl;
}
else
cout<<”\t Sorry… Queue is empty”<<endl;
}
void main()
{
Queue Q;
int choice, item;
while(1)
{
cout<<endl<<”1.Enqueue”<<endl<<”2.Dequeue
“<<endl<<”3.Print Queue”<<”4.Exit”<<endl;
MES PU COLLEGES 31
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

cout<<Ënter 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.getSize();
break;
case 4: {
cout<<”Thank you … Visit again “;
exit(1);
}
default : cout << “Invalid choice “<<endl;
}
}
}

OUTPUT 1:

*****

32 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

PROGRAM : 16
Write a program to create a linked list and appending nodes.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class LinkList
{
private :
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<<endl<<”Sorry… Linked List is empty”<<endl;
return;
}
cout<<”Linked list contains “;
Node* tmp = START;
while(tmp != NULL)
{
cout<<tmp->data<<” “;
tmp = tmp ->Link;
}
}
void LinkList :: Append (int num)
{

MES PU COLLEGES 33
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

Node *newNode;
newNode = new Node;
newNode –>data = num;
newNode ->Link = NULL;
if(START == NULL)
{
START = newNode;
cout <<endl<<num<<” is inserted as 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();
Obj -> Print();
Obj -> Append(100);
Obj -> Print();
Obj ->Count();

Obj-> Append(200);
Obj->Print();
Obj->Count();

Obj-> Append(300);
Obj->Print();
Obj->Count();
34 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

OUTPUT 1:

*****

MES PU COLLEGES 35
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

SECTION – B (SQL)
SQL PROGRAM-17
1. Generate the Electricity bill for one consumer.

1. Create a table for household electricity bill with following fields:


Field name Type
RR_number varchar2(10)
consumer_name varchar2(25)
date_billing Date
units number(4)

➢ Solution: Create table EB(


RR_number varchar2(10),
consumer_name varchar2(25),
Date_billing date,
units number(4));

2. Insert 10 records into table:


➢ Solution: insert into EB values(‘A1001’, ‘Manjunath’, ’25-Nov-2022’, 34);
insert into EB values(‘A1002’, ‘Reeta’, ’26-Nov-2022’, 32);
insert into EB values(‘A1003’, ‘Nithin’, ’27-Nov-2022’, 28);
insert into EB values(‘A1004’, ‘Vikas’, ’28-Nov-2022’, 20);
insert into EB values(‘A1005’, ‘Parinitha’, ’30-Nov-2022’, 44);
insert into EB values(‘A1006’, ‘Tarun’, ’01-Dec-2022’, 256);
insert into EB values(‘A1007’, ‘Solanki’, ’02- Dec-2022’, 178);
insert into EB values(‘A1008’, ‘Patil’, ’03- Dec-2022’, 200);
insert into EB values(‘A1009’, ‘Lakshman ’, ’04- Dec-2022’, 433);
insert into EB values(‘A1010’, ‘Yashaswini’, ’05- Dec-2022’, 400);
3. Check the structure of table:
➢ Solution: desc EB;

4. Add two new fields to table:


bill_amt number(6, 2),due_date date

➢ Solution: alter table EB add(amount number(6, 2), due_date date);

5. Compute the bill amount for each customer as per the following rules:

36 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

min_amt Rs. 50
first 100 units Rs. 4.50/unit
>100 units Rs. 5.50/unit
➢ Solution: update EB set amount=50;
update EB set amount=amount +100*4.50+(units-100)*5.50
where units>100;
update EB set due_date=date_billing+15;

6. List all bills generated:


➢ Solution: select * from EB;
OUTPUT:
Consumer
Rr_number Date_bill Units Amount Due date
name
A1001 Manjunath 25-Nov-2022 34 203 10-Dec-2022
A1002 Reeta 26-Nov-2022 32 194 11-Dec-2022
A1003 Nithin 27-Nov-2022 28 176 12-Dec-2022
A1004 Vikas 28-Nov-2022 20 140 13-Dec-2022
A1005 Parinitha 30-Nov-2022 44 248 15-Dec-2022
A1006 Tarun 01-Dec-2022 256 1358 16-Dec-2022
A1007 Solanki 02-Dec-2022 178 929 17-Dec-2022
A1008 Patil 03-Dec-2022 200 1050 18-Dec-2022
A1009 Lakshman 04-Dec-2022 433 2331.5 19-Dec-2022
A1010 Yashaswini 05-Dec-2022 400 1842 20-Dec-2022

*****

MES PU COLLEGES 37
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

SQL PROGRAM -18


2. Create a student database and compute the result.
1. Create a table for a class of students with following details:
Field name Type
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)

➢ Solution: Create table STD(


std_id number(4) ,
std_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. Add records into the table for 6 students:


➢ Solution: insert into STD values(1124, ‘Anuthara’, 67, 82, 86, 90, 56, 78);
insert into STD values(1127, ‘Bhargavi’, 56, 69, 78, 34, 52, 59);
insert into STD values(1113, ‘Manjunath’, 45, 47, 51, 40, 50, 51);
insert into STD values(1121, ‘Bhavani’, 28, 36, 45, 34, 37, 39);
insert into STD values(1123, ‘Vijetha’, 90, 91, 95, 96, 92, 89);
insert into STD values(1125, ‘Nisarga’, 78, 79, 80, 90, 88, 85);
3. Display the description of fields in table:
➢ Solution: desc STD;

4. Alter the table and calculate total and percentage:


total number (3)
percentage number(2)
result varchar(10)

38 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

➢ Solution: Alter table STD add(total number(3),


Percentage number(2),
result varchar2(10));
➢ Solution: update STD set total=
sub1_marks+sub2_marks+sub3_marks+sub4_marks+sub5_marks+sub6_marks;

Solution: update STD set percentage=total/6.0 where std_id>0;

5 Compute result as “pass”

➢ Solution: update STD 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;
Compute result as “fail”
➢ Solution: update STD set result=’fail’ where
sub1_marks<= 35 and sub2_marks<=35 and
sub3_marks<=35 and sub4_marks<=35 and
sub5_marks<=35 and sub6_marks<=35;
6. Retrieve all records of the table:

➢ Solution: select * from STD;

7. Retrieve only student_id and student_name of all students:


➢ Solution: select std_id, std_name from STD;

8. List the students who have result as “pass”:


➢ Solution: select * from STD where result=’pass’;

9. List the students who have result as “fail”:


➢ Solution: select * from STD where result=’fail’;

10. Count the number of students who have passed:


➢ Solution: Select count(*) from STD where result=’pass’;

11. Count the number of students who have failed:

MES PU COLLEGES 39
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

➢ Solution: Select count(*) from STD where result=”fail”;

12. List the students who have percentage greater than 60:
➢ Solution: select * from STD where percentage>=60;

13. Sort the table according to order of student_id:


➢ Solution: select * from STD order by std_id;

14. Display all records generated:


➢ Solution: select * from STD;

OUTPUT:
Student Student Sub1 Sub2 Sub3 Sub4 Sub5 Sub6 Total Per Result
id name marks marks marks marks marks marks cen
tag
e
1124 Anuthara 67 82 86 90 56 78 459 77 Pass
1127 Bhargavi 56 69 78 34 52 59 348 58 Fail
1113 Manjunath 45 47 51 40 50 51 284 47 Pass
1121 Bhavani 28 36 45 34 37 39 219 37 Fail
1123 Vijetha 90 91 95 96 92 89 553 92 Pass
1125 Nisarga 78 79 80 90 88 85 500 83 Pass

*****

40 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

SQL PROGRAM -19


3. Generate the Employee details and compute salary based on department.
1. Create the following table employee:
Field name Data type
emp_id number(4)
dept_id number(2)
emp_name varchar2(25)
emp_salary number(5)
➢ Solution: Create table EMPY(emp_id number(4),
dept_id number(2), emp_name varchar2(25),
emp_salary number(5));

2. Create another table department with following structure.


dept_id number(2)
dept_name varchar2(20)
supv varchar2(20)

➢ Solution: Create table DEPI(dept_id number(4),


dept_name varchar2(25),
supv varchar2(20));

3. Enter 5 rows of data for employee table and 4 rows of data for
department table:
➢ Solution: insert into EMPY values(1000, 11, ‘Arun’, 30000);
insert into EMPY values(1001, 13, ‘Priya’, 57500);
insert into EMPY values(1002, 12, ‘Anup’, 20000);
insert into EMPY values(1003, 14, ‘Surya’, 40000);
insert into EMPY values(1004, 12, ‘Keerthi’, 50000);

➢ Solution: insert into DEPI values(11, ‘Purchase’, ‘Aman’);


insert into DEPI values(12, ‘Accounts’, ‘Shubha’);
insert into DEPI values(13, ‘Sales’, ‘Gopal’);
insert into DEPI values(14, ‘Apprentice’, ‘Madhu’);

MES PU COLLEGES 41
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

4. Find the names of all employees who work for accounts department:
➢ Solution: select * from EMPY where dept_id=(select dept_id from
DEPI where dept_name=’Accounts’);

5. How many employees work for accounts department?


➢ Solution: select count(*) from EMPY where dept_id=(select dept_id
from DEPI where dept_name=’Accounts’);

6. What is minimum, maximum and average salary of employees working


for accounts department?
➢ Solution: select min(emp_salary) from EMPY where dept_id=(select
dept_id from DEPI where dept_name=’Accounts’);

Select max(emp_salary) from EMPY where dept_id=(select


dept_id from DEPI where dept_name=’Accounts’);

Select avg(emp_salary) from EMPY where dept_id=(select


dept_id from DEPI where dept_name=’Accounts’);

7. List the employees working for a particular supervisor:


➢ Solution: select * from EMPY where dept_id=(select
dept_id from DEPI where supv=’Aman’);

8. Retrieve the department names of each department where only one


employee works:
➢ Solution: select dept_name from DEPI where dept_id in(select
dept_id from EMPY group by dept_id having count(*)=1);

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


➢ Solution: update EMPY set
emp_salary=emp_salary+emp_salary*0.15 where
dept_id=(select dept_id from DEPI where
dept_name=’sales’);

42 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

10. Add a new column to table employee called bonus number(5) and
compute 5% of salary to said field:

Solution: alter table EMPY add bonus number(5);

Update EMPY set bonus=emp_salary*0.15;

11. Delete all rows for employees in apprentice department:


➢ Solution: delete from EMPY where dept_id=(select dept_id from DEPI
where
dept_name=’Apprentice’);

12. Display all records in employee table:


➢ Solution: select * from EMPY;

OUTPUT:
emp_id dept_id emp_name emp_salary bonus
1000 11 Arun 30000 1500
1001 13 Priya 57500 2875
1002 15 Anup 20000 1000
1003 14 Surya 40000 2000

*****

MES PU COLLEGES 43
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

SQL PROGRAM - 20
4. Create a database for bank transaction.
1. Create a customer table having following fields:

Field name Data type


cno. number(4)
cname char(25)
caddress varchar2(50)
cphone char(12)

➢ Solution: create table customer (cno number(4) primary key,


cname char(25), caddress varchar2(50), cphone char(12));

2. Create another table bank having following structure:


Field name Data type
accno. number(8)
tramt number(8, 2)
trdate date
trtype char(12)
cno. number(4)

➢ Solution: Create table bank(accno number(8) not NULL,


tramt number(8, 2) check(tramt>0), trdate date,
trtype char(20), cno number(4));

3. Describe the structure of customer table.


➢ Solution: desc customer;

4. Describe the structure of bank table:


➢ Solution: desc bank;

5. Insert 5 values into customer table:


➢ Solution: insert into customer values(1123, ‘Raj’, ‘MG Road, Bangalore’, 123456789);
insert into customer values(1345, ‘Vijetha’, ‘Vijayanagar, Bangalore’, 98765439);
insert into customer values(1678, ‘Khushi’, ‘Rajajinagar, Bangalore’, 78456785);
insert into customer values(2233, ‘Rohith’, ‘Shivanagar, Bangalore’, 98746574);
insert into customer values(2345 ‘Ketan’, ‘Sreenagar, Delhi’, 984567346);
insert into customer values(1342, ‘Rohith’, ‘Sreenagar, Delhi’, 984567346);

44 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

Insert 5 values into bank table:


➢ Solution: insert into bank values(1342, 59357.23, ‘12-Dec-2022’, ‘C’, 1123);
insert into bank values(1149, 597897.43, ‘12-Dec-2022’, ‘A’, 1345);
insert into bank values(2920, 78290.78, ‘12-Dec-2022’, ‘B’, 1678);
insert into bank values(8901, 737387.56, ‘12-Dec-2022’, ‘A’, 2233);
insert into bank values(9999, 32432.78, ‘12-Dec-2022’, ‘O’, 2345);

6. Display all records of customer table and bank table:


➢ Solution: select * from customer;
Select * from bank;

7. Display all records from bank table transaction data is greater than or
equal to a particular data:
➢ Solution: select * from bank where trdate>=’10-Dec-2022’;

8. List the contents of matching customer number from t--- table:


➢ Solution: select accno, customer.cno, cname from customer, bank where
customer.cno=bank.cno;

9. Sort the names in customer table in descending order:


➢ Solution: select* from customer order by cname desc;

10. Update a record in bank table where transaction amount is 70000 to


particular account no:
➢ Solution: update bank set tramt = 70000 where accno=8901;

11. Alter a record caddress char(50):


➢ Solution: alter table customer modify caddress char(50);

12. Delete a record from bank table for a particular accno.:


➢ Solution: delete from bank where accno=9999;

MES PU COLLEGES 45
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

13. Select one record from customer table where names is starting with a
particular letter:
➢ Solution: select* from customer where cname like ‘A%’;

14. Display current date:


➢ Solution: Select sysdate from dual;

15. Calculate sum of transaction amount in bank table:


➢ Solution: select sum (tramt) from bank;

16. Create a view with cno, cphone as contents:


➢ Solution: create view vcust as select cno, cphone from customer;

17. Select unique customer number from bank table using district
command:
➢ Solution: select distinct (cno) from bank;

18. Display accno, count(*) from bnkapr group by accno having count (*) >1;
➢ Solution: select * from customer where cphone = ‘98765439’;

19. Display all records from both tables:


➢ Solution: select * from customer;
select * from bank;

20. Delete all the records from customer


➢ Solution:Delete from customer;

21. Drop bank table:

46 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

➢ Solution: drop table bank;

OUTPUT:
Cno Cname Caddress Cphone
1123 Roy MG Road, Bangalore 123456789
1345 Vijetha Vijayanagar, Bangalore 98765439
1678 Khushi Rajajinagar, Bangalore 78456785
2333 Rohith Shivanagar, Bangalore 98746574
2345 Ketan Shreenagar, Delhi 94567346

accno tramt trdate trtype Cno


1342 59357.83 12-Dec-2022 C 1123
1149 597897.43 12-Dec-2022 A 1345
2980 78290.78 12-Dec-2022 B 1678
8901 70000 12-Dec-2022 A 2233

*****

MES PU COLLEGES 47
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

SECTION – C (HTML)
Experiment No - 21
Write a HTML program to create a study time table

<!doctype html>
<html>
<head>
<style> th,td,table
{
border:1px solid black;
}
</style>
</head>
<body bgcolor="lightgreen">
<h1> <center> <Color="red"> MY STUDY TIME TABLE FOR THE WEEK
</color> </center> <h1>
<h2> <center> Beautiful sunrise </center> </h2>
<img border="0" src="web.jpg" width="304" height="228">
<table align=”center” “ width=”900px” >
<tr>
<th>Days</th>
<th>Subject</th>
<th>Morning study time only reading</th>
<th>College study time</th>
<th>Evening study time</th>
<th>Question Paper Solution Time only writing</th>
</tr>
<tr>
<th>Monday</th>
<th>Lang I </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th>Tuesday</th>
<th>Lang II </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th> Wednesday</th>

48 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

<th>Optional I</th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th>Thursday</th>
<th>Optional II </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th> Friday</th>
<th>Optional III </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
<tr>
<th>Saturday</th>
<th>Optional Lang I </th>
<th>5:00-6:30 A.M</th>
<th>8:30-4:00 P.M</th>
<th>6:00-8:30 P.M</th>
<th>9:00-11:00 P.M</th>
</tr>
</table>
<marquee direction="right">Enjoy life as a student !!</marquee>
</body>
</html>
OUTPUT

*****

MES PU COLLEGES 49
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

Experiment No- 22
Create an HTML Program with table and Form
<html>
<form name="htmlform" method="post" action="html_form_send.php">
<head>
<table width="450px">
<style>
td, th, table
{
border : 1px solid red; color : blue ;
}
</style>
</table>
</head>
<body bgcolor="lightblue" >
<h1> ATTENDANCE DETAILS : </h1>
<h3> SUBJECT : COMPUTER SCIENCE </h2>
<table style = "WIDHT:300 px">
<tr>
<th> Month</th>
<th> No of classes held </th>
<th> No of classes attended </th>
</tr>
<tr>
<th> JUNE </th>
<th> 10</th>
<th> 10 </th>
</tr>
<tr>
<th> JULY</th>
<th> 20 </th>
<th> 15 </th>
</tr>
<tr>
<th> AUGUST </th>
<th> 20 </th>
<th> 18 </th>
</tr>
<tr>
<th> SEPTEMBER </th>
<th> 20 </th>
<th> 12 </th>
</tr>
<tr>
<th> OCTOBER </th>

50 MES PU COLLEGES
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

<th> 10 </th>
<th> 04 </th>
</tr>
<tr>
<th> NOVEMBER </th>
<th> 10 </th>
<th> 14 </th>
</tr>
<tr>
<th> DECEMBER </th>
<th> 10 </th>
<th> 04 </th>
</tr>
<tr>
<th> JANUARY </th>
<th> 10</th>
<th> 10</th>
</tr>
<tr>
<th> FEBRUARY </th>
<th> 10 </th>
<th> 10 </th>
</tr>

<tr>
<th> Total No of Days </th>
<th> 120 </th>
<th> 97</th>
</tr>
<tr>
<th> PERCENTAGE </th>
<th> </th>
<th> </th>
</tr>
</table>
<br>
<br>

<table WIDTH=200px>
<tr>
<th> <label for ="Student_ID"> Student ID*
</label> </th>
<td> <input type = "text" name= " Student_ID" maxlength="50" size="30"> </td>
</tr>
<tr>

MES PU COLLEGES 51
𝑪𝑶𝑴𝑷𝑼𝑻𝑬𝑹 𝑺𝑪𝑰𝑬𝑵𝑪𝑬 𝑷𝑹𝑨𝑪𝑻𝑰𝑪𝑨𝑳 𝑴𝑨𝑵𝑼𝑨𝑳 − 𝑰𝑰𝑷𝑼𝑪

<th> <label for = "Student_name"> Student Name*


</label> </th>
<td><input type ="text" name ="Student name" maxlength="50" size="30"></td>
</tr>
<tr>
<th> <label for ="Comments"> Comments*
</label> </th>
<td><textarea name=comments" maxlength="1000" cols="30" rows="6"></textarea>
</td>
</tr>
<tr>
<th> <input type="button" value="submit"> </th>
<th> <input type ="button" value="cancel"> </th>
</tr>
</table>
</form>
</body>
</html>
OUTPUT

*****

52 MES PU COLLEGES

You might also like