Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Programing notes for monday of 2-8-15
- ----------------------------------------
- Winds was blowing like crazy outside so we talked about that a bit
- x 1 doesn't work, but x 2 does in mathamatics guy's program
- teacher taught programing in 9 other programing languages, lol. never has he used the word stream till C++
- ------------------------------------------------------
- last week we talked about c in this week we are goint to talk aobut
- NON INTERACTIVE PROGRAMS
- 1. input form an input file
- 2. output from an output file
- 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...
- We only use interactive programs when the amount intered into the program is small.
- when you have 100 pieces of data you need to input while the program is running is awful.
- what if instead throughout the week we had them put the info down into an input file.
- 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.
- They make a mistake no big deal. The can back space and move to the start of the file.
- ------------------------------------------------------
- Instead of putting output to the screen we can put it to and output file and don't have to run the program again
- (alternative to print screen and then paste in word)
- ------------------------------------------------------
- pg. 153
- Stream is to vague of a word, and we can't have vague in programing.
- ifstream inFile;
- ofstream outFile'
- (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() )
- ifstream inData;
- ofstream outData;
- 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.
- ------------------------------------------------------
- pg. 154
- best place to create visual studio ide. (new text file. not microsoft word. you can use note pad or notpad ++)
- inData.open("D:\\LoanIn.txt"); // This is found on the jumpdrive. always use two backslashes.
- // "inData"this is an internal file name. this name doesn't exist outside of your file name. loanin is an external file name.
- // 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
- ------------------------------------------------------
- output file
- outData.open("D:\\LoanOut.txt"); // this file won't exist till after program runs. This is placing it on the flash drive
- // now the file the second time it runs. It will replace it and erase it so the new input goes into the file clean.
- ------------------------------------------------------
- pg. 156
- Step 4:
- //Look at the syntext it looks like cin. It is exactly like cinn.
- //just input file name for cout and it works just fine.
- inData >> LoanAmount >> yearlyInterest >> NumberOfYears;
- //input buffer input file is the input buffer.
- fixed set precision. do you need to do that twice. you only need to do that once
- fixed and set precision are set manips no need to do it twice.
- sets it to four then wants it to go back to two
- ------------------------------------------------------
- pg. 158
- program where the code we've just been talking about has been inbedded with this program
- step one in this program is
- include fstream
- include file variable
- open statements are step 3
- step four is the reading of the values from the input file
- pg.159
- data placed in the input file "loan.in"
- YOU HAVE TO KNOW THE DATA OF THE STRUCTURE IN THE INPUT FILE BEFORE YOU WRITE YOUR PROGRAM
- THEY HAVE TO BE PERFECT.
- IN THIS CASE WHEN LOAN AMOUNT IS READ IN THE INPUT FILE WHAT IS PLACED IN THE AMOUNT
- LOAN AMOUNT WILL BE 50000 WILL BE READ INTO LOAN AMOUNT
- 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.
- ------------------------------------------------------
- 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.
- outData.open("D:\\LoanOut.txt"); // th
- pg. 160
- file time error will not produce a run time error it's been fixed.(ignore those two paragraphs.)
- pg.162
- input failure
- input file goes into a fail state. wednessday we will get code to fix this.
- we will also get code on wednessday to see if input file will go into a fail state.
- 3 things input file into a fail state.
- (1)open statement fails
- (2)wrong type of data is entered
- (3)reach the end of the file
- ------------------------------------------------------
- pg. 163
- sofware design methodologies.
- pg. 170 perspective on design.
- THESE DON'T BELONG IN CHAPTER 4.
- WE ARE NOT WRITING THES TYPE OF PROGRAMS IN CHAPTER 9
- these are for multiple function programs.
- ------------------------------------------------------
- We got a handout:data files
- Data files aren't computer programs they just hold info
- // this is the input file. (DON'T PUT THAT IN A DATA FILE! YOU CAN'T PUT DATA)
- // DONT' PUT THE WORD FILE IN THE FILE.
- Focuse on the invisible files on this page.
- 1. blank spaces seperate values
- 2. end of each of the lines of these files is an end of line character. the enter key seperates
- 3. end of file mark. at the end you can't see, but it's really inportant.
- data stored in computer files are not stored in lines they are linear.
- FILE 1
- debra (b) Ann \n Samuel (B) Mark \n
- they are simply delimiters (idk how to spell that)
- ------------------------------------------------------
- program number 2 for chapter four is a non interactive program
- we are creating a non interactive program.
- it will read the input data in the file above
- ------------------------------------------------------
- #include <fstream>
- fstream PayInFile;
- outstream PayOutFile;
- PayFileIn.txt
- ------------------------------------------------------
- #include <fstream>
- fstream PayInFile;
- outstream PayOutFile;
- PayFileIn.txt("D:\\PayFileIn.txt");
- PayOutFile.open("D:\\PayFileOut.txt");
- ------------------------------------------------------
- part 3 is to open the file.
- so in the pay file in
- 4. read the values of the input file
- ------------------------------------------------------
- #include <fstream>
- fstream PayInFile;
- outstream PayOutFile;
- PayFileIn.txt("D:\\PayFileIn.txt");
- PayOutFile.open("D:\\PayFileOut.txt");
- PayInFile >>
- ------------------------------------------------------
- //we have a big problem because we can't finish this statement before declaring some variables
- ------------------------------------------------------
- #include <fstream>
- fstream PayInFile;
- char Cat1, Cat2, Cat3;
- int EmpNr1, EmpNr2, EmpNr3;
- double pay1; pay2; pay3. //2 variables type double
- outstream PayOutFile;
- PayFileIn.txt("D:\\PayFileIn.txt");
- PayOutFile.open("D:\\PayFileOut.txt");
- PayInFile >>
- ------------------------------------------------------
- we are now ready to finish this statement
- ------------------------------------------------------
- #include <fstream>
- fstream PayInFile;
- char Cat1, Cat2, Cat3;
- int EmpNr1, EmpNr2, EmpNr3;
- double pay1; pay2; pay3. //2 variables type double
- outstream PayOutFile;
- PayFileIn.txt("D:\\PayFileIn.txt");
- PayOutFile.open("D:\\PayFileOut.txt");
- PayInFile >> Cat1 >> pay1 >> EmpNr1
- >> cat2 >> pay2 >> EmpNr2
- >> cat3 >> pay3 >> EmpNr3;
- ------------------------------------------------------
- //this is one single statement. no endl alowed.
- this is the first task to read the data from the input file
- now we need to output the input data. write to the output data with somehting like
- "this output file contains the following data
- ------------------------------------------------------
- task 3 will ask you to compute five averages.
- then anouther output file
- you may also output to the screen, but it's not required
- the only think you will see is press any key to continue
- ------------------------------------------------------
- how the teacher would write this program
- he would totally disregard if it's an output file
- he would use cout
- when it was perfect and output is exactly what I would want it to do.
- I would copy cout statements to the output file name
- now when file runs it shows on the screena and shows up on the screen
- ------------------------------------------------------
- you HAVE TO USE SET PRECISION.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement