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

The Pair class template Practice creating a class template by writing a template

ID: 3869112 • Letter: T

Question

The Pair class template

Practice creating a class template by writing a template for a class named "Pair". This class will represent a pair of data members of a type that is parameterized in the template definition. For example, you could have a Pair of integers, a Pair of doubles, etc.

Use this driver to test your program:

// your file prologue goes here
#include <iostream>
#include "pair.h"
using namespace std;


int main( )
{
   Pair<char> letters('a', 'd');
   cout << " The first letter is: " << letters.getFirst( );
   cout << " The second letter is: " << letters.getSecond( );

   cout << endl;
   system("Pause");
   return 0;
}

Explanation / Answer

#include <iostream>
#include "pair.h"
using namespace std;


int main( )
{
   Pair<char> letters('a', 'd');
   cout << " The first letter is: " << letters.getFirst( );
   cout << " The second letter is: " << letters.getSecond( );

   cout << endl;
   system("Pause");
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote