lab04 : C++ Big-Three Review
num | ready? | description | submit.cs link |
---|---|---|---|
lab04 | true | C++ Big-Three Review |
Goals
By the end of this lab, given a description of a class containing data members that point to structures on the heap, you will be able to:
- write a correct copy constructor for the class
- write a correct destructor for the class
- write a correct assignment operator for the class
Step-by-Step
Step 1: Get the lab04 starter code into your repository directory
In this step, we are going to copy the lab04 starter files from the instructors directory into your ~/cs32/lab04 directory.
The files are in the instructors directory at
~aduncan/public_html/cs32/s17/labs/lab04/*
The *
here stands in as a “wildcard” that matches “all files”.
You want to copy these files into your ~/cs32/lab04 directory.
By now you should know (or remember) how to copy files; if you need a refresher, see earlier labs.
Step 2: Getting the test cases to pass for lab04!
Now, we are ready to to work on lab04.
In this week’s lab, you have the following files:
Makefile
student.h
,student.cpp
studentRoll.h
,studentRoll.cpp
studentTest00.cpp
, etc.studentRollTest00.cpp
, etc.
Your job is, as usual, get all the test cases to pass. This involves implementing the “big three”: Copy Constructor, Overloaded Assignment Operator, and Destructor.
In addition to the regular test cases, there are also “leakTests”.
This involves running a utility called valgrind
on your code to see whether there are any memory leaks,
or other problems involving memory management. You will only pass the tests if your code has proper memory management.
You will submit only the student.cpp
and studentRoll.cpp
files.
As a result, there are two quite annoying things that you’ll just have to put up with:
-
In the
Student
class, thename
attribute is implemented with a C-string that is allocated with dynamic memory on the heap. This is annoying. Your might prefer to use the std::string class.
Of course you would. But, that’s not the point of this assignment.
The point of this assignment is to know whether you can manage memory properly. -
In the
StudentRoll
class, the list of students is a linked list of structs rather than anstd::list<Student>
orstd::vector<Student>
or something.
This is indeed annoying. Tough. We are training you for the situation where you don’t have any choice, but have to work with the data structures you are given.
In certain later assignments, you will be given the freedom to choose whatever data structure or implementation is appropriate. You’ll be able to decide whether to use std::string
, or C-strings, whether to use array or std::vector
, etc. This is not one of those assignments.
Suggested way to proceed
I suggest proceeding in the following steps:
- (0) Look at the tests in
testStudent00.cpp
. You may want to get the simple tests to pass first, including the test fortoString()
. Runmake testStudent00
to compile this file, and then run./testStudent00
to run the tests. Iterate until the tests for testStudent00 pass. - (1) Repeat for
testStudent01.cpp
, etc.- To get these to pass, you need to implement, possibly among other things, the Copy Constructor and Overloaded Assignment Operator for
Student
- To get these to pass, you need to implement, possibly among other things, the Copy Constructor and Overloaded Assignment Operator for
- (2) Then, try to get the leak tests to pass as they pertain to
Student
, i.e.make lts00
make lts01
make lts02
make lts03
- This will require implementing the destructor for
Student
- (3) Work on each test file for
StudentRoll
, getting those tests to pass, i.e.testStudentRoll00.cpp
,testStudentRoll01.cpp
, etc.- To get these to pass, you need to implement, possibly among other things, the Copy Constructor and Overloaded Assignment Operator for
StudentRoll
- To get these to pass, you need to implement, possibly among other things, the Copy Constructor and Overloaded Assignment Operator for
- (4) Then, try to get the leak tests for StudentRoll to pass, i.e.
make ltsr00
make ltsr01
make ltsr02
- This will require implementing the destructor for
StudentRoll
How do I know if I’m done?
When you are done, you should be able to do both of the following, and see no error messages:
make tests
make leaktests
Step 3: Submission
To submit, use:
~submit/submit -p 739 student.cpp studentRoll.cpp
Grading
- (300 pts) Test cases on submit.cs, as indicated on that system.