12
March 27 - Files Big Idea: I will know how to create software that can open and save to files Minds On: Learn how to learn Action: File Review Consolidation: Continue or move on?

March 27 - Files Big Idea: I will know how to create software that can open and save to files Minds On: Learn how to learn Action: File Review

Embed Size (px)

Citation preview

Page 1: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

March 27 - Files Big Idea: I will know how to create

software that can open and save to files Minds On: Learn how to learn Action: File Review Consolidation: Continue or move on?

Page 2: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

Learn how to learn What strategies do you use to be

successful in school? How do you learn independently?

Page 3: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

What strategies do you use to be successful in school?

Organization

In class/on time

Do your homework

Stay awake

Stay focused

Stay clean

Page 4: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

How do you learn independently?

Research

Practice

Trial and error

Have initiative

Read a book

Youtube

Be responsibl

e

Time table plan

Page 5: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

File Streams

D r e w   8 4 Cr Lf

T i a   9 2 Cr Lf

-1

Page 6: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

//Example 3 System.IO.FileInfo textFile3 = new

System.IO.FileInfo("wonder.txt"); System.IO.StreamReader readFile; String lineOfText;

Page 7: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

try { readFile = new

System.IO.StreamReader(textFile3.FullName); while ((lineOfText = readFile.ReadLine()) != null) { Console.WriteLine(lineOfText); } readFile.Close(); }

Page 8: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

catch (Exception e) { Console.WriteLine("File does not exist

or could not be found."); Console.WriteLine(e.Message); }

Page 9: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

YOUR TASK Create a console application called u3MMDDReadFileName

that reads and then displays the contents of a file containing instructions for this assignment. Use Notepad to create the file and be sure it is saved as a Text file (TXT). The application will need to include the correct path to the location. Bonus marks if you can figure out how to do it without a path!

AND ANOTHER TASK Create a program called u3MMDDReadNumbersName that

reads a text file that has a number on each line. As each line is read the number should be output and the number should be added to a variable called intTotal. Another variable intNumbOfItems is increased by one. Once the file is finished, then the average is calculated and displayed.

Page 10: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

FileInfo dataFile = new FileInfo("scores.dat");

StreamReader readFile; String score; Double avgScore; Double totalScores = 0; Int32 numScores = 0;

Page 11: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

try { readFile = new StreamReader(dataFile.FullName); while ((score = readFile.ReadLine()) != null) { numScores += 1; Console.WriteLine(score); totalScores += Double.Parse(score); } avgScore = totalScores / numScores; Console.WriteLine("Average = " + avgScore); readFile.Close(); }

Page 12: March 27 - Files  Big Idea: I will know how to create software that can open and save to files  Minds On: Learn how to learn  Action: File Review

catch(Exception ex){ Console.WriteLine("The following error

occurred: "); Console.WriteLine(ex.Message); }