Question
Note: Do not write in Java because my teacher accidentally writes it in Java and that it does not the answer I want to receive
Note: Do not write in Java because my teacher accidentally writes it in Java and that it does not the answer I want to receive due to I did not take itJava.
Instructions for C++:
Task 1 - The Pair Class
Many times in writing software we come across problems that require us to store a pair of values. For example, a coordinate system would require an x, y value pair or a hash table as a data, key value pair. Your task on this assignment is to create a simple template pair class called Pair that has one generic / template type but two type parameters. You should call these parameters F and S.
Functionality
- Constructor - You should create a working constructor that takes two type parameters one for each of the pair values.
- getFirst - This is an accessor method that will return the first of the pair values.
- getSecond - This is an accessor method that will return the second of the pair values.
- setFirst - This is a mutator method that will set the first pair value
- setSecond - This is a mutator method that will set the second pair value
Task 2 The PairList Class
Using a vector and the Pair class that you created in Step 1. Create a PairList class that will hold a list of Pairs. To construct the PairList class you should use the vector as a base class and derive the PairList class from vector.
Many student will want to derive PairList from vector and then add no functionality to it. The idea is that a PairList is a specialized version of the vector. This means that you should have functionality that is specific to a PairList. To help you understand this I am going to specify what function are required. You are required at a minimum to have the following functionality:
- void addPair(T first, T second) - Adds the Pair to the list.
- T getFirst(T second) - searches on second and returns first
- T getSecond(T first) - searches on first and returns second
- void deletePair(T first, T second) - Deletes the Pair that contains first and second
- void printList() - Prints the entire list of Pairs
It is important to note that the vector for the PairList should hold the Pair class.
Whichever method you use make sure you have a reason for doing it and be ready to explain it.
Finally
Make sure you provide code to test your functionality thoroughly. In addition, make sure you are documenting everything. This means all methods and main with some instructions on how to demonstrate the use of your code.
If need help look up C++ templates and C++ STL
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started