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++ Plus MyLab Programming with Pearson eText -- Access Card Package (10th 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
- Consider the following template function prototype: template <class Type> Type addem (Type x, Type y) Write the DEFINITION (code) of the template to implement the function that would ADD the two parameters x and y and return the result. NO include or using statements required in this code segment. Write a STATEMENT that would call (invoke) the function with two integer values/variables.arrow_forwardComputer Science Write the definition of the class template ArrayListType, and the derived class unordered ArrayListType. Provide implementations for the non abstract functions in the base template class, and implementations of the template functions in the derived template class. Write a test program to test the functions in the derived template class. Instantiate objects of type derived class in your test program using template parameters of type float, int.arrow_forwardWAP to demonstrate the concept of class template using a constructor inside the class template ?arrow_forward
- Q #1. Apply concepts of Advanced Data Structures to implement a template class forarray based list with following attributes and functionalities:template <class T>class ABList{private:int max_size;int actual_size;T* list_array;public:ABList(int Size);~ABList();int getLength(); Page 2 of 3 T getItem(int);void insertItem(T value);int findAndRemoveItem(T);void displayList();void MergeList(ABList);void ReducetoHalf();};• Constructor will dynamically allocate the list of size ‘Size’.• insertItem() function will insert new item at the end of the list, only if item is notpresent in the list already. If item is already present, it will display a message,‘Item already in the list’.• FindAndRemoveItem() will search an item in the list, if found, item will be removedfrom the list. If item is not found, function will return -1.• ReducetoHalf() will reduce the size of the List to half and copy all the items from the oldlist to the new list and destroy the old list.• MergeLists() will combine…arrow_forwardUsing 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. A class template with 2 template parameters, T1 and T2 For this another 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_forwardTemplates enable us to specify, with a single code segment, an entire range of relatedfunctions called___________ , or an entire range of related classes called_____________arrow_forward
- Using 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_forwardExplain which is more like a stencil—a class template or a class-template specialization?arrow_forwardUse the aggregation (composition) concept to define and implement the class line(p1.x, p1.y, p2.x, p2.y) by using two points variables P1, and P2 of type point2D class defined in Q1. Beside the two points P1 and P2, the line class has the following functions: print(), MoveRel(Dx,Dy) (use the point2D’s MoveRel(Dx,Dy) function of the two points to achieve that), line(), line(x1,y1,x2,y2), line(P2D1,P2D2). * Your answerarrow_forward
- Consider the following definition of class Person: 1 public class Person 2 { 3 public final String name; 4 5 public Person(String name) 6 { 7 if (name == null) this.name = "<NoName>"; //No null names... 8 else this.name = name; 9 } 10 } and the definition of class PersonListUtils implemented by a student... 1 public class PersonListUtils 2 { 3 //Replaces the first occurrence of a Person in the list with the given oldPersonName with a new Person having the newPersonName. 4 //Returns true if the substitution is successful, false otherwise 5 public static boolean substitute(ArrayList<Person> list, String oldPersonName, String newPersonName) 6 { 7 for (Person person: list) { 8 if (person.name == oldPersonName) { 9 person = new Person(newPersonName); 10 return true; 11 } 12 } 13 return false; 14 } 15 16 //Removes from the list the first occurrence of a Person with the given nameToRemove. 17 //Returns true if the deletion is successful, false otherwise 18 public static boolean…arrow_forwardImplement a class representing a circular sorted linked list. The class must have the following requirements: The linked list and the nodes must be implemented as C++ templates First must point to the largest value in the list It must include a constructor, a destructor, a copy constructor and an operator= It must include functions to insert a given item, delete a given item, search for a given item, check if the list is empty, return the length of the list and print the list (from smallest to largest) Hint: Use the menu-driven program of the linked list to test all the functions in your class. Screenshot the output and make comments on each area on the program.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
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning