Ch2_12 - Section 2.12 Using Arrays Section 2.12 Using...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Section 2.12: Using Arrays Section 2.12: Using Arrays 11 ® Arrays Part II ® Reading data from a .txt file into an array ® Reading and skipping text in .txt files ® Calling functions with arrays as arguments ® Calculations with single-indexed arrays Section 2.12: Using Arrays Section 2.12: Using Arrays Section 2.12: Using Arrays 22 ® Reading data ® at the point of read, file must contain only data ® read data using a loop, and assign to designated array member using integer indexing ® Reading text (single-indexed arrays) ® reading single words is done using a char array ® input command reads in letters until a blank is encountered ® does not require specification of number of letters in a word ® reading entire line of text uses "getline" command ® specify a character array of size 80 (e.g. char line[80]; ) ® if file input command is “indata”, would write: l indata.getline(line, 80); ® reads up to 80 characters (including spaces) into "line" when called ® character name can be anything ® Is used to echo print text from file, or skip text to access data in file Reading from a file using arrays Section 2.12: Using Arrays Section 2.12: Using Arrays 33 Reading data from a file using an array: Ex. 1 defines array to hold data open input file prints table heading uses while (data failure) loop outputs total sales to screen sales_1D_array.cpp the data file sums sales echo prints data uses for loop to read first set of data uses for loop inside while loop to read next data set salesdata.txt Section 2.12: Section 2....
View Full Document

This note was uploaded on 05/19/2008 for the course ENGR 25 taught by Professor All during the Spring '08 term at Lehigh University .

Page1 / 12

Ch2_12 - Section 2.12 Using Arrays Section 2.12 Using...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online