Write a C++ program to create a class template using an array. Perform operations like sorting, searching, and displaying the array using a class template.
CLASS TEMPLATE - ARRAY
Arya has completely learned about function templates and using them in Arrays, her teacher has given her a task to implement class Templates for all the same things-searching, sorting, and displaying an array using templates. You are her friend and you have knowledge about class templates, help Arya to make a class template to search, sort, and display an array.
Write a C++
Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.
A class named Array with the following member variables.
Data Type | Variable Name |
Integer | size |
T* | array |
Define the following public functions inside the class Array.
Function Name | Description |
void sorting() | This function is used to sort the array elements in ascending order and display the array. |
void search(T &search) | This function is used to search the array element, if the element is found display "Element found at position x" else print "Element not found" |
Problem Constraint:
Use the template class to perform the operations
template <class T>
Note:
Use integer array for sorting and use an array of double values to search.
In the main method, display the menu and according to the user's choice get the size of the array from the user and create the array using the class name and call the corresponding function. If the user enters a choice other than 1 or 2 print "Invalid number"
Input and Output Format:
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds to output]
Sample Input and Output 1:
Menu
1.Sorting integer array
2.Searching array of double values
Enter your choice:
1
Enter size of array:
3
Enter the array elements:
5
2
55
Sorted array
2
5
55
Sample Input and Output 2:
Menu
1.Sorting integer array
2.Searching array of double values
Enter your choice:
2
Enter size of array:
3
Enter the array elements:
23.45
15.78
324.67
Enter the element to search:
15.78
Element found at position 2
Sample Input and Output 3:
Menu
1.Sorting integer array
2.Searching array of double values
Enter your choice:
2
Enter size of array:
2
Enter the array elements:
55.45
35.78
Enter the element to search:
19.28
Element not found
Sample Input and Output 4:
Menu
1.Sorting integer array
2.Searching array of double values
Enter your choice:
3
Invalid number
Trending now
This is a popular solution!
Step by step
Solved in 2 steps