#include<iostream>
#include<iomanip>
#include<conio.h>
class flag
{
int n, freq, i, a[10], ele;
public:
void read();
void find();
void display();
};
void flag :: read()
{
cout<<"Enter the size of an array ";
cin>>n;
cout<<endl<<"Enter the element into an array ";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to be searched ";
cin>>ele;
}
void flag :: find()
{
freq=0;
for(i=0; i<n; i++)
{
if(a[i] == ele)
{
freq++;
}
}
}
void flag :: display()
{
if(freq>0)
cout<<endl<<ele<<" is found and "<<freq<<" frequeny";
else
cout<<ele<<" is not found";
}
#include<iostream>
#include<iomanip>
usingnamespace std;
class flag
{
int n, freq, i, a[10], ele;
public:
void read();
void find();
void display();
};
void flag :: read()
{
cout<<"Enter the size of an array ";
cin>>n;
cout<<endl<<"Enter the element into an array ";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to be searched ";
cin>>ele;
}
void flag :: find()
{
freq=0;
for(i=0; i<n; i++)
{
if(a[i] == ele)
{
freq++;
}
}
}
void flag :: display()
{
if(freq>0)
cout<<endl<<ele<<" is found and "<<freq<<" frequeny";
else
cout<<ele<<" is not found";
}
int main()
{
flag F;
F.read();
F.find();
F.display();
}
#include <iostream>
#include <algorithm>
constexpr size_t MaxArr {10};
class flag {
int ele {}, a[MaxArr] {};
size_t n {}, freq {};
public:
void read();
void find();
void display();
};
void flag::read() {
std::cout << "Enter the size of array (max of " << MaxArr << "): ";
std::cin >> n;
n = std::min(n, MaxArr);
std::cout << "\nEnter the elements into array ";
for (size_t i = 0; i < n; ++i)
std::cin >> a[i];
}
void flag::find() {
std::cout << "Enter the element to be searched ";
std::cin >> ele;
freq = 0;
for (size_t i = 0; i < n; ++i)
freq += a[i] == ele;
}
void flag::display() {
if (freq > 0)
std::cout << '\n' << ele << " is found and " << freq << " frequency\n";
else
std::cout << '\n' << ele << " is not found\n";
}
int main() {
flag F;
F.read();
F.find();
F.display();
}