EECs 183 Discussion 10 Hannah Westra.

Slides:



Advertisements
Similar presentations
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Advertisements

1 6/20/2015CS150 Introduction to Computer Science 1 Functions Chapter 6, 8.
C++ data types. Structs vs. Classes C++ Classes.
1 11/8/06CS150 Introduction to Computer Science 1 Arrays Chapter 8 page 477 November 13, 2006.
1 11/8/06CS150 Introduction to Computer Science 1 More Functions! page 343 November 8, 2006.
CS 117 Spring 2002 Review for Exam 3 arrays strings files classes.
More C++ Bryce Boe 2013/07/18 CS24, Summer 2013 C.
Operator Overloads Part2. Issue Provide member +(int) operator Rational + int OK int + Rational Error.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
Arrays.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Defining Your Own Classes II
ECE Application Programming
EECS 183 Discussion #10: I’m actually Alex Trebek. November 15th, 2016
CMSC202 Computer Science II for Majors Lecture 09 – Overloaded Operators and More Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
Eine By: Avinash Reddy 09/29/2016.
Andrew(amwallis) Classes!
Topics: Templates Exceptions
ECE Application Programming
Pseudocode Key Revision Points.
I/O Streams File I/O 2-D array review
ECE Application Programming
COSC 220 Computer Science II
Class: Special Topics Copy Constructors Static members Friends this
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
ECE Application Programming
Templates.
CS 1430: Programming in C++.
Chapter 15 Pointers, Dynamic Data, and Reference Types
CS 2308 Exam I Review.
CS212: Object Oriented Analysis and Design
Operator Overloading; String and Array Objects
Review for Final Exam.
Topic 1: Problem Solving
CS150 Introduction to Computer Science 1
Reference Parameters.
Classes.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Multidimensional Arrays
Review for Final Exam.
CS150 Introduction to Computer Science 1
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Method of Classes Chapter 7, page 155 Lecture /4/6.
EECE.2160 ECE Application Programming
Suggested self-checks: Section 7.11 #1-11
Lecture 14 2D Arrays Richard Gesick.
Arrays Arrays A few types Structures of related data items
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
CS410 – Software Engineering Lecture #5: C++ Basics III
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Class: Special Topics Overloading (methods) Copy Constructors
C++ Array 1.
Class rational part2.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
C++ data types.
Review for Midterm 3.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Announcements Exam 2 Lecture Grades Posted on blackboard
Object Oriented Programming (OOP) Lecture No. 12
Hossain Shahriar CISC 101: Fall 2011 Hossain Shahriar
Announcements Lab 5 due Wednesday at noon.
Presentation transcript:

EECs 183 Discussion 10 Hannah Westra

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?

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]

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

Iterating Through 1D Arrays int array4[14] = 0; int size4 = 9; for (int i = 0; i < size4; i++) { cout << array4[i]; }

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

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

Filestreams

>_chrysanthemum Input stream USER INPUTS “chrysanthemum” output stream >_chrysanthemum PROGRAM INPUTS “chrysanthemum”

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()??

Classes

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

Parts of a Class Constructors Setters Getters Relevant functions Default and non-default Setters Getters Relevant functions Member variables

Questions?

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

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?