SI204

Lab 3

Pre-lab homework.  None.

 

1.  Write a program 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:

Command: Convert 3.50 Euros to Dollars
Results: 4.7719
		    
Command: Convert 3.50 Euros to Pounds
Results: 2.3653
		    

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

 

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

 

Command: Convert 3.50 Euros to Dollars US
Results: 4.7719
			  
Command: Convert 11.72 Dollars US to Dollars Canadian
Results: 12.3458
			  

 


Going Further 

If you finish the lab assignment early you should try to tackle this problem: 

 

It is often necessary to write programs that produce output that is intended as input for other programs. You will write a program that reads in three points from the user and prints output that the user can cut-and-paste into Excel 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. (You should probably look at this info on using Excel to plot points.) Here's a sample run of the program:

And here's the plot that is produced by copying your programís output into Excel with the above data:

 

Going Even Further 

For a tougher challenge consider this problem: 

 

 

A triangle can be classified in two ways:

  1. By describing its interior angles
  1. By describing the lengths of the sides in relation to each other

 

A triangle can be described using these two classifications in combination.  For example, Figure 1 is an acute isosceles triangle.

 

 

Figure 1

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.

Where s is the semiperimeter of the triangle.

s = 1/2(a + b + c)

Also, using the 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.

Where R is the radius of the circle that circumscribes the triangle.  How am I supposed to calculate THAT!?  Calm down, we'll tell you...

It just so happens that calculating the area of the triangle will help you.  The diameter of a circumscribing circle (also known as 2R) is equal to the product of the three lengths, divided by two times the area.

Using this knowledge write a program that:

  1. Display your name and alpha code.

  2. Prompts the user for the three lengths of the sides of a triangle

  3. Checks and states whether the given input can form a triangle

  4. Calculates and displays the area of the triangle

  5. Calculates and displays the measurements of all three interior angles

  6. States what type of triangle is formed by the input.  I.e. "This is a obtuse scalene triangle"