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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
### 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.
Transcribed Image Text:### 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.
# 7.21 LAB: Triangle Area Comparison (Classes)

Given the class `Triangle` (in files Triangle.h and Triangle.cpp), complete `main()` to read and set the base and height of `triangle1` and `triangle2`. Determine which triangle's area is larger, and output that triangle's information, making use of `Triangle`'s relevant member functions.

**Example:**

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, `5.0` is triangle2's height.

The output is:

```
Triangle with larger area:
Base: 4.00
Height: 5.00
Area: 10.00
```
Transcribed Image Text:# 7.21 LAB: Triangle Area Comparison (Classes) Given the class `Triangle` (in files Triangle.h and Triangle.cpp), complete `main()` to read and set the base and height of `triangle1` and `triangle2`. Determine which triangle's area is larger, and output that triangle's information, making use of `Triangle`'s relevant member functions. **Example:** 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, `5.0` is triangle2's height. The output is: ``` Triangle with larger area: Base: 4.00 Height: 5.00 Area: 10.00 ```
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education