Beruflich Dokumente
Kultur Dokumente
PRACTICAL RECORD
2019-2020
COMPUTER APPLICATIONS
1
Practical Record
Computer Applications
Name : ………………………………………………………………….
Class : ………………………………………………………………….
2
CONTENTS
I. C++ SECTION
1. Check whether the number is positive, negative or zero.
2. Display the first N terms of Fibonacci series.
3. Input a digit and display the corresponding word using switch.
4. Write a program to find the Factorial of a given number.
5. Sum of the digits of an integer number.
6. Write a program to find the sum of first n natural numbers.
7. Display the multiplication table of a number having 12 rows.
8. Calculate area of a rectangle, circle and triangle using switch.
9. Finding highest price of textbooks using array.
10. Sum of squares of first N natural numbers without formula.
11. Length of a string without using strlen() function.
12. Swap two numbers using function.
3
C++ Section
4
1) Input a number and check whether it is positive, negative or
zero
Program Code:
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter a number";
cin>>n;
if(n>0)
cout<<"The number is positive";
else if(n<0)
cout<<"The number is negative";
else
cout<<"The number is Zero";
return 0;
}
Output:
Enter a number 8
The number is positive
Enter a number -5
The number is negative
5
2) Display the first N terms of Fibonacci series.
Program Code:
#include<iostream>
using namespace std;
int main()
{
int f1=0,f2=1,f3,n,i;
cout<<"Fibonacci series\n";
cout<<"Input limit : ";
cin>>n;
if(n==1)
{
cout<<f1;
}
else
{
cout<<f1<<"\t"<<f2;
for(i=3;i<=n;i++)
{
f3=f1+f2;
cout<<"\t"<<f3;
f1=f2;
f2=f3;
}
}
}
Output:
Fibonacci Series
Input limit : 8
0 1 1 2 3 5 8 13
6
3) Input a digit and display the corresponding word using switch.
Program Code :
#include <iostream>
using namespace std;
int main()
{
char d;
cout<<"Input a digit : ";
cin>>d;
switch (d)
{
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<<"Not a digit";
}
}
Output :
Input a digit : 0
Zero
7
4) Write a program to find the Factorial of a given number.
(Example 3 factorial=1*2*3 ie 6)
Program Code :
#include<iostream>
using namespace std;
int main()
{
int n,i,fact=1;
cout<<"Enter the limit : ";
cin>>n;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
cout<<"Factorial ="<<fact;
}
Output:
8
5) Find the sum of the digits of an integer number.
Program Code :
#include <iostream>
using namespace std;
int main()
{
int n,t,d,s=0;
cout<<"Input a number : ";
cin>>n;
t=n;
while(n>0)
{
d=n%10;
s=s+d;
n=n/10;
}
cout<<"Sum of digits of "<<t<<" = "<<s;
}
Output :
9
6) Write a program to find the sum of first n natural numbers
Program Code :
#include<iostream>
using namespace std;
int main()
{
int n,s=0,i;
cout<<"Enter the limit : ";
cin>>n;
for(i=1;i<=n;i++)
{
s=s+i;
}
cout<<"Sum ="<<s;
}
Output :
10
7) Display the multiplication table of a number having 12 rows.
Program Code :
#include<iostream>
using namespace std;
int main()
{
int x,i;
cout<<"Enter a Number:\n";
cin>>x;
for(i=1;i<12;i++)
{
cout<<x<<" x"<<i<<x*i<<"\n";
}
return 0;
}
Output :
Input a number : 5
1x5=5
2 x 5 = 10
3 x 5 = 15
4 x 5 = 20
5 x 5 = 25
6 x 5 = 30
7 x 5 = 35
8 x 5 = 40
9 x 5 = 45
10 x 5 = 50
11 x 5 = 55
12 x 5 = 60
11
8) Find the area of a rectangle, a circle and a triangle. Use switch
statement for selecting an Option from a menu.
Program Code :
#include<iostream>
using namespace std;
int main()
{
int ch,l,w,area,r,b,h;
cout<<"1.Area of Rectangle\n";
cout<<"2.Area of Circle\n";
cout<<"3.Area of Triangle\n";
cout<<"Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the Length and Width : ";
cin>>l>>w;
area=l*w;
cout<<"Area of Rectangle = "<<area;
break;
case 2: cout<<"Enter the radius : ";
cin>>r;
area=3.14*r*r;
cout<<"Area of Circle = "<<area;
break;
case 3: cout<<"Enter the base and height : ";
cin>>b>>h;
area=0.5*b*h;
cout<<"Area of Triangle = "<<area;
break;
default :cout<<"Invalid Input";
}
return 0;
}
Output :
1.Area of Rectangle
2.Area of Circle
3.Area of Triangle
Enter your choice : 2
Enter the radius : 5
Area of circle is = 78
12
9)Input the price of a set of higher secondary textbooks and find
the highest price.
Program Code :
#include<iostream>
using namespace std;
int main()
{
int price[100],Large,i,n;
cout<<"Enter the number of textbooks : ";
cin>>n;
cout<<"Enter the Price of textbooks \n";
for(i=0;i<n;i++)
{
cin>>price[i];
}
Large=price[0];
for(i=1;i<n;i++)
{
if(Large<price[i])
Large=price[i];
}
cout<<"Highest price is = "<<Large;
return 0;
}
Output :
13
10) Find the sum of the squares of the first N natural numbers
without using any formula.
Program Code :
#include<iostream>
using namespace std;
int main()
{
int n,s=0,i;
cout<<"Enter the limit : ";
cin>>n;
for(i=1;i<=n;i++)
{
s=s+i*i;
}
cout<<"Sum of the squares = "<<s;
return 0;
}
Output :
14
11)Find the length of a string without using strlen() function.
Program Code :
#include<iostream>
using namespace std;
int main( )
{
char name[100];
int count=0;
cout<<"Enter a String : ";
cin.getline(name,100);
while(name[count]!='\0')
{
count ++;
}
cout<<"The length of the string is : "<<count;
return 0;
}
Output :
15
12 ) Define a function to swap the contents of two variables.
Program Code :
#include<iostream>
using namespace std;
void swap(int,int);
int main( )
{
int a,b,c;
cout<<"Enter the values of a,b \n";
cin>>a>>b;
cout<<"The values of a,b before swapping are :";
cout<<a<<"\t"<<b;
swap(a,b);
return 0;
}
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"\nThe values of a,b after swapping are :";
cout<<x<<"\t"<<y;
}
Output :
16
HTML SECTION
17
HTML – 1 :
Aim : Write HTML code to create an attractive web page about Kerala
(Use alignments, font color, background color etc.)
Procedure / Code :
<HTML>
<HEAD>
<TITLE> Kerala </TITLE>
</HEAD>
<BODY BGCOLOR=”GREEN” TEXT=”BLUE”>
<CENTER>
<H1> Kerala State </H1>
<FONT COLOR=RED>
<H4> Welcome to god’s own country </H4>
</FONT>
</CENTER>
<BR>
<H5> <U> Tourist Places </U><H5>
Varkala, Bepoor, Kovalam
<BR>
<IMG SRC="kerala.jpg" ALIGN=”center”>
</BODY>
</HTML>
18
Output :
19
HTML – 2:
Procedure / Code :
<HTML>
<HEAD>
<TITLE> OOTY </TITLE>
<U><H1 ALIGN="CENTER">VISIT OOTY</H1></U>
</HEAD>
<BODY>
<CENTER>
<H2>THE 'QUEEN' OF HILL STATIONS</H2>
<I> Extremely pleasant stay
<br>
Climate excellent
</I>
</CENTER>
<H2>SPECIAL ATTRACTIONS</H2>
20
<OL>
<LI> Annual flower show in Botanical garden
<LI> Racing
<LI> Horse riding facilities
<LI> Boating
</OL>
<I>
Stay facilities at moderate charges in guest house
<br>
Special rates for families
</I>
<H5 ALIGN="right"> By</H5>
<H3 ALIGN="right"><I> DIRECTOR OF TOURISM<I>
</CENTER>
</BODY>
</HTML>
21
HTML – 3 :
Aim : Write HTML code to create an attractive web page about your school and save
it with the name ‘school’. Prepare another web page with the address of your school
and save it with the name ‘address’. Now create a link in the web page ‘school’ to
link to the web page ‘address’.
Theory : There are two types of links in HTML, internal link and external link. Here
we use external link. Tag for link is <A HREF=”FILENAME> LINK NAME </A>
Procedure / Code :
School.html
<HTML>
<HEAD>
<TITLE> School </TITLE>
</HEAD>
<BODY BGCOLOR=”Green” TEXT=”Blue” LINK=”Red”>
<CENTER>
<H1> My School </H1>
<H2><U> St. Joseph’s Higher Secondary School</U> <H2>
Our School is one of the leading higher secondary schools at Thrissur.
<BR>
We celebrated our Centenary last year.
<BR>
<BR>
<A HREF=”ADDRESS.HTML”> Click Here to See Address Page </A>
</CENTER>
</BODY>
</HTML>
22
Address.html
<HTML>
<HEAD>
<TITLE> Address </TITLE>
</HEAD>
<BODY BGCOLOR=”GREEN” TEXT=”BLUE” LINK=”RED”>
<CENTER>
<H1> My School Address </H1>
<H2> St. Joseph’s Higher Secondary School <H2>
<H3> P.O. Pavaratty </H3>
<H3>Thrissur</H3>
<H3> Kerala</H3>
<H3> Pin : 680507 </H3>
<H3> Ph : 0487 2640282 </H3>
<A HREF=”SCHOOL.HTML”> Click Here to See School Page </A>
</CENTER>
</BODY>
</HTML>
23
Output :
School.html
Address.html
24
HTML – 4 :
Aim : Write HTML code to create a simple web page as shown below.
Department of Tourism
Kerala State
Tourist attractions in Kerala
Trivandrum
1. Kovalam Beach
2. Padmanabha Temple
3. Museum
Ernakulam
1. Bolghatty Palace
2. Vembanad Lake
Calicut
1. Beypore Port
2. Kappad Beach
Theory : Use List tags in HTML, ordered list, unordered list and definition list are the
three types of lists. Here we use <UL> for unordered list , <OL> for ordered list and
<LI> for list item.
Procedure / Code :
<HTML>
<HEAD>
<TITLE> Kerala </TITLE>
</HEAD>
<BODY>
<CENTER>
<H1> Department of Tourism </H1>
<H2> Kerala State </H2>
</CENTER>
<I><B> Tourist attractions in Kerela </I> </B>
<BR>
25
<UL TYPE=”DISC”>
<LI> Trivandrum
<OL>
<LI>Kovalam Beach
<LI>Padmanabha Temple
<LI>Museum
</OL>
<LI> Ernakulam
<OL>
<LI>Bolghatty Palace
<LI>Boating in Vembanad Lake
</OL>
<LI> Calicut
<OL>
<LI>Beypore Port
<LI>Kappad Beach
</OL>
</UL>
</BODY>
</HTML>
26
HTML – 5 :
Theory: HTML is a simple language used to describe the layout of web pages.
HTML consists of special codes called tags which when embedded with text apply
different format to the text.
Procedure: All normal web pages consist of head and body. The Head is used for
a text and tags that do not appear on the page. The tags <HEAD> … </HEAD>
physically identify the head of the document. The title of the web page can be
included in <TITLE>…</TITLE> tags, within the head section.
<TABLE>…</TABLE> to create a table
<TR>..</TR> - to insert a row in a table
<TH>…</TH> - Table heading
<TD>…</TD> - to create a cell in a row
Source Code:
<HTML>
<CENTER>
<HEAD>
<H1> SIMPLE TABLE </H1>
</HEAD>
<BODY>
<TABLE BORDER=1>
<TR ALIGN=”Center”>
<TH> ITEM </TH>
<TH> QUANTITY </TH>
<TH> RATE </TH>
</TR>
<TR ALIGN=”Center”>
<TD> PEN </TD>
<TD> 1</TD>
<TD >Rs. 15</TD>
27
</TR>
<TR ALIGN="Center">
<TD> PENCIL </TD>
<TD> 2</TD>
<TD >Rs. 10</TD>
</TR>
<TR ALIGN="Center">
<TD>RUBBER</TD>
<TD>3</TD>
<TD>Rs. 15 </TD>
</TR>
</TABLE>
</BODY>
</CENTER>
</HTML>
Output :
28
HTML – 6 :
Theory: HTML is a simple language used to describe the layout of web pages.
HTML consists of special codes called tags which when embedded with text apply
different format to the text.
Procedure: All normal web pages consist of head and body. The Head is used for
a text and tags that do not appear on the page. The tags <HEAD> … </HEAD>
physically identify the head of the document. The title of the web page can be
included in <TITLE>…</TITLE> tags, within the head section.
<TABLE>…</TABLE> to create a table
<TR>..</TR> - to insert a row in a table
<TH>…</TH> - Table heading
<TD>…</TD> - to create a cell in a row
Source Code:
<HTML>
<HEAD>
<TITLE>SIMPLE TABLE </TITLE>
</HEAD>
<BODY>
<TABLE BORDER=1>
<TR>
<TH ROWSPAN=2> State Bank of India </TH>
<TH COLSPAN=3> Interest Rates </TH>
</TR>
<TR>
<TH> Less than <BR> Rs. 50,000.00 </TH>
<TH> Between <BR> Rs. 50,000.00 & <BR> Rs. 1 Lakh </TH>
<TH >Above<BR>R s. 1 Lakh </TH>
</TR>
<TR ALIGN="Center">
29
<TH>Less than 5 <BR> Years </TH>
<TD>8 </TD>
<TD>8.5 </TD>
<TD>9 </TD>
</TR>
<TR ALIGN="Center">
<TH> Between 5 & <BR> 10 years </TD>
<TD>8.5 </TD>
<TD>9 </TD>
<TD>9.5 </TD>
</TR>
<TR ALIGN="Center">
<TH> Above 10 <BR> years </TD>
<TD>9 </TD>
<TD>9.5 </TD>
<TD>10 </TD>
</TABLE>
</BODY>
</HTML>
Output :
30
SQL SECTION
31
SQL -1 :
Theory : To build up the new table we are using the CREATE TABLE command.
At the time of the table creation you must specify the column name, data type, size
of each column.
After creating the table you may insert the data into it by using the INSERT
INTO command
Sometimes you need to change some or all of the values in an existing row. It
can done by using UPDATE command of SQL
Procedure : First you create a table with name Student. For that you may open the
SQL window. Press the enter key on your keyboard.
Table Creation : Type the following SQL command on your SQL window
CREATE TABLE STUDENT( RollNo integer primary key, Name char(25), Batch
varchar(25),Mark1 integer, Mark2 integer, Mark3 Integer, Total integer);
32
Press enter key, Message ‘The command(s) completed successfully.’ will be
displayed on the screen.
Insert the data into the table and type the following commands in the SQL window
INSERT INTO student (RollNo, Name, Batch, Mark1, Mark2, Mark3) VALUES (1,
’Akhil’, ’science’, 20, 30, 25);
It will show ‘(1 row(s) affected )’
INSERT INTO student (RollNo, Name, Batch, Mark1, Mark2, Mark3) VALUES (2,
’Sreejith’, ’humanities’, 140, 110, 20);
INSERT INTO student (RollNo, Name, Batch, Mark1, Mark2, Mark3) VALUES (3,
‘Chithra’, ’commerce’, 45, 35, 28);
INSERT INTO student (RollNo, Name, Batch, Mark1, Mark2, Mark3) VALUES (4,
’Arun’, ’science’, 120, 150, 100);
INSERT INTO student (RollNo, Name, Batch, Mark1, Mark2, Mark3) VALUES (5,
’Vinitha’, ’commerce’, 22, 25, 35);
Press enter key Message ‘5 row(s) affected.’ will be displayed on the screen.
33
ii) Display details of students in commerce batch
SELECT * FROM student WHERE Batch=’commerce’;
Output will be as shown below.
c) Display the name and total marks of students who are failed (Total < 90).
SELECT Name,Total FROM student WHERE Total<90;
Output will be as shown below
d) Display the name and batch of those students who scored 90 or more in Mark1
and Mark2.
SELECT Name,Batch FROM student WHERE Mark1>90 AND Mark2>90;
34
SQL - 2 :
Aim : Create a table Employee with the following fields and insert at least 5 records
into the table except the column Grosspay and DA.
Empcode Integer Primary key
Empname Varchar (20)
Designation Varchar(25)
Department Varchar (25)
Basic Decimal (10,2)
DA Decimal (10,2)
Grosspay Decimal (10,2)
a) Update DA with 75% of Basic.
b) Update the Gross_pay with the sum of Basic and DA.
c) Display the details of employees in Purchase, Sales and HR departments.
d) Display the details of employee with gross pay below 10000.
e) Delete all the clerks from the table.
SQL Query to create the table .
CREATE TABLE Employee ( Empcode INT PRIMARY KEY, Empname
VARCHAR (20), Designation VARCHAR(25), Department VARCHAR(25), Basic
DEC(10,2), DA DEC(10,2), Grosspay DEC(10,2) );
35
SELECT * FROM Employee
36
d. SELECT * FROM Employee WHERE Grosspay < 10000;
37
SQL-3
Aim: Create a table Stock, which stores daily sales of items in a shop, with the
following fields and insert at least 5 records into the table.
Itemcode Integer Primary key
Itemname Varchar (20)
Manucode Varchar (5)
Qty Integer
UnitPrice Decimal (10,2)
ExpDate Date
a. Display the details of items which expire after 31/3/2016 in the order of expiry date.
SQL statements :
1. SQL Query to create the table .
CREATE TABLE Stock ( Itemcode INT PRIMARY KEY, Itemname VARCHAR
(20), ManuCode VARCHAR(5), Qty INT, UnitPrice DEC(10,2), ExpDate Date );
2. SQL Query to insert 5 records into the table
INSERT INTO Stock VALUES (1, ’Fridge’, ’VOLTA’, 30 , 9000, ’2018-12-25’),
(2, ’Washing Machine’, ’SATA’,55, 8000, ’2016-05-01’),
(3, ’Pressure Cooker’, ‘PREST’, 38, 4000, ’2016-02-04’),
(4, ’Grinder’, ’SATA’, 17, 6000, ’2016-03-22’),
(5, ’Mixie’, ’SATA’, 60, 3000, ‘2016-07-28’);
38
b. SELECT ManuCode , COUNT(*) FROM Stock WHERE ManuCode=’SATA’;
39
SQL-4
Aim : Create a table Book with the following fields and insert at least 5 records into
the table.
BookID Integer Primary key
BookName Varchar (20)
AuthorName Varchar (25)
PubName Varchar (25)
Price Decimal (10,2)
a. Display the average price of books published by each publisher.
b. Display the details of book with the highest price.
c. Display the publisher and number of books of each publisher.
d. Display the title, current price in the alphabetical order of book title.
SQL statements :
1. SQL Query to create the table .
CREATE TABLE Book ( BookID INT PRIMARY KEY, BookName VARCHAR
(20), AuthorName VARCHAR(25), PubName VARCHAR(25), Price DEC(10,2) );
2. SQL Query to insert 5 records into the table
INSERT INTO Book VALUES (1, ’Agnichirakukal’, ’A.P.J Abdul Kalam’, ’DC
Books’, 157), (2, ’Computer Science’, ’Team of Teachers’, ’SCERT’,100),
(3, ’Aarachar’, ‘Meera.K.R’, ’DC Books’,370),
(4, ’Randamoozham’, ’M.T Vasudevan Nair’, ‘Current Books’,249),
(5, ’Computer Application’, ’Team of Teachers’, ‘SCERT’,120);
3. SQL Query for each question
40
c. SELECT PubName , COUNT(*) FROM Book GROUP BY PubName ;
41
SQL-5
Aim: Create a table Bank with the following fields and insert at least 5 records into
the table.
Acc_No Integer Primary key
AccName Varchar (20)
Branch Varchar (25)
Acctype 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 :
1. SQL Query to create the table .
CREATE TABLE Bank ( AccNo INT PRIMARY KEY, AccName VARCHAR (20),
Branch VARCHAR(25), Acctype VARCHAR(10), Amount DEC(10,2) );
42
b. ALTER TABLE Bank ADD COLUMN Minimumamt DEC(10,2) DEFAULT 1000;
43
e. DELETE FROM Bank WHERE AccType =’SB’ AND
branch=’Thiruvananthapuram’ AND Amount<=0;
44