Docsity

Notes on Classifying Triangles - Programming Project | CSC 1253, Study notes of Computer Science

Toggle sidebar
bg1
Describing Triangles CSc 1253: Programming Project # 4
Describing Triangles
Out: 3/10
Due: 3/20 by 11:50 PM
Learning Objectives
•To review external text file input,
•To use multi-level modular design,
•To use while-not-end-of-file loop,
•To review standard library functions,
•To review formatted output of real numbers,
•To implement value-returning, and
•To implement void functions with reference parameters.
A triangle is a three-sided polygon. Every triangle has three sides and three
angles, some of which may be the same. Every triangle satisfies the so-called
triangle inequality: the sum of any two sides must be greater than the
third side. Triangles can be classified by the length of their sides or the val-
ues of their angles. The study of triangles is sometimes known as triangle
geometry, and is of interest to mathematicians and artists interested in gen-
erating oblique shapes composed of triangles. They usually give beautiful
results and unexpected properties. August Leopold Crelle, a nineteenth cen-
tury German mathematician, once remarked, ”It is indeed wonderful that so
simple a figure as the triangle is so inexhaustible in properties. How many
as yet unknown properties of other figures may there not be?”
Your program will a set of triples from a text file, triple.in. If these num-
bers cannot form the sides of a triangle, your program will print a message
indicating so. If these numbers can represent the lengths of the sides of a
triangle, your program will print a report showing the sides of the triangle,
its area and perimeter, and classify the triangle according to the definitions:
Duncan 1 Spring 2011
pf3
pf4
pf5

Partial preview of the text

Download Notes on Classifying Triangles - Programming Project | CSC 1253 and more Study notes Computer Science in PDF only on Docsity!

Describing Triangles

Out: 3/ Due: 3/20 by 11:50 PM

Learning Objectives

  • To review external text file input,
  • To use multi-level modular design,
  • To use while-not-end-of-file loop,
  • To review standard library functions,
  • To review formatted output of real numbers,
  • To implement value-returning, and
  • To implement void functions with reference parameters.

A triangle is a three-sided polygon. Every triangle has three sides and three angles, some of which may be the same. Every triangle satisfies the so-called triangle inequality: the sum of any two sides must be greater than the third side. Triangles can be classified by the length of their sides or the val- ues of their angles. The study of triangles is sometimes known as triangle geometry, and is of interest to mathematicians and artists interested in gen- erating oblique shapes composed of triangles. They usually give beautiful results and unexpected properties. August Leopold Crelle, a nineteenth cen- tury German mathematician, once remarked, ”It is indeed wonderful that so simple a figure as the triangle is so inexhaustible in properties. How many as yet unknown properties of other figures may there not be?” Your program will a set of triples from a text file, triple.in. If these num- bers cannot form the sides of a triangle, your program will print a message indicating so. If these numbers can represent the lengths of the sides of a triangle, your program will print a report showing the sides of the triangle, its area and perimeter, and classify the triangle according to the definitions:

  1. An isosceles triangle is a triangle with (at least) two equal sides.
  2. A triangle with all sides equal is called an equilateral triangle.
  3. A triangle with no two sides equal is called a scalene triangle.
  4. A right triangle is a triangle whose sides, a, b, and c, satisfy the equation c^2 = a^2 + b^2.

Be sure to use this include directive ( #include < cmath > ) in order to use stand math library functions such as pow and sqrt. Format all output of real numbers to 1 decimal place. Assume that all input values are positive. Relevant Formulas: Let A, B and C denote the sides of the triangle: P erimeter = A + B + C Area =

S(S − A)(S − B)(S − C), where S = P erimeter 2

A modular implementation must be designed using functions. In addition to the main function, your program will consist of the following user-defined functions; you may design more:

/* determines whether three numbers satisfies the triangle

  • inequality; that is, can form the sides of a triangle.
  • @param num1 a non-negative fixed-point value
  • @param num2 a non-negative fixed-point value
  • @param num3 a non-negative fixed-point value
  • @return true if these numbers satisfy the triangle
  • inequality; otherwise, false is returned. Also returns
  • false if any of the numbers is non-positive. */ bool isTriangle(double num1, double num2, double num3)

/* determines whether a triangle is a right-triangle

  • @param sideA the length of the first side of the triangle
  • @param sideB the length of the second side of the triangle
  • @param sideC the length of the third side of the triangle
  • @return true if the sum of squares of the lengths of two sides
  • is equal to the third side; otherwise, false is returned. */ bool isRight(double sideA, double sideB, double sideC)

the triple could represent the sides of a triangle. If so, your program should calculate and display the area and perimeter of the triangle and then classify the triangle, indicating whether it is a right triangle, an isosceles triangle, an equilateral triangle and a scalene triangle. On the other hand, if the triple does not satisfy the triangle inequality, your program should print a message indicating so. Once the data from triple.in have been processed, be sure to close the file.

For a sample input file, triple.in, with the data below:

7.5 4.5 6 1.0 2.0 5. 4.1 4.1 5.

A typical program interaction would be:

Enter the name of the data file> triple.in Triangle Program Report ================================= The sides of the triangle are: A = 7.50; B = 4.50; C = 6. Perimeter = 18. Area = 13. Classification: Right: Y Isosceles: N Scalene: Y Equilateral: N

*** 1.00, 2.00, and 5.00 cannot form the sides of a triangle ***

The sides of the triangle are: A = 4.10; B = 4.10; C = 5. Perimeter = 13. Area = 8. Classification: Right: N Isosceles: Y Scalene: N Equilateral: N

*** END OF REPORT ***

Follow the coding style guidelines, as discussed in class, to properly doc- ument each subfunction used in this program. Include function definitions in the appropriate locations, as discussed in class. Be sure to use descriptive names for all identifiers you define in your program. Name your source file triangle.cpp. Your source file must have the following header comments:

/** @file filename @author your name @date 9999-99- Description: describe what the program does. Course: CS1253 Section: x Logon ID: cs1253xx Programming Project #: 4 Instructor: Duncan */

Preparing your workspace and submitting Your Work

  1. Logon to the server (classes.csc.lsu.edu) using your logon ID and pass- word.
  2. Create a directory prog4 in your home area: mkdir prog
  3. Change to the prog4 directory: cd prog
  4. Create a sample data file, to test your program. You may use the sample data given above. Include in the file the three triples above and 7 additional triples to exhaustively test your program. Put only one triple per line in the file: pico whatevernameyouwish Once you have created the data file, save it and exit the editor.
  5. Edit your program using pico and save your work when your are fin- ished: pico triangle.cpp
  6. Compile your program: g++ -o triangle triangle.cpp. Correct syntax errors, if any, and recompile your program.