Due: 0800 next Tuesday

Part 1: Converting Currencies

Write a program (note: name the source code file 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. Here are a couple of sample runs:
~$ ./part1
Convert 3.50 Euros to Dollars

~$ ./part1
Convert 3.50 Euros to Pounds
Here are the conversion rates you'll need:
Submission: Submit via the class submit script as follows:
~/bin/submit -c=IC210 -p=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. 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

~$ ./part2
Convert 11.72 Dollars US to Dollars Canadian

Submission: If you're finished before lab ends, please demo for your instructor. Also submit via the class submit script as follows:
~/bin/submit -c=IC210 -p=lab03 part1.cpp part2.cpp

Part 3: Bounding box

It's often nice to write programs that produce output that's intended for other programs. You will write a program (note: name the source code file part3.cpp) that reads in three points from the user and prints output that the user can put in a file to give the program "gnuplot" to produce a plot showing the triangle defined by the three user-input points along with its bounding box, i.e. the smallest rectangle aligned with the coordinate axes that contains the triangle.

Gnuplot is a standard tool for creating plots. Its input is simply a text file of points, one per line, given by the point's x-coordinate, followed by a space, followed by its y-coordinate. Gnuplot will draw a mark at each point, and connect successive points with segments, as long as they are not separated by blank lines. Note: this means that drawing a closed figure (like a triangle) requires repeating the first point at the end of the input.

First, let's install gnuplot on your laptop WSL, so you can work with it either on your laptop or in the lab(gnuplot is already installed on the lab machines):

sudo apt install gnuplot-x11

Here's a sample of running the program and using gnuplot to plot the results. Note: please print the lines defining the bounding box before the lines defining the input triangle. This is for automatic grading purposes, not because gnuplot cares.

sample runexplanation
~/$ ./part3
(-1.1,-0.5) (1,3.3) (2.7,-1.1) 
-1.1 -1.1
-1.1 3.3
2.7 3.3
2.7 -1.1
-1.1 -1.1

-1.1 -0.5
1 3.3
2.7 -1.1
-1.1 -0.5


← drawing the 
 bounding box




← drawing the 
triangle


checking your output in gnuplot
  1. In your editor: copy & paste the program output (e.g., the text in black color in the left sample run).
  2. Save it as a file named tmp.
  3. Run gnuplot and give a "plot" command (see below).
    ~/$ gnuplot
        G N U P L O T
        ... 
    
    Terminal type set to 'wxt'
    gnuplot> plot "tmp" with linespoints;
  4. A new window will pop up showing gnuplot's output.
Submission:
~/bin/submit -c=IC210 -p=lab03 part1.cpp part2.cpp part3.cpp

Part 4: Going further, Classifying triangles

There are two common ways of classifying a triangle:

This is an acute isosceles triangle.
  1. By describing its interior angles
  2. By describing the lengths of the sides in relation to each other
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.

A corollary of the Pythagorean theorem's converse is a simple means of determining whether a triangle is right, obtuse, or acute, as follows. Let c be chosen to be the longest of the three sides and a + b > c (otherwise there is no triangle according to the triangle inequality). The following statements apply:

Example executions are shown below:

~/$ ./part4 
Enter side lengths: 1 2 3 
Error! these lengths violate the triangle inequality!
~/$ ./part4 
Enter side lengths: 1.5 2 3 
This is a obtuse scalene triangle.
~/$ ./part4 
Enter side lengths: 2 2 3 
This is a obtuse isosceles triangle.
~/$ ./part4 
Enter side lengths: 2 2 2 
This is a acute equilateral triangle.
~/$ ./part4 
Enter side lengths: 2 2 1.5 
This is a acute isosceles triangle.

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

~/bin/submit -c=IC210 -p=lab03 part1.cpp part2.cpp part3.cpp part4.cpp