|
Box Class, need help again :(
Okay so i think im doing a little better and understand a little better on what im doing, but not quite so sure lol.. Anways here it goes.
Last week i built a Point Class:
Quote:
Write a C++ class called point. You should create the following 3 seperate files:
* point.h: the header file for the point class
* point.cpp: the code and data for the point class; and
* pointdrivr.cpp
the point class will consist of the following memeber function:
* constructor with no arguments;
* constructor with arguments for three coordinates that define the point
* seperate functions for setting the x,y, and z coordinates;
* a function to compute the difference between the 2 points;
* a function to compute the midpoint between the to points;
* a function that will display all the point attributes; and
* separate accessor functions for getting each attribute.
|
The files i wrote were:
Point.h
#ifndef POINT_H
#define POINT_H
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
/**************************************************************************
* Author: Glen Newell
* class: XYZPoint
*
* Description:
* A constructor that passes 3 variables
* A default constructor that has preset values
* A function for setting the x,y and z variables
* A function to compute the distance between the two points
* A function to compute the midpoint between the two points
* A function that will display all the points attributes
* Sperate accessor functions fro getting each attribute.
*
***************************************************************************/
class XYZPoint
{
//constructor that passes 3 veriables
private: //declares Coorodinates
double xCoor;
double yCoor;
double zCoor;
public:
/**************************************************************************
* Author: Glen Newell
* Class: XYZPoint
* Function: XYZPoint
*
* Discription:
* Default Constructor that sets the x,y & z Coor to 0.00 if no value
* is passed.
***************************************************************************/
XYZPoint()
{
xCoor = 0.000;
yCoor = 0.000;
zCoor = 0.000;
}
/**************************************************************************
* Author: Glen Newell
* Class: XYZPoint
* Function: XYZPoint
*
* Discription:
* Prototype Constructor that passes three doubles, defines the points
* of the triangle
***************************************************************************/
XYZPoint(double, double, double);
/**************************************************************************
* Author: Glen Newell
* Class: XYZPoint
* Function: get(X,Y,Z)Coor
*
* Discription:
* Prototype get*Coor that passes an X,Y, or Z Coordinate
***************************************************************************/
double getXCoor();
double getYCoor();
double getZCoor();
/**************************************************************************
* Author: Glen Newell
* Class: XYZPoint
* Function: set(X,Y,Z)Coor
*
* Discription:
* Prototype set*Coor that passes an X,Y, or Z Coordinate
***************************************************************************/
void setXCoor(double);
void setYCoor(double);
void setZCoor(double);
/**************************************************************************
* Author: Glen Newell
* Class: XYZPoint
* Function: distance
*
* Discription:
* calculates the distance between coordinates of XYZPoint
***************************************************************************/
double distance(XYZPoint);
/**************************************************************************
* Author: Glen Newell
* Class: XYZPoint
* Function: midPoint
*
* Discription:
* calculates the midpoint between coordinates of XYZPoint
***************************************************************************/
void midPoint(XYZPoint, XYZPoint);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: Display
*
* Discription:
* Allows user to output to anywhere or anything
***************************************************************************/
void display(ostream &);
};
#endif
and Point.cpp:
#include "Box.h"
//prototype Constructor passing two doubles
XYZPoint::XYZPoint(double x, double y, double z)
{
xCoor = x;
yCoor = y;
zCoor = z;
}
/**************************************************************************
*
* class XYZ Accessors
*
***************************************************************************/
double XYZPoint::getXCoor()
{
return xCoor;
}
double XYZPoint::getYCoor()
{
return yCoor;
}
double XYZPoint::getZCoor()
{
return zCoor;
}
/**************************************************************************
*
* class XYZ
* Modifiers
*
***************************************************************************/
void XYZPoint::setXCoor(double x)
{
xCoor = x;
}
void XYZPoint::setYCoor(double y)
{
yCoor = y;
}
void XYZPoint::setZCoor(double z)
{
zCoor = z;
}
/**************************************************************************
*
* class: XYZPoint
* Function distance
* calculates the difference in between the xCoor with
*
***************************************************************************/
double XYZPoint::distance(XYZPoint p1)
{
double xDiff = xCoor - p1.getXCoor();
double yDiff = yCoor - p1.getYCoor();
double zDiff = zCoor - p1.getZCoor();
double result = sqrt(xDiff*xDiff + yDiff*yDiff + zDiff*zDiff);
return result;
}
/**************************************************************************
*
* class: XYZPoint
* Function: midPoint
*
* Function Description: finds the midpoint of the X,Y & Z Corrodinates
*
***************************************************************************/
void XYZPoint::midPoint(XYZPoint p2, XYZPoint p3)
{
xCoor = (p2.getXCoor() + p3.getXCoor())/2.0;
yCoor = (p2.getYCoor() + p3.getYCoor())/2.0;
zCoor = (p2.getZCoor() + p3.getZCoor())/2.0;
}
/**************************************************************************
*
* class: XYZPoint
* Function: Display
*
* Funciont Description: displays the
*
***************************************************************************/
void XYZPoint::display(ostream& out) //pN.display(cout)
{
out << fixed << setprecision(3) << "(" << xCoor << ","
<< yCoor << "," << zCoor <<")";
}
Both the files worked no problem.
Now im working on a new class and im having a little trouble with it.
The New class is a Box Class:
Quote:
Write a C++ class called point. You should create the following 3 seperate files:
* Box.h: the header file for the box class
* Box.cpp: the code and data for the box class; and
* boxtdrivr.cpp
Reuse the C++ class you wrote for the previous assingment.
* Point.h: the header file for the point class
* Point.cpp: the code and data for the point class; and
the point class will consist of the following memeber function:
* constructor with arguments for the three points to define the box;
* constructor with arguments for hidth, width and depth(assume that one , point is the orgin)
* a function to compute the surface area of the box;
* a function to compute the volume of the box;
* seperate accessor fubctions for getting each attribute;
* seperate functions that will return the deminsions of the box (H,W,D)
* a function that will return the largest deminsion of the box
* a function that will return the smallest deminsion of the box
* separate accessor functions for getting each attribute.
|
so ive started to build the two files.
Box.h:
#ifndef BOX_H
#define BOX_H
#include "Point.h"
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
*
* Description:
* A constructor for 3 points that define the box *
* A constructor with arguments for hight, width and depth *
* A function to compute the surface area of the box
* A function to compute the volume
* Sperate accessor functions fro getting each attribute.
* Separate functions that will return the demensions of the box
* A function that will return the largest dimension of the box
* A function that will return the smallest dimension of the box
*
***************************************************************************/
class XYZBox
{
//constructor that defines the 3 points of the box
private: //declares Coorodinates
XYZPoint xCoor;
XYZPoint yCoor;
XYZPoint zCoor;
public:
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: XYZBox
*
* Discription:
* Prototype Constructor that passes three doubles, defines Box(H,W,D)
***************************************************************************/
XYZBox(double, double, double);
XYZBox(XYZPoint, XYZPoint, XYZPoint);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: get(X,Y,Z)Coor
*
* Discription:
* Prototype get*Coor that passes an X,Y, or Z Coordinate
***************************************************************************/
double getXCoor(double);
double getYCoor(double);
double getZCoor(double);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: set(X,Y,Z)Coor
*
* Discription:
* Prototype set*Coor that passes an X,Y, or Z Coordinate
***************************************************************************/
void setXCoor(double);
void setYCoor(double);
void setZCoor(double);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: surfaceArea
*
* Discription:
* calculates the difference in between the xCoor with
***************************************************************************/
double surfaceArea();
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: Volume
*
* Discription:
* calculates the volume of the box
***************************************************************************/
void volume(XYZBox, XYZBox);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: largeDimension
*
* Discription:
* calculates the Largest Dimension of the box
***************************************************************************/
void largeDimension (XYZBox, XYZBox);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: smallDimension
*
* Discription:
* calculates the Smallest Dimension of the box
***************************************************************************/
void smallDimension (XYZBox, XYZBox);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: Display
*
* Discription:
* Allows user to output to anywhere or anything
***************************************************************************/
void display(ostream &);
};
#endif
And Box.cpp:
#include "Box.h"
XYZBox::XYZBox (XYZPoint p1, XYZPoint p2, XYZPoint p3)
{
xCoor = p1;
yCoor = p2;
zCoor = p3;
}
XYZBox::XYZBox (double x, double y, double z)
{
xCoor.setXCoor(0);
xCoor.setYCoor(0);
xCoor.setZCoor(0);
yCoor.setXCoor(x);
yCoor.setYCoor(0);
yCoor.setZCoor(0);
zCoor.setXCoor(x * 0.5);
zCoor.setYCoor(y);
zCoor.setZCoor(0);
}
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: get(X,Y,Z)Coor
*
* Discription:
* Prototype get*Coor that passes an X,Y, or Z Coordinate
*
***************************************************************************/
double XYZBox::getXCoor()
{
return xCoor;
}
double XYZBox::getYCoor()
{
return yCoor;
}
double XYZBox::getZCoor()
{
return zCoor;
}
// double XYZBox::depth()
// {}
// double XYZBox::hight()
// {}
// double XYZBox::depth()
// {}
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: set(X,Y,Z)Coor
*
* Discription:
* Prototype set*Coor that passes an X,Y, or Z Coordinate
*
***************************************************************************/
void XYZBox::setXCoor()
{
return xCoor;
}
void XYZBox::setYCoor()
{
return yCoor;
}
void XYZBox::setZCoor()
{
return zCoor;
}
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: distance
*
* Discription:
* Calculates the difference in between the xCoor with
*
***************************************************************************/
double XYZBox::surfaceArea()
{
double depth = abs(xCoor.getXCoor() - yCoor.getXCoor());
double width = abs(yCoor.getYCoor() - zCoor.getYCoor());
double height = abs(zCoor.getZCoor() - xCoor.getZCoor());
double result = abs((2*(depth*width))+(2*(depth*height))+(2*(width*height)));
return result;
}
double XYZBox::volume()
{
double volume = depth*width*height;
return volume;
}
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: largeDimension
*
* Discription:
* calculates the Largest Dimension of the box
***************************************************************************/
void largeDimension (XYZBox, XYZBox);
/**************************************************************************
* Author: Glen Newell
* Class: XYZBox
* Function: smallDimension
*
* Discription:
* calculates the Smallest Dimension of the box
***************************************************************************/
void smallDimension (XYZBox, XYZBox);
And thus far im getting errors such as:
C:\...Box.cpp(35) : error C2511: 'getXCoor' : overloaded member function 'double (void)' not found in 'XYZBox'
C:\...Box.cpp(35) : error C2511: 'getXCoor' : overloaded member function 'double (void)' not found in 'XYZBox'
and it does that for the get Y, and Z, and Set XYZ and volume functions. Any help would be great.
|