Advertisement
Guest User

Untitled

a guest
May 30th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <map>
  4. using namespace std;
  5. class Exception{};
  6. class InvalidKey : Exception{};
  7. class ValueOutOfRange : Exception{};
  8. template<typename T>
  9. class Evaluation
  10. {  
  11. private:                        //eksplenejszyn 4 podraza:
  12.     map<pair<T, T>, double> key;
  13. public:
  14.     void setKey(T one, T two, double Val)
  15.     {
  16.         if (Val > 1.0 || Val < 0)
  17.             throw ValueOutOfRange();
  18.        
  19.         //map<pair<T, T>, double>::iterator it;
  20.         pair <T, T> tempPair(one, two);
  21.  
  22.         /*for (it = key.begin(); it != key.end(); it++)
  23.         {
  24.             if (it.first() == tempPair)
  25.             {
  26.                 key[tempPair] = Val;
  27.                 return;
  28.             }
  29.         }*/
  30.         if (key.find(tempPair) == key.end())
  31.         throw InvalidKey();
  32.     };
  33.     void debugSet(pair<T, T> given, double toSet)
  34.     {
  35.         key[given] = toSet;
  36.     };
  37.     void pisz(pair<T, T> given)
  38.     {
  39.         cout << given.first << ","<<given.second << " " << key[given];
  40.     };
  41. };
  42. void main()
  43. {
  44.     Evaluation <int> tester;
  45.     try
  46.     {
  47.         pair<int, int> para(1, 1);
  48.         tester.debugSet(para, 1.1);
  49.         tester.pisz(para);
  50.  
  51.         tester.setKey(1, 1, 1.0);
  52.         cout <<endl<< "Oooo, dziala!";
  53.     }
  54.     catch (ValueOutOfRange)
  55.     {
  56.         cout << "Zjebany value";
  57.     }
  58.     catch (InvalidKey)
  59.     {
  60.         cout << "Twój key gdzieś se polazł, nie ma.";
  61.     };
  62. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement