練習用です。いろんなものがごちゃまぜです。
(empty log message)
| @@ -2,21 +2,25 @@ | ||
| 2 | 2 | using namespace std; |
| 3 | 3 | |
| 4 | 4 | class myclass { |
| 5 | - int i, j; | |
| 5 | + int a, b; | |
| 6 | 6 | public: |
| 7 | 7 | myclass(int a, int b); |
| 8 | + int add(){return a + b;} | |
| 8 | 9 | void show(); |
| 9 | 10 | }; |
| 10 | 11 | myclass::myclass(int a, int b) |
| 11 | 12 | { |
| 12 | 13 | cout << "myclass(int a,int b)コンストラクタ呼び出し\n"; |
| 13 | - i = a; | |
| 14 | - j = b; | |
| 14 | + this->a = a; | |
| 15 | + this->b = b; | |
| 15 | 16 | } |
| 16 | 17 | |
| 17 | 18 | void myclass::show() |
| 18 | 19 | { |
| 19 | - cout << i << ' ' << j << "\n"; | |
| 20 | + cout << "myclass::show()の呼び出し\n"; | |
| 21 | + cout << this->a << ' ' << this->b << "\n"; | |
| 22 | + int t = this->add(); | |
| 23 | + cout << t << "\n"; | |
| 20 | 24 | } |
| 21 | 25 | |
| 22 | 26 | int main() |
| @@ -0,0 +1,32 @@ | ||
| 1 | +#include <iostream> | |
| 2 | +using namespace std; | |
| 3 | + | |
| 4 | +class samp{ | |
| 5 | + int a,b; | |
| 6 | +public: | |
| 7 | + samp(int n,int m){a = n;b =m;} | |
| 8 | + int get_a(){return a;} | |
| 9 | + int get_b(){return b;} | |
| 10 | +}; | |
| 11 | + | |
| 12 | +int main() | |
| 13 | +{ | |
| 14 | + samp ob[4][2] = {{samp(1,2),samp(3,4)}, | |
| 15 | + {samp(5,6),samp(7,8)}, | |
| 16 | + {samp(9,10),samp(11,12)}, | |
| 17 | + {samp(13,14),samp(15,16)}}; | |
| 18 | + | |
| 19 | + samp *p = &ob[3][1]; | |
| 20 | + for(int i = 0; i < 4; i++){ | |
| 21 | + for(int j = 0; j < 2; j++){ | |
| 22 | + cout << p->get_a() << ','; | |
| 23 | + cout << p->get_b() << ' '; | |
| 24 | + p--; | |
| 25 | + } | |
| 26 | + cout << "\n"; | |
| 27 | + } | |
| 28 | + | |
| 29 | + cout << "\n"; | |
| 30 | + | |
| 31 | + return 0; | |
| 32 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,19 @@ | ||
| 1 | +#include <iostream> | |
| 2 | +using namespace std; | |
| 3 | + | |
| 4 | +class samp{ | |
| 5 | + int i,j; | |
| 6 | +public: | |
| 7 | + samp(){cout << "コンストラクタ\n";} | |
| 8 | + ~samp(){cout << "デストラクタ\n";} | |
| 9 | + void set_ij(int a, int b){i = a;j = b;} | |
| 10 | + int get_product(){return i*j;} | |
| 11 | +}; | |
| 12 | + | |
| 13 | +int main() | |
| 14 | +{ | |
| 15 | + samp *p = new samp[10]; | |
| 16 | + cout << "hello\n"; | |
| 17 | + delete [] p; | |
| 18 | + return 0; | |
| 19 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,24 @@ | ||
| 1 | +#include <iostream> | |
| 2 | +using namespace std; | |
| 3 | + | |
| 4 | +class samp{ | |
| 5 | + int i,j; | |
| 6 | +public: | |
| 7 | + void set_ij(int a, int b){i = a;j = b;} | |
| 8 | + int get_product(){return i*j;} | |
| 9 | +}; | |
| 10 | + | |
| 11 | +int main() | |
| 12 | +{ | |
| 13 | + samp *p; | |
| 14 | + p = new samp; | |
| 15 | + if(!p){ | |
| 16 | + cout << "メモリ割り当てエラー\n"; | |
| 17 | + return 1; | |
| 18 | + } | |
| 19 | + | |
| 20 | + p->set_ij(4,5); | |
| 21 | + cout << "積は:" << p->get_product() << "\n"; | |
| 22 | + delete p; | |
| 23 | + return 0; | |
| 24 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,17 @@ | ||
| 1 | +#include <iostream> | |
| 2 | +using namespace std; | |
| 3 | + | |
| 4 | +int main() | |
| 5 | +{ | |
| 6 | + int *p; | |
| 7 | + p = new int; | |
| 8 | + if (!p){ | |
| 9 | + cout << "メモリ割り当てエラー\n"; | |
| 10 | + return 1; | |
| 11 | + } | |
| 12 | + | |
| 13 | + *p = 1000; | |
| 14 | + cout << "pがさしている整数型は:" << *p << "\n"; | |
| 15 | + delete p; | |
| 16 | + return 0; | |
| 17 | +} | |
| \ No newline at end of file |