1 / 11

CSS 342

CSS 342. Data Structures, Algorithms, and Discrete Mathematics I Lecture 3. 141001. Announcements. Carpool question Questions on HW -12 -30 -30 setHour to 1– what happens? Example of code handed in IntStack Posted. Encapsulation and Data.

caia
Download Presentation

CSS 342

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSS 342 Data Structures, Algorithms, and Discrete Mathematics I Lecture 3. 141001.

  2. Announcements • Carpool question • Questions on HW • -12 -30 -30 • setHour to 1– what happens? • Example of code handed in • IntStack Posted

  3. Encapsulation and Data • public: contract exposes functions for class • The What • Actions • Designed first • Private: All data, helper functions • Base types like int, double, … • Arrays • Vectors • Linked Lists • Queues • Stacks • Trees • Graphs

  4. Overloading +,-,*,/ as member functions class Rational • { • public: • Rational(); • Rational(inta, int b); • intgetNumerator() const; • intgetDenominator() const; • Rational operator*(const Rational &rat) const; • Rational operator/(const Rational &rat) const; • Rational operator+(const Rational &rat) const; • Rational operator-(const Rational &rat) const; • ………. • }

  5. Overloading +,-,*,/ as member functions class Rational • { • public: • Rational(); • Rational(inta, int b); • intgetNumerator() const; • intgetDenominator() const; • Rational operator*(const Rational &rat) const; • Rational operator/(const Rational &rat) const; • Rational operator+(const Rational &rat) const; • Rational operator-(const Rational &rat) const; • bool operator==(const Rational &rat) const; • Rational& operator+=(const Rational &rat); • ………. • }

  6. Overloading input/output <<, >> class Rational • { • friend std::ostream& operator<<(std::ostream &outStream, const Rational &rat); • friend std::istream& operator>>(std::istream &inStream, Rational &rat); • public: • Rational(); • Rational(inta, int b); • intgetNumerator() const; • intgetDenominator() const; • Rational operator*(const Rational &rat) const; • Rational operator/(const Rational &rat) const; • Rational operator+(const Rational &rat) const; • Rational operator-(const Rational &rat) const; • ………. • }

  7. Pointers Pointer variables int *p, *q; Static allocation int x; Address-of operator p = &x; Memory cell to which P points *p = 6; Pointer operations q = p; ? ? ? ? 6 ? ? 6 p p p p q q q q x x x x 4 3 1 5

  8. Computer Scientist of the week Alan Turing • Turing Machine • Code Breaking in WWII for England • Improvements to Enigma machine • Winston Churchill: Turing made the single biggest contribution to Allied victory in the war against Nazi Germany • Father of Artificial Intelligence • Turing Test

  9. Programming example for pointers

  10. this : pointer to self

  11. Accessing Linux Lab and compiling • Good Sites for Linux access: http://depts.washington.edu/cssuwb/wiki/connecting_to_the_linux_lab http://www.bothell.washington.edu/css/facilities/unix • Install putty on your system • Transfer files with filezilla: http://www.washington.edu/itconnect/connect/web-publishing/shared-hosting/sftp/ • Compile and link all .cpp files (list as many .cpp files as you have for your program) then create an executable file called a.out: •      g++ file1.cpp file2.cpp • Trick will in getting .h files correct if porting from other system • Unix simple commands: http://courses.washington.edu/css342/zander/css332/basicunix.html

More Related