GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Nov-2006, 18:51
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 118
TransformedBG is on a distinguished road

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
CPP / C++ / C Code:
#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:
CPP / C++ / C Code:
#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:
CPP / C++ / C 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:
/**************************************************************************
*	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:

CPP / C++ / C 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(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.
  #2  
Old 12-Nov-2006, 19:00
ubergeek ubergeek is offline
Awaiting Email Confirmation
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: Box Class, need help again :(


You prototyped the get_Coor functions (in the class) as taking a double parameter, but then implemented (and called) them with no parameters. The compile is confused. The set_Coor functions are the opposite: you meant them to take a double, but they are implemented with no parameters. I would just look for a second at your set_Coor functions. Do they make sense as set functions?

The volume has a similar issue with parameters and return types. This is a fundamental requirement in C++: when you tell the compiler what the function looks like (in the prototype), it expects the function to look like that!
  #3  
Old 12-Nov-2006, 19:11
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 118
TransformedBG is on a distinguished road

Re: Box Class, need help again :(


Quote:
Originally Posted by ubergeek
You prototyped the get_Coor functions (in the class) as taking a double parameter, but then implemented (and called) them with no parameters. The compile is confused. The set_Coor functions are the opposite: you meant them to take a double, but they are implemented with no parameters. I would just look for a second at your set_Coor functions. Do they make sense as set functions?

The volume has a similar issue with parameters and return types. This is a fundamental requirement in C++: when you tell the compiler what the function looks like (in the prototype), it expects the function to look like that!

So should i have the get_Coor funtions as

double get_Coor(double);? or woudl it be double get_Coor();?

Okay im just really confused cause im thinking this falls under what he was asking for "sepeate accessor functions for getting each atribute" right? i reall just dont now how to define a box and its pissing me off. Im not used to this object orinted mumbo jumbo .

So a function conists of 2 things a prototype:
Code:
double getXCoor(); //or double getXCoor (double); double getYCoor(); //or double getYCoor (double); double getZCoor(); //or double getZCoor (double);

and a function call:
Code:
double XYZBox::getXCoor() { return xCoor; } double XYZBox::getYCoor() { return yCoor; } double XYZBox::getZCoor() { return zCoor; }
  #4  
Old 12-Nov-2006, 19:16
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 118
TransformedBG is on a distinguished road

Re: Box Class, need help again :(


okay and my volume i think i see the problem but i could be wrong.

My prototype looks like:

CPP / C++ / C Code:
void volume (XYZBox, XYZBox)

and my call looks like:
CPP / C++ / C Code:
	double XYZBox::volume()
	{
		double volume = xCoor*yCoor*zCoor;
		return volume;
	}

so i want a returning function:

prototype:
CPP / C++ / C Code:
double volume(); 

i want it a double cause its returning a value and and i dont want anything in the parenthisis *cause i dont know why lol*

call:
CPP / C++ / C Code:
	double XYZBox::volume()
	{
		double volume = xCoor.getXCoor()*yCoor.getYCoor()*zCoor.getZCoor();
		return volume;
	}

But here, im making a return value set to volume
i want it to get the xCoor*using funcion get_Coor()* and then multiply it by Y & Z. and this should work right?

or should it be like:

prototype:
CPP / C++ / C Code:
void volume(XYZBox); 

i want it a void cause its computing a value and and i want XYZBox in the parenthisis cause im pulling the points from the box.

call:
CPP / C++ / C Code:
	double XYZBox::volume(XYZBox p1)
	{
		double volume = p1.getXCoor()*p2.getYCoor()*p3.getZCoor();
		return volume;
	}

then im get the x, y and z point from p1?
  #5  
Old 12-Nov-2006, 19:52
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 118
TransformedBG is on a distinguished road

Re: Box Class, need help again :(


okay let me just try to rationalize myself out loud.

Ill go like this:

Prototype:
CPP / C++ / C Code:
	XYZBox(double, double, double);
	XYZBox(XYZPoint, XYZPoint, XYZPoint);

okay bing that a box is made up of three points i need three doubles
an "X" a "Y" and a "Z". or I can use my point class, which i have three XYZPoint 's because each XYZPoint represents 1 point (i tihnk? lol)

So now my call looks something like this:
CPP / C++ / C Code:
	XYZBox::XYZBox (double x, double y, double z)
	{
		xCoor.setXCoor(x);
		xCoor.setYCoor(y);
		xCoor.setZCoor(z);

		yCoor.setXCoor(x);
		yCoor.setYCoor(y);
		yCoor.setZCoor(z);

		zCoor.setXCoor(x);
		zCoor.setYCoor(y);
		zCoor.setZCoor(z);
	}

Im not sure why i made three _Coor for each set_Coor. I just did sometihng simalar in class and didnt really understand it. (maybe you can help?)

but i do know that:
CPP / C++ / C Code:
	XYZBox::XYZBox (XYZPoint p1, XYZPoint p2, XYZPoint p3)
	{
		xCoor = p1;
		yCoor = p2;
		zCoor = p3;
	}

i used XYZPoint and gave it a p_ as a point. So now my _Coor is = to p_. giving me 3 points to make a box? Sound right so far?

now to get a point:
prototype:
CPP / C++ / C Code:
	double getXCoor();
	double getYCoor();
	double getZCoor();

so double gives me some sort of intager. get_Coor is the function name, and () is what i want to get.

CPP / C++ / C Code:
	double XYZBox::getXCoor()
	{
		return xCoor;
	}

	double XYZBox::getYCoor()
	{
		return yCoor;
	}

	double XYZBox::getZCoor()
	{
		return zCoor;
	}

All i want to do is return X,Y&Z Coor so i return the values of xCoor, yCoor, and zCoor
  #6  
Old 12-Nov-2006, 21:00
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 118
TransformedBG is on a distinguished road

Re: Box Class, need help again :(


Do i need to do sometihng like:
XYZBox::XYZPoint;?
  #7  
Old 12-Nov-2006, 22:13
TransformedBG TransformedBG is offline
Member
 
Join Date: Oct 2006
Posts: 118
TransformedBG is on a distinguished road

Re: Box Class, need help again :(


I give up. I dont know whats going on.
  #8  
Old 13-Nov-2006, 15:11
Sokar Sokar is offline
Member
 
Join Date: May 2005
Posts: 243
Sokar has a spectacular aura aboutSokar has a spectacular aura about

Re: Box Class, need help again :(


Quote:
Originally Posted by TransformedBG
So should i have the get_Coor funtions as

double get_Coor(double);? or woudl it be double get_Coor();?

Okay im just really confused cause im thinking this falls under what he was asking for "sepeate accessor functions for getting each atribute" right? i reall just dont now how to define a box and its pissing me off. Im not used to this object orinted mumbo jumbo .

So a function conists of 2 things a prototype:
The prototype and the definition MUST match!

prototype :
CPP / C++ / C Code:
double getXCoor(double);
definition :
CPP / C++ / C Code:
double XYZBox::getXCoor()
	{
		return xCoor;
	}
Those do not match. The prototype takes a double as a argument but the definition does not.

These match.
prototype :
CPP / C++ / C Code:
double getXCoor(double);
definition :
CPP / C++ / C Code:
double XYZBox::getXCoor(double)
	{
		return xCoor;
	}
or
prototype :
CPP / C++ / C Code:
double getXCoor();
definition :
CPP / C++ / C Code:
double XYZBox::getXCoor()
	{
		return xCoor;
	}

Quote:
Originally Posted by TransformedBG
and a function call:
A function call is when you actually use/call the function in your code.


Quote:
Originally Posted by TransformedBG
I give up. I dont know whats going on.
Some of your post are a little hard to follow. You could try reposting your qustions with any new or updated code. It might help.
 
 

Recent GIDBlogCompress Your Web Site by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Card class help verticalvoid C++ Forum 2 29-Jun-2006 21:51
C++ class -- Please help vnca_1 C++ Forum 3 14-Jun-2006 12:31
a tester class and then some. postage Java Forum 1 06-May-2006 15:48
Error C2146: syntax error : missing ',' before identifier 'C4' mattchew008 C++ Forum 2 19-Dec-2004 06:06
hashing help saiz66 C++ Forum 1 06-Jul-2004 06:16

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:26.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.