-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_main_cpp.cpp
More file actions
86 lines (83 loc) · 1.86 KB
/
sort_main_cpp.cpp
File metadata and controls
86 lines (83 loc) · 1.86 KB
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
# include <iostream>
using namespace std;
template <typename T>
void show(T A[], int size)
{
for (int i = 0 ; i < size; ++i)
{
cout << " A[ " << i << " ] = " << A[i] << endl;
}
}
template <typename T>
void array_data(T A[], int size)
{
for (int i = 0; i<size; i++)
{
cout<<"enter data at index "<<i<<" : ";
cin>>A[i];
}
cout<<"Before sorting :\n";
show(A,size);
// code // enter the sorting function
cout<<"After sorting :\n";
show(A,size);
}
int main ()
{
char ch = 'y';
while (ch == 'y')
{
int size;
cout<<"enter the size of the array : ";
cin>>size;
cout << "Valid data types are int, float, double, char, string\n";
string datatype;
cout << "Enter data type of the array: ";
cin >> datatype;
if (datatype == "int")
{
int*A = new int[size];
array_data(A,size);
delete[] A;
}
else if (datatype == "char")
{
char*A = new char[size];
array_data(A,size);
delete[] A;
}
else if (datatype == "float")
{
float*A = new float[size];
array_data(A,size);
delete[] A;
}
else if (datatype == "double")
{
double*A = new double[size];
array_data(A,size);
delete[] A;
}
else if (datatype == "string")
{
string*A = new string[size];
array_data(A,size);
delete[] A;
}
else
{
cout << "Invalid data type\n";
}
cout << "Do you want to continue? (y/n): ";
cin >> ch;
}
if(ch == 'n')
{
cout << "Goodbye!\n";
}
else if (ch != 'y' && ch != 'n')
{
cout << "Invalid input\n";
}
return 0;
}