CS Lab All Programs
CS Lab All Programs
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>
<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>
<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>
<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.
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 table student( rollno int primary key, name varchar(25), batch varchar(15),
mark1 int, mark2 int, mark3 int, total int);
SQL Queries
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);
SQL Queries
mysql> create table stock (item_code int primary key, item_name varchar(20), manuf_code
varchar(5), qty int, unit_p float);
SQL Queries
mysql> create table book (book_id int primary key, book_name varchar(20), author_name
varchar(25), pub_name varchar(25), price float);