0% found this document useful (0 votes)
10 views22 pages

CS Lab All Programs

The document outlines various computer science lab programs for the year 2023-24, including C++, HTML, JavaScript, and SQL exercises. Each section contains specific programming tasks, procedures, and example code for tasks such as calculating quadratic roots, creating web pages, and managing databases. The document serves as a comprehensive guide for students to practice and apply their programming skills across multiple languages.

Uploaded by

eddf4937
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)
10 views22 pages

CS Lab All Programs

The document outlines various computer science lab programs for the year 2023-24, including C++, HTML, JavaScript, and SQL exercises. Each section contains specific programming tasks, procedures, and example code for tasks such as calculating quadratic roots, creating web pages, and managing databases. The document serves as a comprehensive guide for students to practice and apply their programming skills across multiple languages.

Uploaded by

eddf4937
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/ 22

COMPUTER SCIENCE

LAB PROGRAMS 2023-24


Index Page
SL.No. Date Title Page No.
C++
1 Roots of Quadratic equation
2 Display names of digits
3 Sum of squares of first N natural numbers
4 Check a number is Palindrome or not
5 Check a number is Prime or not
6 Array sorting
7 Length of the string without strlen()
8 Find nCr using function
9 Structure to store student details
10 Swap two numbers using pointer
HTML
11 Simple webpage about Kerala Tourism
12 External link
13 Unordered List
14 Table creation
15 Simple login form
JAVASCRIPT
16 Case conversion of text in a textbox
SQL
17 Student Table
18 Employee Table
19 Stock Table
20 Book Table
1. Input the three coefficients of a quadratic equation and find the roots.

PROCEDURE

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,c,d;
float root1,root2;
cout<<"Enter three coefficients";
cin>>a>>b>>c;
d=b*b-4*a*c;
if(d==0)
{
root1=-b/(2*a);
cout<<"Single root:"<<root1;
}
else if(d>0)
{
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
cout<<"Root1:"<<root1<<",Root2:"<<root2;
}
else
{
cout<<"Imaginary roots";
}
}
2. Input a digit and display the same in word. (Zero for 0, One for 1, ...., Nine for 9)

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
int digit;
cout<<"Enter a Digit";
cin>>digit;
switch(digit)
{
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;
case 0: cout<<"ZERO";break;
}
}
3. Find the sum of the squares of the first N natural numbers without using formula.

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
int num,i,sum=0;
cout<<"Enter a number";
cin>>num;
i=1;
while(i<=num)
{
sum=sum+i*i;
i++;
}
cout<<"Sum of squares="<<sum;
}
4. Input an integer number and check whether it is palindrome or not.

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
int num,rem,rev=0,copy;
cout<<"Enter a number";
cin>>num;
copy=num;
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
if(rev==copy)
cout<<copy<<" is Palindrome";
else
cout<<copy<<" is Not Palindrome";
}
5. Input an integer number and check whether it is a prime or not.

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
int num,flag=1,i;
cout<<"Enter a number";
cin>>num;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
flag=0;
break;
}
}
if(flag==1)
cout<<num<<" is Prime number";
else
cout<<num<<" is Not Prime number";
}
6. Create an array to store the heights of some students and sort the values.

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
int num,i,j,temp,stud[20];
cout<<"How many students";
cin>>num;
cout<<"Enter hieghts of "<<num<<" Students\n";
for(i=0;i<num;i++)
cin>>stud[i];
for(i=0;i<num-1;i++)
{
for(j=i+1;j<num;j++)
{
if(stud[i]>stud[j])
{
temp=stud[i];
stud[i]=stud[j];
stud[j]=temp;
}
}
}
cout<<"Sorted Array\n";
for(i=0;i<num;i++)
cout<<stud[i]<<"\n";

}
7. Find the length of a string without using strlen() function.

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
int count=0;
char str[30];
cout<<"Enter a string\n";
cin.getline(str,30);
while(str[count]!='\0')
{
count++;
}
cout<<"Length of the String is :"<<count;
}
8. Define a function to find the factorial of a number. Using this function find the value of nCr.

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
int n,r,ncr;
int fact(int);
cout<<"Enter value for n and c\n";
cin>>n>>r;
ncr=fact(n)/(fact(n-r)*fact(r));
cout<<"\nf:"<<ncr;
}
int fact(int f)
{
int i;
int ft=1;
for(i=1;i<=f;i++)
ft=ft*i;
return ft;
}
9. Create a structure to represent admission number, name and marks given for CE, PE and
TE of a subject. Input the details of a student and display admission number, name and total
marks obtained.

PROCEDURE

