Introducing
Your new presentation assistant.
Refine, enhance, and tailor your content, source relevant images, and edit visuals quicker than ever before.
Trending searches
INTRODUCTION
C++ AND DATA STRUCTURES
computer science engineer
former lecturer teresian college mysore
https://www.youtube.com/channel/UCpsOGE9XP-vD-flK6sFNzKA
Frequency is number of times an element present in an array
Write a C++ program to find the frequency presence of an element in an array.
10 20 20 20 30 40
frequency 20 is 3
#include<iostream.h> #include<conio.h>
class Frequency
{
private: int a[10], n, ele, count;
public: void readdata( );
void findfreq( );
void display( );
};
void Frequency::readdata( )
{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter the array elements:"<<endl;
for(int i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to find the frequency"<<endl;
cin>>ele;
}
void Frequency::findfreq( )
{
count=0;
for(int i=0; i<n; i++)
if(ele == a[i])
count++;
}
void Frequency::display( )
{
if(count > 0)
cout<<ele<<"Occurs"<<count<<" Time"; else cout<<ele<<" Does Not Exists";
}
void main( )
{
Frequency f;
clrscr( );
f.readdata( );
f.findfreq( );
f.display( );
getch( );
}
void Frequency::display( )
{
if(count > 0)
cout<<ele<<" Occurs"<<count<<" Time"; else
cout<<ele<<" Does Not Exists";
}
void main( ) //Main function
{
Frequency f;
clrscr( );
f.readdata( );
f.findfreq( );
f.display( );
getch( );
}
#include<iostream.h>
#include<conio.h>
class Frequency
{
private: int a[10], n, ele, count;
public: void readdata( );
void findfreq( );
void display( );
};
void Frequency::readdata( )
{
cout<<"Enter the size of the array:"<<endl;
cin>>n;
cout<<"Enter the array elements:"<<endl;
for(int i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to find the frequency"<<endl
; cin>>ele;
}
void Frequency::findfreq( ) /
{
count=0;
for(int i=0; i<n; i++)
if(ele == a[i])
count++;
}