Write a program to find the frequency of presence of an element in an array

#include<iostram.h> #include<iomanip.h> #include<conio.> class frequency{ private: int n, m[100], ele, freq; public: void getdata(); void findfreq(); void display(); }; void frequency::getdata(){ cout<<"Enter the size of the array: "; cin>>n; cout<<"Enter "<<n<<" elemens into the array: "; for(int i=0; i<n; i++) cin>>m[i]; cout<<"Enter the search element: "; cin>>ele; } void frequency::findfreq(){ freq = 0; for (int i=0; i<n; i++) if(m[i] == ele) freq++; } void frequency::display(){ if(freq > 0) count<<"Frequency of "<<ele<<" is "<<freq; else cout<<ele<<" does not exist"; } void main(){ frequency F; clrscr(); F.getdata(); F.findfreq(); F.display(); getch(); }
[wp_ad_camp_1]
OUTPUT: ------------------- Enter the size of the array: 5 Enter 5 elements into the array: 10 50 40 30 40 Enter the search element: 40 Frequency of 40 is 2 -------------------- ------------------- Enter the size of the array: 5 Enter 5 elements into the array: 10 50 40 30 40 Enter the search element: 35 25 does not exist --------------------