C++ code written by Dr. Stephen A Wells, University of Bath, 2020.