#include<iostream>
using namespace std;
int main()
{
struct student
{
int admno,CE,PE,TE;
char name[30];
}s;
cout<<"Enter Admission number=>";
cin>>s.admno;
cout<<"Enter Name=>";
cin>>s.name;
cout<<"Enter CE and PE=>";
cin>>s.CE>>s.PE;
s.TE=s.CE+s.PE;
cout<<"\nAdmission number:"<<s.admno;
cout<<"\nNAME:"<<s.name;
cout<<"\nTotal Mark:"<<s.TE;

}
10. Input two numbers and swap them by defining a function with pointer arguments.

PROCEDURE

#include<iostream>
using namespace std;
void swap(int*, int*);
int main()
{
int a,b;
cout<<"Enter two numbers";
cin>>a>>b;
cout<<"Before swapping: a= "<<a<<" b= "<<b;
swap(&a, &b);
cout<<"\nAfter swapping: a= "<<a<<" b= "<<b;
}
void swap(int *n1, int *n2)
{
int temp;
temp = *n1;
*n1 = *n2;
*n2 = temp;
}
11. Design a simple and attractive web page for Kerala Tourism. It should contain features
like background colour/image, headings, text formatting and font tags, images, etc.

HTML code

<html>
<head>
<title>Lab-1</title>
</head>
<body bgcolor="#507080">
<h1 align="center">Kerala Tourism</h1>
<h3 align="center">Welcome to God's own country</h3>
<img src="cjhss.jpg" width=300 height=200><br>
<font size=4 color="yellow">
<b><u>Attractive places in Kerala</u></b><br>
<i>Bekal Fort</i><br>
<i>Munnar</i>
<i>Wayanad</i>
</font>
</body>
</html>
12. Design a simple webpage about your school. Create another webpage named address.html
containing the school address. Give links from school page to address.html and reverse.

HTML code(Save the file as school.html)

<html>
<head>
<title>Lab2</title>
</head>
<body>
<h2>CJHSS</h2>
<h4>Subject Combinations</h4>
Biology Science<br>
Computer Science<br>
Commerce<br>
Humanities<br>
<a href="address.html">Address</a>
</body>
</html>

HTML code(Save the file as address.html)

<html>
<head>
<title>Lab2</title>
</head>
<body>
<address>PO.Chemnad,<br> Kasaragod</address>
<a href="school.html">Back</a>
</body>
</html>
13. Design an attractive web page showing the following list.
Leading Institutions in Kerala for Higher Education
•  Indian Institute of Technology, Palakkad
•  National Institute of Technology, Calicut
•  Indian Institute of Science Education and Research, Tvpm.
•  National University of Advanced Legal Studies, Kochi
•  Indian Institute of Space Science and Technology

HTML code

<html>
<head>
<title>Lab-3</title>
</head>
<body>
<h1>Leading Institutions in Kerala for Higher Education</h1>
<ul>
<li>Indian Institute of Technology, Palakkad</li>
<li>National Institute of Technology, Calicut</li>
<li>Indian Institute of Science Education and Research, Tvpm.</li>
<li>National University of Advanced Legal Studies, Kochi</li>
<li>Indian Institute of Space Science and Technology</li>
</ul>
</body>
</html>
14. Design a web page containing a table as shown below.

HTML Code

<html>
<head>
<title>Lab-4</title>
</head>
<body>
<table border=2 >
<caption><b>Terrestrial Planets</b> (Source: NASA)</caption>
<tr>
<th>Planet</th>
<th>Day Length<br>(In Earth hours)</th>
<th>Year Length<br>(In Earth hours)</th>
</tr>
<tr>
<td>Mercury</td>
<td>1408</td>
<td>88</td>
</tr>
<tr>
<td>Venus</td>
<td>5832</td>
<td>224.7</td>
</tr>
<tr>
<td>Earth</td>
<td>24</td>
<td>365.26</td>
</tr>
</table>
</body>
</html>
15. Design a simple web page as shown below.

HTML Code

<html>
<head>
<title>Lab-5</title>
</head>
<body>
<form>
<fieldset>
<center>
<h3>Client login</h3>
Enter User Name <input type="text"><br>
Enter your Password <input type="password"><br>
<input type="submit">
<input type="reset" value="clear">
</center>
</fieldset>
</form>
</body>
</html>
16. A web page should contain one text box for entering a text. There should be two buttons
labelled “To Upper Case” and “To Lower Case”. On clicking each button, the content in the
text box should be converted to upper case or lower case accordingly. Write the required
JavaScript for these operations.

HTML and JAVASCRIPT Code

<html>
<head>
<title>JavaScript Lab work</title>
<script language="javascript">
function upper()
{
var text=document.f.t.value;
document.f.t.value=text.toUpperCase();
}
function lower()
{
var text=document.f.t.value;
document.f.t.value=text.toLowerCase();
}
</script>
</head>
<body>
<form name="f">
Enter a Text<input type="text" name="t"><br>
<input type="button" value="To Upper Case" onclick="upper()">
<input type="button" value="To Lower Case" onclick="lower()">
</form>
</body>
</html>
17. Create a table Student with the following fields and insert at least 5 records into the table
except for the column Total.

