0% found this document useful (0 votes)
6 views9 pages

C++ and HTML Programming Examples

Uploaded by

cabhiram004
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)
6 views9 pages

C++ and HTML Programming Examples

Uploaded by

cabhiram004
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

CPP PROGRAMS

[Link] ,negative or zero


Input a number and check whether the given number is positive ,negative or zero
#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;
}
[Link] number
Input a number and display the corresponding day name using switch(eg.1-Sunday)
#include <iostream>
using namespace std;
int main()
{
int day;
cout<<"Input a number ";
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 digit";
}
return 0;
}
[Link] table
Display the multiplication table of a number having 12 rows.
#include<iostream>
using namespace std;
int main()
{
int n,i;
cout<<"Enter a number";
cin>>n;
for(i=1;i<=12;i++)
cout<<i<<"*"<<n<<"="<<n*i<<"\n";
return 0;
}
[Link] among three numbers
Input three numbers and find the largest.
#include<iostream>
using namespace std;
int main()
{
int n1,n2,n3;
cout<<"Enter three numbers ";
cin>>n1>>n2>>n3;
if((n1>n2)&&(n1>n3))
cout<<n1<<"is largest";
else if(n2>n3)
cout<<n2<<"is largest";
else
cout<<n3<<"is largest";
return 0;
}
[Link] length
Input a string and find length of a string without using strlen() function
#include<iostream>
using namespace std;
int main()
{
int i;
char str[100];
cout<<"Enter a string ";
[Link](str,100);
for(i=0;str[i]!='\0';i++);
cout<<" Number of Characters is "<<i;
cout<<"\n";
return 0;
}
[Link] of natural numbers
Find the sum of first N natural numbers
#include<iostream>
using namespace std;
int main()
{
int n,sum=0,i;
cout<<"Enter a number";
cin>>n;
for(i=0;i<=n;i++)
sum=sum+i;
cout<<"Sum of numbers ="<<sum;
return 0;
}
[Link] of array elements
Program to find sum of 10 numbers using an array.
#include <iostream>
using namespace std;
int main()
{
int i,n[10],sum=0;
cout<<"Enter 10 Numbers ";
for(i=0;i<=9;i++)
{
cin>>n[i];
sum=sum+n[i];
}
cout<<" Sum of 10 numbers = "<< sum;
return 0;
}
[Link]
Find the factorial of a number with the help of a user-defined function.
#include <iostream>
using namespace std;
double factorial(int n)
{
long int i,fact=1;
for(i=1;i<=n;i++)
fact=fact*i;
return fact;
}
int main()
{
int n;
cout<<"Input a number ";
cin>>n;
cout<<" factorial of "<<n<<" = "<< factorial(n);
}
[Link] function
Input two numbers and swap them with the help of a user defined function.
#include<iostream>
using namespace std;
void swap(int &A, int &B)
{
int temp;
temp=A;
A=B;
B=temp;
}
int main()
{
int X, Y;
cout<<"Enter two numbers:";
cin>>X>>Y;
cout<<"\n Before Swapping\n";
cout<<"X="<<X<<" Y="<<Y;
swap(X,Y);
cout<<"\n After Swapping\n";
cout<<"X="<<X<<" Y="<<Y;
return 0;
}
[Link] height using array
Create an array to store the heights of 10 students and find the largest value.
#include<iostream>
using namespace std;
int main()
{
int height[10],N,i,large;
cout<<"Enter the size of the Array:";
cin>>N;
cout<<"Enter the heghts of "<<N <<" students:";
for(i=0;i<N;i++)
{
cin>>height[i];
}
large=height[0];
for(i=1;i<N;i++)
{
if(large < height[i])
large = height[i];
}
cout<<"The largest height is " <<large;
return 0;
}
[Link] or odd
Input a number and check whether the given number is odd or even
#include<iostream>
using namespace std ;
int main ()
{
int num ;
cout<<"Enter a number";
cin>>num;
if(num%2==0)
cout<<"The given number is even";
else
cout<<"The Given number is odd";
return 0;
}
[Link]
Write a C++ Program to design the following pattern
*
**
***
****
*****
#include<iostream>
using namespace std;
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
cout<<"*";
cout<<"\n”;
}
}

