forked from ccgcv/Cplus-plus-for-hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplate.cpp
101 lines (98 loc) · 2.02 KB
/
Template.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
using namespace std;
template <typename T>
class search
{
private:
T arr[5];
public:
void setdata(T element)
{
static int i=0;
arr[i]=element;
i++;
}
// void setdata(T element);
int linear(T data)
{
for (int j = 0; j < 5; j++)
{
if (arr[j] == data)
return j;
}
return -1;
}
};
int main()
{
int choice, ind;
cout << "1.INTEGER\n2.FLOATING POINT\n3.CHARACTER" << endl;
cin >> choice;
if (choice == 1)
{
search<int> s1;
int element, n;
cout << "Enter the Integer data:";
for (int j = 0; j < 5; j++)
{
cin >> element ;
s1.setdata(element);
}
cout << "Enter the element to search:";
cin >> n;
ind=s1.linear(n);
if(n!=-1)
{
cout<<"data found at position "<<ind+1<<endl;
}
else
{
cout << "data is not found ";
}
}
if (choice == 2)
{
search<float> s1;
float element,n;
cout << "Enter the floating data:";
for (int j = 0; j < 5; j++)
{
cin >> element ;
s1.setdata(element);
}
cout << "Enter the element to search:";
cin >> n;
ind=s1.linear(n);
if(n!=-1)
{
cout<<"data found at position "<<ind+1<<endl;
}
else
{
cout << "data is not found ";
}
}
if (choice == 3)
{
search<char> s1;
char element,n;
cout << "Enter the character data:";
for (int j = 0; j < 5; j++)
{
cin >> element ;
s1.setdata(element);
}
cout << "Enter the element to search:";
cin >> n;
ind=s1.linear(n);
if(n!=-1)
{
cout<<"data found at position "<<ind+1<<endl;
}
else
{
cout << "data is not found ";
}
}
return 0;
}