Volume Computation Gone Wrong!

Pages: 12
OK now your functions only store 2 points, but main still asks for 4 points.

The easiest thing to do is have another class called CPoint2D say ( or you could have a 3d point)

1
2
3
4
5
6
7
Class CPoint2D {
private:

double m_x;
double m_y;

};


then your CBox class could be:

1
2
3
4
5
6
7
8
class CBox {

CPoint2D m_LL;  //The Lower Left point
CPoint2D m_TR; //The Top Right point

// the other length width and height variables here
};


then the code for length width and height variables becomes:

1
2
3
4
m_length = m_TR.m_x - m_LL.m_x;
m_width = m_TR.m_y - m_LL.m_y;
//something similar if you had a 3dpoint for the height


IN main, you only need to get input for the LL & TR points, not all 4 points.

IF you had a 3dpoint class then you still only need 2 points to define the 3d box - it would be silly to ask for all 8 of them.

I made the points doubles, but you could stick to ints, to avoid problems in comparing doubles.

still cant get print function to print properly. how can i access the different volumes for the different boxes if i havent specified a name or a way to identify them to add up their volumes? I feel like I shouldn't need to store them in an in an array of volumes for each individual object?


That is what the array of boxes is for - you refer to each box by the array subscript. The Volume is part of the box class - so there is no need to have a separate array just for volumes.
Thank you. unfortunately I had to turn in incomplete code due to my lack of understanding of how this works. I will fix my code tomorrow and perhaps email my professor the completed code? Are professors usually understanding on that kind of thing? Thank you again.
uh.. so i already turned in the incomplete assignment and i rewrote the code to try and at least print the volume just for my own interest. I'm still having trouble. Can you help me?
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include<iostream>
#include<iomanip>
#include<string>
#include<iomanip>

using namespace std;

class CPoint2D
{
public:
	void printData();
	double m_x;
	double m_y;
	
};
class Box
{
public:
	Box();

	int boxid;
	int getDepth(), getWidth(), getHeight(), getVolume();
	string getType();
	void setData();
    
    CPoint2D m_LL; // lower left point
    CPoint2D m_TR; // top right point

private:
	int heightstore, absheight, width, depth, height, volume, localmaxx, localminy, localminx, localmaxy;
	string type;
};

Box::Box()
{
	boxid = 0;
	heightstore =0;
	absheight = 0;
	width = 0;
	depth = 0;
	height = 0;
	volume = 0;
	localmaxx = 0;
	localminy = 0;
	localminx = 0;
	localmaxy = 0;
}
void getInput() // grab input of all 5 boxes and store in placeholder variables
{
	static int xholder[2], yholder[2], heightstore[1];
	for (int i=0;i<4;i++)
	{   
		cout << "\n\ntEnter X, Y: " << endl;
		cin >> xholder[i] >> yholder[i];
	}
		cout << "\n\n\tEnter height: " << endl;
		cin >> heightstore[1];
}

void Box::setData() 
{
     // setting values
	for (int i=0;i<4;i++)
	{
		boxid = i;
	}
		width = m_TR.m_x - m_LL.m_x;
		depth = m_TR.m_y - m_LL.m_y;
		height = absheight;
		volume = getVolume();
}

int Box::getWidth()
{
	width = m_TR.m_x - m_LL.m_x;
	return width;
}

int Box::getDepth()
{
	depth = m_TR.m_y - m_LL.m_y;
    return depth;
}

int Box::getHeight()
{
    height = heightstore;
	return height;
}

string Box::getType() 
{
	if (width == depth && depth == height)
	{type = "Square";}
	else
	{type = "Rectangular";}	
	return type;
}

int Box::getVolume()
{
	volume = depth * height * width;
	return volume;
}

void printData(Box BoxObjects5[5])
{
	{
		cout << left << setw(25) << "Box#";
		cout << left << setw(25) << "Type";
		cout << right << setw(25) << "Volume";
   
		for (int i=0;i<4;i++)
	{
		cout << left << setw(25) << BoxObjects5[i].boxid;
		cout << left << setw(25) << BoxObjects5[i].getType();
		cout << right << setw(25) << BoxObjects5[i].getVolume();
    }  
	}
}

int main()
{
	Box BoxObjects5[5];
	CPoint2D newobject;
	getInput();
     
		for (int i=0;i<5;i++)
		{
			BoxObjects5[i].setData();
			BoxObjects5[i].getWidth();
			BoxObjects5[i].getDepth();
			BoxObjects5[i].getHeight();
			BoxObjects5[i].getVolume();
			cout << "\n\n\t" << endl;
		}
			newobject.printData();

		cout<<"\n\n\t"<<endl;
		cout<<system("PAUSE");
		return 0;
};


1>fmain.obj : error LNK2019: unresolved external symbol "public: void __thiscall CPoint2D::printData(void)" (?printData@CPoint2D@@QAEXXZ) referenced in function _main

Last edited on
The printData() you declared as a member of CPoint2D on line 11 takes no parameters.
The printData() you defined on lines 105-119 takes one parameter and is not a member of any class.

PS: Much of your code makes no sense whatsoever. This needs a near complete rewrite.
Last edited on
Topic archived. No new replies allowed.
Pages: 12