Square or Rectangle Program

I'm new to C++ and have a problem here. My code is below, I need to finish my two 'isRectangle' and 'isSquare' statements, to determine whether or not the quadrilateral is a rectangle or square. Here is what I have, but it keeps giving me errors and doesn't work properly. How do I make this work correctly? Thank you!


HEADER FILE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #pragma once
class Quadralateral
{
public:
	Quadralateral(int=0,int=0,int=1,int=0,int=1,int=1,int=0,int=1);
	bool isRectangle();
	bool isSquare();



	~Quadralateral(void);
private:
	int X1,Y1,X2,Y2,X3,Y3,X4,Y4;
};



SOURCE FILE
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
#include "Quadralateral.h"


Quadralateral::Quadralateral(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
  X1 = x1;	// memberwise assignment
  Y1 = y1;
  X2 = x2;
  Y2 = y2;
  X3 = x3;
  Y3 = y3;
  X4 = x4;
  Y4 = y4;
}

bool Quadralateral::isRectangle() // HELP ON THIS FUNCTION
{
	int s1; // top
	int s2; // left
	int s3; // right
	int s4; // bottom

  if (X1 != X3)
    return false;   
  if (Y1 != Y2)
    return false;  
	s1 = X2 - X1;    
	s4 = X4 - X3;  
  if (s1 != s4)
    return false;
	s2 = X1 - X3;
	s3 = X2 - X4;
  if (s2 != s3)
    return false;

  if ((s2 = s3) && (s1 = s4))
	  return true;  
  
  
  // All tests for a rectangle passed
}

bool Quadralateral::isSquare() // HELP ON THIS FUNCTION
{
	int s1; // top
	int s2; // left
	int s3; // right
	int s4; // bottom

  if (X1 != X3)
    return false;   
  if (Y1 != Y2)
    return false;  
	s1 = X2 - X1;    
	s4 = X4 - X3;  
  if (s1 != s4)
    return false;
	s2 = X1 - X3;
	s3 = X2 - X4;
  if (s2 != s3)
    return false;

  if (s2 = s3 = s1 = s4)
	  return true;  
 
  // Test for square passed
}

Quadralateral::~Quadralateral(void)
{

}
Last edited on
if you want to compare values you need to use ==.

= is an assignment operator.
Oh wow, how did I miss that? It's still not working correctly, what else is wrong? Am I even going about it the right way?
i don't know what error you are getting. a sample of your program would be helpful.
Well it compiles fine, it just doesn't do anything after I build the solution. I feel as if I'm missing something easy here.
do you output anything to the console?
No it just says, 'press any key to continue...'

Like I said earlier, I'm really new to this, any suggestions?
what code do you have in main?
Nothing now, I have all my code in that second source file I sent you. This is what my main looks like...
1
2
3
4
5
6
7
8
#include "Quadralateral.h"

int main()
{


return 0;
}

Should I have something in there? :(
yes you need to put something in between {}.

you would need to add #include <iostream> before int main().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main()
{
  
// you need to instantiate the class 
  Quadralateral q(2,2,2,2,2,2);
  
//checks for the return value of the method.
  if(q.isRectangle())
  {
// this code outputs to the console
    std::cout << "is a rectangle" <<  std::endl;
  }
  else
  {
      std::cout << "is not a rectangle" << std::endl;
  }
  
  
}
Oh my goodness, It works like a charm, thank you so much!!!!!
oh! One more thing, It just keeps saying that is isn't a rectangle though, no matter what I put in. What numbers would i put in to check if it is working right for a rectangle?
Points that represent a valid rectangle? If you are incapable of coming up with a valid set of points, you don't have much chance of getting the code right.
Topic archived. No new replies allowed.