CS 225 Data Structures Se Septembe ber 4 - Li Lifecycle G G - - PowerPoint PPT Presentation

cs 225
SMART_READER_LITE
LIVE PREVIEW

CS 225 Data Structures Se Septembe ber 4 - Li Lifecycle G G - - PowerPoint PPT Presentation

CS 225 Data Structures Se Septembe ber 4 - Li Lifecycle G G Carl Evans Exam 1 No stream next Friday Exam 1 is during lecture Covers pre-req theory material and basic C++ More info here


slide-1
SLIDE 1

CS 225

Data Structures

Se Septembe ber 4 - Li Lifecycle

G G Carl Evans

slide-2
SLIDE 2

Exam 1

  • No stream next Friday Exam 1 is during lecture
  • Covers pre-req theory material and basic C++
  • More info here https://courses.engr.illinois.edu/cs225/fa2020/exams/exam1/
  • Practice Exam available later today
  • Exam using CBTF Online
slide-3
SLIDE 3

CBTF Online

Online proctoring with Zoom and CBTF proctors

How does it work?

1.

Make a reservation in the CBTF Scheduler .

2.

Visit the Scheduler near your reservation time to check in and receive further instructions, including the link to the Zoom meeting for your proctoring.

3.

Join the Zoom meeting from your phone and position it to view you taking your exam. The proctor is present to help get you set up, answer questions, etc.

4.

Once checked in, you will be given instructions via the Scheduler on how to take the exam.

slide-4
SLIDE 4

CBTF Online

Visit cbtf.engr .illinois.edu

  • Full instructions
  • FAQ
  • Walkthrough of check-in process
  • Conflict exam request form
  • CBTF Scheduler

Still have questions or concerns? Chat, ask questions, and get to know the proctors during our regularly scheduled Fall 2020 CBTF Proctor Office Hours:

  • Mon, 5:30 pm - 6:30 pm CST
  • Tue, 12:00 pm - 1:00 pm CST
  • Wed, 5:30 pm - 6:30 pm CST
  • Thu, 7:30 pm - 8:30 pm CST
  • Fri, 12:00 pm - 1:00 pm CST
  • Sat, 5:30 pm - 6:30 pm CST
  • Sun, 7:30 pm - 8:30 pm CST
slide-5
SLIDE 5

Cop Copy Con Constru ructor

  • r
slide-6
SLIDE 6

Cop Copy Con Constru ructor

  • r

Automatic Copy Constructor Custom Copy Constructor

slide-7
SLIDE 7

#pragma once namespace cs225 { class Cube { public: Cube(); Cube(double length); double getVolume() const; double getSurfaceArea() const; 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 namespace cs225 { Cube::Cube() { length_ = 1; cout << "Default ctor" << endl; } Cube::Cube(double length) { length_ = length; cout << "1-arg ctor" << endl; } // ...

Cube.cpp

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 …

slide-8
SLIDE 8

/* * Creates a new Cube that contains the exact volume * of the volume of the two input Cubes. */ Cube joinCubes(Cube c1, Cube c2) { double totalVolume = c1.getVolume() + c2.getVolume(); double newLength = std::pow( totalVolume, 1.0/3.0 ); Cube result(newLength); return result; }

joinCubes-byValue.cpp

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 int main() { Cube *c1 = new Cube(4); Cube *c2 = new Cube(5); Cube c3 = joinCubes(*c1, *c2); return 0; } 28 29 30 31 32 33 34 35

slide-9
SLIDE 9

Ca Calls t to c

  • con
  • nstru

ructor

  • rs

By Value

void foo(Cube a) { … }

By Pointer

void foo(Cube *a) { … }

By Reference

void foo(Cube &a) { … }

Cube::Cube() Cube::Cube(double) Cube::Cube(const Cube&)

slide-10
SLIDE 10

/* * Creates a new Cube that contains the exact volume * of the volume of the two input Cubes. */ Cube joinCubes(Cube * c1, Cube * c2) { double totalVolume = c1->getVolume() + c2->getVolume(); double newLength = std::pow( totalVolume, 1.0/3.0 ); Cube result(newLength); return result; }

joinCubes-byPointer.cpp

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 int main() { Cube *c1 = new Cube(4); Cube *c2 = new Cube(5); Cube c3 = joinCubes(c1, c2); return 0; } 28 29 30 31 32 33 34 35

slide-11
SLIDE 11

/* * Creates a new Cube that contains the exact volume * of the volume of the two input Cubes. */ Cube joinCubes(Cube & c1, Cube & c2) { double totalVolume = c1.getVolume() + c2.getVolume(); double newLength = std::pow( totalVolume, 1.0/3.0 ); Cube result(newLength); return result; }

joinCubes-byRef.cpp

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 int main() { Cube *c1 = new Cube(4); Cube *c2 = new Cube(5); Cube c3 = joinCubes(*c1, *c2); return 0; } 28 29 30 31 32 33 34 35

slide-12
SLIDE 12

#pragma once #include "cs225/Cube.h" using cs225::Cube; class Tower { public: Tower(Cube c, Cube *ptr, const Cube &ref); Tower(const Tower & other); private: Cube cube_; Cube *ptr_; const Cube &ref; };

Tower.h

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

slide-13
SLIDE 13

Tower::Tower(const Tower & other) { cube_ = other.cube_; ptr_ = other.ptr_; ref_ = other.ref_; }

Tower.cpp

10 11 12 13 14

slide-14
SLIDE 14

Tower::Tower(const Tower & other) { cube_ = other.cube_; ptr_ = other.ptr_; ref_ = other.ref_; }

Tower.cpp

10 11 12 13 14

slide-15
SLIDE 15

Tower::Tower(const Tower & other) { cube_ = other.cube_; ptr_ = other.ptr_; ref_ = other.ref_; }

Tower.cpp

10 11 12 13 14 Tower::Tower(const Tower & other) : cube_(other.cube_), ptr_(other.ptr_), ref_(other.ref_) { }

Tower.cpp

10 11 12 13 14

Constructor Initializer List

slide-16
SLIDE 16

Tower::Tower(const Tower & other) { // Deep copy cube_: // Deep copy ptr_: // Deep copy ref_: }

Tower.cpp

slide-17
SLIDE 17

Des Destr tructor

slide-18
SLIDE 18

#pragma once namespace cs225 { class Cube { public: Cube(); Cube(double length); Cube(const Cube & other); ~Cube(); double getVolume() const; double getSurfaceArea() const; 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 namespace cs225 { Cube::Cube() { length_ = 1; cout << "Default ctor" << endl; } Cube::Cube(double length) { length_ = length; cout << "1-arg ctor" << endl; } // ...

Cube.cpp

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 …

slide-19
SLIDE 19

Operators that can be overloaded in C++ Arithmetic

+ - * / % ++ --

Bitwise

& | ^ ~ << >>

Assignment

=

Comparison

== != > < >= <=

Logical

! && ||

Other

[] () ->

slide-20
SLIDE 20

#pragma once namespace cs225 { class Cube { public: Cube(); Cube(double length); Cube(const Cube & other); ~Cube(); double getVolume() const; double getSurfaceArea() const; 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 namespace cs225 { Cube::~Cube() { cout << "dtor called"; << endl; } // ...

Cube.cpp

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 …