Given Triangle struct (in files Triangle.h and Triangle.c), complete main() to read and set the base and height data members of triangle1 and of triangle2, determine which triangle's area is smaller, and output that triangle's info, making use of the relevant Triangle 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 smaller area: Base: 3.00 Height: 4.00 Area: 6.00
Given Triangle struct (in files Triangle.h and Triangle.c), complete main() to read and set the base and height data members of triangle1 and of triangle2, determine which triangle's area is smaller, and output that triangle's info, making use of the relevant Triangle 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 smaller area: Base: 3.00 Height: 4.00 Area: 6.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
Related questions
Question
![Given Triangle struct (in files Triangle.h and Triangle.c), complete main() to read and set the base and height data members of triangle1 and
of triangle2, determine which triangle's area is smaller, and output that triangle's info, making use of the relevant Triangle 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 smaller area:
Base: 3.00
Height: 4.00
Area: 6.00
412800.2778464.gx320/7
LAB
ACTIVITY
1 #include <stdio.h>
2 #include "Triangle.h"
3
4 void setBase (Triangle *triangle, double base) {
5
triangle->base = base;
6}
7
8 void setHeight (Triangle triangle, double height) {
9
triangle->height = height;
10}
11
12 void calculateArea(Triangle *triangle) {
13
14}
9.11.1: LAB: Triangle area comparison
24
25
26
27
28
29
15
16 void printTriangle(Triangle triangle) {
17
18
19
20 }
30
31
32
21
22 main() {
23
33
34
35
36
37
38
39
40
41
triangle->area = 0.5 * triangle->base triangle->height;
printf("Base: %.2f\n", triangle.base);
printf("Height: %.2f\n", triangle.height);
printf("Area: %.2f\n", triangle.area);
Triangle trianglel;
Triangle triangle2;
double base1, height1, base2, height2;
scanf("%lf %1f", &basel, &height1);
scanf("%lf %lf", &base2, &height2);
setBase(&trianglel, basel);
setHeight (&triangle1, height1);
calculateArea(&trianglei);
Current file: main.c
setBase(&triangle2, base2);
setHeight (&triangle2, height 2);
calculateArea (&triangle2);
printf("Triangle with smaller area: \n");
if (triangle1.area < triangle2.area) {
printTriangle(triangle1);
} else {
}
42
43
44
45}
46
47 Triangle.h
48
49 #ifndef TRIANGLE_H
50 #define TRIANGLE_H
print Triangle (triangle2);
51
52 typedef struct Triangle {
53
double base;
double height;
double area;
54
55
56
57
58 void setBase (Triangle *triangle, double base);
59 void setHeight (Triangle triangle, double height);
60 void calculateArea(Triangle triangle);
61 void printTriangle(Triangle triangle);
62
63 #lendi+
Triangle;
0/10
Load default template.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0861d444-2540-428c-80bb-c7cdc7cbe35e%2Fd089daed-190b-4586-ac68-98f82b2e7378%2Fcgo02r_processed.png&w=3840&q=75)
Transcribed Image Text:Given Triangle struct (in files Triangle.h and Triangle.c), complete main() to read and set the base and height data members of triangle1 and
of triangle2, determine which triangle's area is smaller, and output that triangle's info, making use of the relevant Triangle 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 smaller area:
Base: 3.00
Height: 4.00
Area: 6.00
412800.2778464.gx320/7
LAB
ACTIVITY
1 #include <stdio.h>
2 #include "Triangle.h"
3
4 void setBase (Triangle *triangle, double base) {
5
triangle->base = base;
6}
7
8 void setHeight (Triangle triangle, double height) {
9
triangle->height = height;
10}
11
12 void calculateArea(Triangle *triangle) {
13
14}
9.11.1: LAB: Triangle area comparison
24
25
26
27
28
29
15
16 void printTriangle(Triangle triangle) {
17
18
19
20 }
30
31
32
21
22 main() {
23
33
34
35
36
37
38
39
40
41
triangle->area = 0.5 * triangle->base triangle->height;
printf("Base: %.2f\n", triangle.base);
printf("Height: %.2f\n", triangle.height);
printf("Area: %.2f\n", triangle.area);
Triangle trianglel;
Triangle triangle2;
double base1, height1, base2, height2;
scanf("%lf %1f", &basel, &height1);
scanf("%lf %lf", &base2, &height2);
setBase(&trianglel, basel);
setHeight (&triangle1, height1);
calculateArea(&trianglei);
Current file: main.c
setBase(&triangle2, base2);
setHeight (&triangle2, height 2);
calculateArea (&triangle2);
printf("Triangle with smaller area: \n");
if (triangle1.area < triangle2.area) {
printTriangle(triangle1);
} else {
}
42
43
44
45}
46
47 Triangle.h
48
49 #ifndef TRIANGLE_H
50 #define TRIANGLE_H
print Triangle (triangle2);
51
52 typedef struct Triangle {
53
double base;
double height;
double area;
54
55
56
57
58 void setBase (Triangle *triangle, double base);
59 void setHeight (Triangle triangle, double height);
60 void calculateArea(Triangle triangle);
61 void printTriangle(Triangle triangle);
62
63 #lendi+
Triangle;
0/10
Load default template.
![J
File is marked as read only
1 #include <stdio.h>
2
3 #include "Triangle.h"
4
5 Triangle InitTriangle() {
6
Triangle triangle;
7
8
9
10 }
11
triangle.base= 0.0;
triangle.height = 0.0;
return triangle;
12 Triangle SetBase(Triangle triangle, double userBase) {
13
triangle.base = userBase;
14 return triangle;
15 }
16
17 Triangle SetHeight (Triangle triangle, double userHeight) {
18
triangle.height = userHeight;
19
return triangle;
20 }
21
22 double GetArea(Triangle triangle) {
23 double area = 0.5 triangle.base triangle.height;
return area;
24
25 }
26
27 void PrintInfo(Triangle triangle) {
28
printf("Base: %.21f\n", triangle.base);
29 printf("Height: %.21f\n", triangle.height);
30 printf("Area: %.21f\n", GetArea(triangle));
31
t.png
File is marked as read only
Current file: Triangle.c
1 #ifndef TRIANGLE_H_
2 #define TRIANGLE_H_
3
4 typedef struct Triangle_struct {
5
double base;
double height;
12 double GetArea(Triangle triangle);
13 void PrintInfo(Triangle triangle);
14
15 #endif
Current file: Triangle.h
6
7} Triangle;
8
9 Triangle InitTriangle();
10 Triangle SetBase(Triangle triangle, double userBase);
11 Triangle SetHeight(Triangle triangle, double userHeight);
⠀
O
100%
I](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0861d444-2540-428c-80bb-c7cdc7cbe35e%2Fd089daed-190b-4586-ac68-98f82b2e7378%2Fdhif10j_processed.png&w=3840&q=75)
Transcribed Image Text:J
File is marked as read only
1 #include <stdio.h>
2
3 #include "Triangle.h"
4
5 Triangle InitTriangle() {
6
Triangle triangle;
7
8
9
10 }
11
triangle.base= 0.0;
triangle.height = 0.0;
return triangle;
12 Triangle SetBase(Triangle triangle, double userBase) {
13
triangle.base = userBase;
14 return triangle;
15 }
16
17 Triangle SetHeight (Triangle triangle, double userHeight) {
18
triangle.height = userHeight;
19
return triangle;
20 }
21
22 double GetArea(Triangle triangle) {
23 double area = 0.5 triangle.base triangle.height;
return area;
24
25 }
26
27 void PrintInfo(Triangle triangle) {
28
printf("Base: %.21f\n", triangle.base);
29 printf("Height: %.21f\n", triangle.height);
30 printf("Area: %.21f\n", GetArea(triangle));
31
t.png
File is marked as read only
Current file: Triangle.c
1 #ifndef TRIANGLE_H_
2 #define TRIANGLE_H_
3
4 typedef struct Triangle_struct {
5
double base;
double height;
12 double GetArea(Triangle triangle);
13 void PrintInfo(Triangle triangle);
14
15 #endif
Current file: Triangle.h
6
7} Triangle;
8
9 Triangle InitTriangle();
10 Triangle SetBase(Triangle triangle, double userBase);
11 Triangle SetHeight(Triangle triangle, double userHeight);
⠀
O
100%
I
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education