Code in C++
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
___________________________________________________________________
GIVEN (in main.cpp):
#include
#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;
}
Triangle.h
#pragma once
#include<iostream>
#include<iomanip>
using namespace std;
class Triangle
{
private:
double base, height;
public:
Triangle();
Triangle(double, double);
double GetBase();
void SetBase(double);
double GetHeight();
void SetHeight(double);
double CalculateArea();
void PrintInfo();
};
Triangle.cpp
#include "Triangle.h"
Triangle::Triangle()
{
this->base = this->height = 0.0;
}
Triangle::Triangle(double base, double height)
{
SetBase(base);
SetHeight(height);
}
double Triangle::GetBase() { return base; }
void Triangle::SetBase(double base) { this->base = base; }
double Triangle::GetHeight() { return height; }
void Triangle::SetHeight(double height) { this->height = height; }
double Triangle::CalculateArea() { return (0.5 * base * height); }
void Triangle::PrintInfo()
{
cout << setprecision(2) << fixed;
cout << "Base: " << base <<
"\tHeight: " << height << "\tArea: " <<
CalculateArea() << endl;
}
Main.cpp (Main class)
#include "Triangle.h"
int main()
{
double base1, height1, base2, height2;
Triangle triangle1, triangle2;
cout << "Enter base and height (separated by
space) of triangle 1: ";
cin >> base1 >> height1;
cout << "Enter base and height (separated by
space) of triangle 2: ";
cin >> base2 >> height2;
triangle1.SetBase(base1);
triangle1.SetHeight(height1);
triangle2.SetBase(base2);
triangle2.SetHeight(height2);
double area1 = triangle1.CalculateArea();
double area2 = triangle2.CalculateArea();
cout << "\nTriangle with larger area:\n";
if (area1 > area2)
triangle1.PrintInfo();
else
triangle2.PrintInfo();
return 0;
}
********************************************************* SCREENSHOT *******************************************************
CODE SCREENSHOTS :



CONSOLE OUTPUT :

Code in C++ Given class Triangle (in files Triangle.h and Triangle.cpp), complete main() to read and...
this is a jave program please help, I'm so lost import java.util.Scanner; public class TriangleArea { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Triangle triangle1 = new Triangle(); Triangle triangle2 = new Triangle(); // Read and set base and height for triangle1 (use setBase() and setHeight()) // Read and set base and height for triangle2 (use setBase() and setHeight()) // Determine larger triangle (use getArea()) private int base; private int height; private...
C++ The Shape.hcontains the information of the length of an edge. The derived triangle class has the length of the height of the corresponding edge. Use the two values to compute the area of this triangle in getarea member function.Create the instance and output its result in the main function. Triangle.cpp: #include "triangle.h" Triangle ::Triangle() { //default constructor } float Triangle ::getarea() { //compute the area of the shape } void Triangle ::setheight( float h ) { //set the height...
Solve in C++ for Car.h and Car.cpp
8.21 LAB: Car value (classes) Given main, complete the Car class (in files Car hand Car.cpp) with member functions to set and get the purchase price of a car (SetPurchase Price().GetPurchase Price)and to output the car's information (Printinfo). Ex If the input is 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, the output is Car's information Model year: 2011 Purchase...
Description There are 4 classes, Figure is the base class,both Triangle, Rectangle and Circle are all inherited from it. Figure class is like following: class FIGURE { public: void set_size(double x, double y = 0); virtual double get_area() = 0; protected: double x_size, y_size; }; You should implement Figure, Triangle, Rectange, Circle class. Output Area of triangle is 60 Area of rectangle is 120 Area of circle is 706.858 //Figure.h #ifndef FIGURE_H #define FIGURE_H const double PI = 3.14159; class...
*****language : java****** ceate a class RightTriangle with three instance variables of type double called base, height, and hypotenuse and three instance variables of type int called ID, xLoc and yLoc. Also add a static variable of type double called scaleFactor. This should be initialized to a default value of 1. Then define an appropriate constructor that takes initial values for all instance variables except hypotenuse and sets the values of all instance variables including calculating the hypotenuse. Then define...
In C programming language: This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or *....
In C++ please.
7.26 LAB: Nutritional information (classes/constructors) Given main(), complete the Food Item class (in files Foodltem.h and Fooditem.cpp) with constructors to initialize each food item. The default constructor should initialize the name to "None" and all other fields to 0.0. The second constructor should have four parameters (food name, grams of fat, grams of carbohydrates, and grams of protein) and should assign each private field with the appropriate parameter value. Ex: If the input is: M&M's 10.0 34.0...
10.18 LAB: Plant information (vector) Given a base Plant class and a derived Flower class, complete main() to create a vector called myGarden. The vector should be able to store objects that belong to the Plant class or the Flower class. Create a function called PrintVector(), that uses the PrintInfo() functions defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to...
Solve in C++ for Team.h and Team.cpp
Given main(). define the Team class (in files Team.h and Team.cpp). For class member function GetWinPercentage, the formula is: teamwins / (teamins + teamLosses) Note: Use casting to prevent integer division Ex: If the input is Ravens 13 3 where Ravens is the team's name, 13 is number of team wins, and 3 is the number of team losses, the output is: Congratulations, Team Ravens has a winning average! If the input is...
This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. (1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt) (2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the...