• 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

Revision44 (tree)
Time2015-09-25 09:24:51
Authorbellyoshi

Log Message

(empty log message)

Change Summary

Incremental Difference

--- TeachYourSelf/newsamp.cpp (revision 43)
+++ TeachYourSelf/newsamp.cpp (revision 44)
@@ -4,7 +4,7 @@
44 class samp{
55 int i,j;
66 public:
7- void set_ij(int a, int b){i = a;j = b;}
7+ samp(int a, int b){i = a;j = b;}
88 int get_product(){return i*j;}
99 };
1010
@@ -11,13 +11,11 @@
1111 int main()
1212 {
1313 samp *p;
14- p = new samp;
14+ p = new samp(6,5);
1515 if(!p){
1616 cout << "メモリ割り当てエラー\n";
1717 return 1;
1818 }
19-
20- p->set_ij(4,5);
2119 cout << "積は:" << p->get_product() << "\n";
2220 delete p;
2321 return 0;
--- TeachYourSelf/new.cpp (revision 43)
+++ TeachYourSelf/new.cpp (revision 44)
@@ -4,13 +4,12 @@
44 int main()
55 {
66 int *p;
7- p = new int;
7+ p = new int(9);
88 if (!p){
99 cout << "メモリ割り当てエラー\n";
1010 return 1;
1111 }
1212
13- *p = 1000;
1413 cout << "pがさしている整数型は:" << *p << "\n";
1514 delete p;
1615 return 0;
--- TeachYourSelf/swapargs.cpp (nonexistent)
+++ TeachYourSelf/swapargs.cpp (revision 44)
@@ -0,0 +1,31 @@
1+#include <iostream>
2+using namespace std;
3+
4+void swapargs(int &x,int &y);
5+
6+int main()
7+{
8+ int i, j;
9+ i = 10;
10+ j = 19;
11+
12+ cout << "i:" << i << ", ";
13+ cout << "j:" << j << "\n";
14+
15+ swapargs(i,j);
16+
17+ cout << "交換後: ";
18+ cout << "i;" << i << ", ";
19+ cout << "j:" << j << "\n";
20+
21+ return 0;
22+}
23+
24+void swapargs(int &x,int &y)
25+{
26+ int t;
27+ t = x;
28+ x = y;
29+ y = t;
30+}
31+
\ No newline at end of file
--- TeachYourSelf/f.cpp (nonexistent)
+++ TeachYourSelf/f.cpp (revision 44)
@@ -0,0 +1,18 @@
1+#include <iostream>
2+using namespace std;
3+
4+void f(int &n);
5+
6+int main()
7+{
8+ int i = 0;
9+ f(i);
10+ cout << "iの新しい値:" << i << "\n";
11+
12+ return 0;
13+}
14+
15+void f(int &n)
16+{
17+ n = 100;
18+}
\ No newline at end of file
--- TeachYourSelf/myclassf.cpp (nonexistent)
+++ TeachYourSelf/myclassf.cpp (revision 44)
@@ -0,0 +1,25 @@
1+#include <iostream>
2+using namespace std;
3+
4+class myclass {
5+ int who;
6+public:
7+ myclass(int n){
8+ who = n;
9+ cout << "コンストラクタの呼び出し " << who << "\n";
10+ }
11+ ~myclass(){cout << "デストラクタの呼び出し" << who << "\n";}
12+ int id(){return who;}
13+};
14+
15+void f(myclass o)
16+{
17+ cout << "受け取り" << o.id() << "\n";
18+}
19+
20+int main()
21+{
22+ myclass x(1);
23+ f(x);
24+ return 0;
25+}
\ No newline at end of file
--- TeachYourSelf/retref.cpp (nonexistent)
+++ TeachYourSelf/retref.cpp (revision 44)
@@ -0,0 +1,17 @@
1+#include <iostream>
2+using namespace std;
3+
4+int &f();
5+int x;
6+
7+int main()
8+{
9+ f() = 100;
10+ cout << x << "\n";
11+ return 0;
12+}
13+
14+int &f()
15+{
16+ return x;
17+}
\ No newline at end of file
--- TeachYourSelf/newarray.cpp (nonexistent)
+++ TeachYourSelf/newarray.cpp (revision 44)
@@ -0,0 +1,26 @@
1+#include <iostream>
2+using namespace std;
3+
4+int main()
5+{
6+ int *p;
7+ p = new int [5];
8+
9+ if(!p){
10+ cout << "メモリ割り当てエラー\n";
11+ return 1;
12+ }
13+
14+ for(int i = 0; i < 5; i++){
15+ p[i] = i;
16+ }
17+
18+ for(int i = 0; i < 5; i++){
19+ cout << "整数型p[" << i << "]は:";
20+ cout << p[i] << "\n";
21+ }
22+
23+ delete [] p;
24+
25+ return 0;
26+}
\ No newline at end of file
--- TeachYourSelf/newchars.cpp (nonexistent)
+++ TeachYourSelf/newchars.cpp (revision 44)
@@ -0,0 +1,14 @@
1+#include <iostream>
2+#include <string.h>
3+
4+using namespace std;
5+
6+int main()
7+{
8+ char *p = new char[100];
9+ strcpy(p,"This is a test");
10+
11+ cout << p << "\n";
12+
13+ return 0;
14+}
\ No newline at end of file
--- TeachYourSelf/neg1.cpp (nonexistent)
+++ TeachYourSelf/neg1.cpp (revision 44)
@@ -0,0 +1,23 @@
1+#include <iostream>
2+using namespace std;
3+
4+void neg(int &num);
5+void neg(int *num);
6+
7+void neg(int &num){
8+ num = -num;
9+}
10+
11+void neg(int *num){
12+ *num = -*num;
13+}
14+int main()
15+{
16+ int num = 20;
17+ neg(num);
18+ cout << num << ' ';
19+ neg(&num);
20+ cout << num << ' ';
21+
22+ return 0;
23+}
\ No newline at end of file
--- TeachYourSelf/strtypeshow.cpp (nonexistent)
+++ TeachYourSelf/strtypeshow.cpp (revision 44)
@@ -0,0 +1,47 @@
1+#include <iostream>
2+#include <cstring>
3+#include <cstdlib>
4+using namespace std;
5+
6+class strtype {
7+ char *p;
8+ int len;
9+public:
10+ strtype(char *ptr);
11+ ~strtype();
12+ char *get(){return p;}
13+};
14+
15+strtype::strtype(char *ptr)
16+{
17+ int l = strlen(ptr);
18+ p = new char[l];
19+ if (!p) {
20+ cout << "メモリ割り当てエラー\n";
21+ exit(1);
22+ }
23+ strcpy(this->p, ptr);
24+ this->len = l;
25+}
26+
27+strtype::~strtype()
28+{
29+ cout << "pを解放する。\n";
30+ delete [] p;
31+}
32+
33+void show(strtype &x)
34+{
35+ char *s;
36+ s = x.get();
37+ cout << s << "\n";
38+}
39+
40+int main()
41+{
42+ strtype a("Hello"), b("There");
43+ show(a);
44+ show(b);
45+
46+ return 0;
47+}
\ No newline at end of file
--- TeachYourSelf/my_round.cpp (nonexistent)
+++ TeachYourSelf/my_round.cpp (revision 44)
@@ -0,0 +1,29 @@
1+#include <iostream>
2+#include <cmath>
3+using namespace std;
4+
5+void my_round(double &num);
6+
7+int main()
8+{
9+ double i = 100.4;
10+ cout << i << "を丸めると ";
11+ my_round(i);
12+ cout << i << "\n";
13+
14+ i = 10.9;
15+ cout << i << "を丸めると ";
16+ my_round(i);
17+ cout << i << "\n";
18+
19+ return 0;
20+}
21+
22+void my_round(double &num)
23+{
24+ double frac;
25+ double val;
26+ frac = modf(num, &val);
27+ if(frac < 0.5) num = val;
28+ else num = val + 1.0;
29+};
\ No newline at end of file
--- TeachYourSelf/newdouble.cpp (nonexistent)
+++ TeachYourSelf/newdouble.cpp (revision 44)
@@ -0,0 +1,9 @@
1+#include <iostream>
2+using namespace std;
3+
4+int main()
5+{
6+ double *d = new double(-123.099);
7+ cout << *d << "\n";
8+ return 0;
9+}
\ No newline at end of file