Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <map>
- using namespace std;
- class Exception{};
- class InvalidKey : Exception{};
- class ValueOutOfRange : Exception{};
- template<typename T>
- class Evaluation
- {
- private: //eksplenejszyn 4 podraza:
- map<pair<T, T>, double> key;
- public:
- void setKey(T one, T two, double Val)
- {
- if (Val > 1.0 || Val < 0)
- throw ValueOutOfRange();
- //map<pair<T, T>, double>::iterator it;
- pair <T, T> tempPair(one, two);
- /*for (it = key.begin(); it != key.end(); it++)
- {
- if (it.first() == tempPair)
- {
- key[tempPair] = Val;
- return;
- }
- }*/
- if (key.find(tempPair) == key.end())
- throw InvalidKey();
- };
- void debugSet(pair<T, T> given, double toSet)
- {
- key[given] = toSet;
- };
- void pisz(pair<T, T> given)
- {
- cout << given.first << ","<<given.second << " " << key[given];
- };
- };
- void main()
- {
- Evaluation <int> tester;
- try
- {
- pair<int, int> para(1, 1);
- tester.debugSet(para, 1.1);
- tester.pisz(para);
- tester.setKey(1, 1, 1.0);
- cout <<endl<< "Oooo, dziala!";
- }
- catch (ValueOutOfRange)
- {
- cout << "Zjebany value";
- }
- catch (InvalidKey)
- {
- cout << "Twój key gdzieś se polazł, nie ma.";
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement