I need help trying to complete this practice question. I have listed my main function, my header file named "Triangle" and another .cpp file named "Triangle" as well. This is the question being asked:
Design a main function to test the Triangle class in the following way:
1. Declare an object tri of the Triangle. Get the triangle’s width, length and name from the
user, and store them in this object using member functions. Then display the name,
base, height, and area of the tri object.
2. Declare a Triangle pointer triPtr. Dynamically allocate an object belonging to the
Triangle class, assign the values that was read by the user to name, base, and height
using member functions, and then display the name, base, height, and area. At last,
delete dynamically allocated object.
This is what I have so far...
MAIN:
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
#include <cstring>
#include "Triangle.h"
using namespace std;
int main()
{
}
|
HEADER:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Triangle
{
private:
double base;
double height;
std::string name;
public:
void setValues(double a, double b);
void setName(std::string s);
void getValues();
void getName();
double getArea();
};
|
.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include "Triangle.h"
void Triangle::setValues(double a, double b)
{
base = 0;
height = 0;
}
void Triangle::setName(std::string s)
{
name = new char[0];
}
void Triangle::getValues()
{
}
void Triangle::getName()
{
}
double Triangle::getArea()
{
return 0;
}
|