Signature in Vivaldi

return to coursework

PROG 2100

Programming C++

60 credit-hours

This course seemed to be aimed towards teaching us Microsoft Visual C++ and applying OOP to C++ (syntax for classes, polymorphism, dynamic casting). And next semester, we'll study fundamental data structures through the medium of C++. I wonder if we're doing this completely backwards?

We could have used any modern implementation of C++, but the host machines at school had the C++ in Microsoft Visual Studio 2010, so that's what the instructor and most of the rest of us used. If you want to compile my code for another platform, you'll probably have to make some adjustments. The colors in the Antlions program are only going to work for Windows, and the regular expression support needed for EZFrac might not be available yet on all compilers.

I exhibit here two of the five major deliverables from the course: A rational number caculator (the intent of the assingment was to show how to overload operators), and a ant/antlion simulaton (to exhibit inheritance, polymorphism, and dynamic casting). The executables buried in "Debug" might work straight away if you're on a recent version of Windows, but I'd reccomend recompiling from the source code.

"EZFrac" Rational Number Calculator

The intent of this assignment was to show how to overload operators (in C++ code) the calculator was an optional component for bonus points, and the operators used in the user input are just characters in string not the programmatic operators we're talking about overloading (i.e., (re)defining the behavior of).

We worked with objects of a self-made class Rational that had numerators and denominators. We wrote code that allowed us to perform programmatic and mathematical operations on them and get sensible results e.g. the overloaded "+" operator would add two Rationals together according to the rules for adding fractions.

The calculator was fiendishly difficult because there were all kinds of permutations of the 4 basic operations that had to be parsed correctly, made complicated by the fact that the symbol (/) indicated both division and two parts of a rational. Worse, the symbol (-) is for subtraction as well as indicating a negative integer, necessitating 16 different cases to handle: I had regular expressions with nicknames like "nominus-dualminus" ((n or n/n) - -n/-n) and "trailingminusonly-leadingminusonly" (n/-n - -n/n). Certain expressions like 3/2/3 (is that 3/2 divided by 3 (1/2), or 3 divided by 2/3 (9/2)?) would always be ambiguous and required prompting the user. I learned how to use regular expressions to identify the different kinds of fraction/operation combinations and build up the appropriate Rationals on which to perform the appropriate calculations.

In the end I gained a greater proficiency with regular expressions and using them in C++, and they're a critical (and, if this IT program is any indication, oft-neglected) part of a problem-solving toolkit.

- - -

The Antlions download includes some components from the Scrum project in Project Management (in which I worked with Ben Allen, Isaac Benoit, and Jamie Curnew).

"EZFrac" Rational Number Calculator "Antlions" Ant/Antlion Simulation
Sceenshot of calculator - click to enlarge Screenshot of simulator - click to expand
Download: 1.3 MB (ZIP) Download: 2.2 MB (ZIP)