DOC PREVIEW
UD CISC 181 - Study Notes

This preview shows page 1-2-3-4-5-6-7-8-9-10-67-68-69-70-71-72-73-74-75-135-136-137-138-139-140-141-142-143-144 out of 144 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 144 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CISC 181 final overview• Next Tuesday, May 25—10:30 am-12:30 pm, Memorial 113• Worth 20% of your grade• Covers topics from class in chapters listed on course page from April 8 up to May 11 inclusive– Will not test on gdb, OpenGL (or recursion or exception handling)• Format: Just like the midterm…only no tic-tac-toe programs 1-1Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Topic list• Classes Chap. 10.3, 14-14.1, 15-15.2 (through p. 678)• Templates Chap. 16-16.2• Linked data structures Chap. 17-17.2 (through p. 763)• STL Chap. 7.3, 19-19.2 (through p. 872, + pp. 876-883)1-2Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Chapter 10Pointers, Dynamic Arrays, & ClassesCopyright © 2010 Pearson Addison-Wesley. All rights reservedChap. 10.3 Learning Objectives• Classes, Pointers, Dynamic Arrays– The this pointer– Destructors, copy constructors10-4Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Back to Classes• The -> operator– Shorthand notation• Combines dereference operator, *, anddot operator• Specifies member of class "pointed to"by given pointer• Example:MyClass *p;p = new MyClass;p->grade = "A"; Equivalent to:(*p).grade = "A";10-5Copyright © 2010 Pearson Addison-Wesley. All rights reserved.The this Pointer• Member function definitions might need to refer to calling object• Use predefined this pointer – Automatically points to calling object:Class Simple{public:void showStuff() const;private:int stuff;};• Two ways for member functions to access:cout << stuff;cout << this->stuff;10-6Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Overloading Assignment Operator• Assignment operator returns reference– So assignment "chains" are possible– e.g., a = b = c;• Sets a and b equal to c• Operator must return "same type" as itsleft-hand side– To allow chains to work– The this pointer will help with this!10-7Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Overloading Assignment Operator• Recall: Assignment operator must bemember of the class– It has one parameter– Left-operand is calling objects1 = s2;• Think of like: s1.=(s2);• s1 = s2 = s3;– Requires (s1 = s2) = s3;– So (s1 = s2) must return object of s1"s type• And pass to " = s3";10-8Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Overloaded = Operator Definition• Uses string Class example:StringClass& StringClass::operator=(const StringClass& rtSide){if (this == &rtSide) // if right side same as left sidereturn *this;else{capacity = rtSide.length;lengthlength = rtSide.length;delete [] a;a = new char[capacity];for (int I = 0; I < length; I++)a[I] = rtSide.a[I];return *this;}}10-9Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Shallow and Deep Copies• Shallow copy– Assignment copies only member variablecontents over– Default assignment and copy constructors• Deep copy– Pointers, dynamic memory involved– Must dereference pointer variables to"get to" data for copying– Write your own assignment overload andcopy constructor in this case!10-10Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Destructor Need• Dynamically-allocated variables– Do not go away until "deleted"• If pointers are only private member data– They dynamically allocate "real" data• In constructor– Must have means to "deallocate" whenobject is destroyed• Answer: destructor!10-11Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Destructors• Opposite of constructor– Automatically called when object is out-of-scope– Default version only removes ordinaryvariables, not dynamic variables• Defined like constructor, just add ~– MyClass::~MyClass(){//Perform delete clean-up duties}10-12Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Copy Constructors• Automatically called when:1. Class object declared and initialized to other object2. When function returns class type object3. When argument of class type is "plugged in"as actual argument to call-by-value parameter• Requires "temporary copy" of object– Copy constructor creates it• Default copy constructor– Like default "=", performs member-wise copy• Pointers  write own copy constructor!10-13Copyright © 2010 Pearson Addison-Wesley. All rights reserved.The “Big 3”• If you do one, you’ll probably need to do all because of new/delete issue1. Overloading assignment operator2. Copy constructor3. Destructor• Also, these are not inherited (nor is constructor)1-14Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Chapter 14InheritanceCopyright © 2010 Pearson Addison-Wesley. All rights reservedLearning Objectives• Inheritance Basics– Derived classes, with constructors– Redefining member functions– Non-inherited functions14-16Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Introduction to Inheritance• Object-oriented programming– Powerful programming technique– Provides abstraction dimension called inheritance• General form of class is defined– Specialized versions then inherit properties ofgeneral class– And add to it/modify its functionality for itsappropriate use14-17Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Inheritance Basics• New class inherited from another class• Base class– "General" class from which others derive• Derived class– New class– Automatically has base class’s:• Member variables• Member functions– Can then add additional member functionsand variables14-18Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Derived Classes• Consider example:Class of "Employees"• Composed of:– Salaried employees– Hourly employees• Each is "subset" of employees– Another might be those paid fixed wage eachmonth or week14-19Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Derived Classes• Don’t "need" type of generic "employee"– Since no one’s just an "employee"• General concept of employee helpful!– All have names– All have social security numbers– Associated functions for these "basics" aresame among all employees• So "general" class can contain all these"things" about employees14-20Copyright © 2010 Pearson Addison-Wesley. All rights reserved.Employee Class• Many members of "employee" class applyto all types of employees– Accessor functions– Mutator functions– Most data items:• SSN• Name• Pay• We won’t have


View Full Document
Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?