• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

練習用です。いろんなものがごちゃまぜです。


Commit MetaInfo

Revision53 (tree)
Time2015-10-13 11:57:45
Authorbellyoshi

Log Message

(empty log message)

Change Summary

Incremental Difference

--- TeachYourSelf/coord.cpp (revision 52)
+++ TeachYourSelf/coord.cpp (revision 53)
@@ -18,6 +18,8 @@
1818 coord operator--();
1919 coord operator--(int notused);
2020 coord operator-();
21+ coord operator<<(int x);
22+ coord operator>>(int x);
2123 friend coord operator+(coord ob1, int i);
2224 friend coord operator+(int i, coord ob1);
2325 };
@@ -44,6 +46,20 @@
4446 return (x && ob2.x) && (y && ob2.y);
4547 }
4648
49+coord coord::operator<<(int n)
50+{
51+ coord temp;
52+ temp.x = x << n;
53+ temp.y = y << n;
54+ return temp;
55+}
56+coord coord::operator>>(int n)
57+{
58+ coord temp;
59+ temp.x = x >> n;
60+ temp.y = y >> n;
61+ return temp;
62+}
4763 coord coord::operator+(coord &ob2)
4864 {
4965 coord temp;
@@ -126,5 +142,9 @@
126142 print(o3);
127143 o3 = o3 + 2;
128144 print(o3);
145+ o3 = o3 << 2;
146+ print(o3);
147+ o3 = o3 >> 1;
148+ print(o3);
129149 return 0;
130150 }
\ No newline at end of file
--- TeachYourSelf/three_d.cpp (nonexistent)
+++ TeachYourSelf/three_d.cpp (revision 53)
@@ -0,0 +1,74 @@
1+#include <iostream>
2+using namespace std;
3+
4+class three_d {
5+ int x, y, z;
6+public:
7+ three_d(int i, int j, int k)
8+ {
9+ x = i;y = j; z = k;
10+ }
11+ three_d(){ x = z = y = 0;}
12+ void get(int &i, int &j, int &k)
13+ {
14+ i = x;j = y;k = z;
15+ }
16+ three_d operator+(three_d ob);
17+ three_d operator-(three_d ob);
18+ three_d operator++();
19+ three_d operator--();
20+};
21+
22+three_d three_d::operator+(three_d ob)
23+{
24+ three_d temp;
25+ temp.x = x + ob.x;
26+ temp.y = y + ob.y;
27+ temp.z = z + ob.z;
28+ return temp;
29+}
30+
31+three_d three_d::operator-(three_d ob)
32+{
33+ three_d temp;
34+ temp.x = x - ob.x;
35+ temp.y = y - ob.y;
36+ temp.z = z - ob.z;
37+ return temp;
38+}
39+three_d three_d::operator++()
40+{
41+ x++;
42+ y++;
43+ z++;
44+ return *this;
45+}
46+three_d three_d::operator--()
47+{
48+ x--;
49+ y--;
50+ z--;
51+ return *this;
52+}
53+void print(three_d ob)
54+{
55+ int x,y,z;
56+ ob.get(x,y,z);
57+ cout << x << ',' << y << ',' << z << "\n";
58+}
59+
60+int main()
61+{
62+ three_d a(10,5,15),b(1,1,2);
63+ print(a);
64+ ++a;
65+ print(a);
66+ three_d c = a + b;
67+ print(c);
68+ --c;
69+ print(c);
70+ c = a-b;
71+ print(c);
72+
73+ return 0;
74+}
\ No newline at end of file