Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

31
Cramming for CS 247

Transcript of Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Page 1: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Cramming for CS 247

Page 2: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

FAQ

• Q: Will you post these slides online?

• A: Yes.

Page 3: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Single ADT Design

Page 4: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

02 - Classes in C++

• ADTs, Classes, Objects• Constructor• Destructor• Private vs public• Friends

Page 5: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

03 – Design decisions for a single class

• Should we write a constructor?• Should the constructor be explicit?

class Stack{public:

explicit Stack(int size);};

Page 6: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

03 – Design decisions for a single class

• Accessor and Mutatorclass Integer{

int x;public:

void setX(const int x);int getX() const;

};

Page 7: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

03 – Design decisions for a single class

• Operator overloadingclass Integer{

int x;public:

Integer operator+ (const Integer &y) const;};

Page 8: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

04 – Consts and References

• int *p;• const int *p;• int const *p;• int *const p;• const int *const p;

Page 9: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

05 – Copy constructor

• Purpose: Duplicating an existing object

• How copy constructors work• How operator= works• How operator== works

• More design decisions

Page 10: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Multiple ADT Design

Page 11: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

06 – Modules

• .h files contain DECLARATIONS• .cpp files contain DEFINITIONS

• The “make” command• Makefile

Page 12: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

06 – Modules

• Namespaces• What does “using namespace” std mean?

Page 13: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

08 – UML Diagrams

• Visual representation of ADTs

class Integer{int x;

public:void setX(const int x);int getX() const;

}

Integer

- x : int

+ setX(int)+ getX() : int

Page 14: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

08 – UML Diagrams• Arrows : navigability

A has a pointer to B

• Numbers : multiplicity

A has 2 instances of B

A B

A B2

Page 15: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

08 – UML Diagrams

A and B are related

B is part of A

B is part of A, and B cannot exist without A

A B

A B

A B

Page 16: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

09 – Aggregation and Composition

How to code aggregation

and composition

in C++

A B

A B

Page 17: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

10 - Inheritance

• Creating new classes based on previous onesclass Animal {public: void walk();};

class Cat : public Animal {public: void purr();};

Animal has 1 function:walk

Cat has 2 functions:purrwalk

Page 18: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

11 - Polymorphism

• Allowing objects to take many forms

• Animal *a = new Animal(); //OK• Animal *b = new Cat(); //Also OK

• Function override, virtual functions

Page 19: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

12 – Design principles

• What CAN we inherit?• What SHOULD we inherit?• HOW should we inherit?

• Inheritance vs Composition

Page 20: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Program Maintenance

Page 21: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

07 - Testing

• What is unit testing?• System vs Integration testing• What is boundary testing?• Black box vs white box testing

• Assert function

Page 22: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

15 - Debugging

• Using the GDB debugger• Debugger commands

Page 23: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

14 - Exceptions

• try and catch syntax in C++

• More design principles– When SHOULD we try and catch?– When SHOULDN’T we try and catch?

Page 24: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

Design Patterns

Page 25: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

16 – 19 - Design Patterns

• An algorithm is a standard step-by-step routine for solving a problem (e.g. quicksort)

• A data structure is a standard organization of data in memory (e.g. linked list)

• A design pattern is a standard object-oriented architectural layout (e.g. strategy pattern)

Page 26: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

16 – 19 - Design Patterns

• Strategy Pattern

SortStrategysort()

Quicksortsort()

Mergesortsort()

SortedArraysort()

Element*

Page 27: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

16 – 19 - Design Patterns

• Strategy Pattern• Template Method• Factory Method• Observer Pattern• Model View Controller• Composite Pattern• Iterator Pattern• Decorator Pattern

Page 28: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

STL

Page 29: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

20 - Templates

• Classes that support multiple data types template <typename T> class Stack{ … };• Stack <int> integerStack;• Stack <float> floatStack;

Page 30: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

21 – Generic Algorithms in STL

• #include <algorithm>– copy– find

• #include <iterator>• #include <functional>

Page 31: Cramming for CS 247. FAQ Q: Will you post these slides online? A: Yes.

21 – Generic Contains in STL

• #include <vector>• #include <deque>• #include <list>• #include <set>• #include <map>

• More STL iterators