Presentation is loading. Please wait.

Presentation is loading. Please wait.

Brendan Murphy bemurphy@cs.umass.edu CS 377 Discussion 1 Brendan Murphy bemurphy@cs.umass.edu.

Similar presentations


Presentation on theme: "Brendan Murphy bemurphy@cs.umass.edu CS 377 Discussion 1 Brendan Murphy bemurphy@cs.umass.edu."— Presentation transcript:

1 Brendan Murphy bemurphy@cs.umass.edu
CS 377 Discussion 1 Brendan Murphy

2 Administrative Stuff Purpose of this discussion section
Keep up with reading and lectures (short quizzes) Review course material (working out problems) Office hours Monday: 1:15 – 2:15 Friday: 2:30 – 3:30 Room CS207 Or by appointment

3 Today: C++ Review C++ concepts Structs Classes Pointers
Worksheet + Programming Assignment

4 Structs Collection of data, short for data structure
Can have different data types Example:

5 Structs Can have multiple instances Examples:

6 Structs Fields are inherently public Example:

7 Classes Much like structs, except usually contain functions
Fields are inherently private Fields and functions grouped by access specifiers Can have multiple instances (objects) Examples:

8 Classes: Functions Two ways to do function definitions
Example of normal way:

9 Classes: Functions Example of other way:

10 Classes: Constructors
Constructors are like Java's Function name is same as class name Accepts parameters and assigns them to fields How can we modify set_values from the previous two examples to become car's constructor?

11 Pointers Variables that contain memory addresses to other variables
Declaration: type* name Examples:

12 Pointers: Referencing and Derefencing
Assign addresses of variables to pointers using the & operator Example: Access values of variables that pointers point to using the * operator The following example is a true statement:

13 Pointers: Referencing and Derefencing
If num is at memory location 100 and numPointer is at memory location 200, what are the values of the following:

14 Pointers: Referencing and Derefencing
If num is at memory location 100 and numPointer is at memory location 200, what are the values of the following:

15 Pointers: Structs and Classes
To access a field or function of a struct or class that a pointer points to, use the -> operator Examples:

16 Programming Assignment
Goal: Given a text file, determine the frequency of each word as well as what lines they're on Specifications: Create a binary search tree from the words and record their frequencies and locations Print the alphabetized list of words, the frequency of each word, and the line numbers to the console Due before next week's discussion section, submit through Moodle Skeleton code is provided!

17 Programming Assignment
Helpful classes/functions: ifstream: class to read files getline(ifstream, string): gets the next line in the file, saves to string strtok(char* str, const char* delim): multiple calls split the input string into multiple tokens, must specify delimiters string1.compare(string2): determines if string1 is alphabetically before or after string2

18 Programming Assignment


Download ppt "Brendan Murphy bemurphy@cs.umass.edu CS 377 Discussion 1 Brendan Murphy bemurphy@cs.umass.edu."

Similar presentations


Ads by Google