Advertisement
skb50bd

CSE107Final_Q3

Sep 9th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class T>
  6. class MyPair {
  7. private:
  8.     T first, second;
  9. public:
  10.     MyPair() {}
  11.     ~MyPair() {}
  12.     bool isGreaterThan() {
  13.         return (first > second) ? true : false;
  14.     }
  15.  
  16.     void read() {
  17.         cin >> first >> second;
  18.     }
  19.  
  20.  
  21. };
  22.  
  23.  
  24. int main() {
  25.     int choice;
  26.     cout << "1 - int, 2 - float" << endl << "Enter Choice: ";
  27.     cin >> choice;
  28.  
  29.     if(choice == 1) {
  30.         MyPair<int> mp;
  31.         mp.read();
  32.         if(mp.isGreaterThan()) cout << "First is Greater" << endl;
  33.         else cout << "First is Not Greater" << endl;
  34.     }
  35.     else {
  36.         MyPair<float> mp;
  37.         mp.read();
  38.         if(mp.isGreaterThan()) cout << "First is Greater" << endl;
  39.         else cout << "First is Not Greater" << endl;
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement