Question: baseValue and heightValue are read from input. Declare and assign pointer myTriangle with a new Triangle object. Then, set myTriangle's base and height to baseValue
baseValue and heightValue are read from input. Declare and assign pointer myTriangle with a new Triangle object. Then, set myTriangle's base and height to baseValue and heightValue, respectively.
Ex: if the input is 10.0 5.5, then the output is:
Triangle's base: 10.0 Triangle's height: 5.5
#include
class Triangle { public: Triangle(); void Print();
double base; double height; }; Triangle::Triangle() { base = 0.0; height = 0.0; } void Triangle::Print() { cout << "Triangle's base: " << fixed << setprecision(1) << base << endl; cout << "Triangle's height: " << fixed << setprecision(1) << height << endl; }
int main() { double baseValue; double heightValue; /* Additional variable declarations go here */ cin >> baseValue; cin >> heightValue; /* Your code goes here */ myTriangle->Print(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
