Question: The syntax for class templates is basically the same as that for function templates: / / Class for a pair of values of type T:
The syntax for class templates is basically the same as that for function templates:
Class for a pair of values of type T:
template
class Pair
public:
Pair;
PairT firstvalue, T secondvalue;
void setelementint position, T value;
Tgetelementint position const;
private:
T first;
T second;
;
Here are the definitions for the member functions setelement and the constructor Pair with two arguments.
Use iostream and cstdlib
template
void Pair::setelementint position, T value
ifposition
first value;
else ifposition
second value;
else
cout "Error: Illegal pair position.
;
exit;
template
Pair::PairT firstvalue, T secondvalue : firstfirstvalue secondsecondvalue
empty body
Requirement:
Write the definitions for the member functions getelement for the class template Pair and the constructor Pair with no argument. Add to the class a member function called displaypairs that displays the pairs.
Write a complete program that uses the class to read a pair of integers and a pair of strings and assign them to the appropriate objects, grades and names.
Here is an example of an input pair:
first pairs:
second pairs:
Tom Martha
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
