Programming in C++ (PC3762, also PHYS30762)
This page functions as a hub to all the stuff I have related to this course. The course's homepage is located on the teachweb so you need a login to access it. The course is taught(in 2007) by Henggui Zhang (page seems rather old). There is a lot of stuff on http://www.hep.man.ac.uk/u/johna/pub/PC3762/. You can find the source code for my PC3762/PHYS30762 assignment solutions here.
The syllabus is available in the bluebook: Programming in C++.
FenggShui contains some problems I find interesting, most of the ones here are rather boring.
Contents
Assignments
The course has weekly assignments, I will try and keep the list of which ones I have solved updated as we go along.
Converting miles
A little program to convert miles to km and vice versa. Nothing exciting just to get everyone going with Visual Studio and Co. My solution is here. Its probably not working any more because I fiddled with it, but you get the idea.
Computing stats on input data
This program will compute the Mean, Standard_deviation and the standard deviation of the mean for a set of numbers read from a data file. It is clever enough to deal with non numbers in the input, though there is debate over how to exactly do this nicely. The conclusion so far is that there is no non-hack way of doing it. The code is here.
Complex number class
A class that implements a complex number. Code is here. Any other ideas what one could do with it?
Lorentz four vector
These classes implement a Lorentz four vector, using a three vector. The Lorentz vector can be boosted along the x direction. Using a three vector to build a four vector is an example of the "delegation" pattern. source code: /uni/pc3762/LorentzVector
Simple string class
This shows how to implement a simple string class. It shows off operator overloading, a copy constructor and how "friends" work. As a little bonus the string implements some functions to search it. source code: /uni/pc3762/string
Shapes, Cubes and Inheritance
Demonstrating inheritance using the infamous Shape, Rectangle etc example. Nothing too exciting here. source code: /uni/pc3762/rect
Abstract base classes
Building on the previous example, this demonstrates the concept of an Abstract Base Class([google:abstract%20base%20class google] [wikipedia:Abstract_base_class wikipedia]). We have an ABC Student with two virtual functions, this is the ABC, promising a certain interface. Derived from it are two concrete classes CsStudent and PhysStudent. They implement the interface and take care of the difference between computer science students and physics students. source code: /uni/pc3762/ABC
DynamicType project
This is the final project I choose. The objective is to implement a type which can hold arbitrary types. Basically implementing basic "dynamic typing" for c++. Here is an example:
1 #include "DynamicType.h"
2 DynamicType dt;
3 double dd;
4 int di=3;
5
6 dt = 23;
7 dt = di;
8 dt = 42.1;
9 // The kicker
10 dd = dt // dd=42.1
It is now finished and handed in. The source code(only 493 lines) can be found here. The Stores.h header defines most of the storing and is where you want to get active in order to provide new types that can be stored. If you just want to use it, then look at DynamicType.h and the tests in test.cpp. The report is called "A dynamic type system for C++" and discusses some of the issues and most of the design decisions.
