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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.