Question
Can someone help me finish the third and final part of this assignment? I have the first two parts attached. Here is the assignment transcribed.
Can someone help me finish the third and final part of this assignment? I have the first two parts attached. Here is the assignment transcribed.
Below are the instructions in text...
Step 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 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
Step 2 The Linked List Class From the lecture material create a linked list class. This class should be generic so that it will operate on any given type. In C++ we call this a template class. In Java it is a Generic. Of course in Java a generic will not operate on a primitive type but that should be ok for what we are doing Your class should have the ability to add to the front, add to the rear, insert (you can insert before or after a node), delete, and find. As for the naming conventions and interface into the list I will leave all of that up to you.
Step 3 The PairList Class Using the linked list you created in Step 2 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 code from the linked list as a base class and derive the PairList class from the linked list. How you implement all of this is up to you. You could derive Pair from your linked list and then PairList from Pair. In C++ you can have multiple inheritance so you could derive PairList and use Pair and the linked list as parents. Which ever method you use make sure you have a reason for doing it and be ready to explain it. Finally Make sure you are documenting everything. This means all methods and main with some instructions on how to demonstrate the use of your code
#include
using namespace std;
template class Pair { T first; T second; public: Pair(T f, T s) { first = f; second = s; }
void setFirst(T f) { first = f; }
void setSeconf(T s) { second = s; }
T getFirst() { return first; }
T getSecond() { return second; }
};
template class LinkedLIst { struct Node { T data; Node* next; };
Node *first;
public: LinkedLIst() { first = NULL; }
void insertFirst(T data) { Node *newNode = new Node(); newNode -> data = data; newNode -> next = first; first = newNode; }
void insert(T data, int position) { if (position == 0) return insertFirst(data); Node *newNode = new Node(); newNode -> data = data; Node *curr = first; for ( int i = 1; i < position; i++) curr = curr -> next;
newNode -> next = curr -> next; curr -> next = newNode; }
void insertRear(T data) { if (first == NULL) return insertFirst(data); Node *newNode = new Node(); newNode -> data = data; newNode -> next = NULL; Node *curr = first; while (curr -> next != NULL) curr = curr -> next;
curr -> next = newNode; }
T get(int position) { Node *curr = first; for ( int i = 0; i < position; i++) curr = curr -> next; return curr -> data; }
};
int main(int argc, char const *argv[]) { /* code */ return 0; }
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