My target is to make a code of Cartesian coordinating points of a rectangle... then it must be tested by quadrilateral and square. If the tested point is a rectangle then the out put program will be like this.....

Program Output:


************************************************************


....+y .....+
..............+ ..point a............................................................................. point b
..............+ ..ax,ay................................................................................... bx,by
..............+
..............+
..............+ .........................................point e
..............+ ...........................................ex,ey
..............+
..............+
..............+ point c................................................................................ point d
..............+ ..cx,cy ..................................................................................dx,dy
..............+ + + + + + + + + + + + + + + + + + +++++++++++++++++++++
............0.0 ...............................................................................................+x
Cartesian Coordinate System


Point a is upper left, b is upper right c is lower left, d if lower right


Side a is ad, b is ba, c is bd and d is dc


Diagonal a is cb, Diagonal b is ad
************************************************************
For a rectangle use points 4,12,11,5,-12,-4,-5,-11


For a square use points 1,9,8,2,-6,2,1,-5
************************************************************


Enter coordinate ax: 1
Enter coordinate ay: 9
Enter coordinate bx: 8
Enter coordinate by: 2
Enter coordinate cx: -6
Enter coordinate cy: 2
Enter coordinate dx: 1
Enter coordinate dy: -5


********************


Calculating Sides and x/y Components


dy1= 7
dx1= 7
Side a = 9.8995


dy2= -7
dx2= 7
Side b = 9.8995


dy3= -7
dx3= -7
Side c = 9.8995


dy4= -7
dx4= 7
Side d = 9.8995


********************


Calculating Diagonals


Diagonal a= 14 Diagonal b= 14
Difference= 0


***********************************


Plane Figure is a Rectangle!
Diagonal difference zero
Side a= 9.8995 Side b= 9.8995
The Area of the Rectangle is = 98


***********************************


Plane Figure is a Square!
Side = 9.8995
Center Coordinates of the Square are: (1,2)



I have here the code


File Name: main.cp


// Main Program
//
#include "square.h" // Derived Class square
int main()
{


//*******************************************************************************
cout << "\t\t\t+y";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\tpoint a" << "\t\t\t\tpoint b";
cout << "\n\t\t\t +" << "\t ax,ay" << "\t\t\t\t bx,by";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\t\t\t point e";
cout << "\n\t\t\t +" << "\t\t\t ex,ey";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\tpoint c" << "\t\t\t\tpoint d";
cout << "\n\t\t\t +" << "\t cx,cy" << "\t\t\t\t dx,dy";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t + + + + + + + + + + + + + + + + +";
cout << "\n\t\t\t0.0" << "\t\t\t\t\t\t\t\t +x";
cout << "\n\t\t\t\tCartesian Coordinate System";
cout << "\n";
cout << "\nPoint a is upper left, b is upper right" << endl;
cout << "c is lower left, d if lower right" << endl;
cout << "\nSide a is ad, b is ba, c is bd and d is dc" << endl;
cout << "\nDiagonal a is cb, Diagonal b is ad" << endl;
cout << "************************************************************" << endl;
cout << "For a rectangle use points 4,12,11,5,-12,-4,-5,-11" << endl;
cout << "\nFor a square use points 1,9,8,2,-6,2,1,-5" << endl;
cout << "************************************************************" << endl;
Square Square_Results;


Square_Results.Square_Data();


return 0;


}
******************************************************************************************************************************************


File Name: quad.h


// Base Class Quadrilateral
//
// //*************************************************************
//The program will use cartesian coordinate system,
//The axises will be x,y as follows:
//
//
// ............................+
//................... +y.... +.. point a ..........side_a ..........point b
// ............................+.. ax,ay .......................................bx,by
//............................ +
// ............................+
// ............................+ ..side_c........... point e ...........side_b
// ............................+............................. ex,ey
// ............................+
//............................ +
//............................ + ..point c............ side d ...........point d
// ............................+ ..cx,cy ........................................dx,dy
// ............................+
// ............................+ + + + + + + + + + + + + + + + + +
// ..........................0.0............................................... +x
// Point a is upper left *** side_a is between points a and c
// Point b is upper right *** side_b is between points a and b
// Point c is lower left *** side_c is between points b and d
// Point d is lower right *** side_d is between points c and d
//
// *************************************************************
#include<iostream>
#include <cmath> // Needed fo "fabs" & "sqrt" functions
using namespace std;
class Quadrilateral
{


public:
// Declare coordinate point variables
float ax, ay, bx, by, cx, cy, dx, dy; // Corner points
Quadrilateral() // Default constructor
{


// Initialize variables to 0 ax = ay = bx = by= cx = cy = dx = dy = 0;
// Enter coordinate data points for corners
cout << "\nEnter coordinate ax: ";
cin >> ax;
cout << "Enter coordinate ay: ";
cin >> ay;
cout << "Enter coordinate bx: ";
cin >> bx;
cout << "Enter coordinate by: ";
cin >> by;
cout << "Enter coordinate cx: ";
cin >> cx;
cout << "Enter coordinate cy: ";
cin >> cy;
cout << "Enter coordinate dx: ";
cin >> dx;
cout << "Enter coordinate dy: ";
cin >> dy; };


}
~Quadrilateral() // Call Destructor
{


cout << "\n\nThe Base Class Rectangle has been destroyed!" << endl;


};


};
******************************************************************************************************************************************


File Name: rect.h


//
//DERIVED CLASS RECTANGLE
//*************************************************************
//
//Derived Class rect.h


#include <iomanip>


#include "quad.h" // Base Class file


class Rectangle : public Quadrilateral // Inherit from Class Quadrilateral
{


public:


float dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4; // differences
double side_a, side_b, side_c, side_d;
double diagonal_a, diagonal_b; // Diagonals
int typeo; // Type of Figure
double area;
double diag_diff;


Rectangle() // Default constructor
{


// Initialize variables to 0
area= 0;
cout << "\n********************" << endl;


// Calculate sides - dxn and dyn are x and y components
cout << "\n\tCalculating Sides and x/y Components" << endl;


dy1= ay - cy;
cout << "\ndy1= " << dy1;
dx1= ax - cx;
cout << "\ndx1= " << dx1;
side_a= sqrt(dx1 * dx1 + dy1 * dy1);
cout << "\nSide a = " << side_a;


dy2= by - ay;
cout << "\n\ndy2= " << dy2;
dx2= bx - ax;
cout << "\ndx2= " << dx2;
side_b= sqrt(dx2 * dx2 + dy2 * dy2);
cout << "\nSide b = " << side_b;


dy3= dy - by;
cout << "\n\ndy3= " << dy3;
dx3= dx - bx;
cout << "\ndx3= " << dx3;
side_c= sqrt(dx3 * dx3 + dy3 * dy3);
cout << "\nSide c = " << side_c;


dy4= dy - cy;
cout << "\n\ndy4= " << dy4;
dx4= dx - cx;
cout << "\ndx4= " << dx4;
side_d= sqrt(dx4 * dx4 + dy4 * dy4);
cout << "\nSide d = " << side_d;
cout << "\n\n********************" << endl;


// Calculate diagonals to check for rectangle
cout << "\n\tCalculating Diagonals" << endl;


diagonal_a = sqrt (side_a * side_a + side_b * side_b);
diagonal_b = sqrt (side_c * side_c + side_d * side_d);
diag_diff= fabs(diagonal_a - diagonal_b);
cout << "\nDiagonal a= " << diagonal_a
<< "\t\tDiagonal b= " << diagonal_b
<< "\nDifference= " << diag_diff << endl;


if (diag_diff == 0)
{


cout << "\n***********************************" << endl;
cout << "\tPlane Figure is a Rectangle!" << endl;
cout << "Diagonal difference zero" << endl;
cout << "Side a= " << side_a << "\t\tSide b= " << side_b << endl;
area = side_a * side_b; // Calculate the area
cout << "The Area of the Rectangle is = " << area << endl;


}


else


if (diag_diff < 0.0001)


{


cout << "\n***********************************" << endl;
cout << "\tPlane Figure is approximately a Rectangle!" << endl;
cout << "Diagonal difference less than 0.0001" << endl;
cout << "Side a= " << side_a << "\t\tSide b= " << side_b << endl;
area = side_a * side_b; // Calculate the area
cout << "The Area of the Rectangle is = " << area << endl;


}
else
{


cout << "\n\n\tPlane Figure is NOT a Rectangle!" << endl;
cout << "Diagonal difference greater than 0.0001" << endl;


}


};


~Rectangle() { }; // Call Destructor


};


******************************************************************************************************************************************


File Name: square.h


//
//DERIVED CLASS SQUARE
//
//*************************************************************
//Devived Class square.h


# include "rect.h" // Base Class file


class Square : Rectangle // Inherit from Class Rectangle
{


private:


// Declare coordinate point variables
float ex, ey;


public:


Square() // Default constructor
{


// Initialize variables to 0
ex= 0;
ey= 0;


};


~Square() { }; // Call Destructor


// Test for Square, Calculate Center Points and Display results


void Square_Data()
{


// Calculate sides - dxn and dyn are x and y components


dy1= ay - cy;
dx1= ax - cx;
side_a= sqrt(dx1 * dx1 + dy1 * dy1);
dy2= by - ay;
dx2= bx - ax;
side_b= sqrt(dx2 * dx2 + dy2 * dy2);
dy3= dy - by;
dx3= dx - bx;
side_c= sqrt(dx3 * dx3 + dy3 * dy3);
dy4= dy - cy;
dx4= dx - cx;
side_d= sqrt(dx4 * dx4 + dy4 * dy4);


// Calculate diagonals to check for rectangle


diagonal_a = sqrt (side_a * side_a + side_b * side_b);
diagonal_b = sqrt (side_c * side_c + side_d * side_d);


if ((diag_diff < 0.0001) && (fabs(side_a - side_b) < 0.0001))
{


ex= bx - (bx - cx)/2;
ey= ay - (ay - dy)/2;
cout << "\n***********************************" << endl;
cout << "\tPlane Figure is a Square!" << endl;
cout << "Side = " << side_a << endl;
cout << "Center Coordinates of the Square are: (" << ex << "," << ey << ")" << endl; }


else
{


cout << "\n***********************************" << endl;
cout << "\n\tObject is not a Square!" << endl;


}


};


};

but I've got the error:

Error   1   error C2588: '::~Quadrilateral' : illegal global destructor c:\documents and settings\aldrich uy\my documents\visual studio 2005\projects\rectangle\rectangle\quad.h    60

Recommended Answers

All 6 Replies

Without looking for any other errors, or checking the functionality of your code, I can see that in quad.h you have an extra closing bracket:

....
cin >> dy; };

} <--- remove this one
~Quadrilateral() // Call Destructor
....

If you used code-formatting and code-tags, you could have found this error yourself. Code-tags preserve the formatting of text (so code or your program's output)

First of all, please use code tags when you post your code.

You have an extra curly brace there ...

// }  <- extra curly brace here
~Quadrilateral() // Call Destructor
{
    cout << "\n\nThe Base Class Rectangle has been destroyed!" << endl;
};

[EDIT]
Oh well, niek_e got there first ...


Oh well, niek_e got there first ...

You know what they say: Brilliant minds think alike ;)

j/k of course

I've got 2 errors when i remove the curly brace

Error 1 error C2504: 'Quadrilateral' : base class undefined c:\documents and settings\aldrich uy\my documents\visual studio 2005\projects\rectangle\rectangle\rect.h 14

Error 2 fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\aldrich uy\my documents\visual studio 2005\projects\rectangle\rectangle\quad.h(32)' was matched c:\Documents and Settings\Aldrich Uy\My Documents\Visual Studio 2005\Projects\RECTANGLE\RECTANGLE\main.cpp 41

I've got 2 errors when i remove the curly brace

Error 1 error C2504: 'Quadrilateral' : base class undefined c:\documents and settings\aldrich uy\my documents\visual studio 2005\projects\rectangle\rectangle\rect.h 14

Error 2 fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\aldrich uy\my documents\visual studio 2005\projects\rectangle\rectangle\quad.h(32)' was matched c:\Documents and Settings\Aldrich Uy\My Documents\Visual Studio 2005\Projects\RECTANGLE\RECTANGLE\main.cpp 41

Code reposted without any attempt to compile. Done to make copying/pasting a bit easier.

// Main Program
//
#include "square.h" // Derived Class square
int main()
{

//*******************************************************************************
cout << "\t\t\t+y";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\tpoint a" << "\t\t\t\tpoint b";
cout << "\n\t\t\t +" << "\t ax,ay" << "\t\t\t\t bx,by";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\t\t\t point e";
cout << "\n\t\t\t +" << "\t\t\t ex,ey";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +" << "\tpoint c" << "\t\t\t\tpoint d";
cout << "\n\t\t\t +" << "\t cx,cy" << "\t\t\t\t dx,dy";
cout << "\n\t\t\t +";
cout << "\n\t\t\t +";
cout << "\n\t\t\t + + + + + + + + + + + + + + + + +";
cout << "\n\t\t\t0.0" << "\t\t\t\t\t\t\t\t +x";
cout << "\n\t\t\t\tCartesian Coordinate System";
cout << "\n";
cout << "\nPoint a is upper left, b is upper right" << endl;
cout << "c is lower left, d if lower right" << endl;
cout << "\nSide a is ad, b is ba, c is bd and d is dc" << endl;
cout << "\nDiagonal a is cb, Diagonal b is ad" << endl;
cout << "************************************************************" << endl;
cout << "For a rectangle use points 4,12,11,5,-12,-4,-5,-11" << endl;
cout << "\nFor a square use points 1,9,8,2,-6,2,1,-5" << endl;
cout << "************************************************************" << endl;
Square Square_Results;

Square_Results.Square_Data();

return 0;

}
******************************************************************************************************************************************

File Name: quad.h

// Base Class Quadrilateral
//
// //*************************************************************
//The program will use cartesian coordinate system,
//The axises will be x,y as follows:
//
//
// ............................+
//................... +y.... +.. point a ..........side_a ..........point b
// ............................+.. ax,ay .......................................bx,by
//............................ +
// ............................+
// ............................+ ..side_c........... point e ...........side_b
// ............................+............................. ex,ey
// ............................+
//............................ +
//............................ + ..point c............ side d ...........point d
// ............................+ ..cx,cy ........................................dx,dy
// ............................+
// ............................+ + + + + + + + + + + + + + + + + +
// ..........................0.0............................................... +x
// Point a is upper left *** side_a is between points a and c
// Point b is upper right *** side_b is between points a and b
// Point c is lower left *** side_c is between points b and d
// Point d is lower right *** side_d is between points c and d
//
// *************************************************************
#include<iostream>
#include <cmath> // Needed fo "fabs" & "sqrt" functions
using namespace std;
class Quadrilateral
{

public:
// Declare coordinate point variables
float ax, ay, bx, by, cx, cy, dx, dy; // Corner points
Quadrilateral() // Default constructor
{

// Initialize variables to 0 ax = ay = bx = by= cx = cy = dx = dy = 0;
// Enter coordinate data points for corners
cout << "\nEnter coordinate ax: ";
cin >> ax;
cout << "Enter coordinate ay: ";
cin >> ay;
cout << "Enter coordinate bx: ";
cin >> bx;
cout << "Enter coordinate by: ";
cin >> by;
cout << "Enter coordinate cx: ";
cin >> cx;
cout << "Enter coordinate cy: ";
cin >> cy;
cout << "Enter coordinate dx: ";
cin >> dx;
cout << "Enter coordinate dy: ";
cin >> dy; };


// removed the curley brace

~Quadrilateral() // Call Destructor
{

cout << "\n\nThe Base Class Rectangle has been destroyed!" << endl;

};

};
******************************************************************************************************************************************

File Name: rect.h

//
//DERIVED CLASS RECTANGLE
//*************************************************************
//
//Derived Class rect.h

#include <iomanip>

#include "quad.h" // Base Class file

class Rectangle : public Quadrilateral // Inherit from Class Quadrilateral
{

public:

float dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4; // differences
double side_a, side_b, side_c, side_d;
double diagonal_a, diagonal_b; // Diagonals
int typeo; // Type of Figure
double area;
double diag_diff;



Rectangle() // Default constructor
{

// Initialize variables to 0
area= 0;
cout << "\n********************" << endl;

// Calculate sides - dxn and dyn are x and y components
cout << "\n\tCalculating Sides and x/y Components" << endl;

dy1= ay - cy;
cout << "\ndy1= " << dy1;
dx1= ax - cx;
cout << "\ndx1= " << dx1;
side_a= sqrt(dx1 * dx1 + dy1 * dy1);
cout << "\nSide a = " << side_a;

dy2= by - ay;
cout << "\n\ndy2= " << dy2;
dx2= bx - ax;
cout << "\ndx2= " << dx2;
side_b= sqrt(dx2 * dx2 + dy2 * dy2);
cout << "\nSide b = " << side_b;

dy3= dy - by;
cout << "\n\ndy3= " << dy3;
dx3= dx - bx;
cout << "\ndx3= " << dx3;
side_c= sqrt(dx3 * dx3 + dy3 * dy3);
cout << "\nSide c = " << side_c;

dy4= dy - cy;
cout << "\n\ndy4= " << dy4;
dx4= dx - cx;
cout << "\ndx4= " << dx4;
side_d= sqrt(dx4 * dx4 + dy4 * dy4);
cout << "\nSide d = " << side_d;
cout << "\n\n********************" << endl;

// Calculate diagonals to check for rectangle
cout << "\n\tCalculating Diagonals" << endl;

diagonal_a = sqrt (side_a * side_a + side_b * side_b);
diagonal_b = sqrt (side_c * side_c + side_d * side_d);
diag_diff= fabs(diagonal_a - diagonal_b);
cout << "\nDiagonal a= " << diagonal_a
<< "\t\tDiagonal b= " << diagonal_b
<< "\nDifference= " << diag_diff << endl;

if (diag_diff == 0)
{

cout << "\n***********************************" << endl;
cout << "\tPlane Figure is a Rectangle!" << endl;
cout << "Diagonal difference zero" << endl;
cout << "Side a= " << side_a << "\t\tSide b= " << side_b << endl;
area = side_a * side_b; // Calculate the area
cout << "The Area of the Rectangle is = " << area << endl;

}

else

if (diag_diff < 0.0001)

{

cout << "\n***********************************" << endl;
cout << "\tPlane Figure is approximately a Rectangle!" << endl;
cout << "Diagonal difference less than 0.0001" << endl;
cout << "Side a= " << side_a << "\t\tSide b= " << side_b << endl;
area = side_a * side_b; // Calculate the area
cout << "The Area of the Rectangle is = " << area << endl;

}
else
{

cout << "\n\n\tPlane Figure is NOT a Rectangle!" << endl;
cout << "Diagonal difference greater than 0.0001" << endl;

}

};

~Rectangle() { }; // Call Destructor

};

******************************************************************************************************************************************

File Name: square.h

//
//DERIVED CLASS SQUARE
//
//*************************************************************
//Devived Class square.h

# include "rect.h" // Base Class file

class Square : Rectangle // Inherit from Class Rectangle
{

private:

// Declare coordinate point variables
float ex, ey;

public:

Square() // Default constructor
{

// Initialize variables to 0
ex= 0;
ey= 0;

};

~Square() { }; // Call Destructor

// Test for Square, Calculate Center Points and Display results

void Square_Data()
{

// Calculate sides - dxn and dyn are x and y components

dy1= ay - cy;
dx1= ax - cx;
side_a= sqrt(dx1 * dx1 + dy1 * dy1);
dy2= by - ay;
dx2= bx - ax;
side_b= sqrt(dx2 * dx2 + dy2 * dy2);
dy3= dy - by;
dx3= dx - bx;
side_c= sqrt(dx3 * dx3 + dy3 * dy3);
dy4= dy - cy;
dx4= dx - cx;
side_d= sqrt(dx4 * dx4 + dy4 * dy4);

// Calculate diagonals to check for rectangle

diagonal_a = sqrt (side_a * side_a + side_b * side_b);
diagonal_b = sqrt (side_c * side_c + side_d * side_d);

if ((diag_diff < 0.0001) && (fabs(side_a - side_b) < 0.0001))
{

ex= bx - (bx - cx)/2;
ey= ay - (ay - dy)/2;
cout << "\n***********************************" << endl;
cout << "\tPlane Figure is a Square!" << endl;
cout << "Side = " << side_a << endl;
cout << "Center Coordinates of the Square are: (" << ex << "," << ey << ")" << endl; }

else
{

cout << "\n***********************************" << endl;
cout << "\n\tObject is not a Square!" << endl;

}

};

};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.