CS 225 Data Structures Au August 26 – Cl Classes es and Ref efer eren ence ce Variables es G G Carl Evans
St Stream Ru Rules TL;DR: Treat the stream like a classroom, don't say anything that would send you to the Dean of Students. Mods will strongly enforce timeouts and bans. • Be kind and excellent to each other. • No racist, sexist, bullying, sexual, or hate-based comments or remarks. • Constructive criticism is always welcome, insulting or offhand remarks are not. • No excessive disruptive conversation; keep your contributions academic. • The staff/moderation team has final say; don't argue with them.
Va Variables in C++ int myFavoriteInt; char grade = 'A'; double gamma = 0.653; Cat katia, gwenevere; Cube rubix; Person evans;
Enc Encapsul sulation Cube.h Cube.cpp
Cube.h 1 #pragma once 2 3 class Cube { 4 public: 5 6 7 8 9 10 11 private: 12 13 14 }; 15 16 17 18 19 20
Cube.cpp 1 #include "Cube.h" 2 3 double Cube::getVolume() { 4 5 6 } 7 8 9 10 11 12 13 14 15 Cube.h 16 4 17 class Cube { 5 18 public: 19 6 double getVolume(); 20
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
Names Namespaces aces
Names Namespaces aces cs225 std cout Cube vector PNG ... HSLAPixel queue …
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
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
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 }
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 }
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 }
Con Constru ructor or
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
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
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
Ha Hate e Typi ping ng co cout:: a :: and cs cs225::? 225::? 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!
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 }}
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 }}
CS 225 CS 225 – Thi Things ngs To Be e Doing ng lab_intro start in lab (Due Sept. 9 th ) Make sure to attend your lab section every week – they’re worth points and EC starting the third week! 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!
Recommend
More recommend