Roll_Number Integer Primary key


Name Varchar (25)
Batch Varchar (15)
Mark1 Integer
Mark2 Integer
Mark3 Integer
Total Integer

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 of students in alphabetical order and in batch based.

SQL Queries

mysql> create database lab1;

mysql> use lab1;

mysql> create table student( rollno int primary key, name varchar(25), batch varchar(15),
mark1 int, mark2 int, mark3 int, total int);

mysql> insert into student values(1,’Aj’,’cs’,45,35,54,0);


mysql> insert into student values(4,’Bj’,’com’,42,35,25,0);
mysql> insert into student values(8,’Abc’,’cs’,58,60,48,0);
mysql> insert into student values(34,’Lmn’,’hum’,25,21,24,0);
mysql> insert into student values(23,’Pqr’,’com’,55,53,54,0);

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

b)mysql> select * from student where batch=’com’;

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

d)mysql> select name,batch from student order by batch asc,name asc;


18. Create a table Employee with the following fields and insert at least 5 records into the
table except the column Gross_pay and DA.

Emp_code Integer Primary key


Emp_name Varchar (20)
Designation Varchar (25)
Department Varchar (25)
Basic Decimal (10,2)
DA Decimal (10,2)
Gross_pay Decimal (10,2)

a. Update DA with 75% of Basic.


b. Display the details of employees in Purchase, Sales and HR departments.
c. Update the Gross_pay with the sum of Basic and DA.
d. Display the details of employee with gross pay below 10000.

SQL Queries

mysql> use lab1;

mysql> create table employee (emp_code int primary key, emp_name varchar(20),
designation varchar(25), department varchar(25),basic float, da float, gross float);

mysql> insert into employee values(11,’Abc’,’Manager’,’Purchase’,15000,0,0);


mysql> insert into employee values(12,’Def’,’Clerk’,’FO’,4000,0,0);
mysql> insert into employee values(13,’Ghi’,’Accountant’,’Production’,5000,0,0);
mysql> insert into employee values(14,’Jkl’,’MD’,’Sales’,20000,0,0);
mysql> insert into employee values(15,’Mno’,’CEO’,’HR’,30000,0,0);

a)mysql> update employee set da=basic*0.75;

b)mysql> select * from employee where department in(‘Purchase’,‘Sales’,’HR’);

c)mysql> update employee set gross=basic+da;

d)mysql> select * from employee where gross<10000;


19. 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.

Item_code Integer Primary key


Item_name Varchar (20)
Manufacturer_Code Varchar (5)
Qty Integer
Unit_Price Decimal (10,2)

a. Display the item names with stock zero.


b. Display the number of items manufactured by the same manufacturer.
c. Display the highest price and lowest quantity in the stock.
d. Increase the unit price of all items by 10%.

SQL Queries

mysql> use lab1;

mysql> create table stock (item_code int primary key, item_name varchar(20), manuf_code
varchar(5), qty int, unit_p float);

mysql> insert into stock values(101,’pen’,’mm1’,100,7);


mysql> insert into stock values(102,’pencil’,’mm2’,150,5);
mysql> insert into stock values(103,’sharpner’,’mm1’,0,3);
mysql> insert into stock values(104,’eraser’,’mm3’,125,3);
mysql> insert into stock values(105,’notebook’,’mm2’,100,18);

a)mysql> select item_name from stock where qty=0;

b)mysql> select manuf_code,count(*) from stock group by manuf_code;

c)mysql> select max(unit_p),min(qty) from stock;

d)mysql> update stock set unit_p=unit_p*1.1;


20. Create a table Book with the following fields and insert at least 5 records 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) Display the details of books with price 100 or more.


b) Display the Name of all books published by SCERT.
c) Increase the price of the books by 10% which are published by SCERT.
d) List the details of books with the title containing the word "Programming" at the end.

SQL Queries

mysql> use lab1;

mysql> create table book (book_id int primary key, book_name varchar(20), author_name
varchar(25), pub_name varchar(25), price float);

mysql> insert into book values(501,’CS’,’at1’,’SCERT’,230);


mysql> insert into book values(502,’HTML’,’at2’,’NCERT’,210);
mysql> insert into book values(503,’C++ Programming’,’at23’,’SCERT’,300);
mysql> insert into book values(504,’Java Programming’,’at4’,’SCERT’,350);
mysql> insert into book values(505,’DBMS Basics’,’at5’,’DC Books’,90);

a)mysql> select * from book where price>=100;

b)mysql> select book_name from book where pub_name=’SCERT’;

c)mysql> update book set price=price*1.1 where pub_name=’SCERT’;

d)mysql> select * from book where book_name like ‘%Programming’;

You might also like