Class Declaration into main??

Mar 1, 2017 at 4:01am
Write your question here.
My class wasn't declared?
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
#include "lab4.h"
#include <iostream>

using namespace std;

int main()
{
	char repeat;
	do
	{
	labf box;
	
	double rad,heightz,sidez;
	int choose;
	cout << "Select a shape: " << endl << "1. sphere " << endl << "2. cube " << endl << "3. cylinder";
	cin >> choose;
	
	switch(choose)
	{
		case 1 : cout << "Enter the radius of a sphere: ";
				 cin >> labf.setradius(rad);
		box.calcvols(); break;
	
		case 2 : cout << "Enter the side of a cube: ";
 		   		 cin >> labf.setside(sidez);
		box.calcvolc(); break;
	
		case 3 : cout << "Enter the height of a cylinder: ";
				 cin >> labf.setheight(heightz);
				 cout << "Enter the radius of a cylinder: ";
				 cin >> labf.setradius(rad);
		box.calcvolr(); break ;
	
	}
	
	
	
	cout << "Do you wish to continue? y or w and ENTER to continue: ";
	cout << endl;	
	}while (repeat == 'y' || repeat =='w');
}
Mar 1, 2017 at 4:02am
my class
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
#include <iostream>
#include <cmath>

using namespace std;

const double pi = 3.14;

class labf
{
	private:
		double volumec;
		double volumes;
		double volumer; //cylinder
		double radius; //radius
		double side; // side
		double height; //height
	public:
		void setside();
		void setheight();
		void setradius();
		void calcvolc();
		void calcvols();
		void calcvolr();
};
void labf::setside(double s)
{
	side = s;
}
void labf::setradius(double r)
{
	radius = r;
}
void labf::setheight(double h)
{
	height = h;
}

void labf::calcvolc(double cube,double side)
{
	volumec = pow(side,3);
	cout << "The volume of the cube is " << volumec << endl;
}
void labf::calcvolr(double cyli, double height, double radius)
{
	volumer = pi*(pow(radius,2))*height;
	cout << "The volume of the cylinder is " << volumer << endl;
}
void labf::calcvols(double sphere, double radius)
{
	volumes = 1.33*pi(pow(radius),3)
	cout << "The volume of the sphere is " << volumes << endl;
}
Mar 1, 2017 at 4:15am
Your method declaration signatures does not match with their implementation. For instance void setradius(); has no parameter.
Mar 1, 2017 at 4:23am
updated
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
#include <iostream>
#include <cmath>

using namespace std;

const double pi = 3.14;

class labf
{
	private:
		double volumec;
		double volumes;
		double volumer; //cylinder
		double radius; //radius
		double side; // side
		double height; //height
	public:
		void setside(double&s);
		void setheight(double&h);
		void setradius(double&r);
		void calcvolc(double cube,double side);
		void calcvols(double sphere, double radius);
		void calcvolr(double cyli, double height, double radius);
};
void labf::setside(double&s)
{
	side = s;
}
void labf::setradius(double&r)
{
	radius = r;
}
void labf::setheight(double&h)
{
	height = h;
}

void labf::calcvolc(double cube,double side)
{
	volumec = pow(side,3);
	cout << "The volume of the cube is " << volumec << endl;
}
void labf::calcvolr(double cyli, double height, double radius)
{
	volumer = pi*(pow(radius,2))*height;
	cout << "The volume of the cylinder is " << volumer << endl;
}
void labf::calcvols(double sphere, double radius)
{
	volumes = 1.33*pi(pow(radius),3)
	cout << "The volume of the sphere is " << volumes << endl;
}
Mar 1, 2017 at 4:42am
Add at the top of the header the directive #pragma_once if it is still complaining show us the error message because I don't have an IDE opened I might have missed something
Topic archived. No new replies allowed.