Give the definition of a template class called HeterogeneousPair that is like the class template Pair discussed in the section “Syntax for Class Templates,” except that with HeterogeneousPair the first and second positions may store values of different types. Use two type parameters T1 and T2; all items in the first position will be of type T1, and all items in the second position will be of type T2. The single mutator function setElement in the template class Pair should be replaced by two mutator functions called setFirst and setSecond in the template class HeterogeneousPair. Similarly, the single accessor function getElement in the template class Pair should be replaced by two accessor functions called getFirst and getSecond in the template class HeterogeneousPair.
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Absolute Java (6th Edition)
Database Concepts (8th Edition)
Concepts of Programming Languages (11th Edition)
Artificial Intelligence: A Modern Approach
Java: An Introduction to Problem Solving and Programming (7th Edition)
Starting Out with C++: Early Objects
- Using your own creativity, make a set of function templates that have these features: This function must return a value. A function template with 1 template parameter, T. And, any other parameters you want. A function template with 2 template parameters, T1 and T2. And, any other parameters you want. Using your own creativity, make a set of class templates that have these features: For this class template, put everything in one place--do not declare the member functions and have separate definition of the member functions elsewhere. Keep them in one place. Include a private variable. Include a constructor that loads the private variable when constructed. Include a destructor that clears the private variable to zero. Include set and get functions to set and get the private variable. For this class template, use declarations for variables and functions, like you do in header file (which you may use if you want). Then, separately put the full function definitions for each class…arrow_forwardDesign a template class and derived from non-template class and calculate the area of cube.arrow_forwardWrite a function template that takes a single type parameter (T) and accepts four function arguments: an array of T, a start index, a stop index (inclusive), and an optional initial value. The function returns the sum of all the array elements in the specified range and the initial value. Use the default constructor of T for the default initial value.arrow_forward
- Write templates for the two functions min and max. min should accept two arguments and return the value of the argument that is the lesser of the two. max should accept two arguments and return the value of the argument that is the greater of the two. Design a simple driver program that demonstrates the templates with various data types.arrow_forwardC++ Idk how to refactor the code below to use smartpointers and implement the class as a Template class. Add a function to test your DynamicArray changes. Note: Apply the template type to the declaration int* base as T* base: template <typename T> class DynamicArray { T* base; ... Other 'T' changes will also be needed in the original code. If there are any errors in the code, please fix it to let it become a good program. class DynamicArray{ int* base; int size = 0; int capacity = 0;public: DynamicArray(int c = 10) : capacity(c), size(0) { allocate(capacity); } void set(int v, int offset) { if (offset >= capacity) resize(capacity * 2); base[offset] = v; size++; } int get(int offset) { return base[offset]; } int length() { return size; } int extent() { return capacity; } int begin() { return base[0]; } int end() { return base[size - 1]; } void push(int t) { set(t, size); } void…arrow_forwardUsing C++ make a set of function templates that have these features: This function must return a value. A function template with 1 template parameter, T. And, any other parameters you want. A function template with 2 template parameters, T1 and T2. And, any other parameters you want. Using your own creativity, make a set of class templates that have these features: For this class template, put everything in one place--do not declare the member functions and have separate definition of the member functions elsewhere. Keep them in one place. Include a private variable. Include a constructor that loads the private variable when constructed. Include a destructor that clears the private variable to zero. Include set and get functions to set and get the private variable. For this class template, use declarations for variables and functions, like you do in header file (which you may use if you want). Then, separately put the full function definitions for each class member function…arrow_forward
- Please answer in c++. Create a template class UniversalArray which createss an array of a given ssize, which is part of template declaration as given below: template<typename T, typename T1, int ArraySize> Besides the consstructor and destructor, the class should include:arrow_forwardQuestion 3 use c++ to Write a template class Point with two class parameters representing the two coordinates of the Point. Include public methods to display and set the data values as well as a function that swaps the values so that, after the swap, the first element is cast into the second and the second is cast into the first. Also write a main function that creates a Point object and calls the public methods.arrow_forwardUsing C++ Using your own creativity, make a set of class templates that have these features: For this class template, put everything in one place--do not declare the member functions and have separate definition of the member functions elsewhere. Keep them in one place. A class template with 2 template parameters, T1 and T2. Include a private variable. Include a constructor that loads the private variable when constructed. Include a destructor that clears the private variable to zero. Include set and get functions to set and get the private variable. For this class template, use declarations for variables and functions, like you do in header file (which you may use if you want). Then, separately put the full function definitions for each class member function on their own, like you do in a separate implementation file (which you may use if you want). Include at least 2 private variables. Include a constructor that loads the private variables when constructed. Include a…arrow_forward
- use case template assignmentarrow_forwardC++ Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class linkedStackType that returns true if two stacks of the same type are the same; it returns false otherwise. Also, write the definition of the function template to overload this operator. Write a program to test the various functions and operators of the class linkedStackType.arrow_forwardTHIS QUESTION IS RELATED TO SUBJECT OBJECT ORIENTED PROGRAMMING IN C++ . SOLVE this question in dev c++. please send it in 30 minutes and solve step by step. THANKS Q#5 Start with the safearay class from the ARROVER3 program in Chapter 8 of Object Orient programming by Rober Lafore. Make this class into a template, so the safe array can store any kind of data. Include following member functions in Safe array class. The minimum function finds the minimum value in array. The maximum function find the maximum value in array. The average function find average of all the elements of an array. The total function finds the running total of all elements of an array. In main(), create safe arrays of at least two different types int and double and store some data in them. Then display minimum, maximum, average and total of array elements. Note: use subscript ([]) operator in sasfearay class.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning