CS Record - KB CS
CS Record - KB CS
Aim
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
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
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
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
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.
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>
Client Login
<BR><BR><BR>
Enter the User Name
<INPUT Type="text">
<BR><BR>
Enter Your Password
<INPUT Type="Password">
<BR>
<BR><BR>
<INPUT Type="Submit" value="SUBMIT">
<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.
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.
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>
<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.
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.
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);
Output
Structure of the student table
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;
Result
The above code was executed, and the output was verified successfully.
OUTPUT
Structure of employee table
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);
Result
The above code was executed, and the output was verified successfully.
Output
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));
Result
The above code was executed, and the output was verified successfully.
OUTPUT
Structure of book table
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));
Result
The above code was executed, and the output was verified successfully.
OUTPUT