-
Notifications
You must be signed in to change notification settings - Fork 0
/
166.cpp
54 lines (50 loc) · 1.01 KB
/
166.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
// WAP to find sort an integer array and a float array, using class template..
#include <iostream>
using namespace std;
template <typename T>
class Sort
{
T a[5];
public:
void getdata()
{
cout << "Enter 5 elements: ";
for (int i = 0; i < 5; i++)
cin >> a[i];
}
void sort()
{
T temp;
for (int i = 0; i < 5; i++)
{
for (int j = i + 1; j < 5; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
void display()
{
cout << "Sorted array is: ";
for (int i = 0; i < 5; i++)
cout << a[i] << " ";
cout << endl;
}
};
int main()
{
Sort<int> s1;
Sort<float> s2;
s1.getdata();
s1.sort();
s1.display();
s2.getdata();
s2.sort();
s2.display();
return 0;
}