Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** gen_array3.hpp **/
- template <class T, int s = 50, class E = std::range_error>
- class Array {
- public:
- T& operator[](int i);
- const T& operator[](int i) const;
- };
- /** gen_array3_main.cpp **/
- #include <iostream>
- #include <stdexcept>
- #include <string>
- #include "gen_array3.hpp" // sablon
- using namespace std;
- class BajVan {
- public:
- BajVan(const string&) {}
- };
- /// TESZT 1.
- void test_1() {
- Array<int> arr; // default (50) elemû int tömb
- int idx;
- int val;
- cout << "default (50) elemu int tomb" << endl;
- while ( cin >> idx >> val) {
- arr[idx] = val;
- cout << "arr[" << idx << "]=" << arr[idx] << endl;
- }
- }
- /// TESZT 2
- void test_2() {
- Array<double, 100> arr; // 100 elemû double tömb
- int idx;
- double val;
- cout << "100 elemu double tomb" << endl;
- while ( cin >> idx >> val) {
- arr[idx] = val;
- cout << "arr[" << idx << "]=" << arr[idx] << endl;
- }
- }
- /// TESZT 3
- void test_3() {
- Array<string, 11, BajVan> arr; // 11 elemû string saját kivétellel
- int idx;
- string val;
- cout << "11 elemu string saját kivetellel" << endl;
- while ( cin >> idx >> val) {
- arr[idx] = val;
- cout << "arr[" << idx << "]=" << arr[idx] << endl;
- }
- }
- /// Fõprogram a standard inputról olvas egy egész számot, majd
- /// meghivja az annak megfelelõ tesztesetet.
- /// A további inputot és outputot a teszteset kezeli.
- int main() {
- try {
- int nr;
- cin >> nr; // hanaydik teszt eset
- switch (nr) {
- case 1:
- test_1(); // default (50) elemû int tömb
- break;
- case 2:
- test_2(); // 100 elemû double tömb
- break;
- case 3:
- test_3(); // 11 elemû string saját kivételosztállyal
- break;
- }
- // kivétel elkapása
- } catch (exception& e) {
- cerr << e.what() << endl;
- } catch (BajVan&) {
- cerr << "Sajat kivetel jott" << endl;
- } catch (...) {
- cerr << "*** Nagy baj van! ****" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement