Homework: Class Templates

  < Previous  Next >

For this homework assignment, submit a copy of hwkClassTemplates.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.

Your copy needs to compile on ranger using the following command-line:
g++  -std=c++0x  hwkClassTemplates.cpp
Finally, when your code is executed, the output must match what's in hwkClassTemplates-stdout.txt exactly:
Adding: 45
Multiplying: 126

Adding: 10
Multiplying: 21

Adding: 4.13249
Multiplying: 3.84422

Rubric:

Points         Item
---------      --------------------------------------------------------------
_____ / 3      1	       
_____ / 2      2	       
_____ / 1      3	       
_____ / 1      4	       
        
_____ / 7      Total
      

Notes

  1. You should verify that your output matches the above output exactly with the following commands on ranger:
    g++  -std=c++0x  hwkClassTemplates.cpp  -o hwkClassTemplates-yourlastname
    ./hwkClassTemplates-yourlastname  &>  hwkClassTemplates-yourlastname.txt
    diff  /nfshome/hcarroll/public_html/3110/private/hwk/hwkClassTemplates-stdout.txt  hwkClassTemplates-yourlastname.txt
    

Last Modified: