fall 2015cisc/cmpe320 - prof. mcleod1 cisc/cmpe320 meet with your team later today in ell321 at...
TRANSCRIPT
Fall 2015 CISC/CMPE320 - Prof. McLeod 1
CISC/CMPE320
• Meet with your team later today in ELL321 at 6:30pm.
• Teams are listed on the Project page of the course web site.
• What to do is on the next slide.• TAs are also prepared to help you with
assignment questions, IDE problems, etc. later in the tutorial.
• Still need to provide you with a list of “incomplete” previous projects.
First Team Meeting
• Introduce each other - Exchange contact info?• Present your background/experience. Which
hardware/OS do you like to use for C++ development?• Has each member read over and understood the projects
page? Do you know what the deliverables are and when they are due?
• Pick a notetaker for this meeting.• Notetaker takes attendance and records any momentous
decisions – is anyone missing? If Redmine is ready (not likely) notes can be recorded in the Wiki, otherwise keep separate notes on paper or on a laptop and copy them into the Wiki for when Redmine is available.
Fall 2015 CISC/CMPE320 - Prof. McLeod 2
First Team Meeting, Cont.
• Discuss project ideas – negotiate?• Other meeting time(s) than just the tutorial time?• If you do settle on a project idea, discuss it with
your TA (your mentor) to see if it is too hard/too easy and just what might be involved with implementation. Write an “executive summary” that will be sent to the CEO and put in your Wiki.
• Start thinking about two major roles that must be filled soon: Team Manager and Primary Software Architect.
Fall 2015 CISC/CMPE320 - Prof. McLeod 3
Fall 2015 CISC/CMPE320 - Prof. McLeod 4
The Role of the Primary Software Architect
• Forms and owns the mental model of the software product.– Includes the detailed
specifications for all functionality.
• Must communicate this model to the rest of the team.
• Prevents deviations from the model.• Must represent the user when it comes time to form tradeoffs between time to completion, cost, performance and ease of use.
• Like a movie director!
Fall 2015 CISC/CMPE320 - Prof. McLeod 5
Primary Software Architect, Cont.
• Does not necessarily write any code (in the “real world”) – in this course he or she will have to!
• This job can be too demanding for one person on a very large project.
• So, it can be split up along very clear system boundaries.
• Object oriented programming languages help enable this splitting up.
• But all architects must agree on the overall vision.
Fall 2015 CISC/CMPE320 - Prof. McLeod 6
Architect – Builder Interaction
• The code writers or “Builders” implement the architect’s vision.
• The architect should not decide on how the functionality is implemented – he can only suggest. This allows the builders to come up with better ideas.
• In CISC/CMPE320 – all team members will be code writers.
Fall 2015 CISC/CMPE320 - Prof. McLeod 7
Project Management Role
• The primary architect will be too busy to fill a management role too.
• So another person should be the project manager.
• Like a movie producer.• He is responsible for the
implementation of the architect’s vision.
Fall 2015 CISC/CMPE320 - Prof. McLeod 8
Other Roles• Chief Programmer• Other Programmers, like component programmers and other
specialist programmers• Note-takers• Archivists (Wiki maintenance)• Technical Writers (Wiki content)• Illustrators• Testers• Accountant• Public relations• Researcher• Interface specialist• Artists• Story writers• Repository design and maintenance• …
Today
• C Strings
• Structs
• Operators
Fall 2015 CISC/CMPE320 - Prof. McLeod 9
Last Time
• We found that arrays are not “policed” very well.
• It is easy to move beyond the bounds of the array without any error, other than getting garbage values.
• You are encouraged to use the vector class in a C++ program instead. Part of the STL.
Fall 2015 CISC/CMPE320 - Prof. McLeod 10
Fall 2015 CISC/CMPE320 - Prof. McLeod 11
Arrays and Strings• In C, you had to use char[] to store a string literal:
char oldString[] = "Hello there!";
• These “C-strings” end with the character '\0', also called the “null character”.
• Manipulating C-strings means manipulating arrays – generally a real pain…
• In C++ use the string class instead!• Defined in the string library, and uses the std
namespace.• More about strings later…
Fall 2015 CISC/CMPE320 - Prof. McLeod 12
Structures
• A kind of class.• Defined as an aggregate of other types.• For example:struct address {
string name;int streetNumber;string street;string city;string province;string postalCode;
}; Note “;”
Fall 2015 CISC/CMPE320 - Prof. McLeod 13
Structures, Cont.
• See StructureDemo.cpp
• (Also note use of pointers with a function, and use of const in parameter list – getting a bit ahead of ourselves!!)
• Note how Eclipse gives you the membership list for an address.
Fall 2015 CISC/CMPE320 - Prof. McLeod 14
Member Selection Operators
• The example also demonstrated the use of the two member selection operators:
• The “dot operator”:
object.member
• De-referencing and membership:
pointer->member
• The latter is the same as:
(*pointer).member• (“Members” are attributes or methods (or member
functions)…)
Structures, Cont.
• A struct is a primitive object definition with no privacy for it’s members.
• Why use them in C++?
Fall 2015 CISC/CMPE320 - Prof. McLeod 15
Fall 2015 CISC/CMPE320 - Prof. McLeod 16
Operators
• Discussed in order of highest to lowest precedence.
• Highest Precedence:
• Scope resolution (when defining only):
class_name::member
• Or namespace_name::member
Fall 2015 CISC/CMPE320 - Prof. McLeod 17
Operators, Cont.
• Next Highest Precedence (level 2):
• Member selection . (see slide 14).• Subscripting arrays: pointer[expr]• ( ) when used with function calls or value
constructors.• Post increment or post decrement: var++ var—-• Type identification: typeid(type or expr)• Casts like static_cast<type>(expr)
Fall 2015 CISC/CMPE320 - Prof. McLeod 18
Aside – typeid()
• Used to find out the types of pointers.• More useful in a function:• A trivial example:
int aVal = 100;int* ptr_aVal = &aVal;cout << typeid(ptr_aVal).name() << endl;
• Displays: Pi
Fall 2015 CISC/CMPE320 - Prof. McLeod 19
Operators, Cont.
• Level 3 Precedence:• sizeof(type)• Pre-increment and pre-decrement.• Complement: ~expr• Not: !expr• Negation: -expr• Address of and dereference (& and *)• The heap operators: new, delete and delete[]• C – style cast: (type)expr
Fall 2015 CISC/CMPE320 - Prof. McLeod 20
Operators, Cont.
• Level 4:• Member selection (and dereference) ->
• Level 5:• Multiply, Divide, Modulo: *, /, %
• Level 6:• Add, subtract: +, -
Fall 2015 CISC/CMPE320 - Prof. McLeod 21
Operators, Cont.
• Level 7:• Bitwise shift left: expr << expr• Bitwise shift right: expr >> expr
• Level 8:• <, <=, >, >=
• Level 9:• ==, !=
Fall 2015 CISC/CMPE320 - Prof. McLeod 22
Operators, Cont.
• Levels 10 to 12:• Bitwise AND: expr & expr• Bitwise exclusive OR (or XOR): expr ^ expr• Bitwise OR: expr | expr
• Levels 13 and 14:• Logical AND: expr && expr• Logical OR: expr || expr
• Level 15:• Conditional Expression: expr ? expr : expr
Fall 2015 CISC/CMPE320 - Prof. McLeod 23
Operators, Cont. (Still!)
• Level 16:• All assignment operators:• =• *=, /=, %=, +=, -=, <<=, >>=, &=, |=, ^=
• Level 17:• Throw exception: throw expr
• Lowest Precedence!:• Comma: ,
Fall 2015 CISC/CMPE320 - Prof. McLeod 24
Notes on Precedence
• Prefix operators (~, !, -, &, *, pre-increment and pre-decrement) and assignment operators are right associative (right to left) – all others are left-associative (left to right).
• So:int a = b + c + d;
• Means int a = (b + c) + d;• But,
int x = y = z;• Means int x = (y = z);• (Yes, an assignment operator can return
something!)
Fall 2015 CISC/CMPE320 - Prof. McLeod 25
Precedence Notes, Cont.
• Use ( ) to control precedence.
• When in doubt, control precedence!
• If an expression gets too long, use intermediate variables to make it more readable.
Fall 2015 CISC/CMPE320 - Prof. McLeod 26
Bit and Shift Operations
• These operate on all integer types and enums.• Complement, ~, carries out a bitwise negation of
each bit (1 becomes 0, 0 becomes 1).• Binary &, | and ^:
A B A&B A|B A^B
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Fall 2015 CISC/CMPE320 - Prof. McLeod 27
Bit and Shift Operations, Cont.
• The left shift operator, <<, moves all bits in val to the left by n positions: val << n.
• Zeros are added to the least significant bits.• This is the same as multiplying a number by 2n.
• Right shift, >>, moves all bits to the right.• For unsigned integers zeros are added to the
most significant bits – same as dividing by 2n.• For signed integers, the result is not predicable as
the sign bit may be duplicated.
Fall 2015 CISC/CMPE320 - Prof. McLeod 28
Bitwise Operations, Examples
• Set the nth bit in a number and the rest are zeros:
1 << n
• To set the nth bit of any number, x, and not change the rest:
x = x | 1 << n
• To check to see if the nth bit is set:
if ((x & 1 << n) != 0)…