Part 1: Converting Currencies

Write a program in a file called part1.cpp that converts between Dollars, Euros and Pounds. The program reads input from the user in the following format: Convert amount currency_1 to currency_2 and prints results in the obvious way. currency_1 and currency_2 can both be any of our three currencies. Here are a couple of sample runs:

~$ ./part1
Convert 3.50 Euros to Dollars
3.5 Euros is 3.78 Dollars.

~$ ./part1
Convert 3.50 Euros to Pounds
3.5 Euros is 2.646 Pounds.

Here are the conversion rates you'll need: 1.00 Dollar is 0.92 Euros and 1.00 Dollar is 0.7 Pounds.

Submission: If you're finished before lab ends, please demo for your instructor. Also submit via the class submit script as follows:

submit lab03 part1.cpp

Part 2: More Currencies

Extend your program from Part 1 (note: name the source code file part2.cpp) to allow for Canadian dollars as well (1.00 Dollars US is 1.42 Dollars Canadian). Now the user can't simply put "Dollars" in the input, it must be either "Dollars US" or "Dollars Canadian". Here are a couple of sample runs:

~$ ./part2
Convert 3.50 Euros to Dollars Canadian
3.5 Euros is 5.3676 Dollars Canadian.
~$ ./part2
Convert 11.72 Dollars US to Dollars Canadian
11.72 Dollars US is 16.6424 Dollars Canadian.

Submission: If you're finished before lab ends, please demo for your instructor. Also submit via the class submit script as follows:

submit lab03 part1.cpp part2.cpp

Part 3: Calculating a bounding box

Given a set of points, let's define a bounding box as a rectangle of horizontal and vertical lines which is as small as possible, yet still contains every point in the set. For example, for the points (0,0.5), (3,2), and (1,4), the bounding box has corners at (0,0.5), (3,0.5), (3,4), and (0,4). You'll write a program in a file called part3.cpp to take in three points, and output this bounding box. An example follows:

~$ ./part3
Enter three points: (1, 3.3) (-1.2, -0.5) (2.7, -1.1)
Bounding box has corners at: (-1.2, -1.1), (-1.2, 3.3), (2.7, 3.3), (2.7, -1.1)

Submission: If you're finished before lab ends, please demo for your instructor. Also submit via the class submit script as follows:

submit lab03 part1.cpp part2.cpp part3.cpp

Part 4: Going even further, a challenge for those who finish fast

There are two common ways of classifying a triangle:


This is an acute isosceles triangle.

  1. By describing its interior angles
    • Acute triangles have three interior angles that are all less than 90 degrees
    • Right triangles have an interior angle that is exactly 90 degrees
    • Obtuse triangles have an interior angle that is greater than 90 degrees
  2. By describing the lengths of the sides in relation to each other
    • Equilateral triangles have three sides that are all of equal length
    • Isosceles triangles have two sides that are of equal length
    • Scalene triangle have all three sides of different lengths

A well known property of all triangles is that the sum of any two sides will always be greater than the third. Given a set of three lengths it is possible to determine if they can form a triangle by adding two lengths together and comparing them to the third. Given the three lengths of the sides of a triangle, a, b and c, it is also possible to calculate the area of a triangle using Heron's formula. $$ \Delta = \sqrt{s(s-a)(s-b)(s-c)} \mbox{, where } s = \frac{1}{2}(a + b + c) $$

The cmath library has a function asin() that computes the arcsine of an angle. Enter man asin on the command line for documentation. We have a bit of a problem in that for any positive angle $\theta$ less than $\pi/2$, we have that $\sin(\theta) = \sin(\pi - \theta)$. Thus, when we use $\theta$= asin(w) for positive w, we don't know whether we really want the angle $\theta$ or $\pi - \theta$. In our triangle case, we cans fix things like this: if the three angles we calculate (A, B and C) sum up to a lot less than $\pi$ (in fact, we should probably check that the sum is less than 3), we replace the angle opposite the longest side with $\pi$ minus that angle. So, for example, if $A$ is opposite the longest side, then we replace $A$ with $\pi - A$.

BTW: as long as you're including cmath, the constant M_PI gives you a high-precision double representation of $\pi$.

Also: the function sqrt( ) computes square roots.

Also, from the side lengths $a$, $b$ and $c$, it is possible to calculate the three interior angles, $A$, $B$ and $C$, of the triangle using the law of sines: $$ \frac{sin{A}}{a} = \frac{sin{B}}{b} = \frac{sin{C}}{c} = \frac{2\Delta}{abc}. $$ Your job: write a program (note: name the source code file part4.cpp) that reads three lengths from the user displays the type of triangle that is formed by the input according to both kinds of classification. E.g. "This is a obtuse scalene triangle"

Submission: If you're finished before lab ends, please demo for your instructor. Also submit via the class submit script as follows:

submit lab03 part1.cpp part2.cpp part3.cpp part4.cpp