Presentation is loading. Please wait.

Presentation is loading. Please wait.

CISC/CMPE320 - Prof. McLeod

Similar presentations


Presentation on theme: "CISC/CMPE320 - Prof. McLeod"— Presentation transcript:

1 CISC/CMPE320 - Prof. McLeod
Winter 2013 CISC/CMPE320 9/22/2018 CISC/CMPE320 Notices: Assignment 1 due tomorrow 7pm. Teamwork: RAD will be due at the end of next week as a document in Confluence. Fall 2017 CISC/CMPE320 - Prof. McLeod Prof. Alan McLeod

2 CISC/CMPE320 - Prof. McLeod
Today RAD – slightly different requirements than what was listed on the group project page. See the next few slides. Start Operator Overloading. Fall 2017 CISC/CMPE320 - Prof. McLeod

3 Project Deliverable – the RAD
The purpose of this deliverable is to make sure you have started on the design of your app. You don’t need to have written any code, but after you have created the RAD, you should have a pretty good overall idea of what you are building. You still may not have decided on the architectural details (see the SDD for this!). Fall 2017 CISC/CMPE320 - Prof. McLeod

4 Project Deliverable – the RAD, Contents
A broad-view summary of what you are planning to build. Consider inputs and outputs and what you are trying to accomplish. Who are the target user(s)? A diagram might best describe these concepts. If you are building a game, what parameters are you going to adjust to ensure the playability of the game? A list of functional requirements. You may have been calling these “features”. What exactly does the program have to do, and in what order? Sketches or prototypes of the GUI interface (all windows) along with a description of how the user will navigate through the interface. A list of the other roles assigned to each team member, on the assumption that everyone is a coder first. Fall 2017 CISC/CMPE320 - Prof. McLeod

5 Project Deliverable – the RAD, Cont.
The information listed above does not have a natural representation in Jira other than in a document in Confluence. So, that is where it should be. As you expand on the design, you will start creating issues and tasks that have a time to completion that you can estimate (at least in relative terms). These will form successive sprints. So, we also want to see some activity in Jira: Fall 2017 CISC/CMPE320 - Prof. McLeod

6 Project Deliverable, Cont.
We want to see demonstrable activity in Jira, HipChat and BitBucket: Jira – we want to see lots of project related issues and at least one sprint in progress or just completed. Can you create enough issues to plan to project completion? Are all team members involved in the process? Are all issues assigned so as to even out the workload? Has everyone created a diary page in Confluence? Fall 2017 CISC/CMPE320 - Prof. McLeod

7 Project Deliverable, Cont.
HipChat – has the chat been used by everyone on the team? (We will not read your logs in detail, so don’t worry!) BitBucket – has the repository been used? Does everyone have a working git client? Has everyone submitted a test commit and/or created a branch? We don’t expect to see code in the repository, yet, but you need to be ready to do so! Fall 2017 CISC/CMPE320 - Prof. McLeod

8 Operator Overloading in Java
You should remember that the binary + operator is overloaded in Java: is 5 “two” + “three” is “twothree” 2 + “three” is “2three” “two” is “two3” So the result of the operator depends on the type of the operands. If there is a String literal on one side then the other side is converted to a String and a concatenation takes place. Fall 2017 CISC/CMPE320 - Prof. McLeod

9 + and string Objects in C++
string two("two"); string three("three"); string sum1 = two + three; // sum1 is "twothree" string sum2 = 2 + three; // doesn’t work Note that a string literal is actually a char* object and the + operator does not work with them if they are on both sides of the operator. Fall 2017 CISC/CMPE320 - Prof. McLeod

10 + and string Objects in C++, Cont.
However, something like: string two("two"); string sum1 = two + "five"; does work. The char* literal is converted to a string object first. So, the operation that takes place depends on the types of the operands on either side of the operator. Fall 2017 CISC/CMPE320 - Prof. McLeod

11 CISC/CMPE320 - Prof. McLeod
Operator Overloading This flexibility is a result of operator overloading in the string class – a task carried out by the class designer to make the class easier to use. In Java operator overloading is almost non-existent. For example, if a, b and c are BigIntegers, to carry out the operation: x = a + b * c; you would have to write x = a.add(b.multiply(c)); Fall 2017 CISC/CMPE320 - Prof. McLeod

12 Overloadable Operators in C++
- * / % ^ & | ~ ! = < > += -= *= /= %= ^= &= |= << >> >>= <<= == != <= >= && || ++ -- ->* , -> [] () new new[] delete delete[] Fall 2017 CISC/CMPE320 - Prof. McLeod

13 Overloadable Operators, Cont.
These include unary operators, binary operators and both bitwise shift and stream insertion operators (already overloaded!). An overloaded operator is only used when one or the other, or both, operands are of your class type. (ie. you cannot overload int + int – sorry…) You cannot create new operators. You cannot change associativity or the order of precedence. You cannot make a unary operator a binary one, or visa-versa. Fall 2017 CISC/CMPE320 - Prof. McLeod

14 Overloadable Operators, Cont.
And, you only overload the ones that make sense for your class!!! Fall 2017 CISC/CMPE320 - Prof. McLeod

15 CISC/CMPE320 - Prof. McLeod
Operator Functions You can overload an operator as a member or a non-member function. Overloading function header syntax: return_type operatoroperator_symbol(parameters) For example, non-member overloading the + operator for an object called MyClass: MyClass operator+(const MyClass& lhs, const MyClass& rhs); Fall 2017 CISC/CMPE320 - Prof. McLeod

16 CISC/CMPE320 - Prof. McLeod
MyComplex Class Demo See the start of a simple class to hold complex numbers: myComplex.h and myComplex.cpp: First version uses non-member overloading and accessors. Second version uses member overloading of the + operator. Third version uses non-member friends and no accessors. Fall 2017 CISC/CMPE320 - Prof. McLeod

17 Summary of MyComplex, So Far
Mixed type expressions (using your object) need conversion constructors, that will be invoked automatically to match types before the operator is evaluated. If you are going to use your binary operators in mixed type expressions it is best to overload them as non-member functions. If you do not wish to provide accessors, then non-member functions will have to be declared as friends. So, we know how to overload the binary arithmetic operators and <<. Fall 2017 CISC/CMPE320 - Prof. McLeod

18 Operator Functions, Cont.
Member overloading functions: For example, overloading the + operator for an object called MyClass: MyClass operator+(const MyClass& rhs) const; The object owning the function is the LHS operand in this case. Non-member overloading function has two parameters instead. Fall 2017 CISC/CMPE320 - Prof. McLeod

19 Member or Non-Member Overloading?
You will probably need to use both kinds. For example, assignment operators must be member functions, because you need to modify the LHS. Non-member functions cannot access private things in the class, unless they are a friend function. Fall 2017 CISC/CMPE320 - Prof. McLeod

20 Conversion Constructors
Suppose you did not have a conversion constructor or accessors? What would you do? Fall 2017 CISC/CMPE320 - Prof. McLeod

21 Overloading Arithmetic Operators
Binary: + - * / and % Easy to do. Usually a non-member function will be best if you can use accessors for the private stuff (or are a friend function). Unary: - * and & (negation, pointer de-reference, address-of operator). Also easy. If a non-member function, you only need a single parameter. A member function does not need any. Fall 2017 CISC/CMPE320 - Prof. McLeod

22 Overloading Boolean Operators
==, <, >, <=, >=, != Normally a non-member function. Return a bool. Consider writing a member function called something like “compare” that returns an int. compare will take two objects and return a negative int if the first is less than the second, zero if they are equal and a positive int if the first is greater than the second. The other comparison operators can invoke compare. Fall 2017 CISC/CMPE320 - Prof. McLeod

23 Overloading Input and Output
Stream output: << This operator takes the RHS, adds it to the stream obtained as the LHS and then returns this stream. As a non-member function: ostream& operator<<(ostream& out, const MyClass myC) { out << myC.convert(); return out; } convert() changes myC to something that can normally be handled by << (an atomic type, a string or a *char). Fall 2017 CISC/CMPE320 - Prof. McLeod

24 Overloading Input and Output, Cont.
Stream input: >> As for output except you use istream& instead of ostream&. Fall 2017 CISC/CMPE320 - Prof. McLeod

25 Aside - Converting Between Strings and Numbers
Is much nicer now in C++11 The <string> library has built-in functions for conversions in both directions: Fall 2017 CISC/CMPE320 - Prof. McLeod


Download ppt "CISC/CMPE320 - Prof. McLeod"

Similar presentations


Ads by Google