classes function problem

I recently added a new function to calculate a volume of a cone, eventually looking to do another for the area, i cant seem to get it to work though,ive played around with it but still keep getting build errors,here is the code along with that the header file includes:
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
#include "testtwo"
#include <cmath>
#include <iostream>
using namespace std;
// function prototype
void menu();

mysecondclass myshape;
int main ()
{
menu();
return 0;
}
void menu()
{
float lengthone,lengthtwo,volume, area, r, h;
int imenu;
cout << "Geometry Menu \n \n";
cout << "1. Area of a Cube \n";
cout << "2. Volume of a Cube \n";
cout << "3. Volume of a Cone \n";
cout << "4. Exit \n";
cout << "Please enter the number of your selection \n";
cin >> imenu;
switch(imenu)
{
case 1:
cout << "Please enter the lenght of the cube\n";
cin >> lengthone;
area = myshape.areaofcube(lengthone);
cout << "The area of that cube is " << area << "\n";
cout << " \n";
menu();
break;
case 2:
cout << "Please enter the lenght of the cube\n";
cin >> lengthtwo;
area = myshape.volumeofcube(lengthtwo);
cout << "The volume of that cube is " << area << "\n";
cout << " \n";
menu();
break;
case 3:
cout << "Please enter the radious of the cone base\n";
cin >> r;
cout << "Please enter the height of the cone\n";
volume = myshape.volumeofcone(r,h);
cout << "The volume of that cone is " << volume << "\n";
cout << " \n";
menu();
break;
case 4:
return; //  go back to main
break;
default:
cout << "Please make a valid choice \n";
menu(); // call this function again to display the menu again
} // end of switch
}


this is what the "testtwo" header file includes:
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
#include <cmath>
class mysecondclass
{
float answer;

public:

float areaofcube(float);
float volumeofcube(float);
float volumeofcone(float,float);
};
float mysecondclass::areaofcube(float lengthone)
{
answer = lengthone*lengthone*6;
return answer;
}
float mysecondclass::volumeofcube(float lengthtwo)
{
answer = lengthtwo*lengthtwo*lengthtwo;(pow(lengthtwo, 3));
return answer;
}
float volumeofcone (float r, float h)   
{
float answer;
const float pi = 3.14159;
answer = (1/3*pi*(r*r)*h);
return answer;
}


here are the errors/warrnings:
main.cpp:47: undefined reference to `mysecondclass::volumeofcone(float, float)

:-1: error: collect2: ld returned 1 exit status


any help would be great :)
Last edited on
sorry ive just noticed the line 47 with the

 
cin>>h;


still comes up with both errors though
You defined a function volumeofcone() that is not a member of mysecondclass. Therefore, mysecondclass::volumeofcone() is not defined anywhere.

By the way, please indent code properly when posting; it makes reading much easier.
float mysecondclass::volumeofcone (float r, float h) doh!!

thanks a lot,for some reason the answer is outputing incorrect
In C++, 1 / 3 is integer division. It will yield 0. If you want floating-point division, you must say 1.0 / 3.0.
Thanks a lot for the help,i never noticed to be honest it work great now :) thanks again
Topic archived. No new replies allowed.