Download presentation
Presentation is loading. Please wait.
1
EECs 183 Discussion 10 Hannah Westra
2
Upcoming Due Dates Final Projects Project 4 Due Today
Exam 2 Wednesday, November 16th Review Session Sunday, November 13th Lectures 1-18 with emphasis on 12-18 1D arrays, 2D arrays, filestreams, classes, testing Do NOT go by exam number - some semesters have 3 exams, and the 2-exam semesters also include python so go by topic, not exam! Final Projects Specs are out! Questions?
3
datatype name[CONST_SIZE]; datatype name[CONST_SIZE][CONST_SIZE];
Arrays datatype name[CONST_SIZE]; datatype name[CONST_SIZE][CONST_SIZE]; [0][0] [0][1] [0][2] [1][0] [1][1] [1][2] [2][0] [2][1] [2][2] ALWAYS: arr[row][col]
4
Exam Review: Array Declaration and Initialization
int my_array[5]; int my_array[] = {1, 2, 3, 4, 5}; //size of 5 int my_array[5] = {1, 2, 3, 4, 5}; int my_array[8] = {1, 2, 3, 4, 5}; //compiler will insert 0’s after 5th elt ALL VALID
5
Iterating Through 1D Arrays
int array4[14] = 0; int size4 = 9; for (int i = 0; i < size4; i++) { cout << array4[i]; }
6
Passing into Functions
void foo(int size, string arr[]); // declaration int main () { string array[2] = {“First Name”, “Last Name”}; foo(2, array); } // foo implementation somewhere down here
7
Initializing Directly
With a 2-dimensional array, the compiler absolutely needs to know the column (the second parameter) size at compile time The row is optional const int HEIGHT = 3; const int WIDTH = 4; int board[HEIGHT][WIDTH] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10 , 11, 12} }; You can also initialize all to the same thing, using nested loops
8
Filestreams
9
>_chrysanthemum Input stream USER INPUTS “chrysanthemum”
output stream >_chrysanthemum PROGRAM INPUTS “chrysanthemum”
12
Check the state of the stream
if (input_file.good()){…} // check if the stream is good ~or~ if (input_file.fail()){…} // check if the state is bad (fail bit is 1) if (!input_file.good()){...} // check if the state is bad (fail bit is 1) if (input_file){…} // check if the state is good (fail bit is 0) if (!input_file){...} // check if the state is bad (fail bit is 1) What happens when you do input_file.clear()??
13
Classes
14
Classes What is a class? A class is a container that can hold different types of objects (objects with different data types) A class is a user-defined data type Just like int and double and string are data types, so is the class you define A class is a way to group together related information Private by default
15
Parts of a Class Constructors Setters Getters Relevant functions
Default and non-default Setters Getters Relevant functions Member variables
16
Questions?
19
More Questions to Practice
1D Arrays: Fall 2012, Exam 2, Free Response, #1 2D Arrays: Winter 2015, Exam 2, Free Response, #1 File I/O: Winter 2014, Exam 3, Free Response, #2 Classes: Fall 2013, Exam 3, Free Response #4
20
Upcoming Due Dates Final Projects Project 4 Due Today
Exam 2 Wednesday, November 16th Review Session Sunday, November 13th Lectures 1-18 with emphasis on 12-18 1D arrays, 2D arrays, filestreams, classes, testing Do NOT go by exam number - some semesters have 3 exams, and the 2-exam semesters also include python so go by topic, not exam! Final Projects Specs are out! Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.