Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 Announcements Final Exam:

2 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

3 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);

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

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

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

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

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

9 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

10 #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); }


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

Similar presentations


Ads by Google