find errors

#include "stdafx.h"
#include<iostream>
using namespace std;
class A
{
double a;
protected:
double b;
double volume(const double& c)
{
return a*b*c;
}
public:
A(double inA,double& inB,const double& inC)
{
a=inA;
b=inB;
c=inC;
}
double c;
double volume()
{
return a*b*c;
}
};
int main ()
{
A(5,4,12 objA);
A objB(5,4,7) objB;
double v1=objB.volume(5.5);
double v2=objB.volume();
}
You have made some pretty bad errors here, so bad I think you need to actually find them yourself if you wish to continue with classes.
Got quite a few weird thing going on in your code so here is an example. Hope it helps you.

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
#include<iostream>

class A{
public:
	//Constructors
	A():height(1),width(1){}
	A(double h, double w){
		setHeight(h);
		setWidth(w);
	}
	//Setters
	void setHeight(double h){//Error Check
		if (h <= 0)
			height = 1;
		else
			height = h;
	}
	void setWidth(double w){//Error Check
		if (w <= 0)
			width = 1;
		else
			width = w;
	}
	//User Functions
	double area(){ return height*width; }
private:
	double height, width;
};

int main()
{
	//Exercise Class
	
	A obj1;//Default Constructor
	A obj2(2, 2);//Argumented Constructor
	A obj3(-5, 0);//Test Error Checking

	std::cout << "Area obj1 " << obj1.area() << std::endl;
	std::cout << "Area obj2 " << obj2.area() << std::endl;
	std::cout << "Area obj3 " << obj3.area() << std::endl;

return 0;
}
Last edited on
Topic archived. No new replies allowed.