Lab 2

Topics: C++ Classes, member functions, constr, destr, CC, AO, interface vs. implementation

Getting started:


Part 1 (14:00)


Part 2 (~14:10)


Part 3 (15:20)


Part 4 (15:30)


Prep Problem 1:

Paste the following code into file e1.cpp and implement Bar's constructor, destructor, CC, and AO in e1.cpp. Also define function main() that invokes Bar's constructor, destructor, CC, and AO
struct Foo
{
  // details immaterial
};

struct Bar
{
  Foo x;
  Foo *p; // always pointing to 10 solely owned Foos
};

Test your program and make sure it doesn't leak memory (using valgrind)

Your project must compile with g++ -Wall -Wextra -O -g -std=c++17 e1.cpp


Prep Problem 2:

For classes Foo, Bar used in problem 1, create individual interface (.h) and implementation (.cpp) files Foo.h, Bar.h, Bar.cpp. For this problem, interface files must not contain ANY method implementations. Also create file main.cpp that defines function main() which allocates 10 Bar objects on the heap and then frees them

Test your program and make sure it doesn't leak memory (using valgrind)

Your project must compile with g++ -Wall -Wextra -O -g -std=c++17 Bar.cpp main.cpp


Prep Solutions (link will be shared in time)

Lab Exercise (link will be shared in time)

Secrets (link will be shared in time)