Lab 16B: Class Templates

  < Previous  Next >

Assignment:

Submit a copy of lab16B.cpp that has a templated Calculator class. This class should have:
  1. Two private data members, each of which can be a separate type and a constructor that take takes two arguments, each of which can be a separate type, and assigns each of their values to a private data member
  2. A copy constructor
  3. A setValue1() member method that takes an argument and assigns it to the first private data member and a setValue2() member method that takes an argument and assigns it to the second private data member
  4. An add() member method that returns the sum of the two private data members (the return type should be the same as the first private data member) and a multiply() member method that returns the product of the two private data members (the return type should be the same as the first private data member)
No other changes should be necessary.
Finally, when your code is executed, the output must match what's in lab16B-answerKey.txt exactly:
Adding: 45
Multiplying: 126

Adding: 10
Multiplying: 21

Adding: 4.13249
Multiplying: 3.84422

Submission

Submit your source code using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  lab16B  lab16B.cpp
To verify your submission, type the following in a terminal window:
handin  lab16B