7.21 LAB: Triangle area comparison (classes) Given class Triangle (in files Triangle.h and Triangle.cpp), complete main() to read and set the base and height of triangle1 and of triangle2, determine which triangle's area is larger, and output that triangle's info, making use of Triangle's relevant member functions. Ex: If the input is: 3.0 4.0 4.0 5.0 where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is: Triangle with larger area: Base: 4.00 Height: 5.00 Area: 10.00
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
7.21 LAB: Triangle area comparison (classes)
Given class Triangle (in files Triangle.h and Triangle.cpp), complete main() to read and set the base and height of triangle1 and of triangle2, determine which triangle's area is larger, and output that triangle's info, making use of Triangle's relevant member functions.
Ex: If the input is:
3.0 4.0 4.0 5.0where 3.0 is triangle1's base, 4.0 is triangle1's height, 4.0 is triangle2's base, and 5.0 is triangle2's height, the output is:
Triangle with larger area: Base: 4.00 Height: 5.00 Area: 10.00![### Lab Activity: Triangle Area Comparison (Classes)
#### File: main.cpp
This code snippet is for a lab activity that involves comparing the areas of two triangles using class concepts in C++. Below is a breakdown of the code provided:
```cpp
#include <iostream>
#include "Triangle.h"
using namespace std;
int main(int argc, const char* argv[]) {
Triangle triangle1;
Triangle triangle2;
// TODO: Read and set base and height for triangle1 (use SetBase() and SetHeight())
// TODO: Read and set base and height for triangle2 (use SetBase() and SetHeight())
// TODO: Determine larger triangle (use GetArea())
cout << "Triangle with larger area:" << endl;
// TODO: Output larger triangle's info (use PrintInfo())
return 0;
}
```
#### Explanation:
1. **Includes and Namespace Declaration**:
- The code begins with including the standard input-output stream library `<iostream>` and a custom header `"Triangle.h"`.
- It uses the standard namespace with `using namespace std;`.
2. **Function `main`**:
- This is the entry point of the program.
- It accepts command-line arguments `argc` and `argv`.
3. **Triangle Objects**:
- Two objects of the Triangle class, `triangle1` and `triangle2`, are declared.
4. **TODO Sections**:
- **Reading and Setting Base and Height**:
- Instructions to read and set the base and height for each triangle using methods `SetBase()` and `SetHeight()` need to be implemented.
- **Determine Larger Triangle**:
- Code is needed to calculate and compare the areas of the triangles using a `GetArea()` method.
- **Output Larger Triangle**:
- The larger triangle's information should be displayed using a `PrintInfo()` method.
5. **Output**:
- The program outputs the text "Triangle with larger area:" but the specific details remain to be implemented.
The code provides a structured foundation for comparing triangle areas by implementing class methods within a given `Triangle` class.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc06e22d6-1f87-4bdc-ba1a-0d1f50ec54b0%2Fccd8301e-1bdc-4902-8505-3e109ccbfc77%2Flzphluf_processed.png&w=3840&q=75)


Trending now
This is a popular solution!
Step by step
Solved in 2 steps









