cs 225
play

CS 225 Data Structures Au August 28 Cl Classes es and Ref efer - PowerPoint PPT Presentation

CS 225 Data Structures Au August 28 Cl Classes es and Ref efer eren ence e Variables es G G Carl Evans La Labs St Start rt T Tod oday Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 3 class Cube { 3


  1. CS 225 Data Structures Au August 28 – Cl Classes es and Ref efer eren ence e Variables es G G Carl Evans

  2. La Labs St Start rt T Tod oday

  3. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 3 class Cube { 3 double Cube::getVolume() { 4 public: 4 5 double getVolume(); 5 6 6 } 7 7 8 8 9 9 10 10 11 private: 11 12 12 13 13 14 }; 14 15 15 16 16 17 17 18 18 19 19 20 20

  4. Na Namespace ces

  5. Na Namespace ces cs225 std cout Cube vector PNG ... HSLAPixel queue …

  6. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 3 namespace cs225 { 3 namespace cs225 { 4 class Cube { 4 double Cube::getVolume() { 5 public: 5 return length_ * length_ * 6 double getVolume(); length_; 7 double getSurfaceArea(); 6 } 8 7 9 8 double 10 Cube::getSurfaceArea() { 11 9 return 6 * length_ * 12 private: length_; 13 double length_; 10 } 14 11 } 15 }; 12 16 } 13 17 14 18 15 19 16 20 17

  7. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 3 namespace cs225 { 3 namespace cs225 { 4 class Cube { 4 double Cube::getVolume() { 5 public: 5 return length_ * length_ * 6 double getVolume(); length_; 7 double getSurfaceArea(); 6 } 8 7 9 8 double 10 Cube::getSurfaceArea() { 11 9 return 6 * length_ * 12 private: length_; 1 #include "Cube.h" 13 double length_; 10 } 2 #include <iostream> 14 11 } 3 15 }; 12 4 int main() { 16 } 13 5 cs225::Cube c; 17 14 6 std::cout << "Volume: " << c.getVolume() << std::endl; 18 15 7 return 0; 19 16 8 } 20 17

  8. main.cpp 1 #include "Cube.h" 2 #include <iostream> 3 4 int main() { 5 cs225::Cube c; 6 std::cout << "Volume: " << c.getVolume() << std::endl; 7 return 0; 8 }

  9. main.cpp 1 #include "Cube.h" 2 #include <iostream> 3 4 int main() { 5 cs225::Cube c; 6 std::cout << "Volume: " << c.getVolume() << std::endl; 7 return 0; 8 }

  10. main.cpp 1 #include "Cube.h" 2 #include <iostream> 3 4 int main() { 5 cs225::Cube c; 6 std::cout << "Volume: " << c.getVolume() << std::endl; 7 return 0; 8 }

  11. CS CS 225 225 – Of Offi fice Hour urs Lab Sections – Meet with your TA and CAs every week! Open Office Hours – Held in the basement of Siebel Center by TAs and CAs, ramping up over the next week. First open office hours start soon. (Great place for both conceptual and programming questions!) Faculty Office Hours – Starting next week. Carl’s Office Hours: Wednesday, 12:15pm – 1:45pm, 3036 ECEB Mattox’s Office Hours: Friday, 12:15pm – 1:45pm, 3036 ECEB

  12. CS CS 225 225 – Ex Exam 0 First exam is coming up next week ! “Exam 0” • Low-stress introduction to the CBTF exam environment. • This exam is worth only 40 points • Focuses primarily on foundational knowledge you have from your prerequisite classes. Full Details: https://courses.engr.illinois.edu/cs225/fa2019/exams/

  13. CB CBTF-ba based d Ex Exams All CS 225 exams are held in the Computer Based Testing Facility (CBTF): - You can choose which day to take your exam within the exam window for a given exam. - Sign up for your exam here: https://cbtf.engr.illinois.edu/

  14. Con Constru ructor or

  15. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 namespace cs225 { 3 namespace cs225 { 3 Cube::Cube() { 4 class Cube { 4 5 public: 5 6 Cube(); 6 } 7 double getVolume(); 7 8 double getSurfaceArea(); 8 double Cube::getVolume() { 9 9 return length_ * length_ * 10 10 length_; 11 11 } 12 12 13 private: 13 double 14 double length_; 14 Cube::getSurfaceArea() { 15 15 return 6 * length_ * 16 }; 16 length_; 17 } 17 } 18 18 } 19 19 20 20

  16. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 namespace cs225 { 3 namespace cs225 { 3 Cube::Cube(double length) { 4 class Cube { 4 5 public: 5 6 Cube(double length); 6 } 7 double getVolume(); 7 8 double getSurfaceArea(); 8 double Cube::getVolume() { 9 9 return length_ * length_ * 10 10 length_; 11 11 } 12 12 13 private: 13 double 14 double length_; 14 Cube::getSurfaceArea() { 15 15 return 6 * length_ * 16 }; 16 length_; 17 } 17 } 18 18 } 19 19 20 20

  17. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 namespace cs225 { 3 namespace cs225 { 3 Cube::Cube(double length) { 4 class Cube { 4 length_ = length; 5 public: 5 6 Cube(double length); 6 } 7 double getVolume(); 7 8 double getSurfaceArea(); 8 double Cube::getVolume() { 9 9 return length_ * length_ * puzzle.cpp 1 #include "Cube.h" 10 10 length_; 2 using cs225::Cube; 11 11 } 3 #include <iostream> 12 12 4 using std::cout; 13 private: 13 double 5 using std::endl; 14 double length_; 14 Cube::getSurfaceArea() { 6 15 15 return 6 * length_ * 7 int main() { 16 }; 16 length_; 8 Cube c; 17 } 17 } 9 cout << "Volume: " << c.getVolume() << endl; 18 18 } 10 return 0; 19 19 11 } 20 20

  18. Hate Typing g co cout:: a :: and cs cs225::? ::? Useful Shortcut: using std::cout; // Imports cout into global scope using std::endl; // Imports endl into global scope using cs225::Cube; // Imports Cube into global scope Strongly Discouraged Shortcut using namespace std; // Imports all of std:: into // global scope! // ...THOUSANDS of things!

  19. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 namespace cs225 { 3 namespace cs225 { 3 4 class Cube { 4 5 public: 5 6 6 7 Cube(double length); 7 Cube::Cube(double length) { 8 double getVolume(); 8 length_ = length; 9 double getSurfaceArea(); 9 } 10 10 11 11 double Cube::getVolume() { 12 12 return length_ * length_ * puzzle.cpp 7 int main() { 13 13 length_; 8 Cube c; 14 private: 14 } 9 cout << "Volume: " << c.getVolume() << endl; 15 double length_; 15 10 return 0; 16 16 double 11 } 17 }; 17 Cube::getSurfaceArea() { 18 } 18 return 6 * length_ * 19 19 length_; 20 20 }}

  20. Cube.h Cube.cpp 1 1 #pragma once #include "Cube.h" 2 2 namespace cs225 { 3 namespace cs225 { 3 4 class Cube { 4 5 public: 5 6 6 7 Cube(double length); 7 Cube::Cube(double length) { 8 double getVolume(); 8 length_ = length; 9 double getSurfaceArea(); 9 } 10 10 11 11 double Cube::getVolume() { 12 12 return length_ * length_ * puzzle.cpp 7 int main() { 13 13 length_; 8 Cube c; 14 private: 14 } 9 cout << "Volume: " << c.getVolume() << endl; 15 double length_; 15 10 return 0; 16 16 double 11 } 17 }; 17 Cube::getSurfaceArea() { 18 } 18 return 6 * length_ * 19 19 length_; 20 20 }}

  21. Po Pointers and References

  22. Po Pointers and References A variable containing an instance of an object: 1 Cube s1; A reference variable of a Cube object: 1 Cube & s1; A variable containing a pointer to a Cube object: 1 Cube * s1;

  23. Re Reference Variable A reference variable is an alias to an existing variable. Key Idea: Modifying the reference variable modifies the variable being aliased.

  24. Re Reference Variable A reference variable is an alias to an existing variable. 1 #include <iostream> 2 3 int main() { 4 int i = 7; 5 int & j = i; // j is an alias of i 6 7 j = 4; 8 std::cout << i << " " << j << std::endl; 9 10 i = 2; 11 std::cout << i << " " << j << std::endl; 12 return 0; 13 }

  25. CS CS 225 225 – Things gs To Be Doing Exam 0 starts on Thursday, Sept. 5 th Ensure you sign up for your CBTF timeslot for Exam 0! lab_intro is due this Sunday (Sept. 1 st ) Make sure to attend your lab section every week – they’re worth points and EC! MP1 is released Today! Due: Monday, Sept. 9 th (~12 days after release) Ensure you are on our Piazza Details on the course website: https://courses.engr.illinois.edu/cs225/ See you Friday!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend