Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ ................... (these are all of the instructions) Step 1 The Pair C

ID: 3849891 • Letter: I

Question

In C++ ................... (these are all of the instructions)

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 Fair that has one type but two type parameters. You should call these parameters Fand 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. get Second 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

Explanation / Answer

Solution:

#include<iostream>
using namespace std;
template<class T>
class Pair
{
T F;
T S;
public:
   Pair();
   Pair(T x,T y);
   T getFirst();
   T getSecond();
   void setFirst(T x);
   void setSecond(T y);
   void disp();
};
template<class T>
Pair<T>::Pair()
{
}
template<class T>
Pair<T>::Pair(T x,T y)
{
   F=x;
   S=y;
}
template<class T>
T Pair<T>::getFirst()
{
   return F;
}
template<class T>
T Pair<T>::getSecond()
{
   return S;
}
template<class T>
void Pair<T>::setFirst(T x)
{
   F=x;
}
template<class T>
void Pair<T>::setSecond(T y)
{
   S=y;
}
template<class T>
void Pair<T>::disp()
{
   cout<<F<<" "<<S<<endl;
}
template <class T>
struct linklstNode
{
T value;
linklstNode<T> *next;
};

template <class T>
class LinkedList
{
   linklstNode<T> *start;
public:
   LinkedList()
   {
       start=null;
   }
   linklstNode<T>* getFront()
   {
       return start;
   }
   void addFront(T val)
   {
       linklstNode<T>* newNod;
       newNod->value=val;
       newNod->next=NULL:
       if(start==null)
           start=newNod;
       else
       {
           newNod->next=start;
           start=newNod;
       }
   }
   void addBack(T val)
   {
       linklstNode<T>* newNod;
       newNod->value=val;
       newNod->next=NULL:
       if(start==null)
           start=newNod;
       else
       {
           linklstNode<T>* temp=front;
           while(temp->next!=NULL)
           {
               temp=temp->next;
           }
           temp->next=newNod;
       }
   }
};
template <class T>
class pairList: public Pair<T>,public LinkedList<T>
{
public:
   pairList()
   {
      
   }
   void insertPair(Pair p)
   {
       LinkedList::addFront(p);
   }
   void display()
   {
       linklstNode<T>* temp=LinkedList::getFront();
       while(temp)
       {
           cout<<Pair::disp();
       }
   }

};

int main()
{
   pairList<int> P;
   Pair<int> k(12,15);
   Pair<int> l(24,25);
   P.insertPair(k);
   P.insertPair(l);
   P.display();
   system("pause");
   return 0;
}