Help with Friend/Overloaded operator

Hello, I need to use a friend function for an overloaded operator. Right now my program takes in user data (height and diameter of a cylinder) and computes the volume. I need this overloaded function to request a new height from the user and then use that height and the old diameter to compute a new volume. The function should then user the overloaded operator to add two the two volumes together and find the combined volume. I am very stuck can someone help me figure out how to do this? Thank you, I appreciate it.

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std;

#define PI		3.14159

class CylinderClass
{
public:
friend	CylinderClass operator +(const CylinderClass& cylinder1, const CylinderClass& cylinder2);
//BoxClass operator +(const BoxClass& box1, const BoxClass& box2);


CylinderClass();					// default constructor
CylinderClass(double x, double y);		// specified constructor

void	set_height(int height);
double	get_height();

void	set_diameter(int diameter);
double	get_diameter();

double	get_volume();
double 	get_extended_volume();

void 	reset_original(int x, int y);
void	reset_specific(int x, int y);

void set_new_height(int new_height);
	
private:
    struct	a_cylinder
    {
	double  height;
	double  diameter;
    } the_cylinder, new_cylinder;
};

int choose_function();

int main()
{
CylinderClass	TheCylinder, NewCylinder;
int		task, height, new_height, diameter;

    task = choose_function();
    while ( task != 10 )
    {
	switch (task)
	{
	    case 1:	cout << " Enter height: ";
				cin  >>  height;
				TheCylinder.set_height(height);
				cout << "\n";
			break;
	    case 2:	cout << "The current height is " << TheCylinder.get_height(); 
				cout << "\n";
			break;
	    case 3:	cout << "Enter diameter: ";
				cin  >> diameter;
				TheCylinder.set_diameter(diameter);
				cout << "\n";
			break;
	    case 4:	cout << "The current diameter is " << TheCylinder.get_diameter();
				cout <<"\n";
			break;
	    case 5:	cout << "Volume is " << TheCylinder.get_volume();
				cout <<"\n";
			break;
		case 6: TheCylinder = CylinderClass();
				cout << "Dimensions reset to default.";
			break;
		case 7: TheCylinder = CylinderClass(5.0, 2.0);
				cout << "Dimensions reset.";
			break;
	   // case 8: TheCylinder = TheCylinder + NewCylinder;
			//	NewCylinder = CylinderClass (new_height, diameter);
		//		cout << "Enter new height:"; 
		//		cin  >> new_height;
	//		break;
	    default:	cout << "please select from the menu choices\n\n";
	}
	task = choose_function();
    }
    cout << "thank you\n\n";
    return(0);
}


int choose_function()
{
int selection;

    cout << "\n\nplease select from the following:\n\t1) Set height\n\t2) Get current height\n"
	 << "\t3) Set diameter\n\t4) Get current diameter\n\t5) Get volume "
	 << "\n\t6) Reset to original "
	 << "\n\t7) Reset to specific dimensions "
	 << "\n\t8) Get an extended Cylinder "
	 << "\n\n\t10) exit this program\n\nplease enter your selection: ";
    cin  >> selection;
	
    return(selection);
}


/*CylinderClass operator +(const CylinderClass& cylinder1, const CylinderClass& cylinder2)
{

tempCylinder = cylinder1.the_cylinder.volume + cylinder2.new_cylinder.extended_volume;

return (tempCylinder);
}

CylinderClass::CylinderClass()
{
    the_cylinder.height  = 1;
    the_cylinder.diameter = 1;
}

CylinderClass:: CylinderClass(double x, double y)
{
    the_cylinder.height  = x;
    the_cylinder.diameter = y;   
}



void CylinderClass::set_height(int height)
{
	the_cylinder.height = height; 
}

double CylinderClass::get_height()
{
    return(the_cylinder.height);
}

void CylinderClass::set_diameter(int diameter)
{
    the_cylinder.diameter = diameter;
}

double CylinderClass::get_diameter()
{
    return(the_cylinder.diameter);
}

double CylinderClass::get_volume()
{
	double volume;
	double radius;
	double radius_squared;
	
	radius = (the_cylinder.diameter / 2);
	radius_squared = pow(radius,2);
	
	volume = PI * radius_squared * the_cylinder.height;
	
	return (volume);
}

double CylinderClass::get_extended_volume()
{
	double extended_volume;
	double radius;
	double radius_squared;
	
	radius = (the_cylinder.diameter / 2);
	radius_squared = pow(radius,2);
	
	extended_volume = PI * radius_squared * new_cylinder.height;
	
	return (extended_volume);
} */
add CylinderClass tempCylinder; to line 111
Topic archived. No new replies allowed.