Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. Programing notes for monday of 2-8-15
  2. ----------------------------------------
  3. Winds was blowing like crazy outside so we talked about that a bit
  4.  
  5. x 1 doesn't work, but x 2 does in mathamatics guy's program
  6. teacher taught programing in 9 other programing languages, lol. never has he used the word stream till C++
  7. ------------------------------------------------------
  8. last week we talked about c in this week we are goint to talk aobut
  9.  
  10. NON INTERACTIVE PROGRAMS
  11. 1. input form an input file
  12. 2. output from an output file
  13.  
  14. interactive program for someone wanting to document sales. They type in the info and computer does the work, but there is a sever problem with that.... one wrong input and we have to start over...
  15. We only use interactive programs when the amount intered into the program is small.
  16. when you have 100 pieces of data you need to input while the program is running is awful.
  17. what if instead throughout the week we had them put the info down into an input file.
  18. they could input the sales data and continue to add to the file. at the end of the week the program would run and input wouldn't come from the keyboard, but the file.
  19. They make a mistake no big deal. The can back space and move to the start of the file.
  20. ------------------------------------------------------
  21.  
  22. Instead of putting output to the screen we can put it to and output file and don't have to run the program again
  23. (alternative to print screen and then paste in word)
  24. ------------------------------------------------------
  25. pg. 153
  26. Stream is to vague of a word, and we can't have vague in programing.
  27.  
  28. ifstream inFile;
  29. ofstream outFile'
  30. (two variables in the whole course you can make global variables. you can't assign a value to a file variable. put it above main. put above main() )
  31.  
  32. ifstream inData;
  33. ofstream outData;
  34.  
  35. when you are making a file name please put the name file in a name so you won't try and assign a file name to it.
  36. ------------------------------------------------------
  37. pg. 154
  38. best place to create visual studio ide. (new text file. not microsoft word. you can use note pad or notpad ++)
  39.  
  40. inData.open("D:\\LoanIn.txt"); // This is found on the jumpdrive. always use two backslashes.
  41. // "inData"this is an internal file name. this name doesn't exist outside of your file name. loanin is an external file name.
  42. // every character between the double quotes must be exactly correct.It will be put into a fail state. you won't get a fail message and your program will still try and run
  43.  
  44. ------------------------------------------------------
  45. output file
  46.  
  47. outData.open("D:\\LoanOut.txt"); // this file won't exist till after program runs. This is placing it on the flash drive
  48. // now the file the second time it runs. It will replace it and erase it so the new input goes into the file clean.
  49. ------------------------------------------------------
  50. pg. 156
  51. Step 4:
  52.  
  53. //Look at the syntext it looks like cin. It is exactly like cinn.
  54. //just input file name for cout and it works just fine.
  55.  
  56. inData >> LoanAmount >> yearlyInterest >> NumberOfYears;
  57.  
  58. //input buffer input file is the input buffer.
  59.  
  60.  
  61. fixed set precision. do you need to do that twice. you only need to do that once
  62. fixed and set precision are set manips no need to do it twice.
  63. sets it to four then wants it to go back to two
  64. ------------------------------------------------------
  65. pg. 158
  66. program where the code we've just been talking about has been inbedded with this program
  67.  
  68. step one in this program is
  69. include fstream
  70. include file variable
  71.  
  72. open statements are step 3
  73.  
  74. step four is the reading of the values from the input file
  75.  
  76. pg.159
  77. data placed in the input file "loan.in"
  78. YOU HAVE TO KNOW THE DATA OF THE STRUCTURE IN THE INPUT FILE BEFORE YOU WRITE YOUR PROGRAM
  79. THEY HAVE TO BE PERFECT.
  80. IN THIS CASE WHEN LOAN AMOUNT IS READ IN THE INPUT FILE WHAT IS PLACED IN THE AMOUNT
  81. LOAN AMOUNT WILL BE 50000 WILL BE READ INTO LOAN AMOUNT
  82.  
  83. UNLESS WE ARE GOING TO RE READ THE INPUT FILE THERE IS NO REASON TO CLOSE IT. IT'S AUTO CLOSED AFTER PROGRAM HAS STOPPED RUNNING.
  84. ------------------------------------------------------
  85.  
  86. inData.open("D:\\LoanIn.txt"); // could this be a little restricing? what if we want to put in a new one each day? what if we could change it as the program is running.
  87. outData.open("D:\\LoanOut.txt"); // th
  88.  
  89.  
  90. pg. 160
  91.  
  92.  
  93. file time error will not produce a run time error it's been fixed.(ignore those two paragraphs.)
  94.  
  95.  
  96. pg.162
  97. input failure
  98. input file goes into a fail state. wednessday we will get code to fix this.
  99. we will also get code on wednessday to see if input file will go into a fail state.
  100.  
  101.  
  102. 3 things input file into a fail state.
  103. (1)open statement fails
  104. (2)wrong type of data is entered
  105. (3)reach the end of the file
  106.  
  107. ------------------------------------------------------
  108. pg. 163
  109. sofware design methodologies.
  110.  
  111. pg. 170 perspective on design.
  112.  
  113. THESE DON'T BELONG IN CHAPTER 4.
  114. WE ARE NOT WRITING THES TYPE OF PROGRAMS IN CHAPTER 9
  115. these are for multiple function programs.
  116. ------------------------------------------------------
  117. We got a handout:data files
  118. Data files aren't computer programs they just hold info
  119.  
  120. // this is the input file. (DON'T PUT THAT IN A DATA FILE! YOU CAN'T PUT DATA)
  121. // DONT' PUT THE WORD FILE IN THE FILE.
  122.  
  123. Focuse on the invisible files on this page.
  124. 1. blank spaces seperate values
  125. 2. end of each of the lines of these files is an end of line character. the enter key seperates
  126. 3. end of file mark. at the end you can't see, but it's really inportant.
  127. data stored in computer files are not stored in lines they are linear.
  128.  
  129. FILE 1
  130. debra (b) Ann \n Samuel (B) Mark \n
  131. they are simply delimiters (idk how to spell that)
  132.  
  133.  
  134. ------------------------------------------------------
  135. program number 2 for chapter four is a non interactive program
  136.  
  137. we are creating a non interactive program.
  138. it will read the input data in the file above
  139.  
  140. ------------------------------------------------------
  141.  
  142.  
  143. #include <fstream>
  144. fstream PayInFile;
  145.  
  146. outstream PayOutFile;
  147.  
  148. PayFileIn.txt
  149.  
  150. ------------------------------------------------------
  151.  
  152.  
  153. #include <fstream>
  154. fstream PayInFile;
  155.  
  156. outstream PayOutFile;
  157.  
  158. PayFileIn.txt("D:\\PayFileIn.txt");
  159. PayOutFile.open("D:\\PayFileOut.txt");
  160.  
  161. ------------------------------------------------------
  162. part 3 is to open the file.
  163. so in the pay file in
  164.  
  165. 4. read the values of the input file
  166. ------------------------------------------------------
  167.  
  168.  
  169. #include <fstream>
  170. fstream PayInFile;
  171.  
  172. outstream PayOutFile;
  173.  
  174. PayFileIn.txt("D:\\PayFileIn.txt");
  175. PayOutFile.open("D:\\PayFileOut.txt");
  176.  
  177. PayInFile >>
  178. ------------------------------------------------------
  179.  
  180. //we have a big problem because we can't finish this statement before declaring some variables
  181. ------------------------------------------------------
  182.  
  183.  
  184. #include <fstream>
  185. fstream PayInFile;
  186.  
  187. char Cat1, Cat2, Cat3;
  188. int EmpNr1, EmpNr2, EmpNr3;
  189.  
  190. double pay1; pay2; pay3. //2 variables type double
  191.  
  192. outstream PayOutFile;
  193.  
  194. PayFileIn.txt("D:\\PayFileIn.txt");
  195. PayOutFile.open("D:\\PayFileOut.txt");
  196.  
  197.  
  198. PayInFile >>
  199. ------------------------------------------------------
  200. we are now ready to finish this statement
  201. ------------------------------------------------------
  202.  
  203. #include <fstream>
  204. fstream PayInFile;
  205.  
  206. char Cat1, Cat2, Cat3;
  207. int EmpNr1, EmpNr2, EmpNr3;
  208.  
  209. double pay1; pay2; pay3. //2 variables type double
  210.  
  211. outstream PayOutFile;
  212.  
  213. PayFileIn.txt("D:\\PayFileIn.txt");
  214. PayOutFile.open("D:\\PayFileOut.txt");
  215.  
  216.  
  217. PayInFile >> Cat1 >> pay1 >> EmpNr1
  218. >> cat2 >> pay2 >> EmpNr2
  219. >> cat3 >> pay3 >> EmpNr3;
  220. ------------------------------------------------------
  221.  
  222. //this is one single statement. no endl alowed.
  223. this is the first task to read the data from the input file
  224.  
  225. now we need to output the input data. write to the output data with somehting like
  226. "this output file contains the following data
  227. ------------------------------------------------------
  228.  
  229. task 3 will ask you to compute five averages.
  230. then anouther output file
  231. you may also output to the screen, but it's not required
  232. the only think you will see is press any key to continue
  233. ------------------------------------------------------
  234. how the teacher would write this program
  235. he would totally disregard if it's an output file
  236. he would use cout
  237. when it was perfect and output is exactly what I would want it to do.
  238. I would copy cout statements to the output file name
  239.  
  240. now when file runs it shows on the screena and shows up on the screen
  241. ------------------------------------------------------
  242.  
  243. you HAVE TO USE SET PRECISION.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement