0% found this document useful (0 votes)
2 views82 pages

CS Record - KB CS

Kerala sylbus very importquestion and answers in one pdf

Uploaded by

onlyfakenumber
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)
2 views82 pages

CS Record - KB CS

Kerala sylbus very importquestion and answers in one pdf

Uploaded by

onlyfakenumber
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

1. Input the three coefficients of a quadratic equation and find the roots.

Aim

To develop a C++ program to find the roots of a quadratic equation.

Program

#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
int main( )
{
float a,b,c,r1,r2,d;
cout<<"Enter the values of a, b and c:";
cin>>a>>b>>c;
if (a==0)
{
cout<<"Invalid Input";
exit(0);
}
d =pow(b,2)-(4*a*c);
if(d==0)
{
cout<<"The two roots are equal."<<endl;
r1=r2=-b/(2*a);
cout<<"Root1 = "<<r1<<"\n"<<"Root2 = "<<r2;
}
else if(d>0)
{
cout<<"The two roots are real and unequal."<<endl;
r1=-b+sqrt(d)/(2*a);
r2=-b-sqrt(d)/(2*a);
cout<<"Root1 = "<<r1<<"\n"<<"Root2 = "<<r2;
}
else
{
cout<<"The roots are complex and Imaginary "<<endl;
}
return 0;
}

Result
The above code was executed and the output was verified successfully.
Output
2. Display the first N terms of Fibonacci series.

Aim

To develop a C++ program to display the first N terms of Fibonacci series.

Program

#include<iostream>
using namespace std;
int main()
{
int a=0, b=1, c,n,i;
cout<<”Enter the limit:”;
cin>>n;
if(n==1)
{
cout<<a;
}
else
{
cout<<a<<”\t”<<b;
for(i=3;i<=n;i++)
{
c = a+b;
cout<<”\t”<<c;
a = b;
b = c;
}
}
return 0;
}

Result
The above code was executed and the output was verified successfully.
Output
3. Input a number and check whether it is palindrome or not.

Aim

To develop a C++ program to input a number and to check whether it is palindrome or


not.

Program

#include<iostream>
using namespace std;
int main()
{
int n, r=0,d,t;
cout<<”Enter a number :”;
cin>>n;
t=n;
while(t>0)
{
d= t %10;
r = r*10 +d;
t = t / 10;
}
if (r == n)
cout<<”The given number is a palindrome.”;
else
cout<<”The given number is not a palindrome.”;
return 0;
}

Result
The above code was executed and the output was verified successfully.
Output
4. Find the sum of the digits of an integer number.

Aim

To develop a C++ program to find the sum of the digits of an integer number.

Program

#include<iostream>
using namespace std;
int main()
{
int n,rem,s=0;
cout<<“Enter a number”;
cin>>n;
while(n>0)
{
rem=n%10;
s=s + rem;
n=n/10;
}
cout<<“Sum=”<<s;
return 0;
}

Result
The above code was executed and the output was verified successfully.
Flowchart
Output
5. Find the sum of the squares of the first N natural numbers.

Aim

To develop a C++ program to find the sum of the squares of the first N natural numbers.

Program

#include<iostream>
using namespace std;
int main()
{
int n,s=0,i;
cout<<“Enter a Limit”;
cin>>n;
for(i=0;i<=n;i++)
{
s=s+i*i;
}
cout<<“Sum of the squares =”<<s;
return 0;
}

Result
The above code was executed and the output was verified successfully.
Output
6. Find the length of a string without using strlen( ) function.

Aim
To develop a C++ program to find the length of a string without using the strlen( ) function.

Program

#include<iostream>
using namespace std;
int main( )
{
char name[1000];
int count=0;
cout<<”Enter the string”;
[Link](name,1000);
while(name[count]!=’\0’)
{
count++;
}
cout<<”The length of the string is”<<count;
return 0;
}

Result
The above code was executed and the output was verified successfully.
Flowchart

Output
7. Input string into a character pointer and count the vowels in the string.

Aim
To develop a C++ program to input string into a character pointer and to count the vowels
in the string.
Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
int main()
{
char a[20], *s;
int i, count=0;
cout<<"Enter a string: ";
cin>>a;
s=a;
int l=strlen(a);
for(i=0;i<=l;i++)
{
switch(tolower(*(s+i)))
{
case 'a': count++;
break;
case 'e': count++;
break;
case 'i': count++;
break;
case 'o': count++;
break;
case 'u': count++;
break;
}
}
cout<<"\nThe number of vowels in the given string is: "<<count;
return 0;
}

Result
The above code was executed and the output was verified successfully.
Flowchart
Output
8. Define a function to find the factorial of a number. Using this function to find the value
of nCr.

Aim

To develop a C++ program to find the factorial of a number by defining a function and to
use that function to find the value of nCr.

Program

#include<iostream>
using namespace std;
int fact(int k)
{
int i,f=1;
for(i=1;i<=k;i++)
{
f=f*i;
}
return f;
}
int main()
{
int n, r, ncr;
cout<<"Enter the values for n and r: ";
cin>>n>>r;
ncr=fact(n)/fact(r)* fact(n-r);
cout<<"\n"<<n<<"C"<<r<<" = "<<ncr;
return 0;
}
Result
The above code was executed and the output was verified successfully.
Flowchart

Output
9. Define a structure to store the details of books such as Book Code, Book Title, Date of
Purchase, Author, Publisher and Price. Write a program with this structure to store the
details of 10 books and display the details.
Aim
To develop a C++ program to define a structure to store the details of books and to display it.
Program
#include<iostream>
#include<cstdio>
using namespace std;
struct dop
{
int day;
int month;
int year;
};
struct book
{
int bookcode;
char booktitle[100];
dop purchase;
char author[100],publisher[100];
float price;
};
int main()
{
book b[10];
int i,n;
cout<<"Enter the number of books: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the Book Code: ";
cin>>b[i].bookcode;
cout<<"Enter the Book Title: ";
fflush(stdin);
gets(b[i].booktitle);
cout<<"Enter the day of purchase: ";
cin>>b[i].[Link];
cout<<"Enter the month of purchase: ";
cin>>b[i].[Link];
cout<<"Enter the year of purchase: ";
cin>>b[i].[Link];
cout<<"Enter the author: ";
fflush(stdin);
gets(b[i].author);
cout<<"Enter the Publisher's name: ";
gets(b[i].publisher);
cout<<"Enter the Price: ";
cin>>b[i].price;
cout<<endl<<endl;
}
for(i=0;i<n;i++)
{
cout<<endl<<"Book Code: ";
cout<<b[i].bookcode;
cout<<endl<<"Book Title: ";
puts(b[i].booktitle);
cout<<"Date of Purchase: ";
cout<<b[i].[Link]<<"-"<<b[i].[Link]<<"-"<<b[i].[Link];
cout<<endl<<"Author: ";
puts(b[i].author);
cout<<"Publisher: ";
puts(b[i].publisher);
cout<<"Price: ";
cout<<b[i].price;
cout<<endl<<endl;
}
return 0;
}

Result
The above code was executed and the output was verified successfully.
Flowchart:-

Output
10. Read the admission number of N students in a class and search for a given admission
number in the list. Use linear search method of searching.

Aim

To develop a C++ program to read the admission number of N students in a class to use
linear search to find a given admission number in the list.

Program

#include<iostream>
using namespace std;
int main()
{
cout<<"Enter The number of Students: ";
int size;
cin>>size;
int array[size], key, i;
cout<<"Enter the admission numbers:\n";
for(int j=0; j<size; j++)
{
cin>>array[j];
}
cout<<"Enter Key To Search in Array: ";
cin>>key;
for(i=0; i<size; i++)
{
if(key == array[i])
{
cout<<"Key Found At Index Number : "<<i<<endl;
break;
}
}
return 0;
}

Result
The above code was executed and the output was verified successfully.
Flowchart

Output

.
11. Display the multiplication table of a given number
Aim

To develop a C++ program to display the multiplication table of a given number.

Program

#include<iostream>
using namespace std;
int main()
{
int i, num, limit;
cout<<"Enter the number for which multiplication table is to be displayed: ";
cin>>num;
cout<<"Enter the limit: ";
cin>>limit;
cout<<"The multiplication table of "<<num<<" is \n";
for(i=1;i<=limit;i++)
{
cout<<i<<" * " <<num<<" = " <<i * num<<"\n";
}
return 0;
}
Result
The above code was executed and the output was verified successfully.
Flowchart

Output

.
12. Input a digit and display it in word. (Eg:- 0 -> Zero, 1 -> One, ….. 9 -> Nine)
Aim

To develop a C++ program to input a digit and display it in word.

Program

#include<iostream>
using namespace std;
int main()
{
int digit;
cout<<"Enter a digit: ";
cin>>digit;
switch(digit)
{
case 0: cout<<"Zero";
break;
case 1: cout<<"One";
break;
case 2: cout<<"Two";
break;
case 3: cout<<"Three";
break;
case 4: cout<<"Four";
break;
case 5: cout<<"Five";
break;
case 6: cout<<"Six";
break;
case 7: cout<<"Seven";
break;
case 8: cout<<"Eight";
break;
case 9: cout<<"Nine";
break;
default: cout<<"Wrong input";
}
return 0;
}
Result
The above code was executed and the output was verified successfully.

Flowchart
Output

13. Input a day number and display the corresponding day name of a week.
Aim

To develop a C++ program to input a day number and display the corresponding day name
of a week.

Program
#include<iostream>
using namespace std;
int main()
{
int day;
cout<<"Enter a day number (1-7): ";
cin>>day;
switch(day)
{
case 1: cout<<"Sunday";
break;
case 2: cout<<"Monday";
break;
case 3: cout<<"Tuesday";
break;
case 4: cout<<"Wednesday";
break;
case 5: cout<<"Thursday";
break;
case 6: cout<<"Friday";
break;
case 7: cout<<"Saturday";
break;
default: cout<<"Invalid input";
}
return 0;
}

Result
The above code was executed and the output was verified successfully.
Flowchart

Output
14. Definition List of Nobel Prize Winners

Aim
To design a web page as shown below using appropriate list tags.

HTML Code

<HTML>
<HEAD>
<TITLE>List of Nobel Laureates from India</TITLE>
</HEAD>
<BODYLEFTMARGIN=100">
<CENTER><B><FONTSIZE=+2>
List of Nobel Laureates from India
</B>
</CENTER>
<FONTSIZE=+1>
<BR>
<DT><B>Rabindra Nath Tagore</B></DT>
<DD>
He was the first to get Nobel Prize from India. He received prize in literature in 1921. He got
Nobel Prize for his collection of poems “Gitanjali”.
</DD>
<BR><BR>
<DT><B> C V Raman</B></DT>
<DD>
He got Nobel for Physics in 1930. He received Nobel Prize for his contribution called Raman
Effect.
<BR><BR>
</DD>
<DT><B>Mother Teresa</B></DT>
<DD>
Mother Teresa who founded Missionaries of Charity which is active in more than 100 countries
received Nobel Prize in1979.
</DD>
<BR><BR>
<DT><B>Amartya Sen</B></DT>
<DD>
Amartya Sen was awarded Nobel Prize in 1998 in Economics. He has made contributions to
welfare economics, social choice theory etc.
</DD>
<BR><BR>
<DT><B>Kailash Satyarthi</B></DT>
<DD>
He is a child right activist who founded “Bachpan Bachao Andolan” in 1980. He shared Nobel
prize for peace in 2014.
</DD>
</BODY>
</HTML>

Result
The above code was executed, and the output was verified successfully.

Output
15. Kerala Tourism List
Aim
To design a webpage showing the tourist destinations in Kerala using list tags as shown
below.

HTML Code
<html>
<head>
<title>Kerala Tourism</title>
</head>
<body>
<h1 align=center>Department of Tourism</h1>
<h2 align=center>Government of Kerala</h2>
<h3>Tourist Destinations in Kerala</h3>
<OL>
<LI>Beaches</LI>
<OL TYPE=a>
<LI>Kovalam</LI>
<LI>Muzhuppilangad</LI>
<LI>Kappad</LI>
</OL>
<LI>Hill Stations</LI>
<OL TYPE=i>
<LI>Munnar</LI>
<LI>Wayanad</LI>
<LI>Gavi</LI>
</OL>
<LI>Wild Life</LI>
<OL TYPE=a>
<LI>Iravikulam</LI>
<LI>Muthanga</LI>
<LI>Kadalundi</LI>
</OL>
</OL>
</FONT>
</body>
</html>

Result
The above code was executed, and the output was verified successfully.
Tags and Attributes
Tag Attribute Value
H1 Align CENTER
H2 Align CENTER
OL Type 1, i, a

Output
16. Table design
Aim
To design a table as shown below.

HTML Code

<HTML>
<HEAD>
<TITLE>SCHOOL</TITLE>
</HEAD>
<BODY>
<TABLE BORDER="1">
<TR>
<TH ROWSPAN="2">Class</TH>
<TH COLSPAN="3">Strength</TH>
</TR>
<TR>
<TH>Science</TH>
<TH>Commerce</TH>
<TH>Humanities</TH>
</TR>
<TR>
<TH>Plus One</TH>
<TD>49</TD>
<TD>50</TD>
<TD>48</TD>
</TR>
<TR>
<TH>Plus Two</TH>
<TD>50</TD>
<TD>50</TD>
<TD>49</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Result
The above code was executed, and the output was verified successfully.

Tags and Attributes


Tag Attribute Settings
Table Border 100
TH Rowspan 2
Colspan 3

Output
17. Login form
Aim
To design a simple web page as shown below.

HTML Code

<HTML>
<HEAD>
<TITLE>LOGIN</TITLE> </HEAD>
<BODY>
<FORM>
<FIELDSET>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Client Login
<BR><BR><BR>
Enter the User Name &nbsp;&nbsp;
<INPUT Type="text">
<BR><BR>
Enter Your Password &nbsp;&nbsp;
<INPUT Type="Password">
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<BR><BR>
<INPUT Type="Submit" value="SUBMIT">
&nbsp;&nbsp; &nbsp;&nbsp;
<INPUT Type="reset" value="CLEAR">
</FIELDSET>
</FORM>
</BODY>
</HTML>

Result
The above code was executed, and the output was verified successfully.
Tags and Attributes
Tag Attribute Settings
Input Type Submit
Type Submit

Output
18. Hyperlink
Aim
To design a simple web page about the school and to link the same web page to another
web page containing school address.

HTML Code
[Link]
<HTML>
<HEAD>
<TITLE>MY_SCHOOL</TITLE>
</HEAD>
<BODY>
<CENTER>
<B>MY_SCHOOL</B>
<BR>
<IMG Src=”[Link]”>
<BR><BR>
<A Href=[Link]>About</A>
</CENTER>
</BODY>
</HTML>

[Link]
<HTML>
<HEAD>
<TITLE>ADDRESS</TITLE>
</HEAD>
<BODY>
<CENTER bgcolor =” yellow”>
<B>ABOUT</B>
<BR>
<H2>
Gulf Model School<BR>
Muhaisnah 4 <BR>
Behind Lulu Village – Dubai<BR>
</H2>
</CENTER>
</BODY>
</HTML>
Result
The above code was executed, and the output was verified successfully.

Tags and Attributes


Tag Attribute Settings
IMG Src [Link]
A Href [Link]

