CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

Similar documents
Lecture 7. Log into Linux New documents posted to course webpage

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

CSI33 Data Structures

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Chapter 4. Defining Classes I

Chapter 4 Defining Classes I

Encapsulation in C++

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming

Microsoft Visual Basic 2005: Reloaded

Programming Abstractions

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

EECS168 Exam 3 Review

CS304 Object Oriented Programming Final Term

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Abstraction in Software Development

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS 2530 INTERMEDIATE COMPUTING

Dot and Scope Resolution Operator

ADTs & Classes. An introduction

What is an algorithm?

CS313D: ADVANCED PROGRAMMING LANGUAGE

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

G52CPP C++ Programming Lecture 9

Midterm Exam #2 Review. CS 2308 :: Spring 2016 Molly O'Neil

Lecture #1. Introduction to Classes and Objects

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

Topics. Topics (Continued) 7.1 Abstract Data Types. Abstraction and Data Types. 7.2 Object-Oriented Programming

Introduction to Classes

G52CPP C++ Programming Lecture 7. Dr Jason Atkin

TaxiBot New attributes Variables Math! TaxiBot

CIS 190: C/C++ Programming. Classes in C++

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

Object Oriented Design

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

CLASSES AND OBJECTS IN JAVA

CS313D: ADVANCED PROGRAMMING LANGUAGE

l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND

Object-Oriented Programming

Fast Introduction to Object Oriented Programming and C++

Principles of Object Oriented Programming. Lecture 4

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

Object-Oriented Programming Concepts

Abstract Data Types (ADT) and C++ Classes

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Defining Classes and Methods

Chapter 6 Structures and Classes. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo

C++ (Non for C Programmer) (BT307) 40 Hours

What is Class? Remember

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

TDDE18 & 726G77. Functions

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

Intermediate Programming & Design (C++) Classes in C++

Classes. C++ Object Oriented Programming Pei-yih Ting NTOU CS

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Chapter 4. Defining Classes I

C++ Important Questions with Answers

l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND

Software Design and Analysis for Engineers

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

III. Classes (Chap. 3)

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

Friend Functions and Friend Classes

CS3157: Advanced Programming. Outline

Object Oriented Programming. Solved MCQs - Part 2

UNIVERSITY OF SWAZILAND

(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University

by Pearson Education, Inc. All Rights Reserved. 2

CS11 Introduction to C++ Fall Lecture 1

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

And Even More and More C++ Fundamentals of Computer Science

5. Defining Classes and Methods

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Object Orientated Analysis and Design. Benjamin Kenwright

More C++ : Vectors, Classes, Inheritance, Templates

What will this print?

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

An Introduction to C++

C++ Coding Standards and Practices. Tim Beaudet March 23rd 2015

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

Chapter 10 Introduction to Classes

CS1004: Intro to CS in Java, Spring 2005

Programming 2. Object Oriented Programming. Daniel POP

Object oriented programming with C++

EEE-425 Programming Languages (2013) 1

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

AN OVERVIEW OF C++ 1

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

Defining Classes and Methods. Objectives. Objectives 6/27/2014. Chapter 5

Introduction & Review

CS 302: Introduction to Programming in Java. Lecture 15

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations

Lecture 7: Data Abstractions

Transcription:

CMPT 117: Tutorial 1 Craig Thompson 12 January 2009

Administrivia Coding habits OOP Header Files Function Overloading

Class info Tutorials Review of course material additional examples Q&A Labs Work on assignments Get help with specific problems Textbook Website http://www.cs.colorado.edu/~main/dsoc.html Lecture slides, sample code, example exam questions, etc.

Contact info Email: cdt830@mail.usask.ca web: http://www.cs.usask.ca/~cdt830/cmpt117 discussion forum: ihelp.usask.ca

How to approach the assignments the assignment specification will give you a rough idea of what you are supposed to do If you don t understand part of the assignment requirements, ask the professor Write (not code) a detailed description of all of the steps in the assignment Write descriptions of all of the files, classes, functions, etc that you will need

Preconditions & Postconditions Preconditions: specify what must be true when a function is called Postconditions: specify what will be true when a function returns, if the preconditions were true

test your code make a list of ways you can test your code (test cases) you may be required to hand in a description of how you tested your code

Object Oriented Programming Objects vs Classes Encapsulation Separation of Concerns

Classes like struct, but can include variables AND functions access variables within a class by using the dot operator after defining a class, we can declare variables of the new type

member functions define the behavior of a class accessed using the dot operator ensure that the class is used in a consistent manor

information hiding you may want to ensure that a class is only accessed through its member functions public members can be accessed by anyone also called the interface to the class private members can only be accessed by member functions

information hiding How do you get the value of a private variable? make a public member function that returns the value! also called the interface to the class private members can only be accessed by member functions

Constructors one or more functions used to initialize the variables of an object has the same name as the class can take parameters does not have a return type constructors are called when the object is created

function headers and definitions help to improve readability of your code don t need to know about how the function is implemented remove multi-line function definitions from the class definition place long definitions after the class, prepend classname:: to functions

Accessors and Mutators Mutator methods change values within the class Accessor methods don t change values within the class adding the keyword const ensures that the function cannot change the values

parameter passing pass by value creates a copy of the value and sends the copy to the function protects original variable from being changed slow pass by reference sends the location of the variable to the function the original variable can be changed fast

Protecting pass-by-reference parameters from change declare them const only accessor methods can be called on const parameters

Header Files Why: separate what the functions do from how they do it header files (.h) include: class definitions function prototypes global variables header file (.h) contains what the class does, the implementation file (.cpp) contains how the class works #include filename.h

Macro Guards prevent a file from being included multiple times page 53 in the textbook

default parameters default parameters can be used to reduce the number of functions in your code page 65 in the textbook default parameters go in the function prototype (.h file

function overloading we want one function that can operate on multiple datatypes (int, float, double, etc.) convert inputs: write one function, and convert the inputs to match the parameters of the function (slow, may generate warnings for type conversions) write multiple functions: no type conversions, but the code gets messy, and there are multiple functions that are nearly identical overloading: write multiple functions with the same name, but different parameters and return types (for ints, floats, doubles, etc.)