HTML PROGRAMS

[Link] OF KERALA TOURISM


Design a simple and attractive webpage for Kerala Tourism. It should contain features like background colour / image, heading,
text formatting and font tags, images etc.

<HTML>
<HEAD>
<TITLE> KERALA TOURISM </TITLE>
</HEAD>
<BODY Bgcolor=“green” Text=“pink”>
<H1 Align="center"> WELCOME TO THE WEB PAGE OF KERALA TOURISM</H1>
<IMG SRC=”[Link]” Height="300" width="200">
<P> Kerala, <I><B>The God’s Own Country</B> </I>, is a beautiful state in the Southern part of India. <BR>The state is
famous for its Tourist Attractions. There are many places of beauty as well as historical Importance.</P>
<FONT Face=”New Times Roman” Size=5 Color=”blue”>
Some of the important tourist attractions in Kerala are <BR>
Kovalam Beach<BR> Bekkal Fort<BR>
Munnar<BR> Muthanga Wild Life
</FONT>
</BODY>
</HTML>

[Link] LIST
Design a webpage as shown below using appropriate list tags.

Permanent members in UN Security Council

• Russia
• China
• USA
• UK
• France

<HTML>
<HEAD>
<TITLE> UN Security Council </TITLE>
</HEAD>
<BODY>
<H2 > Permanent members in UN Security Council </H2>
<UL>
<Li> Russia </Li>
<Li> China </Li>
<Li> USA </Li>
<Li> UK </Li>
<Li> France </Li>
</UL>
</BODY>
</HTML>
3 .ORDERED LISTS
Design a webpage having list as shown below

Wild life Sanctuaries in Kerala


1. Eravikulam
2. Periyar
3. Chinnar
4. Wayanad

<HTML>
<HEAD>
<TITLE> Wild life </TITLE>
</HEAD>
<BODY>
<H2 > Wild life Sanctuaries in Kerala </H2>
<OL>
<Li> Eravikulam </Li>
<Li> Periyar </Li>
<Li> Chinnar </Li>
<Li> Wayanad </Li>
</OL>
</BODY>
</HTML>

[Link] IN HTML
Design a web page containing a table shown below

Speed Limits in Kerala

Vehicles Near School Within Corporation/ State Highway


(In Km/hour) Municipality (In Km/hour)
(In Km/hour)

Motor Cycle 30 50 50

Motor Car 30 50 80

Light motor vehicles 30 50 80

Heavy motor 30 40 65
vehicles

<HTML>
<HEAD>
<TITLE> Table </TITLE>
</HEAD>
<BODY>
<H3> Speed Limits in Kerala </H3>
<TABLE Border = “2“>
<TR>
<TH> Vehicles </TH>
<TH> Near School <BR>(In Km/hour) </TH>
<TH> Within Corporation/Municipality <BR> (In Km/hour) </TH>
<TH> State Highway <BR> (In Km/hour) </TH>
</TR>

<TR>
<TD> Motor Cycle</TD>
<TD> 30 </TD>
<TD> 50 </TD>
<TD> 50 </TD>
</TR>

<TR>
<TD> Motor car </TD>
<TD> 30 </TD>
<TD> 50 </TD>
<TD> 80 </TD>
</TR>

<TR>
<TD> Light Motor Vehicles </TD>
<TD> 30 </TD>
<TD> 50 </TD>
<TD> 80 </TD>
</TR>

<TR>
<TD> Heavy Motor Vehicles </TD>
<TD> 30 </TD>
<TD> 40 </TD>
<TD> 65 </TD>
</TR>
</TABLE>
</BODY>
</HTML>

[Link] IN HTML
Design a simple web page about your school with its image as background and save the page as [Link]. Design another
webpage named [Link] containing the school address. Give links from school page to [Link] and back to school.

[Link]

<HTML>
<HEAD>
<TITLE>EKNS GHSS VENGAD</TITLE>
</HEAD>
<BODY>
<H1> EKNS GHSS Vengad </H1>
<P> EKNS GHSS Vengad is the only higher secondary school in Vengad Panchayath. The school is situated in Vengad Metta.
The school is famous for its academic excellence. The school is listed number one in co curricular activities in the Sub District
of Mattannur. </P>
<P> The school offers four courses. Science,Computer Science,Humanities and Commerce.
<A Href="[Link]"> Address </A> of the School.</P>
</BODY>
</HTML>

[Link]

<HTML>
<HEAD> <TITLE> School Address</TITLE>
</HEAD>
<BODY Bgcolor=”red”>
<H2> School Address</H2>
THE PRINCIPAL <BR>
EKNS GHSS Vengad<BR>
[Link]<BR>
KANNUR<BR>
PIN-670612<BR>
<A HREF="[Link]">Click here </A> to go back to School Page
</BODY>
</HTML>

[Link] IN HTML
Design a simple web page as shown below.
<HTML>
<HEAD>
<TITLE> Form </TITLE>
</HEAD>
<BODY>
<FORM>
<H2 align="center">Client Login</H2>
Enter User Name &nbsp;&nbsp;&nbsp;&nbsp; <INPUT TYPE ="TEXT" SIZE="15">
<BR> <BR>
Enter your Password <INPUT TYPE="PASSWORD" SIZE="15"> <BR><BR>
<INPUT TYPE="SUBMIT" VALUE="SUBMIT">&nbsp;&nbsp;&nbsp;
<INPUT TYPE=RESET VALUE=CLEAR>
</FORM>
</BODY>
</HTML>

[Link]

To create a web page that displays the capital of a State


<HTML>
<HEAD> <TITLE>Javascript - switch</TITLE>
<SCRIPT Language= "JavaScript">
function capital()
{
var n, answer;
n = [Link];
switch (n)
{
case 0:answer = "Thiruvananthapuram";break;
case 1:answer = "Bengaluru";break;
case 2:answer = "Chennai";break;
case 3:answer = "Mumbai";break;
}
[Link] = answer;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM Name= "frmCapital">
<CENTER> State
<SELECT Size= 1 Name= "cboState">
<OPTION>Kerala</OPTION>
<OPTION>Karnataka</OPTION>
<OPTION>Tamilnadu</OPTION>
<OPTION>Maharashtra</OPTION>
</SELECT>
<BR><BR>
Capital
<INPUT Type= "text" Name= "txtCapital">
<BR><BR>
<INPUT Type= "button" Value= "Show" onClick= "capital()">
</CENTER>
</FORM>
</BODY>
</HTML>
SQL

[Link] table
[Link] a table Student with the following fields and insert at least 5 records into the table except for the column Total.
Rollnumber Integer Primary key, Name Varchar (25),Batch Varchar (15),Mark1 Integer,Mark2 Integer,Mark3 Integer, Total
Integer
1. Update the column Total with the sum of mark1, mark2 and mark3.
2. List the details of students in Commerce batch.
3. Display the name and total marks of students who are failed (total <90).
4. Display the name of students in alphabetical order and in batch based
Ans:-CREATE TABLE student (Rollnumber INT PRIMARY KEY ,Name VARCHAR (25) , batch VARCHAR (25) ,mark1 INT ,
mark2 INT , mark3 INT , total INT);

insert into student values(1 , ’ Alan ’ , ’ Science ’ ,80 , 70 , 55 , null ) ;


insert into student values(2 , ’ Amar ’ , ’ Science ’ ,30 , 40 , 15 , null ) ;
insert into student values(3 , ’ Anugrah ’ , ’ Commerce ’ , 70 , 60 , 40 , null ) ;
insert into student values(4 , ’ Adithya’ , ’ Commerce ’ ,40 , 80 , 50 , null ) ;
insert into student values(5 , ’ Irfan ' , ’ Humanities ’ , 80 , 76 , 69 , null ) ;

select *from student;


[Link] student set total = mark1 + mark2 + mark3 ;
[Link] * from student where batch = ’ Commerce ’;
[Link] name , total from student where total <90;
[Link] name , batch from student order by batch , name ;

[Link] table
Create a table Employee with the following fields and insert at least 5 records into the table
except the column Gross_pay and DA.
Empcode Integer Primary key
Empname 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.
e) Delete all the clerks from the table.

Ans:-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));

insert into employee values(1001,'ARUN’,’ Clerk','SALES’,22000,NULL,NULL);


insert into employee values(1002,'BIJU’,'Clerk’,'ACCOUNTS’,16000,NULL,NULL);
insert into employee values(1003,'SUNU’,'Peon’,'PURCHASE’,20000,NULL,NULL);
insert into employee values(1004,'BINU’,'Accountant’,'ACCOUNTS’,26000,NULL,NULL);
insert into employee values(1005,'ANU’,'Manager’,’ HR ‘,36000,NULL,NULL);

select * from employee;


[Link] employee set DA=Basic*75/100;
select * from employee;
[Link] * from employee where Department in('Purchase', 'Sales','HR');
[Link] employee set Grosspay=Basic+DA;
select * from employee;
[Link] * from employee where Grosspay<10000;
[Link] from employee where Designation='Clerk';

[Link]-Bank
Create a table Bank with the following fields and insert at least 5 records into the table.
Accno Integer Primary key
Accname Varchar (20)
Branchname 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 Minimumamount into the table with default value 1000.
c. Find the number of customers who do not have the amount 1000.
e. Remove the details of SB accounts from Thiruvananthapuram branch .
Ans:
create table bank(Accno int primary key,Accname varchar(20),Branchname varchar(25), AccType varchar(10),Amount
dec(10,2));

insert into bank values(133,'Joy’,'Thirur’,'SB’,5430);


insert into bank values(134,'John’,'Malappuram’,'CB’,930);
insert into bank values(135,'Abi’,'Alappuzha’,'SB’,430);
insert into bank values(136,'Jobi’,’ Thiruvananthapuram’,'SB’,23430);
insert into bank values(137,'Abilash’,'Calicut’,'CB’,45470);
insert into bank values(138,'Rahma’,'Thrissur’,'SB’,0);
select * from bank;
[Link] * from bank order by branch_name,amount asc;
[Link] table bank add Minimumamount int default 1000;
[Link] count(Accname) from bank where Amount<1000;
[Link] from bank where Acctype="SB" and Branch_Name="Thiruvananthapuram" ;

[Link] stock
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),Manufacturercode Varchar (5), Qty Integer, Unitprice Decimal (10,2)

[Link] the item name with stock zero.


[Link] the number of items manufactured by the same manufacturer.
[Link] the highest price and lowest quantity in the stock
[Link] the unit price of all items by 10%
CREATE TABLE stock ( Itemcode INTEGER PRIMARY KEY ,Itemname VARCHAR (20) , Manufacturercode VARCHAR (5) ,Qty
INT , Unitprice DECIMAL (10 ,2) ) ;

INSERT INTO stock VALUES (1001 , ’ Smart Phone ’ , ’ Samsung ’ , 23 , 36000) ;


INSERT INTO stock VALUES (1002 , ’ Smart Watch ’ , ’ Samsung ’ , 16 , 19000) ;
INSERT INTO stock VALUES (1003 , ’ Washing Machine ’ , ’ LG ’ , 21 , 36000) ;
INSERT INTO stock VALUES (1004 , ’ Juicer ’ , ’ Butterfly ’ , ’5 ’ , 7000) ;
INSERT INTO stock VALUES(1005,'Cooker’,'Prestige’,0,1500);

[Link] itemname FROM stock WHERE Qty =0;


[Link] Manufacturercode , COUNT ( Itemcode ) FROM stock GROUP BY Manufacture rcode ;
[Link] MAX ( Unitprice ) ,MIN ( Qty ) FROM stock ;
[Link] stock SET Unitprice = Unitprice +Unitprice

You might also like