Help me

Create a class Rectangle, which has attributes length and width , each of read from user. It has member function that calculate the perimeter and area of the rectangle .It has set and get functions for both length and width . The set function should verify that length and width are each floating – point numbers greater than 0.0 and less than 20.0

I don't understand what they require in the bold line ???
The set function verifies that the numbers are between 0-20, as a float. I dont know what else to tell ya, it seems straight forward.
Last edited on
its a very strange question because if you set the input parameter as float than why would you ever need to check to see if the value was a float...

if thats homework i dont get it at all and i see why you are confused.
Last edited on
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
#include<iostream>

class rectangle 
{
public:

float perimeter() {
	return 2*(length+width);
}

float area() {
	return length*width;
}

bool setLen(float len) {
	if (len>0.0 && len<20.0) {
		length=len;
		return true;
	}
	return false;
}

bool setWid(float wid) {
	if (wid>0.0 && wid<20.0) {
		width=wid;
		return true;
	}
	return false;
}

float getLen() {
	return length;
}

float getWid() {
	return width;
}

private:

float length, width;

} rec;

int main() {
	
}
Last edited on
Topic archived. No new replies allowed.