part1.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 in your laptop (the lab machines already have the program installed, so skip this if you work on a lab machine):
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.
|
|
~/bin/submit -c=IC210 -p=lab03 part1.cpp
part2.cpp
that works like this:
~$ ./part2 B0100 + B1000 = B1100 |
~$ ./part2 B0100 + D16 = D20 |
~$ ./part2 D1 + D3 = B0100 |
~$ ./part2 D1 = B0001 |
number + number = |
number = |
Here, number is binary or decimal. In particular,
As shown in the above sample executions, the program calculates the input equation and prints the output as follows:
~/bin/submit -c=IC210 -p=lab03 part1.cpp part2.cpp
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:
Tip: Think about how to determine the longest side and store it in
variable c.
Example executions are shown below:
~$ ./part3 Enter side lengths: 1 2 3 Error! these lengths violate the triangle inequality! ~$ ./part3 Enter side lengths: 3 1.5 2 This is a obtuse scalene triangle. ~$ ./part3 Enter side lengths: 2 2 3 This is a obtuse isosceles triangle. ~$ ./part3 Enter side lengths: 2 2 2 This is a acute equilateral triangle. ~$ ./part3 Enter side lengths: 2 1.5 2 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