0% found this document useful (0 votes)
4 views11 pages

II PUC LAB

The document contains multiple C++ programs demonstrating various functionalities such as finding frequency of elements in an array, inserting and deleting elements, searching using binary search, computing simple interest, and calculating areas using function overloading. It also includes a series of HTML programs for creating a study timetable and a student application form. Each program is structured with classes and methods to encapsulate the functionality.

Uploaded by

kumarkishor6051
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)
4 views11 pages

II PUC LAB

The document contains multiple C++ programs demonstrating various functionalities such as finding frequency of elements in an array, inserting and deleting elements, searching using binary search, computing simple interest, and calculating areas using function overloading. It also includes a series of HTML programs for creating a study timetable and a student application form. Each program is structured with classes and methods to encapsulate the functionality.

Uploaded by

kumarkishor6051
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/ 11

LAB PRACTICAL

C++ Program to find the frequency of presence of an element in an array.


#include<iostream.h>
#include<conio.h>
class Frequency
{
int A[10],N,ELE,COUNT,I;
public:
void Getdata();
void Putdata();
};
void Frequency::Getdata()
{
cout<<"\nENTER ARRAY LIMITS:";
cin>>N;
cout<<"\nENTER"<<N<<"ARRAY ELEMENTS\n";
for(I=0;I<=N-1;I++)
{
cin>>A[I];
}
}
void Frequency::Putdata()
{
COUNT=0;
cout<<"\nENTER ELEMENT TO FIND FREQUENCY:";
cin>>ELE;
for(I=0;I<=N-1;I++)
{
if(A[I]==ELE)
{
COUNT++;
}
}
cout<<"\nELEMENT"<<ELE<<"OCCURS"<<COUNT<<"TIMES\n";
}
void main()
{
clrscr();
Frequency F;
F.Getdata();
F.Putdata();
getch();
}
C++ program to insert an element into an array at a given position.
#include<iostream.h>
#include<conio.h>
class Insertion
{
int A[10],P,N,ELE,I;
public:
void Getdata();
void Putdata();
};

void Insertion::Getdata()
{
cout<<"\nENTER ARRAY LIMITS:";
cin>>N;
cout<<"\nENTER"<<N<<"ARRAY ELEMENTS\n";
for(I=0;I<=N-1;I++)
{
cin>>A[I];
}
}
void Insertion::Putdata()
{
cout<<"\nENTER POSITION:";
cin>>P;
if(P<=N-1)
{
cout<<"\nENTER ELEMENTS TO INSERT:";
cin>>ELE;
for(I=N-1;I>=P;I--)
{
A[I+1]=A[I];
}
A[P]=ELE;
N=N+1;
cout<<ELE<<"IS SUCCESSFULLY INSERTED\n";
cout<<"ARRAY ELEMENTS ARE \n";
for(I=0;I<=N-1;I++)
{
cout<<A[I]<<"\n";
}
}
else
{
cout<<"\nINVALID POSITION\n";
}
void main()
{
clrscr();
Insertion I;
I.Getdata();
I.Putdata();
getch();
}

C++ program to delete an element from an array from a given position.


#include<iostream.h>
#include<conio.h>
class Deletion
{
int A[10],P,N,ELE,I;
public:
void Getdata();
void Putdata();
};
void Deletion::Getdata()
{
cout<<"\nENTER ARRAY LIMITS:";
cin>>N;
cout<<"\nENTER"<<N<<"ARRAY ELEMENTS\n";
for(I=0;I<=N-1;I++)
{
cin>>A[I];
}
}
void Deletion::Putdata()
{
cout<<"\nENTER POSITION:";
cin>>P;
if(P<=N-1)
{
ELE=A[P];
for(I=P;I<=N-1;I++)
{
A[I]=A[I+1];
}
N=N-1;
cout<<ELE<<"IS SUCCESSFULLY REMOVED\n";
cout<<"ARRAY ELEMENTS ARE \n";
for(I=0;I<=N-1;I++)
{
cout<<A[I]<<"\n";
}
}

else
{
cout<<"\nINVALID POSITION\n";
}
}
void main()
{
clrscr();
Deletion D;
D.Getdata();
D.Putdata();
getch();
}

C++ program to search for a given element in an array using Binary search method.
#include<iostream.h>
#include<conio.h>
class Binary
{
int A[10],LOC,N,ELE;
int BEG,END,MID;

public:
void Getdata();
void Search();
void Putdata();
};
void Binary::Getdata()
{
cout<<"\nENTER ARRAY LIMITS:";
cin>>N;
cout<<"\nENTER"<<N<<"ARRAY ELEMENTS\n";
for(int I=0;I<=N-1;I++)
{
cin>>A[I];
}
}
void Binary::Putdata()
{
int BEG,END,MID;
BEG=0,END=N-1,LOC=-1;
cout<<"\nENTER ELEMENT TO BE SEARCHED:";
cin>>ELE;
while(BEG<=END)
{
MID=int(BEG+END)/2;
if(ELE==A[MID])
{
LOC=MID;
break;
}
else
{
if(ELE<A[MID])
END=MID-1;
else
BEG=MID+1;
}
}
if(LOC>=0)
cout<<"\nELEMENT"<<ELE<<"FOUND AT LOCATION"<<LOC+1;
else
cout<<"\nELEMENT"<<ELE<<"NOT FOUND";
}
void main()
{
clrscr();
Binary B;
B.Getdata();
B.Putdata();
getch();
}

C++ program to compute simple interest using classes and object.


#include<iostream.h>
#include<conio.h>
class Interest
{
double P,T,R,SI;
public:
void Getdata();
void Putdata();
};
void Interest::Getdata()
{
cout<<"\nENTER PRINCIPLEAMOUNT,TIME,INTEREST:";
cin>>P>>T>>R;
}
void Interest::Putdata()
{
SI=(P*T*R)/100;
cout<<"\nSIMPLE INTEREST:"<<SI;
}
void main()
{
clrscr();
Interest I;
I.Getdata();
I.Putdata();
getch();
}

C++ program to find area of a square/rectangle/triangle using function overloading.


#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
class Overload
{
public:
double Area(doubleA)
{
returnA*A;
}
double Area(double L,double B)
{
return L*B;
}
double Area(double P,double Q,double R)
{
float S=(P+Q+R)/2;
return sqrt(S*(S-P)*(S-Q)*(S-R));
}
};
void main()
{
Overload O;
int ANS;
double X,Y,Z;
clrscr( );
cout<<"ENTER NO OF SIDES:";
cin>>ANS;
switch(ANS)
{
case1: cout<<"AREA OF SQUARE:"<<O.Area(5);
break;
case2: cout<<"AREA OF RECTANGLE :"<<O.Area(5,10);
break;
case3: cout<<"AREA OF TRIANGLE:"<<O.Area(8,3,9);
break;

default:cout<<"INVALID CHOICE .. !!!\n";


exit(1);
}
getch();
}

C++ program to find the cube of a number using inline functions.


#include<iostream.h>
#include<conio.h>
inline int Incube(intA)
{
return(A*A*A);
}
void main()
{
clrscr();
int N;
cout<<"\nENTER THE NUMBER:";
cin>>N;
cout<<"\nCUBE OF"<<N<<":"<<Incube(N);
getch();
}

C++ program to find the sum of the series 1+x+x^2+...+x^n usingconstructors.


#include<iostream.h>
#include<conio.h>
class Series
{
int BASE,POWER,SUM;
public:
double Sumseries();
Series(int B,int P)
{
BASE = B;
POWER=P;
}
};
double Series::Sumseries()
{
int TEMP=BASE;
SUM=1;
for(intI=1;I<=POWER;I++)
{
SUM=SUM+TEMP;
TEMP=TEMP*BASE;
}
return SUM;
}

void main()
{
int X,N;
clrscr();
cout<<"\nENTER BASE(X) AND POWER VALUE:";
cin>>X>>N;
SeriesS1(X,N);
cout<<"\nSUM OF SERIES:"<<S1.Sumseries();
getch( );
}

C++ program to create base class and derived class to compute two subject marks using
single level inheritance.
#include<iostream.h>
#include<conio.h>
class Base
{
int ROLLNO;
char NAME[20];
public:
void Bgetdata()
{
cout<<"\nENTER STUDENT NAME AND ROLL NUMBER:";
cin>>NAME>>ROLLNO;
}
void Bputdata()
{
cout<<"\nSTUDENT NAME : "<<NAME;
cout<<"\nROLL NUMBER:"<<ROLLNO;
}
};
class Derived :public Base
{
int M1,M2, TOTAL;
public:
void Dgetdata()
{
cout<<"\nENTER SUB1 AND SUB2 MARKS:";
cin>>M1>>M2;
}
void Dputdata()
{
TOTAL = M1 + M2;
cout<<"\nSUBJECT 1 : "<<M1;
cout<<"\nSUBJECT 2 : "<<M2;
cout<<"\nTOTALMARKS:"<<TOTAL;
}
};

void main()
{
Derived D;
clrscr();
D.Bgetdata();
D.Dgetdata();
D.Bputdata();
D.Dputdata();
getch();
}

C++ program to read and display the data by creating a class using the concept of pointers
to objects.
#include<iostream.h>
#include<conio.h>
class Student
{
int REGNO;
char NAME[20];
float FEES;
public: void Getdata();
void Putdata();
};
void Student::Getdata()
{
cout<<"\nENTER STUDENT REGISTER NO,NAME AND FEES:";
cin>>REGNO>>NAME>>FEES;
}
void Student::Putdata()
{
cout<<"\nREGISTER NUMBER:"<<REGNO;
cout<<"\nSTUDENT NAME : "<<NAME;
cout<<"\nSTUDENT FEES : "<<FEES;
}
void main()
{
Student S,*SP;
SP=&S;
clrscr();
SP->Getdata();
SP->Putdata();
getch();
}
HTML program to create a study time-table.
<html>
<head>
<title>COLLEGE TIME TABLE</title>
</head>
<body bgcolor=PINK>
<center><h2>STUDY TIME TABLE</h2>
<table border=15 cellspacing=10 cellpadding=8>
<tr>
<th>DAY/ TIME</td>
<th><i>MORNING</i></th>
<th><i>EVENING</i></th>
</tr>
<tr>
<th>MON/THU</th>
<td>MAT/ACC </td>
<td>KAN/HIN </td>
</tr>
<tr>
<th>TUE/FRI</th>
<td>CHEM/BUS </td>
<td>ENGLISH</td>
</tr>
<tr>
<th>WED/SAT </th>
<td>PHY/ECO </td>
<td>COMP.SCI.</td>
</tr>
</table>
</center>
</body>
</html>

HTML program to create a form with table.


<html>
<head>
<title>APPLICATION FORM</title>
</head>
<body bgcolor="PINK">
<form name="appl" method="post" action="#">
<center><h1>STUDENT APPLICATION FORM</h1>
<table border=1>
<tr>
<td align=left>STUDENTNAME:<input type="text"name="sname"></td>
</tr>
<tr>
<td align="left">PASSWORD:<input type="password"name="pwd"></td>
</tr>
<tr>
<td><input type="submit" value="SUBMIT"></td>
</tr>
</table>
<form>
</body>
</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy