Start. Error Checking 03/07/11 Check for Opening Error –streams4.2/low_price.cpp.fail() true when an error has occurred –Stream function exit(1) stops.

Slides:



Advertisements
Similar presentations
L which include file needs to be used for string manipulation? what using statement needs to be included fro string manipulation? l how is a string assigned.
Advertisements

Repetition control structures
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 4 Programming with Data Files.
EXCEPTIONS Def: An exception is a run-time error. Examples include: attempting to divide by zero, or manipulate invalid data.
1 Programming with Data Files Chapter 4 2 Standard Input Output C++ Program Keyboard input cin Output Screen cout.
Chapter 5: Control Structures II (Repetition)
1 Lecture 16 Chapter 6 Looping Dale/Weems/Headington.
1 Programming with Data Files Chapter 4. 2 Standard Input Output C++ Program Keyboard input cin Output Screen cout.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Designing Algorithms Csci 107 Lecture 4.
1 Chapter 6 Looping Dale/Weems/Headington. 2 l Physical order vs. logical order l A loop is a repetition control structure based on a condition. l it.
Copyright © 2012 Pearson Education, Inc. Chapter 5 Working with Data Files.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
1 Chapter 5 File Objects and Looping Statements (Some slides have been modified from their original format)
“Here we go Loop de Loo” (Looping) So far you have learned (I hope) some decision making C++ control structures: *if (condition) else *if (condition) else.
Chapter 5: Control Structures II (Repetition)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 5: Control Structures II (Repetition)
CS Class 07 Topics –  When software goes wrong  Count controlled loops  Sentential controlled loops  putting it all together Announcements.
Chapter 6 Looping.
Chapter 5: Control Structures II (Repetition)
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
13&14-2 Know the forms of loop statements in C (while,do/while,for). Understanding how data conversion occurs. Read/Write data in files using Unix redirection.
File I/O ifstreams and ofstreams Sections 11.1 &
Program Errors and Debugging Week 10, Thursday Lab.
1 Streams In C++, I/O occurs in streams. A stream is a sequence of bytes Each I/O device (e.g. keyboard, mouse, monitor, hard disk, printer, etc.) receives.
File Input and Output in C++. Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) Keyboard Screen executing program input data.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 5: Control Structures II (Repetition)
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Control Structures II (Repetition). Objectives In this chapter you will: Learn about repetition (looping) control structures Explore how to construct.
Chapter 6 Looping CS185/09 - Introduction to Programming Caldwell College.
1 Looping. 2 Chapter 6 Topics  While Statement Syntax  Phases of Loop Execution  Two Types of Loops: Count-Controlled Loops &Event-Controlled Loops.
1 Chapter 4: Basic Control Flow ► Chapter Goals  To be able to implement decisions using if statements  To understand statement blocks  To learn how.
Outline Overview Opening a file How to create a file ? Closing a File Check End-of-file Reading a File Line by Line Reading a File Character by Character.
Chapter 11: Data Files and File Processing Files and streams Creating a sequential access file Reading data from a sequential access file Using fgetc()
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Looping ROBERT REVAES. Logical Operators  && AND  Both have to be true for it to evaluate to be true.  || OR  One or the other has to be true for.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition)
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Chapter 4 Introduction to Control Statements
Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 4 Working with Data Files.
Manipulator example #include int main (void) { double x = ; streamsize prec = cout.precision(); cout
Lecture 14 Arguments, Classes and Files. Arguments.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Advanced File Operations Chapter File Operations File: a set of data stored on a computer, often on a disk drive Programs can read from, write to.
File I/O. Files allow permanent storage of programs and data. ifstream and ofstream objects –For file I/O the inclusion of is required. –Objects for file.
Input/Output Chapters 8 & 9. Character Input n Read-char reads a single character n Read-line reads until the next end-of-line –returns a string n Both.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
Chapter 6 Looping. 2 l A loop is a repetition control structure. l it causes a single statement or block to be executed repeatedly What is a loop?
Programming II I/O Streams and Data Files 1(c) Asma AlOsaimi.
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Lecture 13 & 14.
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
CS 1428 Exam II Review.
File I/O.
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Working with Data Files
CS 1428 Exam II Review.
مفاهیم بهره وري.
Alternate Version of STARTING OUT WITH C++ 4th Edition
التدريب الرياضى إعداد الدكتور طارق صلاح.
when need to keep permanently
Iteration: Beyond the Basic PERFORM
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Data Groupings: File File: a group of related records
Programming with Data Files
Chapter 1 c++ structure C++ Input / Output
Chapter 13 Control Structures
Presentation transcript:

Start

Error Checking 03/07/11

Check for Opening Error –streams4.2/low_price.cpp.fail() true when an error has occurred –Stream function exit(1) stops execution –Must #include –Abnormal exit, 1 for error, 0 for no error Permission on the file is set so that I can't read it.

Input Stream Errors –.fail True after reading bad data Can prevent runtime error –.clear Clears error condition Program can then continue –ch4/streams4.2/btu.cpp

Checking for End-of-Data –Want to read in a list of weight of car loads of coal on a train. –Want to add them up. –Don't know exactly how many numbers in the file, coal.txt. –Want an alternative to sentinels.

Checking for End-of-Data –Algorithm: sum = 0 Input tons from stream While(not end-of-file)‏ » Add tons to train_load » Input tons from stream Output train_load.

Checking for End-of-Data –while(!wgt_in.eof( ))‏ eof returns true when attempt to read eof character is made. –In streams4.2 coal2.cpp and coal.txt

On Your Own –Modify ave.cpp so that I don't have to put a sentinel in the file.

Reading –Chapter 5 pp