Class Notes (999,625)
US (389,917)
Santa Clara (847)
CSCI (23)
CSCI 10 (18)
Bannister (16)
Lecture 20

CSCI 10 Lecture 20: CSCI 10 – Day 20
Premium

2 Pages
49 Views
Fall 2016

Department
Computer Science
Course Code
CSCI 10
Professor
Bannister
Lecture
20

This preview shows half of the first page. Sign up to view the full 2 pages of the document.
CSCI 10 Day 19
FILE I/O
Announcements:
-Homework 7 is due Friday!
-Midterm grades: Mean = 80% and Median = 86%!
-STS Presentation details on webpage today!
LECTURE
-Final version of grading program: now with files
-Requirement: user should not need to modify code
-User input will look like:
Michael Bannister, 50, 80, 95
*Keep in mind for your program design that some countries use commas
for decimal points…
-Output will look like:
Michael Bannister, 50, 80, 95, xy.z, C // the last two are percentage and
letter grade
Streams
-We dump data into (<<) output streams, e.g. cout
-We pull data out of (>>) input streams, e.g. cin
-Note: streams ignore whitespace
Why do we want files?
-Long-term/permanent storage
-Large amounts of data (more than that would fit in RAM)
-File reading/writing is sequential, must be read front to back
File objects
-Need to #include <fstream>
-In file stream: ifstream
-Out file stream: ofstream
-Basic operations: open, <<, >>, close and fail
-we will use object operations (dot syntax)
-Ways you could fail at opening a file:
-File not found
-Wrong format
-No permission to read (not to some network resources)
Reading from a file
ifstream in_stream;
in_stream.open("input.txt");
if (in_stream.fail()) {
cout << "Failed to open input.txt" << endl;
exit(1);
find more resources at oneclass.com
find more resources at oneclass.com

Loved by over 2.2 million students

Over 90% improved by at least one letter grade.

Leah — University of Toronto

OneClass has been such a huge help in my studies at UofT especially since I am a transfer student. OneClass is the study buddy I never had before and definitely gives me the extra push to get from a B to an A!

Leah — University of Toronto
Saarim — University of Michigan

Balancing social life With academics can be difficult, that is why I'm so glad that OneClass is out there where I can find the top notes for all of my classes. Now I can be the all-star student I want to be.

Saarim — University of Michigan
Jenna — University of Wisconsin

As a college student living on a college budget, I love how easy it is to earn gift cards just by submitting my notes.

Jenna — University of Wisconsin
Anne — University of California

OneClass has allowed me to catch up with my most difficult course! #lifesaver

Anne — University of California
Description
CSCI 10 Day 19 FILE IO Announcements: Homework 7 is due Friday! Midterm grades: Mean = 80 and Median = 86! STS Presentation details on webpage today! LECTURE Final version of grading program: now with files Requirement: user should not need to modify code User input will look like: Michael Bannister, 50, 80, 95 *Keep in mind for your program design that some countries use commas for decimal points Output will look like: Michael Bannister, 50, 80, 95, xy.z, C the last two are percentage and letter grade Streams We dump data into (<>) input streams, e.g. cin Not
More Less
Unlock Document

Only half of the first page are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

You've reached the limit of 4 previews this month

Create an account for unlimited previews.

Already have an account?

Log In


OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit