C++ with Stack.h, StackNode.h, Triangle.h, Triangle.cpp, and main.cpp please
Work in groups of two or three students. This lab will support the same input as in Lab #4. Use the Stack Template on Blackboard (Course Documents -> S09: Template Example) to store dynamic Triangle objects created from the input triangles.dat file.
// Triangle.h
#ifndef TRIANGLE_H
#define TRIANGLE_H
class Triangle {
public:
Triangle(float base, float height);
float area();
float getBase();
float getHeight();
private:
float base_;
float height_;
};
#endif /* TRIANGLE_H */
Your program will first create the Stack of Triangles before computing the area for each. Again, you may use the following values in your data file or you can create your own.
$ cat triangles.dat
15.0 4.0
6.0 9.0
3.0 4.0
5.23 8.45
52.36 84.78
The area of a triangle is calculated with this formula:
Area = 1/2 * base * height
Expected output format:
$ ./1ab05
Triangle 1: b=52.36, h=84.78, area=2219.54
Triangle 2: b=5.23, h=8.45, area=22.0968
Triangle 3: b=3, h=4, area=6
Triangle 4: b=6, h=9, area=27
Triangle 5: b=15, h=4, area=30
Note: I will use a different input data file to test your program and the file will contain a different number of triangles, including an empty file or missing file. So, do not assume there will always be 5 triangles in the file.