Announcements Final Exam:. Review Passing Arrays as Parameters Pass Array Name into Function int intArray[100]; func(intArray); Accept into Function as.

Slides:



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

Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
C++ provides the following classes to perform output and input of characters to/from files: ofstream: Stream class to write on filesofstream ifstream:
Passing Streams to Functions. Passing Streams to Functions One Rule: always pass a stream as a reference.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 8- 1 Overview 8.1 An Array Type for Strings 8.2 The Standard string.
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.
File streams Chapter , ,
1 Engineering Problem Solving With C++ An Object Based Approach Chapter 4 Programming with Data Files.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
1 CS 105 Lecture 8 Strings; Input Failure Mon, Mar 7, 2011, 3:39 pm.
1 CS 105 Lecture 12 Pass- By-Reference, 2-D Arrays Version: Wed, Apr 20, 2011, 6:25 pm.
Engineering Problem Solving With C++ An Object Based Approach Chapter 6 One-Dimensional Arrays.
#include using namespace std; void main() { int a[3]={10,11,23}; for(int i=0;i
1 CS 105 Lecture 9 Files Version of Mon, Mar 28, 2011, 3:13 pm.
1 CS 105 Lecture 13Vectors version of Wed, Apr 27, 2011, 6:20 pm.
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
File Review Declare the File Stream Object Name –ofstream for output to file –ifstream for input from file Associate a File Name with the File Stream Object.
Upcoming Events Project Check Due Next Week in Lab –Phase I –main(), menu() Functions and Reading in File –Stub Functions Last Lectures Next Week –Project.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Chapter 6 One-Dimensional Arrays ELEC 206 Computer Tools for Electrical Engineering.
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
ITEC 320 C++ Examples.
File I/O ifstreams and ofstreams Sections 11.1 &
File I/O 1 ifstreams and ofstreams Sections 11.1 & 11.2.
TEXT FILES. CIN / COUT REVIEW  We are able to read data from the same line or multiple lines during successive calls.  Remember that the extraction.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Fundamentals of C++ Yingcai Xiao 09/03/08. Outline Class Definition IO Template vector C Pointer Dynamic Memory Allocation.
1 Original Source : and Problem and Problem Solving.ppt.
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,
CSE 332: C++ IO We’ve Looked at Basic Input and Output Already How to move data into and out of a program –Using argc and argv to pass command line args.
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
Quiz 2 Results. What Is Wrong? #include using namespace std int Main() { // Say Hello 4 times for(i == 0; i < 3; i++) { cout >> "Hello World!"
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Chapter 8CS 140 Using The C++ Standard string Class #include #include using namespace std; void main() { string firstName = "Fred"; string lastName =
Input/Output CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
File Handling in C++.
Streams One of the themes of this course is that everything can be reduced to simple (and similiar) concepts. Streams are one example. Keyboard and Screen.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 9. Streams & Files.
Module 1: Array ITEI222 - Advance Programming Language.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 6 I/O Streams as an Introduction to Objects and Classes.
Std Library of C++ Part 2. vector vector is a collection of objects of a single type vector is a collection of objects of a single type Each object in.
Files To read a file – We must know its name – We must open it (for reading) – Then we can read – Then we must close it That is typically done implicitly.
1 Chapter 1 C++ Templates Readings: Sections 1.6 and 1.7.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students File Input and Output Checking input for errors.
CS 1430: Programming in C++ 1. File Input in VS Project Properties Debugging Command Arguments quiz8-1.out We want to know how to do it ourselves, right?
Array. Array is a group of data of the same type. Array elements have a common name –The array as a whole is referenced through the common name Individual.
Arrays as Function Parameters. CSCE 1062 Outline  Passing an array argument (section 9.3)  Reading part of an array (section 9.4)  Searching and sorting.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 19: Container classes; strings.
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
Hank Childs, University of Oregon
Lab 7: File Input/Output Graham Northup
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:
FILE INPUT OUTPUT Skill Area 315 Part B Materials Prepared by
Quiz Next Monday.
group work #hifiTeam
More About File Reading
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
Programming with Data Files
File Review Declare the File Stream Object Name
File I/O.
Function Defaults C++ permits functions to be declared with default values for some, or all, of its parameters Allows for the function to be called without.
CHAPTER 4 File Processing.
COP 3330 Object-oriented Programming in C++
Using string type variables
(Dreaded) Quiz 2 Next Monday.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
File I/O in C++ I.
Announcements Exam 2 Lecture Grades Posted on blackboard
Presentation transcript:

Announcements Final Exam:

Review Passing Arrays as Parameters Pass Array Name into Function int intArray[100]; func(intArray); Accept into Function as an Array with No Set Size int func( int array[] ) Changes to Array in Function *will* Update Original Array

getline() Function Interface Function to an Input Stream Object (i.e., a File Open for Reading) Reads an Entire Line from the File Including White Space Example: ifstream inputFile; string lineOfText; inputFile.open(“datafile”); getline(inputfile,lineOfText);

getline() Function #include using namespace std; int main() { string phrase; cout << "Enter a phrase: "; getline(cin, phrase); cout << phrase << endl; return(0); }

Vectors A Vector Is a Resizable Array Must Include File Declaration of Vector Syntax: vector variableName; vector variableName( size ); vector variableName( size, initialValue );

#include using namespace std; int main() { vector vals1; vector vals2(5); vector vals3(5,100); return(0); }

Using Vectors May Access Data the Same as Arrays Use Square Brackets ( [ ] )

#include using namespace std; int main() { vector vals1; vector vals2(5); vector vals3(5,100); vals2[0] = 6; cout << vals3[2]; return(0); }

Vector Public Functions Remember: ofstream Type Has Public Functions open() and close() Vector Has Public Functions as Well: –resize(int) to Change the Size of the Vector (usually larger) –size() to Return the Current Number of Members in the vector –push_back(elem) to add a new element (of type in vector) to end of vector

#include using namespace std; int main() { vector vals1; vector vals2(5); vector vals3(5,100); vals2[0] = 6; cout << vals3[2] << endl; vals1.resize(50); cout << vals1.size() << endl; vals1.push_back(vals2[0]); return(0); }