Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Project Wikis will be made public tonight. Presentations week 6 – next week. Slack Chat invites sent.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Winter 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assn 4 posted shortly. Demonstrate a memory leak problem using the assignment 4 solution. Back to.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
CIT 590 Intro to Programming Lecture 4. Agenda Doubts from HW1 and HW2 Main function Break, quit, exit Function argument names, scope What is modularity!
Case Study - Fractions Timothy Budd Oregon State University.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 11 Structured Data.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 5 An Array Class Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
Operator Overloading Week 5.
Operator Overloading. Binary operators Unary operators Conversion Operators –Proxy Classes bitset example Special operators –Indexing –Pre-post increment/decrement.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 RAD due Friday in your Wiki. Presentations week 6 – next week. Schedule on next slide. Today: –Operator.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 4 is due Nov. 20 (next Friday). After today you should know everything you need for assignment.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 RAD due Friday in your Wiki. Presentations week 6 – next week. Schedule on next slide. Today: –Operator.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Managers and “mentors” identified on projects page. All member accounts created and projects populated.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Presentations next week. Presentation stuff again. Finish Testing. Lots more jargon!
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Reminders: Have you filled out the questionnaire in Moodle? (23 left – as of last night). Are you able.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 How did your team meetings go? A list of three possible “adoptable” projects is linked near the bottom.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 4 is due Nov. 20 (next Friday). SDD document framework should be set up in your Wiki by now.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Today: –Two simple binding examples. –Function Hiding.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 4 is due Nov. 20 (this Friday). Today: –Templates. –STL –Smart Pointers.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Reminders: Have you filled out the questionnaire in Moodle? (3 left – as of last night). Office hours.
ECE 264 Object-Oriented Software Development
 Binary operators  Unary operators  Conversion Operators  Proxy Classes (simulating a reference) ▪ bitset example  Special operators  Indexing 
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Chapter Structured Data 11. Combining Data into Structures 11.2.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Quiz 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
Problem of the Day  Why are manhole covers round?
Today Encapsulation. Build a fully encapsulated Halloween class, going from Halloween1 to Halloween6 (eventually!): –The final version will have overloaded.
CPSC 252 Templatization Page 1 Templatization In CPSC152, we saw a class vector in which we could specify the type of values that are stored: vector intData(
Programming with ANSI C ++
User-Written Functions
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC124 Labs start this week in JEFF 155. Fall 2018
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
CISC/CMPE320 - Prof. McLeod
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Looping and Multiple Forms TEST REVIEW
Winter 2019 CISC101 4/29/2019 CISC101 Reminders
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
CISC/CMPE320 - Prof. McLeod
CMPE212 – Reminders Assignment 2 due next Friday.
Presentation transcript:

Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Project Wikis will be made public tonight. Presentations week 6 – next week. Slack Chat invites sent out. Assignment 1 sample solution posted. Today: –Gravatar –Assn 1 Algorithms. –Operator Overloading, Cont. (We have already covered what you need for assn 2.)

Presentation Schedule – Week 6 Tuesday, Oct. 20 – Basswood, Beech, Cherry, Walnut. Thursday, Oct. 22, Lecture Time – Hickory, Maple, Oak, Birch. Thursday, Oct. 22, Tutorial Time (room TBA) – Poplar, BalsamFir, Spruce, Cedar. Friday, Oct. 23 – Hemlock, JackPine, Tamarack, WhitePine. Fall 2015CISC/CMPE320 - Prof. McLeod2

Changing Your Icon If you wish to change your Redmine icon and your SlackChat icon: Go to to create your “globally recognized avatar”. It will prompt you to create a wordpress account with your and a photo. You can supply more info, but don’t have to. Use the address (queensu with netID) used with Redmine. Fall 2015CISC/CMPE320 - Prof. McLeod3

Assignment 1 Algorithm Choices The “Good, Bad & Ugly” ways to do this assignment. Focus on generating and sorting unique insults. Ugly, for example: –Append a new insult and re-sort entire vector every time. –Add enough insults, sort, then eliminate duplicates, then generate missing insults, and repeat until entire set is complete and unique. –… Fall 2015CISC/CMPE320 - Prof. McLeod4

Assignment 1 Algorithm Choices, Cont. You can make “non-ugly” choices, which can still be improved upon. Benchmark tests to generate 10,000 unique insults in order: Going from Bad to Good in milliseconds: 7349: Strings only (vector ). Sequential search followed by single coded insertion sort. 2154: Strings only. Sequential search followed by single algorithm::sort. Fall 2015CISC/CMPE320 - Prof. McLeod5

Assignment 1 Algorithm Choices, Cont. You know that comparing strings is slow compared to integers, right? Since you have three columns of phrases of 50 terms each, and they are in order (or would be easy to sort since of only size 50), then generate a “hash” code to represent an insult: hash = rand(50) * rand(50) * rand(50) Then sort and search integers instead. Fall 2015CISC/CMPE320 - Prof. McLeod6

Assignment 1 Algorithm Choices, Cont. Benchmarks in milliseconds, continued: 1165: Integer "hash". Inserting ints, keeping vector in order. Used algorithm::binary_search each pass. 852: Integer "hash". Sequential search followed by single algorithm::sort using vector. Generated insult strings with single pass. Fall 2015CISC/CMPE320 - Prof. McLeod7

Assignment 1 Algorithm Choices, Cont. 29 milliseconds!: Use a bool[50][50][50] array. Initialize all entries to false and then initialize 10,000 random positions to true. Rebuild the vector of insults in a triply nested loop, which will be in order since the phrases are already in order. No sorting or searching! Could also use a bitset object, which would be more memory efficient. Runs about the same time. Fall 2015CISC/CMPE320 - Prof. McLeod8

bool boolArray[sourceSize][sourceSize][sourceSize]; for (num1 = 0; num1 < sourceSize; num1++) for (num2 = 0; num2 < sourceSize; num2++) for (num3 = 0; num3 < sourceSize; num3++) boolArray[num1][num2][num3] = false; while (count < numInsults) { num1 = randInt(sourceSize); num2 = randInt(sourceSize); num3 = randInt(sourceSize); if (!boolArray[num1][num2][num3]) { boolArray[num1][num2][num3] = true; count++; } // end if } // end while Fall 2015CISC/CMPE320 - Prof. McLeod9

count = 0; for (num1 = 0; num1 < sourceSize && count < numInsults; num1++) for (num2 = 0; num2 < sourceSize && count < numInsults; num2++) for (num3 = 0; num3 < sourceSize && count < numInsults; num3++) if (boolArray[num1][num2][num3]) { insult = "Thou " + part1.at(num1) + " " + part2.at(num2) + " " + part3.at(num3) + "!"; insults.push_back(insult); count++; } // end if Fall 2015CISC/CMPE320 - Prof. McLeod10

Fall 2015CISC/CMPE320 - Prof. McLeod11 Overloading Conversion Operators You don’t need to write these for assignment 2. Consider that your Fraction class has top for the numerator and bottom for the denominator. To overload a cast to type double : Fraction::operator double() const { return static_cast (top) / bottom; } If test is a Fraction object, this allows stuff like: double aNum = static_cast (test);

Fall 2015CISC/CMPE320 - Prof. McLeod12 Overloading Conversion Operators, Cont. Similarly for int. Note the lack of return type. But if you have a conversion operator and an applicable conversion constructor this leads to an ambiguity: Which operator should be used in a mixed type expression? See MyComplexAmbiguous

Fall 2015CISC/CMPE320 - Prof. McLeod13 Overloading Conversion Operators, Cont. With just the constructor you can do things like: int aVal = 10; Fraction test = static_cast (aVal); Same as: Fraction test = Fraction(aVal); But you can’t do: aVal = static_cast (test);

Fall 2015CISC/CMPE320 - Prof. McLeod14 Overloading Conversion Operators, Cont. So, what’s to do? If you ditch the one number constructor, then you give yourself a lot more work when you need to overload operators for mixed expressions. Might be easiest to keep the constructor and compromise. Write member functions called intVal() and doubleVal() instead? Or declare the constructor explicit ?

Fall 2015CISC/CMPE320 - Prof. McLeod15 The explicit Keyword If you want a constructor to just be a constructor and not for use as a rule for implicit type conversions, declare it with explicit. For example: class Fraction { // etc. explicit Fraction(int); // etc. };

The explicit Keyword, Cont. If you use explicit : From the MyComplexAmbiguous demo, what is the result of a mixed type expression with a number on one side and a MyComplex instance on the other? Fall 2015CISC/CMPE320 - Prof. McLeod16

Fall 2015CISC/CMPE320 - Prof. McLeod17 Overloading the Subscript Operator: [ ] Appropriate for: –A data structure requiring access using an index. –A data structure that wants to make sure index values are legal. See the SafeArray class. –Note the two versions of operator[] used. –Note the use of a friend non-member function. –Note the use of a destructor (getting ahead of myself…)

Fall 2015CISC/CMPE320 - Prof. McLeod18 Overloading the Function Call Operator: ( ) Allows an object to behave as if it is a function. Called a function object. The only operator where the number of arguments is not fixed or limited to one or two. See the RandomInt class. Used in the STL.

Fall 2015CISC/CMPE320 - Prof. McLeod19 Aside - inline Functions Used in the RandomInt class. Used when the function body is short: –≤ 3 assignment statements. –one conditional. –one return. An inline function is not placed on the activation record stack, but is expanded in place and so is executed faster. Must be in declaration file. The downside is that a copy is made every time the function is invoked – so it should be short.