Seriously need help!

This is a discussion on Seriously need help! within the C++ Programming forums, part of the General Programming Boards category; Currently my mission in life is to write a box class which consists of: Write a C++ class called Box. ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    13

    Seriously need help!

    Currently my mission in life is to write a box class which consists of:
    Write a C++ class called Box. 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 my point class is already done and works:

    Point.h
    Code:
    /**************************************************************************
    *	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:
    /**************************************************************************
    *	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;
    		}
    
    /**************************************************************************
    *	Discription: 
    *		Prototype Constructor that passes three doubles, defines the points
    *		of the triangle
    ***************************************************************************/
    	XYZPoint(double, double, double);
    
    /**************************************************************************
    *	Discription: 
    *		Prototype get*Coor that passes an X,Y, or Z Coordinate
    ***************************************************************************/
    	double getXCoor();
    	double getYCoor();
    	double getZCoor();
    
    /**************************************************************************
    *	Discription: 
    *		Prototype set*Coor that passes an X,Y, or Z Coordinate
    ***************************************************************************/
    	void setXCoor(double);
    	void setYCoor(double);
    	void setZCoor(double);
    
    /**************************************************************************
    *	Discription: 
    *		calculates the distance between coordinates of XYZPoint
    ***************************************************************************/
    	double distance(XYZPoint);
    
    /**************************************************************************
    *	Discription: 
    *		calculates the midpoint between coordinates of XYZPoint
    ***************************************************************************/
    	void midPoint(XYZPoint, XYZPoint);
    	
    /**************************************************************************
    *	Discription: 
    *		Allows user to output to anywhere or anything
    ***************************************************************************/
    	void display(ostream &);
    
    };
    Point.cpp:
    Code:
    	//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;
    	}
    
    /**************************************************************************
    *	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;
    	}
    
    /**************************************************************************
    *	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;
    	}
    
    /**************************************************************************
    *	Funciont Description: displays 
    ***************************************************************************/
    	void XYZPoint::display(ostream& out) //pN.display(cout)
    	{
    	   out << fixed << setprecision(3) << "(" << xCoor << "," 
    			<< yCoor << "," << zCoor <<")";
    	}
    Now im trying to buile my Box class and having problems:
    Box.h:
    Code:
    #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:
    /**************************************************************************
    *	Class: XYZBox 
    *	Function: XYZBox
    *
    *	Discription: 
    *		Prototype Constructor that passes three doubles, defines Box(H,W,D)
    ***************************************************************************/
    	XYZBox(double, double, double);
    	XYZBox(XYZPoint, XYZPoint, XYZPoint);
    
    /**************************************************************************
    *	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); 
    /**************************************************************************
    *	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);
    
    /**************************************************************************
    *	Function: surfaceArea
    *	
    *	Discription: 
    *		calculates the difference in between the xCoor with 
    ***************************************************************************/
    	double surfaceArea();
    
    /**************************************************************************
    *	Function: Volume
    *	
    *	Discription: 
    *		calculates the volume of the box
    ***************************************************************************/
    	double volume(); // not sure if it shouls be this
    //	void volume(XYZBox); // or this
    	
    /**************************************************************************
    *	Function: largeDimension
    *	
    *	Discription: 
    *		calculates the Largest Dimension of the box
    ***************************************************************************/
    	void largeDimension (XYZBox, XYZBox);
    
    /**************************************************************************
    *	Function: smallDimension
    *	
    *	Discription: 
    *		calculates the Smallest Dimension of the box
    ***************************************************************************/
    	void smallDimension (XYZBox, XYZBox);
    };
    #endif
    Box.cpp:
    Code:
    #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(0);
    		yCoor.setYCoor(0);
    		yCoor.setZCoor(0);
    
    		zCoor.setXCoor(0);
    		zCoor.setYCoor(0);
    		zCoor.setZCoor(0);
    	}
    
    /**************************************************************************
    *	Function: get(X,Y,Z)Coor
    *
    *	Discription: 
    *		Prototype get*Coor that passes an X,Y, or Z Coordinate
    *
    ***************************************************************************/
    	double XYZBox::getXCoor() //depth
    	{
    		return xCoor;
    	}
    
    	double XYZBox::getYCoor() //width
    	{
    		return yCoor;
    	}
    
    	double XYZBox::getZCoor() //height
    	{
    		return zCoor;
    	}
    
    /**************************************************************************
    *	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;
    	}
    
    /**************************************************************************
    *	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;
    	}
    
    /**************************************************************************
    *	Function: volume
    *
    *	Discription: 
    *		Calculates the volume of the Box. 
    *
    ***************************************************************************/
    /*	void XYZBox::volume(XYZBox p1) // the other way i think might work?
    	{
    		double volume = p1.getXCoor()*p1.getYCoor()*p1.getZCoor();
    		return volume;
    	}
    */
    	double XYZBox::volume()
    	{
    		double volume = xCoor.getXCoor()*
    			yCoor.getYCoor()*zCoor.getZCoor();
    		return volume;
    	}
    
    /**************************************************************************
    *	Function: largeDimension
    *	
    *	Discription: 
    *		calculates the Largest Dimension of the box
    ***************************************************************************/
    	void largeDimension (XYZBox p1, XYZBox p2);
    	{
                // dont know what to put here?
    	}
    
    /**************************************************************************
    *	Function: smallDimension
    *	
    *	Discription: 
    *		calculates the Smallest Dimension of the box
    ***************************************************************************/
    	void smallDimension (XYZBox p1, XYZBox p2);
    	{
    	}
    Right now im getting errors with the get_Coor Functions, the set_Coor and the volume

    simalar to:
    C:\...Box.cpp(51) : error C2511: 'getXCoor' : overloaded member function 'double (void)' not found in 'XYZBox'


    any suggestions? examples are a plus.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Compare the function declaration in Box.h with the function definition in Box.cpp (the one the error points to). They are supposed to have the same return value and the same argument types.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    Okay so i did this and got the get_Coor to work.

    Code:
    	double XYZPoint::getXCoor() //depth
    	{
    		return xCoor;
    	}
    
    	double XYZPoint::getYCoor() //width
    	{
    		return yCoor;
    	}
    
    	double XYZPoint::getZCoor() //height
    	{
    		return zCoor;
    	}
    that should give me a point in the box function correct?

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    Okay do i need to post sometihng like

    XYZBox::XYZPoint; somewhere?

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    Okay im looking at this as a function:

    Code:
    double getXCoor();
    double is the return type, get_Coor is the function call, and (n?) is what i want? correct?

    now
    Code:
    double XYZBox::get_Coor()
    	{
    		return _Coor;
    	}
    double (return type) XYZBox (the class im calling from) :: <-- what are these? i still dont know.
    then get_Coor (function call), () = im not sure what i want here? all i want it to do is get a point like in my point class i think? then return it to _Coor.

    I really dont understand how to write this function?

  6. #6
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    double (return type) XYZBox (the class im calling from) :: <-- what are these? i still dont know.
    says that get_Coor() is a member of XYZBox

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    Okay so what if i want it to be a part of XYZBox, but use my XYZPoint class get_coor function?

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    The function declaration in Box.h looks like this:
    Code:
    double getXCoor(double);
    Compare that to the function definition in Box.cpp where the error refers to:
    Code:
    double XYZBox::getXCoor() //depth
    Make sure the return types and parameter types match.

    The XYZBox:: is ok, it is supposed to be in the definition so the compiler knows that function belongs to the XYZBox class. It is not needed in the declaration because the function declaration is already inside the class declaration. It is the other difference that is important and causing the error.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    Quote Originally Posted by Daved
    The function declaration in Box.h looks like this:
    Code:
    double getXCoor(double);
    Compare that to the function definition in Box.cpp where the error refers to:
    Code:
    double XYZBox::getXCoor() //depth
    Make sure the return types and parameter types match.

    The XYZBox:: is ok, it is supposed to be in the definition so the compiler knows that function belongs to the XYZBox class. It is not needed in the declaration because the function declaration is already inside the class declaration. It is the other difference that is important and causing the error.
    Okay but if i make it
    Code:
    double getXCoor(double);
    and
    Code:
    double XYZBox::getXCoor(double) //depth
    i get:
    C:\...Box.cpp(55) : error C2440: 'return' : cannot convert from 'class XYZPoint' to 'double'

    all i want to do is pull the xpoint and i cant figure out how. Im really starting to hate object oriented programing.

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    or do i want it to be double xCoor?

  11. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    Okay wait that worked. Okay quesiont how would i find the largestDemention or the smallest demintion?

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Ok, you fixed the original error. For the new one, you have to decide whether you want to return a double or an XYZPoint. Whichever you decide, make sure the function declaration and definition mmatch your choice, and make sure that what you acually return has the type you chose.

  13. #13
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    now i have a problem with this:

    Code:
    	void setXCoor(double);
    	void setYCoor(double);
    	void setZCoor(double);
    Code:
    	void XYZBox::setXCoor() //i dont know what i want here. i want to set the xCoor to a point
    	{
    		return xCoor;
    	}
    
    	void XYZPoint::setYCoor()
    	{
    		return yCoor;
    	}
    
    	void XYZPoint::setZCoor()
    	{
    		return zCoor;
    	}
    im getting:
    C:\..Box.cpp(78) : error C2511: 'setXCoor' : overloaded member function 'void (void)' not found in 'XYZBox'

  14. #14
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Look at your point class. It has a set function. Model the Box class's set functions after it, except you have to change the types as appropriate.

  15. #15
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    I guess the problem im having is trying to describe a box using points. If it was anything else i might get it. Like a data base or sometihng i dont know. Anyways, they are exzactly the same:

    Point class:
    Code:
    	void setXCoor(double);
    	void setYCoor(double);
    	void setZCoor(double);
    [code]
    void XYZPoint::setXCoor(double x)
    {
    xCoor = x;
    }

    void XYZPoint::setYCoor(double y)
    {
    yCoor = y;
    }

    void XYZPoint::setZCoor(double z)
    {
    zCoor = z;
    }
    [code]

    box:
    Code:
    	void setXCoor(double);
    	void setYCoor(double);
    	void setZCoor(double);
    Code:
    	void XYZBox::setXCoor(double x)
    	{
    		xCoor = x;
    	}
    
    	void XYZBox::setYCoor(double y)
    	{
    		yCoor = y;
    	}
    
    	void XYZBox::setZCoor(double z)
    	{
    		zCoor = z;
    	}
    then i get the error:
    C:\..Box.cpp(79) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'double' (or there is no acceptable conversion)

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21