110 likes | 351 Views
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.
E N D
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 • 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
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; • ………. • }
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); • ………. • }
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; • ………. • }
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
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
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