Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

saved

  • Loading branch information...
commit 6b938cba9c97d9c241c88cbdd75507b45290cb5e 0 parents
Andy authored
Showing with 17,707 additions and 0 deletions.
  1. BIN  ecs/30ecs/a.out
  2. +5 −0 ecs/30ecs/cdata.txt
  3. +158 −0 ecs/30ecs/selsortunfinished.c
  4. +162 −0 ecs/30ecs/selsortunfinished.c~
  5. +37 −0 ecs/40ecs/#test.cpp#
  6. +1 −0  ecs/40ecs/.#test.cpp
  7. +18 −0 ecs/40ecs/1p5/Makefile
  8. +85 −0 ecs/40ecs/1p5/Time.cpp
  9. +25 −0 ecs/40ecs/1p5/Time.h
  10. +339 −0 ecs/40ecs/1p5/directory.cpp
  11. +47 −0 ecs/40ecs/1p5/directory.h
  12. +332 −0 ecs/40ecs/1p5/funix.cpp
  13. +37 −0 ecs/40ecs/1p5/funix.h
  14. +3 −0  ecs/40ecs/1p5/linkedlist.cpp
  15. +12 −0 ecs/40ecs/1p5/linkedlist.h
  16. +16 −0 ecs/40ecs/1p5/main.cpp
  17. +43 −0 ecs/40ecs/1p5/permission.cpp
  18. +23 −0 ecs/40ecs/1p5/permission.h
  19. +18 −0 ecs/40ecs/2p5/Makefile
  20. +85 −0 ecs/40ecs/2p5/Time.cpp
  21. +25 −0 ecs/40ecs/2p5/Time.h
  22. BIN  ecs/40ecs/2p5/Time.o
  23. +344 −0 ecs/40ecs/2p5/directory.cpp
  24. +50 −0 ecs/40ecs/2p5/directory.h
  25. +50 −0 ecs/40ecs/2p5/directory.h~
  26. BIN  ecs/40ecs/2p5/directory.o
  27. +332 −0 ecs/40ecs/2p5/funix.cpp
  28. +37 −0 ecs/40ecs/2p5/funix.h
  29. BIN  ecs/40ecs/2p5/funix.o
  30. +27 −0 ecs/40ecs/2p5/linkedlist.cpp
  31. +27 −0 ecs/40ecs/2p5/linkedlist.cpp~
  32. +16 −0 ecs/40ecs/2p5/linkedlist.h
  33. +15 −0 ecs/40ecs/2p5/linkedlist.h~
  34. +16 −0 ecs/40ecs/2p5/main.cpp
  35. BIN  ecs/40ecs/2p5/main.o
  36. +43 −0 ecs/40ecs/2p5/permission.cpp
  37. +23 −0 ecs/40ecs/2p5/permission.h
  38. BIN  ecs/40ecs/2p5/permission.o
  39. +18 −0 ecs/40ecs/3p5/Makefile
  40. +2 −0  ecs/40ecs/3p5/README.txt
  41. +85 −0 ecs/40ecs/3p5/Time.cpp
  42. +25 −0 ecs/40ecs/3p5/Time.h
  43. +355 −0 ecs/40ecs/3p5/directory.cpp
  44. +57 −0 ecs/40ecs/3p5/directory.h
  45. +355 −0 ecs/40ecs/3p5/funix.cpp
  46. +40 −0 ecs/40ecs/3p5/funix.h
  47. +55 −0 ecs/40ecs/3p5/linkedlist.cpp
  48. +27 −0 ecs/40ecs/3p5/linkedlist.h
  49. +16 −0 ecs/40ecs/3p5/main.cpp
  50. +105 −0 ecs/40ecs/3p5/permissions.cpp
  51. +28 −0 ecs/40ecs/3p5/permissions.h
  52. +18 −0 ecs/40ecs/4p5/Makefile
  53. +86 −0 ecs/40ecs/4p5/Time.cpp
  54. +27 −0 ecs/40ecs/4p5/Time.h
  55. BIN  ecs/40ecs/4p5/Time.o
  56. +3 −0  ecs/40ecs/4p5/directories.txt
  57. +379 −0 ecs/40ecs/4p5/directory.cpp
  58. +387 −0 ecs/40ecs/4p5/directory.cpp~
  59. +54 −0 ecs/40ecs/4p5/directory.h
  60. +55 −0 ecs/40ecs/4p5/directory.h~
  61. BIN  ecs/40ecs/4p5/directory.o
  62. +362 −0 ecs/40ecs/4p5/funix.cpp
  63. +362 −0 ecs/40ecs/4p5/funix.cpp~
  64. +39 −0 ecs/40ecs/4p5/funix.h
  65. BIN  ecs/40ecs/4p5/funix.o
  66. BIN  ecs/40ecs/4p5/funix.out
  67. +76 −0 ecs/40ecs/4p5/linkedlist.cpp
  68. +27 −0 ecs/40ecs/4p5/linkedlist.h
  69. BIN  ecs/40ecs/4p5/linkedlist.o
  70. +16 −0 ecs/40ecs/4p5/main.cpp
  71. BIN  ecs/40ecs/4p5/main.o
  72. +108 −0 ecs/40ecs/4p5/permissions.cpp
  73. +107 −0 ecs/40ecs/4p5/permissions.cpp~
  74. +27 −0 ecs/40ecs/4p5/permissions.h
  75. +26 −0 ecs/40ecs/4p5/permissions.h~
  76. BIN  ecs/40ecs/4p5/permissions.o
  77. +1 −0  ecs/40ecs/6p1/.#directory.cpp
  78. +18 −0 ecs/40ecs/6p1/Makefile
  79. +18 −0 ecs/40ecs/6p1/Makefile~
  80. +1 −0  ecs/40ecs/6p1/README.TXT
  81. +86 −0 ecs/40ecs/6p1/Time.cpp
  82. +27 −0 ecs/40ecs/6p1/Time.h
  83. +376 −0 ecs/40ecs/6p1/directory.cpp
  84. +381 −0 ecs/40ecs/6p1/directory.cpp~
  85. +44 −0 ecs/40ecs/6p1/directory.h
  86. +115 −0 ecs/40ecs/6p1/file.cpp
  87. +48 −0 ecs/40ecs/6p1/file.h
  88. +379 −0 ecs/40ecs/6p1/funix.cpp
  89. +39 −0 ecs/40ecs/6p1/funix.h
  90. +41 −0 ecs/40ecs/6p1/funix.h~
  91. +82 −0 ecs/40ecs/6p1/linkedlist.cpp
  92. +31 −0 ecs/40ecs/6p1/linkedlist.h
  93. +16 −0 ecs/40ecs/6p1/main.cpp
  94. +122 −0 ecs/40ecs/6p1/permissions.cpp
  95. +29 −0 ecs/40ecs/6p1/permissions.h
  96. +64 −0 ecs/40ecs/makemake.sh
  97. +16 −0 ecs/40ecs/p4/Makefile
  98. +85 −0 ecs/40ecs/p4/Time.cpp
  99. +25 −0 ecs/40ecs/p4/Time.h
  100. BIN  ecs/40ecs/p4/Time.o
  101. BIN  ecs/40ecs/p4/core
  102. +4 −0 ecs/40ecs/p4/directories.txt
  103. +341 −0 ecs/40ecs/p4/directory.cpp
  104. +337 −0 ecs/40ecs/p4/directory.cpp~
  105. +45 −0 ecs/40ecs/p4/directory.h
  106. +45 −0 ecs/40ecs/p4/directory.h~
  107. BIN  ecs/40ecs/p4/directory.o
  108. +332 −0 ecs/40ecs/p4/funix.cpp
  109. +37 −0 ecs/40ecs/p4/funix.h
  110. BIN  ecs/40ecs/p4/funix.o
  111. BIN  ecs/40ecs/p4/funix.out
  112. +16 −0 ecs/40ecs/p4/main.cpp
  113. BIN  ecs/40ecs/p4/main.o
  114. +43 −0 ecs/40ecs/p4/permission.cpp
  115. +23 −0 ecs/40ecs/p4/permission.h
  116. BIN  ecs/40ecs/p4/permission.o
  117. +18 −0 ecs/40ecs/p5/Makefile
  118. +86 −0 ecs/40ecs/p5/Time.cpp
  119. +27 −0 ecs/40ecs/p5/Time.h
  120. +6 −0 ecs/40ecs/p5/directories.txt
  121. +381 −0 ecs/40ecs/p5/directory.cpp
  122. +380 −0 ecs/40ecs/p5/directory.cpp~
  123. +54 −0 ecs/40ecs/p5/directory.h
  124. +367 −0 ecs/40ecs/p5/funix.cpp
  125. +39 −0 ecs/40ecs/p5/funix.h
  126. +79 −0 ecs/40ecs/p5/linkedlist.cpp
  127. +27 −0 ecs/40ecs/p5/linkedlist.h
  128. +16 −0 ecs/40ecs/p5/main.cpp
  129. +121 −0 ecs/40ecs/p5/permissions.cpp
  130. +29 −0 ecs/40ecs/p5/permissions.h
  131. +18 −0 ecs/40ecs/p6/Makefile
  132. +86 −0 ecs/40ecs/p6/Time.cpp
  133. +27 −0 ecs/40ecs/p6/Time.h
  134. +382 −0 ecs/40ecs/p6/directory.cpp
  135. +54 −0 ecs/40ecs/p6/directory.h
  136. +367 −0 ecs/40ecs/p6/funix.cpp
  137. +39 −0 ecs/40ecs/p6/funix.h
  138. +80 −0 ecs/40ecs/p6/linkedlist.cpp
  139. +28 −0 ecs/40ecs/p6/linkedlist.h
  140. +16 −0 ecs/40ecs/p6/main.cpp
  141. +121 −0 ecs/40ecs/p6/permissions.cpp
  142. +29 −0 ecs/40ecs/p6/permissions.h
  143. +10 −0 ecs/40ecs/p7/Makefile
  144. +178 −0 ecs/40ecs/p7/main.cpp
  145. +106 −0 ecs/40ecs/p7/song.cpp
  146. +31 −0 ecs/40ecs/p7/song.h
  147. +425 −0 ecs/40ecs/p7/songs.txt
  148. +10 −0 ecs/40ecs/p8/AccessTest.txt
  149. +11 −0 ecs/40ecs/p8/Makefile
  150. +8 −0 ecs/40ecs/p8/PopTest.txt
  151. +8 −0 ecs/40ecs/p8/PopText.txt
  152. +7 −0 ecs/40ecs/p8/PushTest.txt
  153. +7 −0 ecs/40ecs/p8/PushText.txt
  154. +47 −0 ecs/40ecs/p8/SVector.cpp
  155. +60 −0 ecs/40ecs/p8/SVector.h
  156. +1 −0  ecs/40ecs/p8/SizeTest.txt
  157. +68 −0 ecs/40ecs/p8/main.cpp
  158. +37 −0 ecs/40ecs/test.cpp
  159. +14 −0 ecs/40ecs/test/#List.cpp#
  160. +18 −0 ecs/40ecs/test/List.cpp
  161. +10 −0 ecs/40ecs/test/List.h
  162. BIN  ecs/40ecs/test/List.h.gch
  163. BIN  ecs/40ecs/test/List.o
  164. +14 −0 ecs/40ecs/test/Makefile
  165. BIN  ecs/40ecs/test/a.out
  166. +5 −0 ecs/40ecs/test/ln.cpp
  167. +11 −0 ecs/40ecs/test/ln.h
  168. BIN  ecs/40ecs/test/ln.h.gch
  169. BIN  ecs/40ecs/test/ln.o
  170. +64 −0 ecs/40ecs/test/makemake.sh
  171. +16 −0 ecs/40ecs/test/test.cpp
  172. BIN  ecs/40ecs/test/test.o
  173. +13 −0 ecs/60ecs/p1/3vp1/Makefile
  174. +95 −0 ecs/60ecs/p1/3vp1/cell.cpp
  175. +22 −0 ecs/60ecs/p1/3vp1/cell.h
  176. BIN  ecs/60ecs/p1/3vp1/cell.o
  177. +1 −0  ecs/60ecs/p1/3vp1/et1.txt
  178. +1 −0  ecs/60ecs/p1/3vp1/et2.txt
  179. +79 −0 ecs/60ecs/p1/3vp1/holder.cpp
  180. +18 −0 ecs/60ecs/p1/3vp1/holder.h
  181. BIN  ecs/60ecs/p1/3vp1/holder.o
  182. +1 −0  ecs/60ecs/p1/3vp1/ht1.txt
  183. +1 −0  ecs/60ecs/p1/3vp1/ht2.txt
  184. +174 −0 ecs/60ecs/p1/3vp1/main.cpp
  185. +174 −0 ecs/60ecs/p1/3vp1/main.cpp~
  186. BIN  ecs/60ecs/p1/3vp1/main.o
  187. +1 −0  ecs/60ecs/p1/3vp1/mt1.txt
  188. +1 −0  ecs/60ecs/p1/3vp1/mt2.txt
  189. +205 −0 ecs/60ecs/p1/3vp1/puzzle.cpp
  190. +204 −0 ecs/60ecs/p1/3vp1/puzzle.cpp~
  191. +27 −0 ecs/60ecs/p1/3vp1/puzzle.h
  192. BIN  ecs/60ecs/p1/3vp1/puzzle.o
  193. +1 −0  ecs/60ecs/p1/3vp1/rt1.txt
  194. BIN  ecs/60ecs/p1/3vp1/solver.out
  195. +1 −0  ecs/60ecs/p1/3vp1/test1.txt
  196. +1 −0  ecs/60ecs/p1/3vp1/test2.txt
  197. +1 −0  ecs/60ecs/p1/3vp1/test3.txt
  198. +1 −0  ecs/60ecs/p1/3vp1/test4.txt
  199. +1 −0  ecs/60ecs/p1/3vp1/test5.txt
  200. +1 −0  ecs/60ecs/p1/3vp1/tt1.txt
  201. +13 −0 ecs/60ecs/p1/4vp1/Makefile
  202. +95 −0 ecs/60ecs/p1/4vp1/cell.cpp
  203. +22 −0 ecs/60ecs/p1/4vp1/cell.h
  204. BIN  ecs/60ecs/p1/4vp1/cell.o
  205. +1 −0  ecs/60ecs/p1/4vp1/et1.txt
  206. +1 −0  ecs/60ecs/p1/4vp1/et2.txt
  207. +80 −0 ecs/60ecs/p1/4vp1/holder.cpp
  208. +18 −0 ecs/60ecs/p1/4vp1/holder.h
  209. BIN  ecs/60ecs/p1/4vp1/holder.o
  210. +1 −0  ecs/60ecs/p1/4vp1/ht1.txt
  211. +1 −0  ecs/60ecs/p1/4vp1/ht2.txt
  212. +1 −0  ecs/60ecs/p1/4vp1/ht3.txt
  213. +1 −0  ecs/60ecs/p1/4vp1/ht4.txt
  214. +190 −0 ecs/60ecs/p1/4vp1/main.cpp
  215. +189 −0 ecs/60ecs/p1/4vp1/main.cpp~
  216. BIN  ecs/60ecs/p1/4vp1/main.o
  217. +1 −0  ecs/60ecs/p1/4vp1/mt1.txt
  218. +1 −0  ecs/60ecs/p1/4vp1/mt2.txt
  219. +235 −0 ecs/60ecs/p1/4vp1/puzzle.cpp
  220. +218 −0 ecs/60ecs/p1/4vp1/puzzle.cpp~
  221. +28 −0 ecs/60ecs/p1/4vp1/puzzle.h
  222. +27 −0 ecs/60ecs/p1/4vp1/puzzle.h~
  223. BIN  ecs/60ecs/p1/4vp1/puzzle.o
  224. +1 −0  ecs/60ecs/p1/4vp1/rt1.txt
  225. BIN  ecs/60ecs/p1/4vp1/solver.out
  226. +1 −0  ecs/60ecs/p1/4vp1/test1.txt
  227. +1 −0  ecs/60ecs/p1/4vp1/test2.txt
  228. +1 −0  ecs/60ecs/p1/4vp1/test3.txt
  229. +1 −0  ecs/60ecs/p1/4vp1/test4.txt
  230. +1 −0  ecs/60ecs/p1/4vp1/test5.txt
  231. +24 −0 ecs/60ecs/p1/4vp1/time.sh
  232. +1 −0  ecs/60ecs/p1/4vp1/time.txt
  233. +1 −0  ecs/60ecs/p1/4vp1/tt1.txt
  234. +14 −0 ecs/60ecs/p1/5vp1/Makefile
  235. +87 −0 ecs/60ecs/p1/5vp1/cell.cpp
  236. +22 −0 ecs/60ecs/p1/5vp1/cell.h
  237. BIN  ecs/60ecs/p1/5vp1/cell.o
  238. 0  ecs/60ecs/p1/5vp1/empty.txt
  239. +1 −0  ecs/60ecs/p1/5vp1/et1.txt
  240. +1 −0  ecs/60ecs/p1/5vp1/et2.txt
  241. +76 −0 ecs/60ecs/p1/5vp1/holder.cpp
  242. +18 −0 ecs/60ecs/p1/5vp1/holder.h
  243. BIN  ecs/60ecs/p1/5vp1/holder.o
  244. +1 −0  ecs/60ecs/p1/5vp1/ht1.txt
  245. +1 −0  ecs/60ecs/p1/5vp1/ht2.txt
  246. +1 −0  ecs/60ecs/p1/5vp1/ht3.txt
  247. +1 −0  ecs/60ecs/p1/5vp1/ht4.txt
  248. +204 −0 ecs/60ecs/p1/5vp1/main.cpp
  249. +204 −0 ecs/60ecs/p1/5vp1/main.cpp~
  250. BIN  ecs/60ecs/p1/5vp1/main.o
  251. +1 −0  ecs/60ecs/p1/5vp1/mt1.txt
  252. +1 −0  ecs/60ecs/p1/5vp1/mt2.txt
  253. +1 −0  ecs/60ecs/p1/5vp1/mt4.txt
  254. +176 −0 ecs/60ecs/p1/5vp1/puzzle.cpp
  255. +176 −0 ecs/60ecs/p1/5vp1/puzzle.cpp~
  256. +28 −0 ecs/60ecs/p1/5vp1/puzzle.h
  257. BIN  ecs/60ecs/p1/5vp1/puzzle.o
  258. +1 −0  ecs/60ecs/p1/5vp1/rt1.txt
  259. BIN  ecs/60ecs/p1/5vp1/sudsolve
  260. +1 −0  ecs/60ecs/p1/5vp1/test1.txt
  261. +1 −0  ecs/60ecs/p1/5vp1/test2.txt
  262. +1 −0  ecs/60ecs/p1/5vp1/test3.txt
  263. +1 −0  ecs/60ecs/p1/5vp1/test4.txt
  264. +1 −0  ecs/60ecs/p1/5vp1/test5.txt
  265. +1 −0  ecs/60ecs/p1/5vp1/time.txt
  266. +1 −0  ecs/60ecs/p1/5vp1/tt1.txt
  267. +1 −0  ecs/60ecs/p1/5vp1/twuTest.txt
  268. 0  ecs/60ecs/p1/5vp1/valgrindOut.txt
  269. +13 −0 ecs/60ecs/p1/Makefile
  270. +77 −0 ecs/60ecs/p1/cell.cpp
  271. +77 −0 ecs/60ecs/p1/cell.cpp~
  272. +20 −0 ecs/60ecs/p1/cell.h
  273. +20 −0 ecs/60ecs/p1/cell.h~
  274. BIN  ecs/60ecs/p1/cell.o
  275. BIN  ecs/60ecs/p1/core
  276. +1 −0  ecs/60ecs/p1/et1.txt
  277. +1 −0  ecs/60ecs/p1/et2.txt
  278. +141 −0 ecs/60ecs/p1/holder.cpp
  279. +18 −0 ecs/60ecs/p1/holder.h
  280. BIN  ecs/60ecs/p1/holder.o
  281. +1 −0  ecs/60ecs/p1/ht1.txt
  282. +1 −0  ecs/60ecs/p1/ht2.txt
  283. +166 −0 ecs/60ecs/p1/main.cpp
  284. +166 −0 ecs/60ecs/p1/main.cpp~
  285. BIN  ecs/60ecs/p1/main.o
  286. +1 −0  ecs/60ecs/p1/mt1.txt
  287. +207 −0 ecs/60ecs/p1/puzzle.cpp
  288. +207 −0 ecs/60ecs/p1/puzzle.cpp~
  289. +26 −0 ecs/60ecs/p1/puzzle.h
  290. +26 −0 ecs/60ecs/p1/puzzle.h~
  291. BIN  ecs/60ecs/p1/puzzle.o
  292. BIN  ecs/60ecs/p1/solver.out
  293. +1 −0  ecs/60ecs/p1/tt1.txt
  294. +13 −0 ecs/60ecs/p1/v2p1/Makefile
  295. +94 −0 ecs/60ecs/p1/v2p1/cell.cpp
  296. +95 −0 ecs/60ecs/p1/v2p1/cell.cpp~
  297. +22 −0 ecs/60ecs/p1/v2p1/cell.h
  298. +22 −0 ecs/60ecs/p1/v2p1/cell.h~
  299. BIN  ecs/60ecs/p1/v2p1/cell.o
  300. +1 −0  ecs/60ecs/p1/v2p1/et1.txt
Sorry, we could not display the entire diff because too many files (467) changed.
BIN  ecs/30ecs/a.out
Binary file not shown
5 ecs/30ecs/cdata.txt
@@ -0,0 +1,5 @@
+3.0 4.0
+2.0 1.0
+2.0 2.0
+3.0 -3.0
+5.0 -8.0
158 ecs/30ecs/selsortunfinished.c
@@ -0,0 +1,158 @@
+#include <stdio.h>
+#include <math.h>
+
+#define NSIZE 20
+
+//
+
+typedef struct {
+ double real, imag;
+} complex_t;
+
+void swap_largest(complex_t *array[], int n, int max_index);
+void select_sort_rec(complex_t *array[], int n);
+int find_biggest(complex_t *array[], int n, int start, int curmax);
+
+double abs_complex(complex_t c); // Make this by modifying the book version
+int scan_complex(FILE *fp,complex_t *c); //From the book (included)
+void print_complex(complex_t c); //From the book (included)
+
+int
+main()
+{
+ complex_t *array[NSIZE];
+ int size, i;
+ complex_t entry[NSIZE];
+ complex_t cno;
+ FILE *fp;
+
+ fp = fopen("cdata.txt", "r");
+ size = 0;
+
+ while(scan_complex(fp, &cno) == 1) {
+ array[size]=malloc(sizeof(complex_t));
+ array[size]->real=cno.real;
+ array[size]->imag=cno.imag;
+ size++;
+ }
+
+ printf("array before sorting = \n");
+
+ for(i=0;i<size;i++){
+ print_complex(*array[i]);
+ }
+
+ printf("***end of array****\n");
+
+ select_sort_rec(array, size);
+
+ printf("\narray after sorting = \n");
+
+ for(i=0;i<size;i++){
+ print_complex(*array[i]);
+ }
+ printf("***end of array****\n");
+ fclose(fp);
+ return 0;
+}
+
+
+/* select_sort_rec
+ * Sorts n elements of an array of complex_numbers
+ * Pre: n > 0 and first n elements of array are defined
+ * Post: array elements are in ascending order
+ * This function is RECURSIVE!!
+ */
+void select_sort_rec(complex_t *array[], int n)
+{
+ int themax = 0;
+
+ if(n>=0){
+
+ select_sort_rec(array, n-1);
+ }
+ return;
+ // Hint: There are two intuitive ways of solving this problem: (1) Finding
+ // the smallest number in the array, placing it at the front (via a swap), and
+ // then recursing on the remainder of the array; or (2), finding the largest
+ // element in the array, placing it at the back of the array (via a swap),
+ // and then recursing on the remainder of the array. This skeleton code assumes
+ // a solution that uses the second approach!
+}
+
+
+/* swap_largest
+ * Before: n > 0 and first n elements of array are defined
+ * the largest element (by abs value) is pointed to
+ * by array[max_index]
+ * After: array[n-1] contains pointer to largest value, which
+ * is at position max_index. The value that used to be pointed
+ * at Array[n-1] is now at Array[max_index].
+ */
+void swap_largest(complex_t *array[], int n,int max_index)
+{
+ // HINT: Got temp?
+
+ // This is a simple swap routine, and there is no need for recursion here!
+
+ // FINISH THIS!!
+}
+
+int find_biggest(complex_t *array[], int n, int start, int curmax) {
+
+ if(start<n){
+ if(abs_complex(*array[start])>abs_complex(*array[curmax])){
+ curmax=start;
+ }
+ curmax=find_biggest(array, n, start+1, curmax);
+ }
+ return curmax;
+}
+
+int scan_complex(FILE *input, complex_t *c)
+{
+
+ int status;
+
+ status = fscanf(input,"%lf%lf", &c->real, &c->imag);
+
+ if (status == 2)
+ status = 1;
+ else if (status != EOF)
+ status = 0;
+
+ return (status);
+}
+
+void print_complex(complex_t c) /* input - complex number to display */
+{
+ double a, b;
+ char sign;
+
+ a = c.real;
+ b = c.imag;
+
+ printf("(");
+
+ if (fabs(a) < .005 && fabs(b) < .005) {
+ printf("%.2f", 0.0);
+ } else if (fabs(b) < .005) {
+ printf("%.2f", a);
+ } else if (fabs(a) < .005) {
+ printf("%.2fi", b);
+ } else {
+ if (b < 0)
+ sign = '-';
+ else
+ sign = '+';
+ printf("%.2f %c %.2fi", a, sign, fabs(b));
+ }
+
+ printf(")\n");
+}
+
+double abs_complex(complex_t c)
+{
+ return sqrt(c.real * c.real + c.imag * c.imag);
+}
+
162 ecs/30ecs/selsortunfinished.c~
@@ -0,0 +1,162 @@
+#include <stdio.h>
+#include <math.h>
+
+#define NSIZE 20
+
+//
+
+typedef struct {
+ double real, imag;
+} complex_t;
+
+void swap_largest(complex_t *array[], int n, int max_index);
+void select_sort_rec(complex_t *array[], int n);
+int find_biggest(complex_t *array[], int n, int start, int curmax);
+
+double abs_complex(complex_t c); // Make this by modifying the book version
+int scan_complex(FILE *fp,complex_t *c); //From the book (included)
+void print_complex(complex_t c); //From the book (included)
+
+int
+main()
+{
+ complex_t *array[NSIZE];
+ int size, i;
+ complex_t entry[NSIZE];
+ complex_t cno;
+ FILE *fp;
+
+ fp = fopen("cdata.txt", "r");
+ size = 0;
+
+ while(scan_complex(fp, &cno) == 1) {
+ array[size]=malloc(sizeof(complex_t));
+ array[size]->real=cno.real;
+ array[size]->imag=cno.imag;
+ size++;
+ }
+
+ printf("array before sorting = \n");
+
+ for(i=0;i<size;i++){
+ print_complex(*array[i]);
+ }
+
+ printf("***end of array****\n");
+
+ select_sort_rec(array, size);
+
+ printf("\narray after sorting = \n");
+
+ for(i=0;i<size;i++){
+ print_complex(*array[i]);
+ }
+ printf("***end of array****\n");
+ fclose(fp);
+ return 0;
+}
+
+
+/* select_sort_rec
+ * Sorts n elements of an array of complex_numbers
+ * Pre: n > 0 and first n elements of array are defined
+ * Post: array elements are in ascending order
+ * This function is RECURSIVE!!
+ */
+void select_sort_rec(complex_t *array[], int n)
+{
+ int themax = 0;
+
+ if(n>=0){
+
+ select_sort_rec(array, n-1);
+ }
+ return;
+ // Hint: There are two intuitive ways of solving this problem: (1) Finding
+ // the smallest number in the array, placing it at the front (via a swap), and
+ // then recursing on the remainder of the array; or (2), finding the largest
+ // element in the array, placing it at the back of the array (via a swap),
+ // and then recursing on the remainder of the array. This skeleton code assumes
+ // a solution that uses the second approach!
+}
+
+
+/* swap_largest
+ * Before: n > 0 and first n elements of array are defined
+ * the largest element (by abs value) is pointed to
+ * by array[max_index]
+ * After: array[n-1] contains pointer to largest value, which
+ * is at position max_index. The value that used to be pointed
+ * at Array[n-1] is now at Array[max_index].
+ */
+void swap_largest(complex_t *array[], int n,int max_index)
+{
+ // HINT: Got temp?
+
+ // This is a simple swap routine, and there is no need for recursion here!
+
+ // FINISH THIS!!
+}
+
+
+/* find_biggest Finds the position of largest value in list array[0]..array[n-1]
+ * find_biggest is RECURSIVE!!
+ */
+int find_biggest(complex_t *array[], int n, int start, int curmax) {
+
+ if(start<n){
+ if(abs_complex(*array[start])>abs_complex(*array[curmax])){
+ curmax=start;
+ }
+ curmax=find_biggest(array, n, start+1, curmax);
+ }
+ return curmax;
+}
+
+int scan_complex(FILE *input, complex_t *c)
+{
+
+ int status;
+
+ status = fscanf(input,"%lf%lf", &c->real, &c->imag);
+
+ if (status == 2)
+ status = 1;
+ else if (status != EOF)
+ status = 0;
+
+ return (status);
+}
+
+void print_complex(complex_t c) /* input - complex number to display */
+{
+ double a, b;
+ char sign;
+
+ a = c.real;
+ b = c.imag;
+
+ printf("(");
+
+ if (fabs(a) < .005 && fabs(b) < .005) {
+ printf("%.2f", 0.0);
+ } else if (fabs(b) < .005) {
+ printf("%.2f", a);
+ } else if (fabs(a) < .005) {
+ printf("%.2fi", b);
+ } else {
+ if (b < 0)
+ sign = '-';
+ else
+ sign = '+';
+ printf("%.2f %c %.2fi", a, sign, fabs(b));
+ }
+
+ printf(")\n");
+}
+
+double abs_complex(complex_t c)
+{
+ return sqrt(c.real * c.real + c.imag * c.imag);
+}
+
37 ecs/40ecs/#test.cpp#
@@ -0,0 +1,37 @@
+friend ifstream& operator >> ( ifstream &is, Results &results){
+
+ stringstream i;
+ string g, dir, name;
+ Vector<bool>b, Vector<float> f;
+ bool a;
+ float fl;
+ Normal *in;
+
+ getline(is, g);
+ while(getline(is, g)){
+ i<<g;
+ getline(i, dir, ',');
+ getline(i, name, ',');
+
+ for(int i=0; i<5; i++){
+ getline(i, g, ',');
+ bool a=(g=='Y')?true: false;
+ b.push_back(a);
+ getline(i, g, ',');
+ fl=atof(g.c_str());
+ f.push_back(fl);
+ }
+
+ if(b.front()){
+
+ in=new Normal(name, b, f);
+ }
+ else{
+
+ in=new Multiple(name, b, f);
+ }
+
+ map.insert(ResultMap::value_type(dir, in));
+ }
+ return is;
+}
1  ecs/40ecs/.#test.cpp
18 ecs/40ecs/1p5/Makefile
@@ -0,0 +1,18 @@
+#Hiu Hong Yu && Wen Xi Zhang
+funix.out: permission.o directory.o funix.o main.o Time.o linkedlist.o
+ g++ -Wall -ansi -g -o funix.out permission.o directory.o funix.o main.o Time.o linkedlist.o
+main.o: main.cpp funix.h
+ g++ -Wall -ansi -g -c main.cpp
+funix.o: funix.cpp funix.h directory.h Time.h linkedlist.h
+ g++ -Wall -ansi -g -c funix.cpp
+directory.o: directory.cpp permission.h directory.h Time.h linkedlist.h
+ g++ -Wall -ansi -g -c directory.cpp
+permission.o: permission.cpp permission.h
+ g++ -Wall -ansi -g -c permission.cpp
+Time.o: Time.cpp Time.h
+ g++ -Wall -ansi -g -c Time.cpp
+linkedlist.o: linkedlist.cpp linkedlist.h
+ g++ -Wall -ansi -g -c linkedlist.cpp
+
+clean:
+ rm -f funix.out permission.o directory.o main.o funix.o Time.o linkedlist.o
85 ecs/40ecs/1p5/Time.cpp
@@ -0,0 +1,85 @@
+#include "Time.h"
+using namespace std;
+
+//Time default constructor
+Time :: Time()
+{
+ //set time, month, day, hour, minute, and second
+ //with current local computer time, and date
+ //then setting the time with local computer time
+ time_set = time(0);
+ tm = localtime(&time_set);
+ month = tm->tm_mon;
+ day = tm->tm_mday;
+ hour = tm->tm_hour;
+ minute = tm->tm_min;
+ second = tm->tm_sec;
+
+}//end Time()
+
+//constructor overload, useless int value to distinguish between =.=
+Time :: Time(int i, int u)
+{
+}//end Time()
+
+//constructor overload
+Time :: Time(Time& new_time) : month(new_time.month), day(new_time.day),
+ hour(new_time.hour), minute(new_time.minute),
+ second(new_time.second)
+{
+}//end Time()
+
+//operator overload
+ofstream& operator << (ofstream &out, const Time &tim)
+{
+ out << tim.month << " "
+ << tim.day << " "
+ << tim.hour << " "
+ << tim.minute << " "
+ << tim.second;
+ return out;
+}//end << operator
+
+//operator overload
+ifstream& operator >> (ifstream &in, Time &ti)
+{
+ in >> ti.month;
+ in >> ti.day;
+ in >> ti.hour;
+ in >> ti.minute;
+ in >> ti.second;
+ return in;
+}//end >> operator
+
+//update the current time to the file time
+void Time :: updateTime()
+{
+ //set the time with local computer time
+ time_set = time(0);
+ tm = localtime(&time_set);
+ month = tm->tm_mon;
+ day = tm->tm_mday;
+ hour = tm->tm_hour;
+ minute = tm->tm_min;
+ second = tm->tm_sec;
+}//end updateTime()
+
+// print out the time of the directory/file when use ls -l
+void Time :: printTime()
+{
+ cout << setfill('0');
+ cout << getMonth()
+ << " " << setw(2) << day
+ << " " << setw(2) << hour
+ << ":" << setw(2) << minute
+ << ":" << setw(2) << second;
+
+}//end printTime()
+
+//convert the number to month from directory.txt
+const char* Time :: getMonth() const
+{
+ const char* const mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+ return mon[month];
+}//end getMonth()
25 ecs/40ecs/1p5/Time.h
@@ -0,0 +1,25 @@
+#pragma once
+#include "Time.h"
+#include <iostream>
+#include <cstring>
+#include <iomanip>
+#include <fstream>
+using namespace std;
+
+class Time
+{
+ private:
+ time_t time_set;
+ struct tm* tm;
+
+ public:
+ Time();
+ Time(int i, int u);
+ Time(Time& new_time);
+ friend ofstream& operator<< (ofstream &out, const Time& ti);
+ friend ifstream& operator>> (ifstream &in, Time& ti);
+ const char* getMonth()const;
+ void printTime();
+ void updateTime();
+ int month, day, hour, minute, second;
+};
339 ecs/40ecs/1p5/directory.cpp
@@ -0,0 +1,339 @@
+//Wen Xi Zhang && Hiu Hong Yu
+#include "directory.h"
+using namespace std;
+
+//constructor with one parameter
+//set default temp = NULL
+Directory :: Directory(char name1[80]) : temp(NULL)
+{
+ //Directory constructor
+ name = new char[80];
+ strcpy(name, name1);
+ subN = 0;
+}//end Directory()
+
+//overloading constructor for read in data from directory.txt
+//creating all the pervious directory that were created during last run
+//use recurrsion, set default temp = NULL
+Directory :: Directory(Directory* original, Directory* prev) : temp(NULL)
+{
+ //overloading directory constructor
+ name = new char[80];// name = new name
+ mask = new Permission();//new umask
+ time = new Time();// new time
+ strcpy(name, (*original).name);
+ subN = (*original).subN;
+ mask = (*original).mask;
+ previousDir = prev;// perviousDirectry = new directory
+ //scan for sub directory within the directory
+ for(int i = 0; i < subN; i++)
+ {
+ subDir[i] = new Directory((*original).subDir[i], this);
+ }//end for
+}//end Directory(overloading constructor)
+
+//overloading constructor for currectory directory
+//creating root, set default temp to NULL
+Directory :: Directory(Directory* currentDir, char name1[80], int umask1) : temp(NULL)
+{
+ mask = new Permission();// new mask value
+ time = new Time();// time
+ if(currentDir == NULL)
+ {
+ currentDir = this;
+ name = new char[2];
+ strcpy(name, "/");
+ subN = 0;
+ (*mask).set(22);
+ return ;
+ }//end if
+
+ //creating new memory for directory and permission
+ name = new char[strlen(name1) + 1];
+ (*mask).set(umask1);//call the set function to set the umask value
+ (*currentDir).subDir[(*currentDir).subN] = this;
+ strcpy(name,name1);//copy the name from name1 to class variable
+ previousDir = currentDir;// set perviousdirectory to current
+ subN = 0;//number of subdirectory = 0
+ (*currentDir).subN++;//number of current directory + 1
+}//end Directory()
+
+//overloaded constructor for only allocating memory
+//set default temp to NULL
+Directory :: Directory() : temp(NULL)
+{
+ name = new char[80];
+ mask = new Permission();
+ time = new Time(1, 2);
+}//end Directory(default constructor)
+
+//use recurrsion
+Directory :: ~Directory()
+{
+ //delete memory that were created for sub directory
+ for(int i = 0; i < subN; i++)
+ {
+ if(subDir[i] != NULL)//if there are sub directory exist
+ {
+ delete subDir[i];//delete the memory of sub directory
+ }//end if
+ }//end for
+ //delete memory of temp that were used to compare
+ if(temp)//if temp exit
+ {
+ delete temp;//delete
+ }//end if
+ //delete the memory of name
+ delete[] name;
+}//end destructor ~Directory
+
+//overloading operator for print
+//use recurrsion
+ofstream& operator << (ofstream &out, const Directory& dir)
+{
+ out << (*dir.name) << " ";
+ out << dir.subN << " ";
+ out << (*dir.mask);
+ out << (*dir.time);
+ out << endl;
+
+ for(int i = 0; i < dir.subN; i++)
+ {
+ out << (*dir.subDir[i]);
+ }//end for
+
+ return out;
+}//end << operator
+
+//overloading operator << scan in
+ifstream& operator >>(ifstream &in, Directory& dir)
+{
+ in >> dir.name;
+ in >> dir.subN;
+ in >> (*dir.mask);
+ in >> (*dir.time);
+
+ return in;
+}//end overloading >> operator
+
+//overloading == operator
+bool Directory :: operator == (const Directory &rhs)
+{
+ return (strcmp(name, rhs.name) == 0);
+}//end == operator
+
+//read in data from directory.txt
+void Directory :: reconstructor(ifstream &in)
+{
+ while(!in.eof())//while not end of file, keep scanning
+ {
+ for(int track = 0; track < subN; track++)
+ {
+ subDir[track] = new Directory();
+ in >> (*subDir[track]);
+ (*subDir[track]).previousDir = this;
+ (*subDir[track]).reconstructor(in);
+ }//end for
+ break;
+ }//end while
+}//end reconstructor
+
+//check if valid permission were entered
+//default paramater to tell if being called from umask or chmod
+bool Directory :: validPermission(char command1[80], int mode)
+{
+ unsigned int i;
+ int track = 0;
+ //check to c if the number of input value is correct
+ for(i = 0; i < strlen(command1); i++)
+ {
+ if(isdigit(command1[i]))//if entered is digit not something else
+ {
+ if(command1[i] == '9' || command1[i] == '8' )
+ {
+ track = 1;
+ }//end if
+ }//end if
+ else//if not print out error
+ {
+ if(mode == 1)
+ {
+ cout << "usage: umask octal" << endl;
+ }//end if
+ else
+ {
+ cout << "chmod: invalid mode string: '" << command1 << "'" << endl;
+ }//end else
+
+ return false;
+ }//end if
+ }//end for
+
+ //if the number are between 0 to 7, then it correct
+ if(atoi(command1) <= 777 && track == 0)
+ {
+ return true;
+ }//end if
+ else//else error message
+ {
+ if(mode == 1)
+ {
+ cout << "usage: umask octal" << endl;
+ }//end if
+ else
+ {
+ cout << "chmod: invalid mode string: '" << command1 << "'" << endl;
+ }//end else
+
+ return false;
+ }//end else
+}//end Valid Umask
+
+void Directory :: changePermission(char name1[80], int new_permission)
+{
+ //create new memory
+ temp = new Directory(name1);
+ //scan tho the directory
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))//found match
+ {
+ //change the new permission to the directory
+ (*subDir[i]->mask).perm = new_permission;
+ (*subDir[i]->time).updateTime();//apply new time
+ return ;
+ }//end if
+ }//end for
+ cout << "chmod: failed to get attributes of '" << name1
+ << "': No such file or directory" << endl;
+}//end change permission
+
+Directory* Directory :: validChange(char name1[80])
+{
+ temp = new Directory(name1);
+ //if cd with ..
+ if(strcmp("..", name1) == 0)
+ {
+ if(previousDir == NULL)//if no previous directory
+ {
+ return this;
+ }//end if
+ else//else return the pervious directory
+ {
+ return (*previousDir).get();
+ }//end else
+ }//end if
+ else if(subN == 0)//if trying to cd into a directory that DNE
+ {
+ cout << name1 << ": no such file or directory" << endl;
+ return this;
+ }//end else if
+ else//look through the directory list, c if there any match
+ {
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))//if found match
+ {
+ return (*subDir[i]).get();
+ break;
+ }//end if
+ else//
+ {
+ if(i == subN - 1)//if no match directory, error message
+ {
+ cout << name1 << ": no such file or directory." << endl;
+ return this;
+ }//end if
+ }//end else
+ }//end for
+ }//else
+ return this;
+}//end validchange()
+
+bool Directory :: validCreate(char name1[80], int mode)
+{
+ temp = new Directory(name1);
+ if(subN < 3)//if number of directory < 3
+ {
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))
+ {
+ if(mode == 1)
+ {
+ cout << "cp: omitting directory '" << name1 << "'" << endl;
+ }//end if
+ else
+ {
+ cout << "mkdir: cannot create directory '" << name1
+ << "': File exists" << endl;
+ }//end else
+ return false;
+ }//end if
+ }//end for
+ return true;
+ }//end else if
+ else// if the directory have already 3 sub directory, error message
+ {
+ if(mode == 1)
+ {
+ cout << "cp: ";
+ }//end if
+ else
+ {
+ cout << "mkdir: ";
+ }//end else
+ cout << name << " already contains the maximum number of directories"
+ << endl;
+ return false;
+ }//end else
+ return true;
+}//end ValidCreate()
+
+void Directory :: list(char command1[80])
+{
+ for(int i = 0; i <= subN - 1; i++)
+ {
+ if(strlen(command1) == 0)//if there no extra list option (-l)
+ {
+ cout << (*subDir[i]).name << " ";
+ }//end if
+ else if(strcmp(command1, "-l") == 0)// if -l included
+ {//list all permission, time, and name of the representing directory
+ (*subDir[i]->mask).printUmask();
+ (*subDir[i]->time).printTime();
+ cout << " " << (*subDir[i]).name << endl;
+ }//end else if
+ else//if command entered incorrectly, error message
+ {
+ cout << "usage: ls [-l]" << endl << command1;
+ return;
+ }//end else
+ }//end for
+ if(subN > 0 && strlen(command1) == 0)// if no sub directory
+ {
+ cout << endl;
+ }//end if
+}//end list()
+
+Directory* Directory :: get()
+{
+ return this;
+}//end get()
+
+//copy function recursively in copy constructor
+void Directory:: copy(char name1[80], char name2[80])
+{
+ temp = new Directory(name1);
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))//if found match directory in current
+ {
+ //create new directory with the name provided
+ subDir[subN] = new Directory(subDir[i], this);
+ strcpy((*subDir[subN]).name, name2 ); //rename the new directory
+ subN++;
+ break;
+ }//end if
+ }//end for
+}//end copy()
47 ecs/40ecs/1p5/directory.h
@@ -0,0 +1,47 @@
+//Hiu Hong Yu && Wen Xi Zhang
+#include <string>
+#include <iostream>
+#include <cstdlib>
+#include <cctype>
+#include <cstring>
+#include <iomanip>
+#include <fstream>
+#include "permission.h"
+#include "Time.h"
+#include "linkedlist.h"
+
+#pragma once
+
+using std::ostream;
+using std::ifstream;
+
+class linkedlist;
+class Directory
+{
+ public:
+ Directory *previousDir;// pointer to previous directory
+ Directory *subDir[3];// pointer to all sub directory
+ Directory *temp;
+ char *name;// name of directory char array
+ Time *time;
+ int subN;//time = time of used, subN = number of sub directory
+ Permission *mask;// permission
+ Directory(char name1[80]);
+ Directory(Directory* original, Directory* prev);
+ Directory(Directory* currentDir, char name1[80], int umask);
+ Directory();
+ ~Directory();
+ friend ofstream& operator<< (ofstream &out, const Directory& dir);
+ friend ifstream& operator >> (ifstream &in, Directory& dir);
+ bool operator == (const Directory &rhs);
+ void reconstructor(ifstream &in);
+ bool validPermission(char command1[80], int mode=0);
+ void changePermission(char name1[80], int new_permission);
+ Directory* validChange(char name1[80]);
+ bool validCreate(char name1[80], int mode=0);
+ void list(char name1[80]);
+ Directory* get();
+ void copy(char name1[80], char name2[80]);
+};//end Directory class
+
+
332 ecs/40ecs/1p5/funix.cpp
@@ -0,0 +1,332 @@
+//Hiu Hong Yu && Wen Xi Zhang
+#include "funix.h"
+#include "permission.h"
+#include "directory.h"
+#include "Time.h"
+using namespace std;
+
+//funix root constructor
+//when funix() was called, default root directory will be created
+Funix :: Funix() : currentDir(new Directory(NULL, NULL, 755))
+{
+ umask = 0;//default mask value
+ //open up directories.txt if it exist
+ ifstream infile("a.txt", ios::in);
+ infile >> (*this);//read in the file to this, current directory
+ //recreate the directory/file that were created during last run recursivly,
+ //if directories.txt is empty, nothing will be create
+ (*currentDir).reconstructor(infile);
+ infile.close();//close file
+}//end funix()
+
+Funix::~Funix()
+{
+ if(currentDir != NULL)//if current directory exist
+ {
+ delete currentDir;// delete the memory of current directory
+ }//end if
+}//end destructor ~Funix()
+
+//overloading << operator
+ofstream& operator << (ofstream& out, const Funix& fn)
+{
+ out << (*fn.currentDir);//calls directory overloaded operator
+ return out;
+}//end << operator
+
+//overloading >> operator
+ifstream& operator >> (ifstream& in, Funix& fn)
+{
+ in >> (*fn.currentDir);//calls directory overloaded operator
+ return in;
+}//end >> operator
+
+void Funix :: cd(char name1[80], char extra[80])
+{
+ //check for extra input(directory name)
+ if(strlen(extra) > 0 || strlen(name1) == 0)
+ {
+ cout << "usage: cd directoryName\n";
+ return;
+ }//end if
+ //set current directory to the directory going to
+ currentDir = (*currentDir).validChange(name1);
+}//end cd()
+
+int Funix :: eXit(char extra[80])
+{
+ //check for extra input
+ if(strlen(extra) > 0)
+ {
+ cout << "usage: exit\n";
+ return 0;
+ }//end if
+ return 1;
+}//end exit
+
+void Funix :: writePrompt()
+{
+ int i = 0, j;
+ char path[100][80];
+ Directory *temp = currentDir;
+ strcpy(path[1], "");
+
+ //print out the address of the directory
+ while(1)
+ {
+ strcpy(path[i], (*temp).name);
+ //if the perviousdir not = null, save name to array
+ if((*temp).previousDir != NULL)
+ {
+ temp = (*temp).previousDir;
+ }//end if
+ else break;
+ i++;
+ }//end while
+
+ for(j = i; j >= 0; j--)
+ {
+ if(j == i)
+ {
+ cout << "/";
+ }//end if
+ else
+ cout << path[j] << "/";
+ }//end for
+ cout << " # ";
+}//end writeprompt
+
+void Funix :: getCommand(char command1[80], char command2[80],
+ char command3[80], char command4[80])
+{
+ unsigned int i, c1 = 0, t = 0;
+ char input[80], commandF1[80] = "\0", commandF2[80] = "\0",
+ commandF3[80] = "\0", commandF4[80]="\0";
+ //command1 = function being call, command2 = name of things being call for function,
+ //command3 = anything extra
+
+ cin.getline(input, 79); //store input command into array
+
+ //sort out user input command
+ for(i = 0; i < strlen(input); i++)
+ {
+ if(input[i] == ' ')
+ {
+ c1++;
+ t = i + 1;
+ if(input[i-1] == ' ' || i == 0)
+ {
+ c1--;
+ }//end if
+ }//end if
+ if(input[i] == '\0')
+ {
+ break;
+ }//end if
+
+ if(input[i] != ' ' && c1 == 0)
+ {
+ commandF1[i-t] = input[i];
+ }//end if
+
+ if(input[i] != ' ' && c1 == 1)
+ {
+ commandF2[i-t] = input[i];
+ }//end if
+
+ if(input[i] != ' ' && c1 == 2)
+ {
+ commandF3[i-t] = input[i];
+ }//end if
+ if(input[i] != ' ' && c1 == 3)
+ {
+ commandF4[i-t] = input[i];
+ }
+ }//end for
+ //copy back to array and return to run()
+ strcpy(command1, commandF1);
+ strcpy(command2, commandF2);
+ strcpy(command3, commandF3);
+ strcpy(command4, commandF4);
+}//end getcommand
+
+void Funix :: ls(char command1[80], char extra[80])
+{
+ if(strlen(extra) > 0 || (strcmp(command1,"-l") != 0 && strlen(command1) > 0))
+ {
+ cout << "usage: ls [-l]\n";
+ return ;
+ }//end if
+ (*currentDir).list(command1);
+}//end ls
+
+void Funix :: mkdir(char name1[80], char extra[80])
+{
+ //check for extra input
+ if(strlen(extra) > 0 || strlen(name1) == 0)
+ {
+ cout << "usage: mkdir directory_name\n";
+ return ;
+ }//end if
+ //check if the input correct, if correct make dir, else print out error
+ //if file already exist, print out error message
+ if((*currentDir).validCreate(name1))
+ {
+ (*currentDir->time).updateTime();
+ new Directory(currentDir, name1, umask);
+ }//end if
+}//end mkdir
+
+void Funix :: setUmask(char command1[80], char extra[80])
+{
+ //check for extra input
+ if(strlen(extra) > 0 || strlen(command1) == 0)
+ {
+ cout << "usage: umask octal\n";
+ return ;
+ }//end if
+
+ //check if number range is valid
+ if((*currentDir).validPermission(command1, 1))
+ {
+ umask = atoi(command1);
+ }//end if
+}//end umask
+
+void Funix :: chmod(char p[80], char name1[80], char extra[80])
+{
+ if(strlen(extra) > 0 || strlen(p) == 0 || strlen(name1) == 0)
+ {
+ if(strlen(extra) > 0)
+ {
+ cout << "chmod: failed to get atrributes of '" << extra
+ << ": No such file or directory" << endl;
+ return ;
+ }//end if
+ else
+ {
+ cout<<"chmod: too few arguements"<<endl;
+ }//end else
+ return ;
+ }//end if
+
+ if((*currentDir).validPermission(p))//if enter valid mask value
+ {
+ //change the file/directory mask vaule to new one
+ (*currentDir).changePermission(name1, 777 - atoi(p));
+ }//end if
+}//end chmod()
+
+//copy function
+void Funix :: cp(char name1[80], char name2[80], char extra[80])
+{
+ if(strlen(extra) > 0)
+ {
+ cout << " cp: too many arguements" << endl;
+ return ;
+ }//end if
+ if(strlen(name2) == 0)
+ {
+ cout << "cp: missing destination file" << endl;
+ return ;
+ }//end if
+ if(strlen(name1) == 0)
+ {
+ cout << "cp: missing file arguements" << endl;
+ return ;
+ }//end if
+ if(strcmp(name1, name2) == 0)
+ {
+ cout << "cp: '" << name1 << "' and '" << name2
+ << "' are the same file" << endl;
+ return ;
+ }//end if
+ //if enter all command correctly
+ if((*currentDir).validCreate(name2, 1))
+ {
+ (*currentDir).copy(name1, name2);
+ }//end if
+}//end cp()
+
+int Funix :: processCommand(char command1[80])
+{
+ int i;
+ //all command choice
+ char const *commands[] = {"cd", "exit", "ls", "mkdir",
+ "umask","chmod","cp", "unknownInput"};
+ for(i = 0; i <= 7; i++)
+ {
+ if(strcmp(command1, commands[i]) == 0)
+ {
+ break;
+ }//end if
+ }//end for
+ return i;
+}//end processCommand
+
+void Funix :: run()
+{
+ // declear command array && variable
+ //
+ int exit = 0;
+ char command1[80] = "\0", command2[80] = "\0",
+ command3[80] = "\0", command4[80]="\0";
+
+ //while loop, run program until the word exit was entered
+ //
+ while(1)
+ {
+ writePrompt();// print out current directory address
+ getCommand(command1, command2, command3, command4);//get command that user want to do
+ //process command that were entered
+ //
+ switch(processCommand(command1))
+ {
+ case 0:
+ cd(command2, command3);// change directory
+ break;
+ case 1:
+ if(eXit(command2))
+ {
+ exit = 1;// exit
+ }//end if
+ break;
+ case 2:
+ ls(command2, command3);// list all file in the directory
+ break;
+ case 3:
+ mkdir(command2, command3);// make directory
+ break;
+ case 4:
+ setUmask(command2, command3);// umask
+ break;
+ case 5:
+ chmod(command2, command3, command4);
+ break;
+ case 6:
+ cp(command2, command3, command4);
+ break;
+ default:// anything else
+ if(strcmp(command1,"") == 0)
+ {
+ }//end if
+ else
+ {
+ cout << command1 << ": Command not found.\n";
+ }//end else
+ break;
+ }//end switch
+ if(exit == 1)
+ {
+ //while exit command, print all data to directory.txt
+ while((*currentDir).previousDir != NULL)//goes back to root 1st.
+ {
+ currentDir = (*currentDir).previousDir;
+ }//end while
+ ofstream outfile("a.txt", ios :: out);//open directory.txt
+ outfile << (*this);//write everything thing to it recursively
+ outfile.close();//close it
+ break;
+ }//end if
+ }// end while
+}//end run
37 ecs/40ecs/1p5/funix.h
@@ -0,0 +1,37 @@
+//Hiu Hong Yu && Wen Xi Zhang
+#include <cstring>
+#include <string>
+#include <iostream>
+#include <cstdlib>
+#include <cctype>
+#include <fstream>
+#include "directory.h"
+
+#pragma once
+//struct for current directory
+
+class Funix
+{
+ private:
+ Directory* currentDir;
+ int umask;
+ void cd(char name1[80], char extra[80]);
+ int eXit(char extra[80]);
+ void writePrompt();
+ void getCommand(char command1[80], char command2[80],
+ char command3[80], char command4[80]);
+ void ls(char command1[80], char extra[80]);
+ void mkdir(char name1[80], char extra[80]);
+ void setUmask(char command1[80], char extra[80]);
+ void chmod(char command1[80], char command2[80], char extra[80]);
+ void cp(char command1[80], char command2[80], char extra[80]);
+ int processCommand(char command1[80]);
+
+
+ public:
+ Funix();
+ ~Funix();
+ void run();
+ friend ofstream& operator << (ofstream& out, const Funix& fn);
+ friend ifstream& operator >> (ifstream& in, Funix& fn);
+};//end Funix class
3  ecs/40ecs/1p5/linkedlist.cpp
@@ -0,0 +1,3 @@
+#include "linkedlist.h"
+
+linkedlist::linkedlist(){}
12 ecs/40ecs/1p5/linkedlist.h
@@ -0,0 +1,12 @@
+
+
+#pragma once
+
+class Directory;
+class linkedlist{
+
+ Directory *ptr;
+
+ public:
+ linkedlist();
+};
16 ecs/40ecs/1p5/main.cpp
@@ -0,0 +1,16 @@
+//Wen Xi Zhang && Hiu Hong Yu
+#include <cstdlib>
+#include <iostream>
+#include "funix.h"
+using namespace std;
+
+int main()
+{
+ //set funix pointer
+ Funix* funix = new Funix();
+ (*funix).run();// start running get command
+ //free memory
+ delete funix;
+
+ return 0;
+}//end main
43 ecs/40ecs/1p5/permission.cpp
@@ -0,0 +1,43 @@
+//Hiu Hong Yu && Wen Xi Zhang
+#include "permission.h"
+using namespace std;
+
+Permission :: Permission()
+{
+
+}//end Permission()
+
+//overloading operator <<
+ofstream& operator << (ofstream& out,const Permission &pe)
+{
+ out << pe.perm << " ";
+ return out;
+}//end << operator
+
+//overloading operator >>
+ifstream& operator >> (ifstream &in, Permission &pe)
+{
+ in >> pe.perm;
+ return in;
+}//end >> operator
+
+void Permission::printUmask()
+{
+ const char* const octal[] = {"rwx", "rw-", "r-x", "r--", "-wx", "-w-",
+ "--x", "---"};// premission list
+ //convert umask value with enter value
+ int o = perm % 10;
+ int g = ((perm - o) / 10) % 10;
+ int u = ((perm - (g * 10) - o) / 100) % 10;
+ cout << octal[u] << octal[g] << octal[o] << " ";
+}//end printUmask()
+
+void Permission :: set(int i)
+{
+ perm = i;
+}//end set()
+
+int Permission :: get()
+{
+ return perm;
+}//end get()
23 ecs/40ecs/1p5/permission.h
@@ -0,0 +1,23 @@
+//Wen Xi Zhang && Hiu Hong Yu
+
+#pragma once
+
+#include <iostream>
+#include <fstream>
+#include <cstdlib>
+
+using namespace std;
+
+//struct that hold the umask value
+class Permission
+{
+ public:
+ int perm;
+ //ofstream outfile;
+ Permission();
+ friend ofstream& operator<< (ofstream &out,const Permission& pe);
+ friend ifstream& operator>> (ifstream &in, Permission &pe);
+ void printUmask();
+ void set(int i);
+ int get();
+};//end class permission
18 ecs/40ecs/2p5/Makefile
@@ -0,0 +1,18 @@
+#Hiu Hong Yu && Wen Xi Zhang
+funix.out: permission.o directory.o funix.o main.o Time.o linkedlist.o
+ g++ -Wall -ansi -g -o funix.out permission.o directory.o funix.o main.o Time.o linkedlist.o
+main.o: main.cpp funix.h
+ g++ -Wall -ansi -g -c main.cpp
+funix.o: funix.cpp funix.h directory.h Time.h linkedlist.h
+ g++ -Wall -ansi -g -c funix.cpp
+directory.o: directory.cpp permission.h directory.h Time.h linkedlist.h
+ g++ -Wall -ansi -g -c directory.cpp
+permission.o: permission.cpp permission.h
+ g++ -Wall -ansi -g -c permission.cpp
+Time.o: Time.cpp Time.h
+ g++ -Wall -ansi -g -c Time.cpp
+linkedlist.o: linkedlist.cpp linkedlist.h directory.h
+ g++ -Wall -ansi -g -c linkedlist.cpp
+
+clean:
+ rm -f funix.out permission.o directory.o main.o funix.o Time.o linkedlist.o
85 ecs/40ecs/2p5/Time.cpp
@@ -0,0 +1,85 @@
+#include "Time.h"
+using namespace std;
+
+//Time default constructor
+Time :: Time()
+{
+ //set time, month, day, hour, minute, and second
+ //with current local computer time, and date
+ //then setting the time with local computer time
+ time_set = time(0);
+ tm = localtime(&time_set);
+ month = tm->tm_mon;
+ day = tm->tm_mday;
+ hour = tm->tm_hour;
+ minute = tm->tm_min;
+ second = tm->tm_sec;
+
+}//end Time()
+
+//constructor overload, useless int value to distinguish between =.=
+Time :: Time(int i, int u)
+{
+}//end Time()
+
+//constructor overload
+Time :: Time(Time& new_time) : month(new_time.month), day(new_time.day),
+ hour(new_time.hour), minute(new_time.minute),
+ second(new_time.second)
+{
+}//end Time()
+
+//operator overload
+ofstream& operator << (ofstream &out, const Time &tim)
+{
+ out << tim.month << " "
+ << tim.day << " "
+ << tim.hour << " "
+ << tim.minute << " "
+ << tim.second;
+ return out;
+}//end << operator
+
+//operator overload
+ifstream& operator >> (ifstream &in, Time &ti)
+{
+ in >> ti.month;
+ in >> ti.day;
+ in >> ti.hour;
+ in >> ti.minute;
+ in >> ti.second;
+ return in;
+}//end >> operator
+
+//update the current time to the file time
+void Time :: updateTime()
+{
+ //set the time with local computer time
+ time_set = time(0);
+ tm = localtime(&time_set);
+ month = tm->tm_mon;
+ day = tm->tm_mday;
+ hour = tm->tm_hour;
+ minute = tm->tm_min;
+ second = tm->tm_sec;
+}//end updateTime()
+
+// print out the time of the directory/file when use ls -l
+void Time :: printTime()
+{
+ cout << setfill('0');
+ cout << getMonth()
+ << " " << setw(2) << day
+ << " " << setw(2) << hour
+ << ":" << setw(2) << minute
+ << ":" << setw(2) << second;
+
+}//end printTime()
+
+//convert the number to month from directory.txt
+const char* Time :: getMonth() const
+{
+ const char* const mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+ return mon[month];
+}//end getMonth()
25 ecs/40ecs/2p5/Time.h
@@ -0,0 +1,25 @@
+#pragma once
+#include "Time.h"
+#include <iostream>
+#include <cstring>
+#include <iomanip>
+#include <fstream>
+using namespace std;
+
+class Time
+{
+ private:
+ time_t time_set;
+ struct tm* tm;
+
+ public:
+ Time();
+ Time(int i, int u);
+ Time(Time& new_time);
+ friend ofstream& operator<< (ofstream &out, const Time& ti);
+ friend ifstream& operator>> (ifstream &in, Time& ti);
+ const char* getMonth()const;
+ void printTime();
+ void updateTime();
+ int month, day, hour, minute, second;
+};
BIN  ecs/40ecs/2p5/Time.o
Binary file not shown
344 ecs/40ecs/2p5/directory.cpp
@@ -0,0 +1,344 @@
+//Wen Xi Zhang && Hiu Hong Yu
+#include "directory.h"
+using namespace std;
+
+//constructor with one parameter
+//set default temp = NULL
+Directory :: Directory(char name1[80]) : temp(NULL)
+{
+ //Directory constructor
+ name = new char[80];
+ strcpy(name, name1);
+ subN = 0;
+}//end Directory()
+
+//overloading constructor for read in data from directory.txt
+//creating all the pervious directory that were created during last run
+//use recurrsion, set default temp = NULL
+Directory :: Directory(Directory* original, Directory* prev) : temp(NULL)
+{
+ //overloading directory constructor
+ name = new char[80];// name = new name
+ mask = new Permission();//new umask
+ time = new Time();// new time
+ strcpy(name, (*original).name);
+ subN = (*original).subN;
+ mask = (*original).mask;
+ previousDir = prev;// perviousDirectry = new directory
+ //scan for sub directory within the directory
+ for(int i = 0; i < subN; i++)
+ {
+ subDir[i] = new Directory((*original).subDir[i], this);
+ }//end for
+}//end Directory(overloading constructor)
+
+//overloading constructor for currectory directory
+//creating root, set default temp to NULL
+Directory :: Directory(Directory* currentDir, char name1[80], int umask1) : temp(NULL)
+{
+ mask = new Permission();// new mask value
+ time = new Time();// time
+ if(currentDir == NULL)
+ {
+ currentDir = this;
+ name = new char[2];
+ strcpy(name, "/");
+ subN = 0;
+ (*mask).set(22);
+ return ;
+ }//end if
+
+ //creating new memory for directory and permission
+ name = new char[strlen(name1) + 1];
+ (*mask).set(umask1);//call the set function to set the umask value
+ (*currentDir).subDir[(*currentDir).subN] = this;
+ strcpy(name,name1);//copy the name from name1 to class variable
+ previousDir = currentDir;// set perviousdirectory to current
+ subN = 0;//number of subdirectory = 0
+ (*currentDir).subN++;//number of current directory + 1
+}//end Directory()
+
+//overloaded constructor for only allocating memory
+//set default temp to NULL
+Directory :: Directory() : temp(NULL)
+{
+ name = new char[80];
+ mask = new Permission();
+ time = new Time(1, 2);
+}//end Directory(default constructor)
+
+//use recurrsion
+Directory :: ~Directory()
+{
+ //delete memory that were created for sub directory
+ for(int i = 0; i < subN; i++)
+ {
+ if(subDir[i] != NULL)//if there are sub directory exist
+ {
+ delete subDir[i];//delete the memory of sub directory
+ }//end if
+ }//end for
+ //delete memory of temp that were used to compare
+ if(temp)//if temp exit
+ {
+ delete temp;//delete
+ }//end if
+ //delete the memory of name
+ delete[] name;
+}//end destructor ~Directory
+
+//overloading operator for print
+//use recurrsion
+ofstream& operator << (ofstream &out, const Directory& dir)
+{
+ out << (*dir.name) << " ";
+ out << dir.subN << " ";
+ out << (*dir.mask);
+ out << (*dir.time);
+ out << endl;
+
+ for(int i = 0; i < dir.subN; i++)
+ {
+ out << (*dir.subDir[i]);
+ }//end for
+
+ return out;
+}//end << operator
+
+//overloading operator << scan in
+ifstream& operator >>(ifstream &in, Directory& dir)
+{
+ in >> dir.name;
+ in >> dir.subN;
+ in >> (*dir.mask);
+ in >> (*dir.time);
+
+ return in;
+}//end overloading >> operator
+
+bool Directory::operator < (const Directory &rhs)
+{
+ return (strcmp(name, rhs.name)>0);
+}
+
+//overloading == operator
+bool Directory :: operator == (const Directory &rhs)
+{
+ return (strcmp(name, rhs.name) == 0);
+}//end == operator
+
+//read in data from directory.txt
+void Directory :: reconstructor(ifstream &in)
+{
+ while(!in.eof())//while not end of file, keep scanning
+ {
+ for(int track = 0; track < subN; track++)
+ {
+ subDir[track] = new Directory();
+ in >> (*subDir[track]);
+ (*subDir[track]).previousDir = this;
+ (*subDir[track]).reconstructor(in);
+ }//end for
+ break;
+ }//end while
+}//end reconstructor
+
+//check if valid permission were entered
+//default paramater to tell if being called from umask or chmod
+bool Directory :: validPermission(char command1[80], int mode)
+{
+ unsigned int i;
+ int track = 0;
+ //check to c if the number of input value is correct
+ for(i = 0; i < strlen(command1); i++)
+ {
+ if(isdigit(command1[i]))//if entered is digit not something else
+ {
+ if(command1[i] == '9' || command1[i] == '8' )
+ {
+ track = 1;
+ }//end if
+ }//end if
+ else//if not print out error
+ {
+ if(mode == 1)
+ {
+ cout << "usage: umask octal" << endl;
+ }//end if
+ else
+ {
+ cout << "chmod: invalid mode string: '" << command1 << "'" << endl;
+ }//end else
+
+ return false;
+ }//end if
+ }//end for
+
+ //if the number are between 0 to 7, then it correct
+ if(atoi(command1) <= 777 && track == 0)
+ {
+ return true;
+ }//end if
+ else//else error message
+ {
+ if(mode == 1)
+ {
+ cout << "usage: umask octal" << endl;
+ }//end if
+ else
+ {
+ cout << "chmod: invalid mode string: '" << command1 << "'" << endl;
+ }//end else
+
+ return false;
+ }//end else
+}//end Valid Umask
+
+void Directory :: changePermission(char name1[80], int new_permission)
+{
+ //create new memory
+ temp = new Directory(name1);
+ //scan tho the directory
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))//found match
+ {
+ //change the new permission to the directory
+ (*subDir[i]->mask).perm = new_permission;
+ (*subDir[i]->time).updateTime();//apply new time
+ return ;
+ }//end if
+ }//end for
+ cout << "chmod: failed to get attributes of '" << name1
+ << "': No such file or directory" << endl;
+}//end change permission
+
+Directory* Directory :: validChange(char name1[80])
+{
+ temp = new Directory(name1);
+ //if cd with ..
+ if(strcmp("..", name1) == 0)
+ {
+ if(previousDir == NULL)//if no previous directory
+ {
+ return this;
+ }//end if
+ else//else return the pervious directory
+ {
+ return (*previousDir).get();
+ }//end else
+ }//end if
+ else if(subN == 0)//if trying to cd into a directory that DNE
+ {
+ cout << name1 << ": no such file or directory" << endl;
+ return this;
+ }//end else if
+ else//look through the directory list, c if there any match
+ {
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))//if found match
+ {
+ return (*subDir[i]).get();
+ break;
+ }//end if
+ else//
+ {
+ if(i == subN - 1)//if no match directory, error message
+ {
+ cout << name1 << ": no such file or directory." << endl;
+ return this;
+ }//end if
+ }//end else
+ }//end for
+ }//else
+ return this;
+}//end validchange()
+
+bool Directory :: validCreate(char name1[80], int mode)
+{
+ temp = new Directory(name1);
+ if(subN < 3)//if number of directory < 3
+ {
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))
+ {
+ if(mode == 1)
+ {
+ cout << "cp: omitting directory '" << name1 << "'" << endl;
+ }//end if
+ else
+ {
+ cout << "mkdir: cannot create directory '" << name1
+ << "': File exists" << endl;
+ }//end else
+ return false;
+ }//end if
+ }//end for
+ return true;
+ }//end else if
+ else// if the directory have already 3 sub directory, error message
+ {
+ if(mode == 1)
+ {
+ cout << "cp: ";
+ }//end if
+ else
+ {
+ cout << "mkdir: ";
+ }//end else
+ cout << name << " already contains the maximum number of directories"
+ << endl;
+ return false;
+ }//end else
+ return true;
+}//end ValidCreate()
+
+void Directory :: list(char command1[80])
+{
+ for(int i = 0; i <= subN - 1; i++)
+ {
+ if(strlen(command1) == 0)//if there no extra list option (-l)
+ {
+ cout << (*subDir[i]).name << " ";
+ }//end if
+ else if(strcmp(command1, "-l") == 0)// if -l included
+ {//list all permission, time, and name of the representing directory
+ (*subDir[i]->mask).printUmask();
+ (*subDir[i]->time).printTime();
+ cout << " " << (*subDir[i]).name << endl;
+ }//end else if
+ else//if command entered incorrectly, error message
+ {
+ cout << "usage: ls [-l]" << endl << command1;
+ return;
+ }//end else
+ }//end for
+ if(subN > 0 && strlen(command1) == 0)// if no sub directory
+ {
+ cout << endl;
+ }//end if
+}//end list()
+
+Directory* Directory :: get()
+{
+ return this;
+}//end get()
+
+//copy function recursively in copy constructor
+void Directory:: copy(char name1[80], char name2[80])
+{
+ temp = new Directory(name1);
+ for(int i = 0; i < subN; i++)
+ {
+ if((*temp) == (*subDir[i]))//if found match directory in current
+ {
+ //create new directory with the name provided
+ subDir[subN] = new Directory(subDir[i], this);
+ strcpy((*subDir[subN]).name, name2 ); //rename the new directory
+ subN++;
+ break;
+ }//end if
+ }//end for
+}//end copy()
50 ecs/40ecs/2p5/directory.h
@@ -0,0 +1,50 @@
+//Hiu Hong Yu && Wen Xi Zhang
+#include <string>
+#include <iostream>
+#include <cstdlib>
+#include <cctype>
+#include <cstring>
+#include <iomanip>
+#include <fstream>
+#include "permission.h"
+#include "Time.h"
+
+#pragma once
+
+using std::ostream;
+using std::ifstream;
+
+class linkedlist;
+class Directory
+{
+ friend class linkedlist;
+ friend ofstream& operator<< (ofstream &out, const Directory& dir);
+ friend ifstream& operator >> (ifstream &in, Directory& dir);
+
+ public:
+ Directory *previousDir;// pointer to previous directory
+ Directory *subDir[];// pointer to all sub directory
+ Directory *temp;
+ char *name;// name of directory char array
+ Time *time;
+ linkedlist *link;
+ int subN;//subN = number of sub directory
+ Permission *mask;// permission
+ Directory(char name1[80]);
+ Directory(Directory* original, Directory* prev);
+ Directory(Directory* currentDir, char name1[80], int umask);
+ Directory();
+ ~Directory();
+ bool operator < (const Directory &rhs);
+ bool operator == (const Directory &rhs);
+ void reconstructor(ifstream &in);
+ bool validPermission(char command1[80], int mode=0);
+ void changePermission(char name1[80], int new_permission);
+ Directory* validChange(char name1[80]);
+ bool validCreate(char name1[80], int mode=0);
+ void list(char name1[80]);
+ Directory* get();
+ void copy(char name1[80], char name2[80]);
+};//end Directory class
+
+
50 ecs/40ecs/2p5/directory.h~
@@ -0,0 +1,50 @@
+//Hiu Hong Yu && Wen Xi Zhang
+#include <string>
+#include <iostream>
+#include <cstdlib>
+#include <cctype>
+#include <cstring>
+#include <iomanip>
+#include <fstream>
+#include "permission.h"
+#include "Time.h"
+
+#pragma once
+
+using std::ostream;
+using std::ifstream;
+
+class linkedlist;
+class Directory
+{
+ friend class linkedlist;
+ friend ofstream& operator<< (ofstream &out, const Directory& dir);
+ friend ifstream& operator >> (ifstream &in, Directory& dir);
+
+ public:
+ Directory *previousDir;// pointer to previous directory
+ Directory *subDir[];// pointer to all sub directory
+ Directory *temp;
+ char *name;// name of directory char array
+ Time *time;
+ linkedlist *list;
+ int subN;//subN = number of sub directory
+ Permission *mask;// permission
+ Directory(char name1[80]);
+ Directory(Directory* original, Directory* prev);
+ Directory(Directory* currentDir, char name1[80], int umask);
+ Directory();
+ ~Directory();
+ bool operator < (const Directory &rhs);
+ bool operator == (const Directory &rhs);
+ void reconstructor(ifstream &in);
+ bool validPermission(char command1[80], int mode=0);
+ void changePermission(char name1[80], int new_permission);
+ Directory* validChange(char name1[80]);
+ bool validCreate(char name1[80], int mode=0);
+ void list(char name1[80]);
+ Directory* get();
+ void copy(char name1[80], char name2[80]);
+};//end Directory class
+
+
BIN  ecs/40ecs/2p5/directory.o
Binary file not shown
332 ecs/40ecs/2p5/funix.cpp
@@ -0,0 +1,332 @@
+//Hiu Hong Yu && Wen Xi Zhang
+#include "funix.h"
+#include "permission.h"
+#include "directory.h"
+#include "Time.h"
+using namespace std;
+
+//funix root constructor
+//when funix() was called, default root directory will be created
+Funix :: Funix() : currentDir(new Directory(NULL, NULL, 755))
+{
+ umask = 0;//default mask value
+ //open up directories.txt if it exist
+ ifstream infile("a.txt", ios::in);
+ infile >> (*this);//read in the file to this, current directory
+ //recreate the directory/file that were created during last run recursivly,
+ //if directories.txt is empty, nothing will be create
+ (*currentDir).reconstructor(infile);
+ infile.close();//close file
+}//end funix()
+
+Funix::~Funix()
+{
+ if(currentDir != NULL)//if current directory exist
+ {
+ delete currentDir;// delete the memory of current directory
+ }//end if
+}//end destructor ~Funix()
+
+//overloading << operator
+ofstream& operator << (ofstream& out, const Funix& fn)
+{
+ out << (*fn.currentDir);//calls directory overloaded operator
+ return out;
+}//end << operator
+
+//overloading >> operator
+ifstream& operator >> (ifstream&