Output
19. Frameset
Aim
To design a webpage containing frames that divide the screen vertically in the ratio 50:50.
One web page consists of the list of Indian cricket team members and the second page
contains a list of Indian football team members.

HTML Code

[Link]

<HTML>
<HEAD>
<TITLE>Team_List</TITLE>
</HEAD>
<FRAMESET Cols=50%,50%>
<FRAME SRC=[Link]>
<FRAME SRC=[Link]>
</FRAMESET>
</HTML>

[Link]

<HTML>
<HEAD>
<TITLE>First Frame</TITLE>
</HEAD>
<BODY>
<B>Indian Cricket Team Members</B><BR><BR>
<UL>
<LI>Virat Kohli</LI>
<LI>Ajinkya Rahane</LI>
<LI>M S Dhoni</LI>
<LI>Mohammed Shami</LI>
<LI>Suresh Raina</LI>
<LI>Akshar Patel</LI>
<LI>Dinesh Karthik</LI>
<LI>Manish Pandey</LI>
<LI>Ravindra Jadeja</LI>
<LI>Bhuvaneswar Kumar</LI>
<LI>Karun Nair</LI>
</UL>
</BODY>
</HTML>

[Link]

<HTML>
<HEAD>
<TITLE>Second Frame</TITLE>
</HEAD>
<BODY>
<B>Indian Football Team Members</B><BR><BR>
<UL>
<LI>Sunil Chhetri</LI>
<LI>Jeje Lalpekhulua</LI>
<LI>Robin Singh</LI>
<LI>Subrata Paul</LI>
<LI>Gurpreet Singh</LI>
<LI>Karanjit Singh</LI>
<LI>Cavin Lobo</LI>
<LI>Bikash Jairu</LI>
<LI>Narayan Das</LI>
<LI>Robin Gurung</LI>
<LI>Augustine Fernandes</LI>
</UL>
</BODY>
</HTML>

Result
The above code was executed, and the output was verified successfully.

Tags and Attributes


Tag Attribute Value
Frameset cols 50%
Frame Src [Link]
Frame Src [Link]
Output
20. Upper case and Lower case
Aim
To develop a web page that contains one text box for entering a text and to convert the
content in the text box to upper case and lower case using JavaScript.

HTML Code

<HTML>
<HEAD>
<TITLE>String_Conversion</TITLE>
<SCRIPT Language="JavaScript">
function upper()
{
[Link]=[Link]( );
}
function lower()
{
[Link]=[Link]( );
}
</SCRIPT>
</HEAD>
<BODY>
<FORM Name="frmconvert">
<CENTER>
Enter the String:
<INPUT Type="text" Name="txtstring">
<BR><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IN
PUT Type="text" Name="txtconvert">
<BR> <BR>
<INPUT Type="button" value="To Upper Case" onClick="upper( )">
<INPUT Type="button" value="To Lower Case" onClick="lower( )">
</CENTER>
</FORM>
</BODY>
</HTML>
Result
The above code was executed, and the output was verified successfully.

Tags and Attributes


Tag Attribute Settings
INPUT Type Button
INPUT value ToUpperCase
INPUT value ToLowerCase

Output
21. Sum of numbers
Aim

To develop a web page with two text boxes and a button to display the sum of all numbers
up to a given limit.

HTML Code

<HTML>
<HEAD>
<TITLE>Sum</TITLE>
<SCRIPT Language="JavaScript">
function sum()
{
var sum=0,i,limit;
limit=Number([Link]);
for(i=1;i<=limit;i++)
{
sum=sum+i;
}
[Link]=sum;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM Name="frmsum">
<CENTER>
Enter the limit:
<INPUT Type="text" Name="txtlimit">
<BR><BR>
Sum of Numbers:
<INPUT Type="text" name="txtsum">
<BR><BR>
<INPUT Type="button" value="Sum" onClick="sum()">
</CENTER>
</FORM>
</BODY>
</HTML>
Result
The above code was executed, and the output was verified successfully.

Tags and Attributes


Tag Attribute Settings
Form Name frmsum
Input Type Text
Input Type Button

Output
22. Multiplication table
Aim
To develop a PHP program to accept a number and to display its multiplication table.
Program Code
[Link]
<html>
<head>
<title>Multiplication Table</title>
</head>
<body>
<center>
<form method=POST action=[Link]>
<h4>Enter a number:</h4>
<input type=”text” name=”num”>
<input type=”submit” value=”Get Table”>
</form>
</center>
</body>
</html>

[Link]
<center>
<?php
$num=$_POST[num];
if($num<=12)
{
for($i=1;$i<=10;$i++)
{
$mul=$i*$num; echo$i*$num=$mul<br>;
}
}
else
{
Echo “Invalid Entry!”;
}
?>
</center>
Result
The above code was executed, and the output was verified successfully.
Output
23. State and its capital
Aim
To develop a PHP program to select a state from combo box and to display its capital.
Program Code
[Link]
<html>
<head>
<title>State and its Capital</title>
</head>
<body>
<center>
<form method=”POST” action=”[Link]”>
<h4>Select a State: </h4>
<select name=”list”>
<option>Kerala
<option>Tamilnadu
<option>Karnataka
<option>AndhraPradesh
<option>Telengana
<option>Maharashtra
</select>
<input type=”submit” value=”Show”>
</form>
</center>
</body>
</html>

[Link]

<center>
<?php
$list=$_POST[‘list’];
switch($list)
{
case “Kerala”:
echo “Thiruvananthapuram”;
break;
case “Tamilnadu”:
echo “Chennai”;
break;
case “Karnataka”:
echo “Bengaluru”;
break;
case “Andhra Pradesh”:
echo “Hyderabad”;
break;
case “Telengana”:
echo “Hyderabad”;
break;
case “Maharashtra”:
echo “Mumbai”;
break;
default:
echo “Invalid Selection”;
}
?>
</center>
Result
The above code was executed, and the output was verified successfully.
Output
24. Sales and Commission
Aim
To develop a PHP program to accept the total sales of a particular salesman and to display
the commission. If the monthly sales amount is greater than 1 lakh – commission is 10%, if
it is between 1 lakh and 1.5 lakh – commission is 12% and if it is greater than 1.5 lakh –
commission is 15%.
Program code

[Link]

[Link]

Result
The above code was executed, and the output was verified successfully.
Tags and Attributes
Tags and Attributes
Tag Attribute Value
FORM method Post
action [Link]
INPUT Type Text
Name Num
INPUT Type Submit
Value Commission

Output
25. Create a table student with the following fields and insert at least 5 records into the table
except for the column Total.

a) Update the column Total with the sum of Mark1, Mark2 and Mark3.
b) List the details of students in Commerce batch.
c) Display the name and total marks of students who are failed (Total<90).
d) Display the name and batch of those students who scored 90 or more in Mark1 and
Mark2.
e) Delete the student who scored below 30 in Mark3.

SQL Statements
Query to create the table
create table student (Roll_Number int primary key, Name varchar(25),Batch
varchar(15), Mark1 int, Mark2 int, Mark3 int, Total int);

Query to view the structure of student table


Desc student;

Query to insert values to the table


insert into student values (1101,'Anu','Commerce',25,34,42, null);
insert into student values (1102,'Anand','Science',30,32,41, null);
insert into student values (1103,'Devika','Science',28,13,19, null);
insert into student values (1104,'Seena','Science',35,38,55, null);
insert into student values (1105,'Vishnu','Commerce',91,95,89, null);
Query to view the values in the table

Select * from student;


SQL Query for each question
a) update student set total=mark1+mark2+mark3;
Select * from student;
b) select * from student where batch='Commerce';
c) select name, total from student where total<90;
d) select name, batch from student where mark1>90 and mark2>90;
e) delete from student where mark3<30;
Select * from student;
Result
The above code was executed, and the output was verified successfully.

Output
Structure of the student table

Student table with values

a) update student set total=mark1+mark2+mark3;

b) select * from student where batch='Commerce';


c) select name, total from student where total<90;

d) select name, batch from student where mark1>90 and mark2>90;

e) delete from student where mark3<30;


26. .

SQL Statements
Query to create the table
create table employee(Emp_code int primary key, Emp_name varchar(25), Designation
varchar(25), Department varchar(25),Basic dec(10,2),DA dec(10,2),Gross_pay dec(10,2));
Query to view the structure of employee table
Desc employee;

Query to insert values to the table


insert into employee values (1167,'Venu','SalesManager','Sales',12000,null, null);
insert into employee values (2304,'Remya','PurchaseManager','Purchase',10000,null, null);
insert into employee values (2508,'Priya Lekshmi','HRManager','HR',12000,null, null);
insert into employee values (2502,'Nehumath','SalesGirl','Sales',5000,null, null);
insert into employee values (2506,'Priyanka','Clerk','Sales',7000,null, null);
Query to view the values in the employee table

Select * from employee;


SQL Query for each question

a) update employee set da=basic*0.75;


Select * from employee;
b) select * from employee where department in ('Purchase', 'Sales', 'HR');
c) update employee set Gross_pay = basic + da;
Select * from employee;
d) select * from employee where Gross_pay<10000;
e) delete from employee where designation= 'Clerk';

Result
The above code was executed, and the output was verified successfully.

OUTPUT
Structure of employee table

Employee table with values

a) update employee set da=basic*0.75;


b) select * from employee where department in ('Purchase', 'Sales', 'HR');

c)update employee set Gross_pay = basic + da;

d) select * from employee where Gross_pay<10000;

e) delete from employee where designation= 'Clerk';


27. .

a) Display the details of items which expire on 31/3/2016.


b) Display the item names with stock zero.
c) Remove the items which expire on 31/12/2015.
d) Increase the unit price of all items by 10%.
e) List the items manufactured by “ABC & CO” with quantity above 100.

SQL Statements
Query to create the table
create table stock(Item_code int primary key, Item_name varchar(20), Manufacturer_code varchar(5), Qty int,
Unit_price dec(10,2), Exp_date date);

Query to view the structure of stock table


Desc stock;

Query to insert values to the table


insert into stock values(2304,'ABC&Co','E106',20,120,'2015-12-31');
insert into stock values(3014,'Ranbaxy','CTZ',10,140,'2015-10-31');
insert into stock values(9010,'Ponds','Bdit',25,130,'2015-11-27');
insert into stock values(9014,'Cuticura','R296',27,0,'2016-10-31');
insert into stock values (12304,'Lux','L126',35, 160,'2016-03-31');
Query to view the values in the stock table

Select * from stock;


SQL Query for each question

a) select * from stock where Exp_date='2016-03-31';


b) select * from stock where Qty=0;
c) delete from stock where Exp_date='2015-12-31';
select * from stock;
d) update stock set Unit_price=Unit_price + Unit_price*0.1;
select * from stock;
e) select * from stock where Item_name='ABC & Co' and Qty>100;

Result
The above code was executed, and the output was verified successfully.

Output

Structure of stock table

Stock table with values

a) select * from stock where Exp_date='2016-03-31';

b) select * from stock where Qty=0;


c) delete from stock where Exp_date='2015-12-31';

d) update stock set Unit_price= Unit_price+Unit_price*0.1;

e) select * from stock where Item_name='ABC & Co' and Qty>100;


28. Create a table Book with the following fields and insert at least 5records into the table.
Book_ID Integer Primary key
Book_Name Varchar(20)
Author_Name Varchar(25)
Pub_Name Varchar(25)
Price Decimal(10,2)
a. Create a view containing the details of books published by SCERT.
b. Display the average price of books published by each publisher.
c. Display the details of book with the highest price.
d. Display the publisher and number of books of each publisher in the descending order of the count.
e. Display the title, current price and the price after a discount of 10% in the alphabetical order of book title.

SQL Statements
Query to create the table
create table book(Book_id int primary key, Book_name varchar(20),Author_name varchar(25),Pub_name varchar(25),Price
dec(10,2));

Query to view the structure of book table


desc book;

Query to insert values to the table


insert into book values (101,'Agnichirakukal','[Link] Kalam', 'DC Books',157);
insert into book values (102,'Computer Science', 'Team of Teachers','SCERT',100);
insert into book values (103,'Aarachar','Meera.K.R','DC Books',370);
insert into book values (104,'Randamoozham','[Link] Nair', 'Current Books',120);
insert into book values (105,'Computer Application', 'Team of Teachers','SCERT',120);

Query to view the values in the book table

Select * from book;


SQL Query for each question
a) select * from book where Pub_name='SCERT';
b) select Pub_name,AVG(Price) from book group by Pub_Name;
c) select * from book where Price=(select max(Price) from book);
d) select Pub_name, count(*) from book group by Pub_name order by count(*) desc;
e) select book_name, price, Price-(Price*10/100) from book order by Book_name ASC;

Result
The above code was executed, and the output was verified successfully.
OUTPUT
Structure of book table

Book table with values

a) select * from book where Pub_name='SCERT';

b) select Pub_name,AVG(Price) from book group by Pub_Name;

c) select * from book where Price=(select max(Price) from book);


d) select Pub_name, count(*) from book group by Pub_name order by count(*) desc;

e) select book_name, price, Price-(Price*10/100) from book order by Book_name ASC;


29. Create a table Bank with the following fields and insert at least 5 records into the table.
Acc_No Integer Primary key
Acc_Name Varchar (20)
Branch_Name Varchar (25)
Acc_ Type Varchar (10)
Amount Decimal (10,2)

a. Display the branch-wise details of account holders in the ascending order of the amount.
b. Insert a new column named Minimum_Amount into the table with default value 1000.
c. Update the Minimum_Amount column with the value 500 for the customers in branches other than Alappuzha
and Malappuram.
d. Find the number of customers who do not have the minimum amount 1000.
e. Remove the details of SB accounts from Thiruvananthapuram branch who have zero (0) balance in their account.

SQL Statements
Query to create the table
create table bank(Acc_no int primary key, Acc_name varchar(20),Branch_name varchar(25),Acc_type varchar(10),Amount
dec(10,2));

Query to view the structure of bank table


desc bank;

Query to insert values to the table


insert into bank values(1001,'Sreya','Alappuzha','SB',7000);
insert into bank values(1002,'Akhil','Thiruvananthapuram','SB',0);
insert into bank values(1003,'Anuroop','Malappuram','FD',2000);
insert into bank values(1004,'Rasheed','Kozhikode','SB',4000);
insert into bank values(1005,'Soumya','Thiruvananthapuram','SB',5000);

Query to view the values in the bank table

Select * from bank;


SQL Query for each question
a) select * from bank order by Branch_name, Amount ASC;
b) alter table bank add column Minimum_amount dec(10,2) default 1000;
select * from bank;
c) update bank set Minimum_amount=500 where Branch_name Not in ('Alappuzha','Malappuram');
select * from bank;
d) select count(*) from bank where Minimum_amount<1000;
e) delete from bank where Acc_type='SB' and Branch_name='Thiruvananthapuram' and Amount<=0;
select * from bank;

Result
The above code was executed, and the output was verified successfully.

OUTPUT

Structure of bank table

Bank table with values

a) select * from bank order by Branch_name, Amount ASC;


b) alter table bank add column Minimum_amount dec(10,2) default 1000;

c) update bank set Minimum_amount=500 where Branch_name Not in ('Alappuzha','Malappuram');

d) select count(*) from bank where Minimum_amount<1000;

e) delete from bank where Acc_type='SB' and Branch_name='Thiruvananthapuram' and Amount<=0;

You might also like