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

cs 225
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CS 225

Data Structures

Au August 28 – Cl Classes es and Ref efer eren ence e Variables es

G G Carl Evans

slide-2
SLIDE 2

La Labs St Start rt T Tod

  • day
slide-3
SLIDE 3

#pragma once class Cube { public: double getVolume(); private: };

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

slide-4
SLIDE 4

Na Namespace ces

slide-5
SLIDE 5

Na Namespace ces

cs225

Cube PNG HSLAPixel

std

cout vector queue …

...

slide-6
SLIDE 6

#pragma once namespace cs225 { class Cube { public: double getVolume(); double getSurfaceArea(); private: double length_; }; }

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

slide-7
SLIDE 7

#pragma once namespace cs225 { class Cube { public: double getVolume(); double getSurfaceArea(); private: double length_; }; }

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 #include "Cube.h" #include <iostream> int main() { cs225::Cube c; std::cout << "Volume: " << c.getVolume() << std::endl; return 0; }

slide-8
SLIDE 8

#include "Cube.h" #include <iostream> int main() { cs225::Cube c; std::cout << "Volume: " << c.getVolume() << std::endl; return 0; }

main.cpp

1 2 3 4 5 6 7 8

slide-9
SLIDE 9

#include "Cube.h" #include <iostream> int main() { cs225::Cube c; std::cout << "Volume: " << c.getVolume() << std::endl; return 0; }

main.cpp

1 2 3 4 5 6 7 8

slide-10
SLIDE 10

#include "Cube.h" #include <iostream> int main() { cs225::Cube c; std::cout << "Volume: " << c.getVolume() << std::endl; return 0; }

main.cpp

1 2 3 4 5 6 7 8

slide-11
SLIDE 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

  • ffice 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

slide-12
SLIDE 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/

slide-13
SLIDE 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/

slide-14
SLIDE 14

Con Constru ructor

  • r
slide-15
SLIDE 15

#pragma once namespace cs225 { class Cube { public: Cube(); double getVolume(); double getSurfaceArea(); private: double length_; }; }

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

slide-16
SLIDE 16

#pragma once namespace cs225 { class Cube { public: Cube(double length); double getVolume(); double getSurfaceArea(); private: double length_; }; }

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

slide-17
SLIDE 17

#pragma once namespace cs225 { class Cube { public: Cube(double length); double getVolume(); double getSurfaceArea(); private: double length_; }; }

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 #include "Cube.h" using cs225::Cube; #include <iostream> using std::cout; using std::endl; int main() { Cube c; cout << "Volume: " << c.getVolume() << endl; return 0; }

puzzle.cpp

slide-18
SLIDE 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!

slide-19
SLIDE 19

#pragma once namespace cs225 { class Cube { public: Cube(double length); double getVolume(); double getSurfaceArea(); private: double length_; }; }

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 7 8 9 10 11 int main() { Cube c; cout << "Volume: " << c.getVolume() << endl; return 0; }

puzzle.cpp

slide-20
SLIDE 20

#pragma once namespace cs225 { class Cube { public: Cube(double length); double getVolume(); double getSurfaceArea(); private: double length_; }; }

Cube.h

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

Cube.cpp

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 7 8 9 10 11 int main() { Cube c; cout << "Volume: " << c.getVolume() << endl; return 0; }

puzzle.cpp

slide-21
SLIDE 21

Po Pointers and References

slide-22
SLIDE 22

Po Pointers and References

A variable containing an instance of an object: A reference variable of a Cube object: A variable containing a pointer to a Cube object:

1 Cube s1; 1 Cube * s1; 1 Cube & s1;

slide-23
SLIDE 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.

slide-24
SLIDE 24

Re Reference Variable

A reference variable is an alias to an existing variable.

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

slide-25
SLIDE 25

CS CS 225 225 – Things gs To Be Doing

Exam 0 starts on Thursday, Sept. 5th

Ensure you sign up for your CBTF timeslot for Exam 0!

lab_intro is due this Sunday (Sept. 1st)

Make sure to attend your lab section every week – they’re worth points and EC!

MP1 is released Today!

Due: Monday, Sept. 9th (~12 days after release)

Ensure you are on our Piazza

Details on the course website: https://courses.engr.illinois.edu/cs225/

See you Friday!