Advertisement
Doflamingo149

Untitled

May 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.82 KB | None | 0 0
  1. CLASS: PeriodicTable
  2.  
  3. CLASSFIELDS: elements (ARRAY OF ElementClass)
  4. count (integer)
  5. constructed (boolean)
  6.  
  7. CONSTRUCTORS:
  8. SUMODULE: Default constructor
  9. IMPORT: none
  10. EXPORT: address of new PeriodicTable object
  11. ASSERTION: Sets default elements, count and constructed
  12. ALGORITHM: FOR i:=0 TO LENGTH OF elements CHANGEBY 1 DO
  13. FOR j:=0 TO WIDTH OF elements CHANGEBY 1 DO
  14. elements := null
  15. ENDFOR
  16. ENDFOR
  17. count := 0
  18. constructed := false
  19. END SUBMODULE
  20.  
  21. SUBMODULE: Alternate constructor
  22. IMPORT: inElements (ARRAY OF ElementClass), inCount (integer), inConstructed (boolean)
  23. EXPORT: none
  24. ASSERTION: Creates object if imports are valid and FAILS otherwise
  25. ALGORITHM:
  26. i:=0
  27. j:=0
  28. WHILE(i<LENGTH OF elements AND elements[i][j] != NULL)DO
  29. WHILE(j<WIDTH OF elements AND elements[i][j] != NULL)DO
  30. elements[i][j] = inElements[i][j]
  31. j:=j+1
  32. ENDWHILE
  33. j:=0
  34. i:=i+1
  35. ENDWHILE
  36. count := inCount
  37. constructed := inConstructed
  38. END SUBMODULE
  39.  
  40. SUBMODULE: Copy constructor
  41. IMPORT: inPeriodicTable (PeriodicTable)
  42. EXPORT: none
  43. ASSERTION:
  44. ALGORITHM:
  45. elements:=inPeriodicTable.getElements<- none
  46. count := inPeriodicTable.getCount <- none
  47. constructed := inPeriodicTable.getConstructed <- none
  48. END SUBMODULE
  49.  
  50. MUTATORS:
  51. SUBMODULE: setElements
  52. IMPORT: inElements (ElementClass)
  53. EXPORT: none
  54. ASSERTION: Sets elements if valid
  55. ALGORITHM:
  56. i:=0
  57. j:=0
  58. WHILE(i<LENGTH OF elements AND elements[i][j] != NULL)DO
  59. WHILE(j<WIDTH OF elements AND elements[i][j] != NULL)DO
  60. elements[i][j] = inElements[i][j]
  61. j:=j+1
  62. ENDWHILE
  63. j:=0
  64. i:=i+1
  65. ENDWHILE
  66. END SUBMODULE
  67.  
  68. SUBMODULE: setCount
  69. IMPORT: inCount
  70. EXPORT: none
  71. ASSERTION: Sets count if valid
  72. ALGORITHM:
  73. count := inCount
  74. END SUBMODULE
  75.  
  76. SUBMODULE: setConstructed
  77. IMPORT: inConstructed
  78. EXPORT: none
  79. ASSERTION:
  80. ALGORITHM: Sets constructed
  81. constructed := inConstructed
  82. END SUBMODULE
  83.  
  84. SUBMODULE: equals
  85. IMPORT: inPeriodicTable PeriodicTable
  86. EXPORT: same (boolean)
  87. ASSERTION: Two periodic tables are interchangeable if they have the same elements, count and constructed
  88. ALGORITHM:
  89. same := false
  90. notEqual:=0
  91. i:=0
  92. j:=0
  93. IF (inObject ISA PeriodicTable) THEN
  94. make inObject a PeriodicTable named inPeriodicTable
  95. IF(count = inPeriodicTable.getCount <- none) THEN
  96. IF(constructed = inPeriodicTable.getConstructed<- none)THEN
  97. WHILE(i< LENGTH OF elements AND element[i][j]!= NULL)
  98. WHILE(j<WIDTH OF elements AND element[i][j]!= NULL)
  99. IF(elements[i][j].equals <-inPeriodicTable.getElements <- none)
  100. same := true
  101. ELSE
  102. notEqual:=notEqual+1
  103. ENDIF
  104. j:=j+1
  105. ENDWHILE
  106. j:=0
  107. i:=i+1
  108. ENDWHILE
  109. ENDIF
  110. ENDIF
  111. ENDIF
  112. IF(notEqual>0)THEN
  113. same := false
  114. ENDIF
  115. END SUBMODULE
  116.  
  117. ACCESSORS:
  118. SUBMODULE: getElements
  119. IMPORT: none
  120. EXPORT: elements
  121. END SUBMODULE
  122.  
  123. SUBMODULE: getCount
  124. IMPORT: none
  125. EXPORT: count
  126. END SUBMODULE
  127.  
  128. SUBMODULE: getConstructed
  129. IMPORT: none
  130. EXPORT: constructed
  131. END SUBMODULE
  132.  
  133. SUBMODULE: readFile
  134. IMPORT: fileName (String)
  135. EXPORT: none
  136. ASSERTION: Reads file and constructs elements
  137. ALGORITHM:
  138. rows = countRows <- fileName
  139. count := 0
  140. i:=0
  141. j:=0
  142.  
  143. theFile = OPENFILE fileName
  144.  
  145. IF(theFile = NULL)
  146. FAIL(THROW EXCEPTION)
  147. ENDIF
  148.  
  149. INPUT line from theFile
  150.  
  151. WHILE(line NOT EOF)
  152. FOR a:=0 TO rows CHANGEBY 1 DO
  153. lineArray = SPLIT line ON "<"
  154. FOR b:= 0 TO columns CHANGEBY 1 DO
  155. classFields = SPLIT lineArray[b+1] ON ","
  156. symbol := classFields[0]
  157. name := classFields[1]
  158. atomicNumber := (CONVERT TO integer) classFields[2]
  159. mass := (CONVERT TO real) classFields[3]
  160. lastClassField := classFields[4] TAKE AWAY last two characters
  161.  
  162. IF(lastClassField EQUALS "S", "L" OR "G" AND count<=100)THEN
  163. state := (CONVERT TO character)lastClassField
  164. elements[i][j] = CONSTRUCT new NonMetalClass USING symbol, name, atomicNumber, mass, state
  165. count := count + 1
  166. ELSE IF(FIRST LETTER OF lastClassField = '0','1','2','3','4','5','6','7','8' OR '9' AND count <=100)THEN
  167. conductivity := (CONVERT TO real)lastClassField
  168. elements[i][j] = CONSTRUCT new MetalClass USING symbol, name, atomicNumber, mass, conductivity
  169. count := count + 1
  170. ENDIF
  171.  
  172. IF(i<LENGTH OF elements-1 AND j = WIDTH OF elements-1)THEN
  173. j:=0
  174. i:=i+1
  175. ELSE IF(j<LENGTH OF elements)THEN
  176. j:=j+1
  177. ENDIF
  178.  
  179. ENDFOR
  180. INPUT line from theFile
  181. ENDFOR
  182. constructed := true
  183. ENDIF
  184. CLOSEFILE theFile
  185. END SUBMODULE
  186.  
  187. SUBMODULE: addElement
  188. IMPORT: inObject (ElementClass) choice (integer)
  189. EXPORT:
  190. ASSERTION:
  191. ALGORITHM:
  192. i:=0
  193. j:=0
  194. added := false
  195. IF(constructed = true AND count < 100)THEN
  196. WHILE(i<LENGTH OF elements AND added = false)DO
  197. WHILE(j<WIDTH OF elements AND added = false)DO
  198. IF(elements[i][j]=NULL AND inObject IS AN INSTANCE OF MetalClass)THEN
  199. elements[i][j]=inObject
  200. added := true
  201. ELSE IF(elements[i][j]=NULL AND inObject IS AND INSTANCE OF NonMetalClass)THEN
  202. elements[i][j]=inObject
  203. added := true
  204. ENDIF
  205. j:=j+1
  206. ENDWHILE
  207. i:=i+1
  208. ENDWHILE
  209. ELSE
  210. END SUBMODULE
  211.  
  212. SUBMODULE: writeFile
  213. IMPORT: choice (integer)
  214. EXPORT: none
  215. ASSERTION: Writes periodicTable to file
  216. ALGORITHM:
  217. theFile = OPENFILE "output.txt"
  218.  
  219. FOR i:=0 TO LENGTH OF elements CHANGEBY 1 DO
  220. FOR j:=0 TO WIDTH OF elements CHANGEBY 1 DO
  221. IF(choice = 1 AND elements[i][j] IS AN INSTANCE OF MetalClass) THEN
  222. WRITE elements[i][j].getSymbol <- none+ "," +elements[i][j].getName <- none+ "," +elements[i][j].getAtomicNumber <- none+ "," +elements[i][j].getMass <- none+ "," +(CONVERT TO MetalClass)elements[i][j].getConductivity <- none
  223. ELSE IF(choice = 2 AND elements[i][j] IS AN INSTANCE OF NonMetalClass)THEN
  224. WRITE elements[i][j].getSymbol <- none+ "," +elements[i][j].getName <- none+ "," +elements[i][j].getAtomicNumber <- none+ "," +elements[i][j].getMass <- none+ "," +(CONVERT TO MetalClass)elements[i][j].getState <- none
  225. ENDIF
  226. ENDFOR
  227. ENDFOR
  228. END SUBMODULE
  229.  
  230. SUBMODULE: clone
  231. IMPORT:
  232. EXPORT: clonePeriodicTable (Object)
  233. ASSERTION:
  234. ALGORITHM:
  235. CONSTRUCT clonePeriodicTable USING ALTERNATE CONSTRUCTROR WITH elements, count, constructed
  236. END SUBMODULE
  237.  
  238. SUBMODULE: toString
  239. IMPORT:
  240. EXPORT:
  241. ASSERTION:
  242. ALGORITHM:
  243. outString = ""
  244. FOR(i:=0 TO LENGTH OF elements CHANGEBY 1)
  245. FOR(j:=0 TO WIDTH Of elements CHANGEBY 1)
  246. IF(elements[i][j] != NULL)
  247. IF(elements[i][j] IS AN INSTANCE of MetalClass) THEN
  248. outString = outString+ elements.getName <- none + ", " +elements.getSymbol <- none + ", " +elements.getAtomicNumber <- none + ", " +elements.getMass <- none+ ", " +(CONVERT TO MetalClass)elements.getConductivity <- none
  249. ELSE IF(elements[i][j] IS AN INSTANCE OF NonMetalClass) THEN
  250. outString = outString+ elements.getName <- none + ", " +elements.getSymbol <- none + ", " +elements.getAtomicNumber <- none + ", " +elements.getMass <- none+ ", " +(CONVERT TO NonMetalClass)elements.getState <- none
  251. ENDIF
  252. ENDFOR
  253. ENDFOR
  254. outString = outString + " count: " +count+ " constructed: " +constructed
  255. END SUBMODULE
  256.  
  257.  
  258.  
  259. PRIVATE SUBMODULES:
  260. SUBMODULE: countRows
  261. IMPORT: fileName (String)
  262. EXPORT: rows (integer)
  263. ASSERTION: Counts number of rows in file
  264. ALGORITHM:
  265. theFile = OPENFILE fileName
  266.  
  267. IF theFile CAN'T BE OPENED THEN
  268. FAIL (THROW EXCEPTION)
  269. ENDIF
  270.  
  271. rows := 0
  272. INPUT line from theFile
  273.  
  274. WHILE (line NOT EOF)
  275. numLines = numLines + 1
  276. INPUT line from theFile
  277. ENDWHILE
  278.  
  279. CLOSEFILE theFile
  280. END SUBMODULE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement