-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray-Search-Frequency.cpp
61 lines (61 loc) · 1.23 KB
/
Array-Search-Frequency.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
using namespace std;
class searchElement
{
private:
int num[50], n, c, counter=0;
public:
void input()
{
cout<<"Enter the number of elements you want to enter: \n";
cin>>n;
cout<<"Enter the elements of the array: \n";
for(int i=0; i<n; i++)
{
cin>>num[i];
}
}
void findIt()
{
cout<<"Enter the number you want to search: \n";
cin>>c;
for(int i=0; i<n; i++)
{
if(num[i]==c)
{
counter++;
}
}
}
void result()
{
if(counter==0)
cout<<"The number "<<c<<" doesn't exist in array.\n";
else
cout<<"The number "<<c<<" is present in the array "<<counter<<" time(s).\n";
}
};
int main()
{
searchElement s;
int a;
s.input();
do
{
cout<<"\nEnter a choice: \n1. Search an element\n2. Exit\n";
cin>>a;
switch(a)
{
case 1:
s.findIt();
s.result();
break;
case 2:
cout<<"Have a nice day ahead!\n";
break;
default:
cout<<"Invalid input!";
}
}while(a!=2);
return 0;
}