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 value by
the assignment in the function.
}
Shape.cpp:
#include
"shape.h"
Shape
::Shape()
{
}
Shape::Shape(
float
s
)
{
// parameterized constructor
}
void
Shape
::setdata(
float
s
)
{
//assign the parameter to the member variable.
}
float
Shape
::getdata()
{
//retrieve the value of the variable.
}
triangle.h
#include
#include "shape.h"
using namespace std;
class Triangle : public Shape
{
public:
Triangle();
float getarea();
void setheight(float);
private:
float height;
};
shape.h
#include
using namespace std;
class Shape
{
private:
float edge;
public:
Shape();
Shape(float);
void setdata(float);
float getdata();
};
Note: not trapezoid. Everything is triangle.
------------------- I used Visual Studio 2013, C++ Language, Console Application -------------------
-------------------Output-------------------
-------------------CODE-------------------
-------------------Shape.h-------------------
class Shape
{
private:
float edge;
public:
Shape();
Shape(float);
void setdata(float);
float getdata();
};
-------------------Shape.cpp-------------------
#include "stdafx.h"
#include "Shape.h"
Shape::Shape()
{
edge = 0.0;
}
Shape::Shape(float s)
{
// In this example no use of parameterized
constructor
}
void Shape::setdata(float s)
{
edge = s;//assign the parameter to the member
variable.
}
float Shape::getdata()
{
return edge;//retrieve the value of the
variable.
}
-------------------Triangle.h-------------------
#include "Shape.h"
using namespace std;
class Triangle : public Shape
{
private:
float height;
public:
Triangle();
float getarea();
void setheight(float);
};
-------------------Triangle.cpp-------------------
#include "stdafx.h"
#include "Triangle.h"
Triangle::Triangle()
{
height = 0;//default constructor
}
float Triangle::getarea()
{
//getdata() is called from base class Shape
return 0.5*getdata()*height; // 1/2 * edge *
height
}
void Triangle::setheight(float h)
{
height = h;//set the height value
}
-------------------ShapeProgram.cpp-------------------
#include "stdafx.h"
#include "Triangle.h"
#include <iostream>
using namespace std;
//This is the main function class called ShapeProgram.cpp
int main()
{
float _edge, _height;
Triangle triangle; //Create instance of child
class
cout << "Enter edge : ";
cin >> _edge;
cout << "Enter height : ";
cin >> _height;
triangle.setdata(_edge); //Passing _edge value to base
class Shape private field edge
triangle.setheight(_height); //Passing _height value
to class triangle private field height
cout << "Area of triangle : " <<
triangle.getarea() << endl;
system("pause");
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------
C++ The Shape.hcontains the information of the length of an edge. The derived triangle class has...
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...
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...
((( Using Only The mentioned Concepts Solve the following question in DETAILS “ Take your time but don’t disappoint me plleeaasseee”: 1- Control structure (if/if else/while/for/switch/do while/ break continue) 2- Functions 3- Arrays 4- pointers and strings 5- classes 6- file processing ))) if it was a program i need to see the code printed on computer and the output too please . 10. Write a C++code that include two classes: Rectangle and Triangle as shown below: #include <iostream> using...
C++ Please complete the implementation of the following source code (Question3.cpp). You need to add your code in the source code where the comment “// your code” locates. After you finish the implementation, please also provide the output of your program. #include <iostream> using namespace std; class Shape { protected: // your code public: void setWidth (int w) { // your code } void setHeight (int h) { // your code } }; class Rectangle: public Shape { public: int...
Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...
Design a class named Triangle that extends GeometricObject class. The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a default triangle with color = "blue", filled = true. A constructor that creates a triangle with the specified side1, side2, side3 and color = "blue", filled = true. The accessor functions for all three data fields, named getSide1(), getSide2(), getSide3(). A function...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...
Using python 3.x to solve this problem. Equilateral Triangle Class EqTri Write a class that has several functions related to an Equilateral length : float Triangle. The constructor shouldgetArea): float accept a one parameter for the +getPerimeter): float length (which is the same for all 3+float-0 : float sides in an equilateral triangle) + _str) string -str--() method should return a string such as "Rectangle (Area:50)" float) method should return the area (Same functionality as getArea) Math (area- length?, perim/circum...
Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse: . a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which stores that salesman's position title . a float which stores their commission percentage, i.e., the percentage of sales they receive as a paycheck . a float which stores...