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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

CLASS TEMPLATE - ARRAY

 

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++ program to create a class template using an array. Perform operations like sorting, searching, and displaying the array using a class template.

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

PROGRAM
C++ Project
SUBMIT
* COMPILE
• EXECUTE
O VALIDATE
O RESET
PREVIOUS SUBMISSIONS
A Save File ( Ctrl +S)
Main.cpp/
1 #include <iostream>
#include "TempArray.cpp"
using namespace std;
2
2877_78830_8199_30
3
Main.cpp
4
5- int main() {
в ТempArray.cpp
//fill your code here
8
9.
return 0;
10
11
12
II
Transcribed Image Text:PROGRAM C++ Project SUBMIT * COMPILE • EXECUTE O VALIDATE O RESET PREVIOUS SUBMISSIONS A Save File ( Ctrl +S) Main.cpp/ 1 #include <iostream> #include "TempArray.cpp" using namespace std; 2 2877_78830_8199_30 3 Main.cpp 4 5- int main() { в ТempArray.cpp //fill your code here 8 9. return 0; 10 11 12 II
PROGRAM
C++ Project
SUBMIT
P VALIDATE
O RESET
COMPILE
EXECUTE
PREVIOUS SUBMISSIONS
A Save File ( Ctrl +S)
Main.cpp/
TempArray.cpp/
1
#include<iostream>
2877_78830_8199_30
2 using namespace std;
O Main.cpp
template <class T>
5- class Array {
T *arr;
int size;
4
O TempArray.cpp
6.
7
8
9.
public:
10
Array(T a[],int size) {
[i/ fiil the code
}
11
12
13
14
void sorting() {
// fill the code
15
16
17
18
void search(T &search) {
| // fill the code
19
20
21
22
23
}
24
};
25
II
Transcribed Image Text:PROGRAM C++ Project SUBMIT P VALIDATE O RESET COMPILE EXECUTE PREVIOUS SUBMISSIONS A Save File ( Ctrl +S) Main.cpp/ TempArray.cpp/ 1 #include<iostream> 2877_78830_8199_30 2 using namespace std; O Main.cpp template <class T> 5- class Array { T *arr; int size; 4 O TempArray.cpp 6. 7 8 9. public: 10 Array(T a[],int size) { [i/ fiil the code } 11 12 13 14 void sorting() { // fill the code 15 16 17 18 void search(T &search) { | // fill the code 19 20 21 22 23 } 24 }; 25 II
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY