LAB 11C - TRIANGLE CLASS
Concept
Focus on defining a Triangle class from scratch, in preparation for the exam.
Suggestion (again): Use NotePad or WordPad
Consider using NotePad or WordPad on your computer to write your code for this lab. Once you feel good about what you've written, then copy the code into Visual Studio. Doing this will help you see where you might make mistakes on the exam!
You should write a main.cpp
that tests each
feature of your class works as expected. You will need to submit your class prototype
file, your class implementation file, and your main.cpp
file for this
lab with Homework 11.
Triangle Class
As you know from earlier assignments (i.e., HW 02, Lab03A, Lab03B, and Lab04A), we have a strange fetish with triangles. Now that you have some skills with classes, write a Triangle class to represent this "thing" to the computer. What properties do you need to represent a triangle? Make these properties private to your class. (You should know why private makes sense; ask if you don't!) In all functions that modify data members, you should always ensure the values being set make sense. Also, use a private helper function wherever one makes sense. Functions you should include in your class:
- A default constructor that sets all three sides of the triangle to one.
- Appropriate getter and setter functions.
- A boolean
validate
member function that tests whether a triangle is possible (e.g., if each side is smaller than the sum of the others). - A function that returns a triangle's area.
- A function that returns a triangle's perimeter.
- A function that returns true if the callee's area is larger than the area of the triangle parameter passed.
main
.