$29
CSCI251/CSCI851 Advanced Programming
Autumn 2019
Laboratory Exercise 6 (Week 7)
There won’t be lab classes in Wollongong in Week 7, due to Friday being Good Friday. If you want
the mark for this please submit your exercises through a Moodle submission link that I’ll set up sometime
during Week 7. As long as you have made a decent effort at the tasks you will get the mark.
Note that lab exercises marked with a * are effectively extension exercises.
1 Task One: Warm–up exercises
Debug Debug-A.cpp. The output should be as follows:
Given name : Alice
Id. number : 12321
Hat type : Beret
Hat size : M
Given name : Bob
Id. number : 2324
Hat type : Trilby
Hat size : S
2 * Task Two: Efficiency
Look at Pi.cpp. It takes an integer argument indicating how many guesses are to be used in determining
π. The method used is described at https://www.youtube.com/watch?v=VJTFfIqO4TU This is not an
efficient way of calculating π, but not is the implementation very good either.
1. Use the chrono time functionality of C++11 to measure the time taken and use the time functionality
from Banshee. Both of these are discussed in lecture set S3e .
2. Improve it as much as possible without changing the overall method using for calculating π.
3 Task Three: Some short tasks
1. Examine, compile, and run Cars.cpp. What is going on?
2. What is happening in Throw.cpp? Add a handler in.
3. What happens if we set a destructor to being a deleted function, using = delete?
4. * What is an Aggregate class? Write an example of one.
5. * What is a Literal class? Write an example of one.
1
4 Task Four: Copy Cat Constructor
In last weeks exercises there was a task to write a Cat class.
1. If you didn’t do this already, you can start from the provided Cat.cpp and add a constructor.
2. Add code to show the addresses of the contents of a Cat object. This is just to see how the internals
are located, relatively.
3. Add a destructor.
4. Add a copy constructor. Think of it as cloning.
5. Add a copy assignment operator.
6. Extend the main function to demonstrate the use of the class and the new operators.
7. * Can you output addresses for the functions?
c Luke McAven, SCIT-EIS-UOW, 2019.
2