練習用です。いろんなものがごちゃまぜです。
(empty log message)
| @@ -0,0 +1,27 @@ | ||
| 1 | +#include <iostream> | |
| 2 | +using namespace std; | |
| 3 | + | |
| 4 | +class a_type{ | |
| 5 | + double a,b; | |
| 6 | +public: | |
| 7 | + a_type(double x, double y){ | |
| 8 | + a = x; | |
| 9 | + b = y; | |
| 10 | + } | |
| 11 | + void show(){cout << a << ' ' << b << "\n";} | |
| 12 | +}; | |
| 13 | + | |
| 14 | +int main(){ | |
| 15 | + a_type a[2][5] = { | |
| 16 | + {a_type(0,1),a_type(2,3),a_type(4,5),a_type(6,7),a_type(8,9)}, | |
| 17 | + {a_type(10,11),a_type(12,13),a_type(14,15),a_type(16,17),a_type(18,19)} | |
| 18 | + }; | |
| 19 | + | |
| 20 | + for (int i = 0; i < 2; i++){ | |
| 21 | + for (int j = 0; j < 5; j++){ | |
| 22 | + a[i][j].show(); | |
| 23 | + } | |
| 24 | + } | |
| 25 | + | |
| 26 | + return 0; | |
| 27 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,54 @@ | ||
| 1 | +#include <iostream> | |
| 2 | +#include <cstdlib> | |
| 3 | +using namespace std; | |
| 4 | + | |
| 5 | +class arrays { | |
| 6 | + int size; | |
| 7 | + char *p; | |
| 8 | +public: | |
| 9 | + arrays(int num); | |
| 10 | + ~arrays(){delete [] p;} | |
| 11 | + char &put(int i); | |
| 12 | + char get(int i); | |
| 13 | +}; | |
| 14 | + | |
| 15 | +arrays::arrays(int num) | |
| 16 | +{ | |
| 17 | + p = new char[num]; | |
| 18 | + if(!p){ | |
| 19 | + cout << "メモリ割り当てエラー\n"; | |
| 20 | + exit(1); | |
| 21 | + } | |
| 22 | + size = num; | |
| 23 | +} | |
| 24 | +char &arrays::put(int i) | |
| 25 | +{ | |
| 26 | + if(i < 0 || i >size-1){ | |
| 27 | + cout << "境界エラー!!!\n"; | |
| 28 | + exit(1); | |
| 29 | + } | |
| 30 | + return p[i]; | |
| 31 | +} | |
| 32 | + | |
| 33 | +char arrays::get(int i) | |
| 34 | +{ | |
| 35 | + if(i < 0 || i > size-1){ | |
| 36 | + cout << "境界エラー!!!\n"; | |
| 37 | + exit(1); | |
| 38 | + } | |
| 39 | + return p[i]; | |
| 40 | +} | |
| 41 | + | |
| 42 | +int main() | |
| 43 | +{ | |
| 44 | + arrays a(10); | |
| 45 | + a.put(3) = 'x'; | |
| 46 | + a.put(2) = 'R'; | |
| 47 | + | |
| 48 | + cout << a.get(3) << a.get(2); | |
| 49 | + cout << "\n"; | |
| 50 | + | |
| 51 | + a.put(11) = 'l'; | |
| 52 | + | |
| 53 | + return 0; | |
| 54 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,16 @@ | ||
| 1 | +#include <iostream> | |
| 2 | +using namespace std; | |
| 3 | + | |
| 4 | +int main() | |
| 5 | +{ | |
| 6 | + int x; | |
| 7 | + int &ref = x; | |
| 8 | + | |
| 9 | + x = 10; | |
| 10 | + ref = 10; | |
| 11 | + ref = 100; | |
| 12 | + | |
| 13 | + cout << x << ' ' << ref << "\n"; | |
| 14 | + | |
| 15 | + return 0; | |
| 16 | +} | |
| \ No newline at end of file |