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

Slides:



Advertisements
Similar presentations
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Advertisements

Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Introduction to Programming Lecture 39. Copy Constructor.
CSCI 160 Midterm Review Rasanjalee DM.
Written by: Dr. JJ Shepherd
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
CSIS 123A Lecture 6 Strings & Dynamic Memory. Introduction To The string Class Must include –Part of the std library You can declare an instance like.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
CS 210 DATA STRUCTURES AND ALGORITHIMS Fall 2006.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 Using Member Functions and Data Members.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
Scis.regis.edu ● CS-362: Data Structures Week 4 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
1 Chapter 12 Classes and Abstraction. 2 Chapter 12 Topics Meaning of an Abstract Data Type Declaring and Using a class Data Type Using Separate Specification.
Arrays Chapter 7.
Defining Your Own Classes II
CS 106A, Lecture 27 Final Exam Review 1
Chapter 12 Classes and Abstraction
Object-Oriented Concepts
ECE Application Programming
COP2800 – Computer Programming Using JAVA
Lecture 7 Data Compression
Chapter 7 Part 1 Edited by JJ Shepherd
More about OOP and ADTs Classes
CS150 Introduction to Computer Science 1
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
Lecture 6 C++ Programming
CS 2308 Final Exam Review.
Heterogeneous aggregate datatypes
Chapter 3 Introduction to Classes, Objects Methods and Strings
CS 2308 Exam I Review.
CSS 161 Fundamentals of Computing Introduction to Computers & Java
More about OOP and ADTs Classes
CS100J Lecture 8 Previous Lecture This Lecture Programming Concepts
C-to-LC3 Compiler Over the course of the next two weeks, you will build a program that will compile C code to LC-3 assembly language Don't panic! You.
Assessment – Java Basics: Part 1
CS150 Introduction to Computer Science 1
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
CISC/CMPE320 - Prof. McLeod
From C to C++: Summary of weeks 1 - 4
Class.
C++ Introduction - 3.
A Deeper Look at Classes
Lecture 19: Working with strings
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
ENERGY 211 / CME 211 Lecture 17 October 29, 2008.
CS 2308 Final Exam Review.
Intro to Programming (in JavaScript)
SPL – PS3 C++ Classes.
CSE 303 Concepts and Tools for Software Development
Week 9 - Monday CS222.
Presentation transcript:

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

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 (bemurphy@cs.umass.edu)

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

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

Structs Can have multiple instances Examples:

Structs Fields are inherently public Example:

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:

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

Classes: Functions Example of other way:

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?

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

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:

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:

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:

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

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!

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

Programming Assignment