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:

Slides:



Advertisements
Similar presentations
Getting Data into Your Program
Advertisements

Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
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.
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 Programming with Data Files Chapter 4 2 Standard Input Output C++ Program Keyboard input cin Output Screen cout.
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.
Programming with Data Files Chapter 4. Standard Input Output C++ Program Keyboard input cin Output Screen cout.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
1 File I/O 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.
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.
Lecture 6: Expressions and Interactivity (Part II) Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
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.
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!"
Chapter 11 Standard C++ Strings and File I/O Dept of Computer Engineering Khon Kaen University.
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.
Writing to Files and Reading From Files. Writing Data to a File Creating a new file, a.dat or.txt file #include #include // for file writing #include.
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.
1 Stream Input and Output Read Text, page Keyboard and Screen I/O #include cin (of type istream) cout (of type ostream) KeyboardScreen executing.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Eight: Streams Slides by Evan Gallagher.
ARRAYS.
Working with Batches of Data
File Processing.
ifstreams and ofstreams
MT262A Review.
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Pointers & Arrays.
Lecture 9 Files, Pointers
Problems With Character Arrays
CS3340 – OOP and C++ L. Grewe.
Copyright © 2003 Pearson Education, Inc.
C++ Arrays.
A solution to a list of records
Quiz Next Monday.
More About File Reading
Interactive I/O Input from keyboard Must prompt user User friendly
Strings A collection of characters taken as a set:
Starting Out with C++: From Control Structures through Objects
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
Programming with Data Files
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.
Chapter 9 File Streams Computing Fundamentals with C++ 3rd Edition
Struct Data Type in C++ What Are Structures?
Standard Input/Output Stream
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Chapter 3 Input output.
CS150 Introduction to Computer Science 1
File I/O in C++ I.
Formatted Input, Output & File Input, Output
CS150 Introduction to Computer Science 1
CHAPTER 4 File Processing.
Fundamental Programming
Pointers & Arrays.
Reading from and Writing to Files
Programming with Data Files
Reading Data From and Writing Data To Text Files
Using string type variables
STL and Example.
(Dreaded) Quiz 2 Next Monday.
ifstreams and ofstreams
COMS 261 Computer Science I
Programming Strings.
File I/O in C++ II.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Lecture 9 Files Handling
File I/O in C++ I.
Input / output (i/o) Acknowledgement: THE Slides are Prepared FROM SLIDES PROVIDED By NANCY M. AMATO AND Jory Denny.
Reading from and Writing to Files
Text Files.
Presentation transcript:

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: int id[NUM_STUDENTS]; double gpa[NUM_STUDENTS]; The array id contains the id for each student. The array gpa contains the gpa for each student. id[0] represents the id for the first student. gpa[0] represents the gpa for the first student. The arrays are called parallel arrays because the data stored in id[i] and gpa[i] relate to the ith student.

Parallel Arrays Example: int id[NUM_STUDENTS]; double gpa[NUM_STUDENTS]; id[0] if[1] id[2] id[3] id[4] id[5] 3423 gpa[0] gpa[1] gpa[2] gpa[3] gpa[4] gpa[5] 3.56 1254 3.65 4532 2.89 2341 1.99 1242 2.77 5673 3.45

Parallel Arrays Assignment # 13: Ref. Election program posted on the Internet/ textbook. Parallel Arrays are: string name[100]; int age[100];

How to get the first character of a string #include <iostream> #include <string> int main() { string inputStr; cin >> inputStr; // if you enter john, your program will display j cout << inputStr . substr(0,1) <<endl; return 0; }

How to get the first character of a string from an array of strings #include <iostream> #include <string> int main() { string inputStr[]={“John", "Robin"};; cout << inputStr[0] . substr(0,1) <<endl; return 0; }

How to get input from file and write to a file #include <iostream> #include <string> #include <fstream> #include <iomanip> int main() { string name[2]; ifstream inFile; ofstream outFile; inFile.open("c:\input.dat");

Continued if (!inFile) { cout << "Can't open it"; return 1; } outFile.open("c:\output.dat"); inFile >> name[0] >> name[1]; //cout << name[0] <<endl; //cout << name[1] <<endl; outFile << name[0] << " "<< name[1]; return 0;