General Computer Science for Engineers CISC 106 Lecture 35 Roger Craig Computer and Information Sciences 05/15/2009.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

Files Used to transfer data to and from disk. Opening an Output File Stream #include // File stream library. ofstream outfile;// Declare file stream variable.
C++ provides the following classes to perform output and input of characters to/from files: ofstream: Stream class to write on filesofstream ifstream:
CS 1620 File I/O. So far this semester all input has been from keyboard all output has been to computer screen these are just two examples of where to.
© 2000 Scott S Albert Structured Programming 256 Chapter 7 Streams and File I/O.
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 4 Programming with Data Files.
File I/O. COMP104 Lecture 20 / Slide 2 Using Input/Output Files * A computer file n is stored on a secondary storage device (e.g., disk) n is permanent.
Computer Skills2 for Scientific Colleges 1 File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
1 Lecture 31 Handling Selected Topics Again!! File I/O Special Lectures.
File I/O. COMP104 Lecture 20 / Slide 2 Using Input/Output Files (Review) * A computer file n is stored secondary storage devices (hard drive, CD) n can.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
File I/O. COMP104 File I/O / Slide 2 Using Input/Output Files * A computer file n is stored on a secondary storage device (e.g., disk) n is permanent.
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
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.
General Computer Science for Engineers CISC 106 Lecture 26 Dr. John Cavazos Computer and Information Sciences 04/24/2009.
This set of notes is adapted from that provided by “Computer Science – A Structured Programming Approach Using C++”, B.A. Forouzan & R.F. Gilberg, Thomson.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Chapter 3 Interactivity and Expressions CSC 125 Introduction to C++ programming.
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
String Constructors string str; // creates an empty //string string str(“abc”); // creates a string // from a C-string string str(aString); // creates.
STREAMS AND FILES OVERVIEW.  Many programs are "data processing" applications  Read the input data  Perform sequence of operations on this data  Write.
C++ Introduction : C++ compilation. Visual Studio 2008 : Creating Command-Line Program.
1 CS161 Introduction to Computer Science Topic #13.
Topics 1.File Basics 2.Output Formatting 3.Passing File Stream Objects to Functions 4.More Detailed Error Testing 5.Member Functions for Reading and 6.Writing.
COP 3530 Data Structures & Algorithms Discussion Session 3.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
Computer Programming TCP1224 Chapter 13 Sequential File Access.
File I/O in C++ II. Open() function Open() is a member function in each classes ( fstream, ifstream, ofstream) Void fstream :: open ( const char *filename,
COMP102 Lab 071 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
Chapter 11 Standard C++ Strings and File I/O Dept of Computer Engineering Khon Kaen University.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 9. Streams & Files.
Program Input and the Software Design Process ROBERT REAVES.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 6 I/O Streams as an Introduction to Objects and Classes.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Today’s Lecture  I/O Streams  Console I/O  File I/O  Tools for File I/O  Sequential.
File I/O in C++. Using Input/Output Files A computer file  is stored on a secondary storage device (e.g., disk);  is permanent;  can be used to provide.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
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.
 Data Streams  Numeric Output  Numeric Input  Multiple Numeric Output  Multiple Numeric Input  Character Output  Character Input  String Output.
General Computer Science for Engineers CISC 106 Lecture 27 Dr. John Cavazos Computer and Information Sciences 04/27/2009.
Computer Programming II Lecture 9. Files Processing - We have been using the iostream standard library, which provides cin and cout methods for reading.
Chapter 14: Sequential Access Files
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Topics discussed in this section:
Parallel Arrays Parallel array =>Two or more arrays with the same number of elements used for storing related information about a collection of data. Example:
Basic File I/O and Stream Objects
Programming with Data Files
Today’s Lecture I/O Streams Tools for File I/O
Sequential input and output Operations in file
Text Files All the programs you've seen so far have one thing in common: Any data the program uses or calculates is lost when the program ends. In order.
Standard Input/Output Stream
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
File I/O.
Introduction to C++ Programming Language
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
File I/O.
CS150 Introduction to Computer Science 1
CHAPTER 4 File Processing.
Reading from and Writing to Files
File I/O in C++ II.
Reading from and Writing to Files Part 2
File I/O in C++ I.
Topics discussed in this section:
Reading from and Writing to Files
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 35 Roger Craig Computer and Information Sciences 05/15/2009

Lecture Overview  Evaluation forms  Filtering using the strcmpi function in matlab  Writing to a file in matlab  Reading and writing to a file in C++  Using the C++ string class

Strcmpi function in Matlab Strcmpi = strcmp but case insensitive For completeness: Strncmp = strcmp for first n characters Demo (Note on code: strcmpiDemo.m writeToFileDemo.m fileInput.cc fileOutput.cc readLineByLine.m can all be copied from /www/htdocs/CIS/106/cavazos/09S/examples/ on strauss.udel.edu

File I/O in Matlab Inputting a file, many ways, textread is one of the straightforward. Outputting to a file, e.g. saving a new playlist Fprintf is most straightforward way; demo

File I/O in C++ File I/O Uses fstream (file streams) Will make variables of type ofstream and ifstream

C++ string class Strings in C++ are variables of type string class #include (NB: strings in C are arrays of characters) (51-53 of Ullmann and Signer; also ) What is a class? (Chapter 7 of U&S) Formal model of an object. An instance of a class is an object. e.g. string line2 = “some text”; line2 is an object of type string class

C++ string class Why use classes and objects? For one, they can have built in functions (methods) e.g. string s = “abcdefgh”; int k = s.length(); char c = “c”; int j = s.find(c); cout << j << endl; List of other string functions/methods: string.html And

C++ string class More examples e.g. string s1 = “abcdefgh”; string s2 = “zyxw”; int j = s1.compare(s2); // just think of this as < (less than) cout << j << endl;

Questions?

Correlation