Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Rectangle.h"
- #include "MathObject.h"
- using namespace std;
- // Constructors
- Rectangle::Rectangle() {
- //memset(angleCoordinates, 0, sizeof(angleCoordinates[0][0]) * 4 * 2);
- //setAllAnglesCoordinatesByHand();
- angleCoordinates[0][0] = 0;
- angleCoordinates[0][1] = 0;
- angleCoordinates[1][0] = 0;
- angleCoordinates[1][1] = 0;
- angleCoordinates[2][0] = 0;
- angleCoordinates[2][1] = 0;
- angleCoordinates[3][0] = 0;
- angleCoordinates[3][1] = 0;
- }
- Rectangle::Rectangle(double leftTopAngleX, double leftTopAngleY, double leftBottomAngleX, double leftBottomAngleY,
- double rightTopAngleX, double rightTopAngleY, double rightBottomAngleX, double rightBottomAngleY) {
- angleCoordinates[0][0] = leftTopAngleX;
- angleCoordinates[0][1] = leftTopAngleY;
- angleCoordinates[1][0] = leftBottomAngleX;
- angleCoordinates[1][1] = leftBottomAngleY;
- angleCoordinates[2][0] = rightTopAngleX;
- angleCoordinates[2][1] = rightTopAngleY;
- angleCoordinates[3][0] = rightBottomAngleX;
- angleCoordinates[3][1] = rightBottomAngleY;
- if (checkAngleCoordinates() == false) {
- cout << "Fill in coordinates correctly please !" << endl;
- system("pause");
- }
- else {
- system("CLS");
- cout << "Your entered correct coordinates for rectangle !" << endl;
- system("pause");
- printSideValue();
- printBottomValue();
- setArea();
- printArea();
- printCounter();
- system("pause");
- }
- }
- // Changing all values
- // by hand
- void Rectangle::setAllAnglesCoordinatesByHand() {
- system("CLS");
- cout << "Iveskite virsutiniojo kairiojo kampo koordinate x : ";
- cin >> angleCoordinates[0][0];
- cout << "Iveskite virsutiniojo kairiojo kampo koordinate y : ";
- cin >> angleCoordinates[0][1];
- cout << "Iveskite apatiniojo kairiojo kampo koordinate x : ";
- cin >> angleCoordinates[1][0];
- cout << "Iveskite apatiniojo kairiojo kampo koordinate y : ";
- cin >> angleCoordinates[1][1];
- cout << "Iveskite virsutiniojo desniojo kampo koordinate x : ";
- cin >> angleCoordinates[2][0];
- cout << "Iveskite virsutiniojo desniojo kampo koordinate y : ";
- cin >> angleCoordinates[2][1];
- cout << "Iveskite apatiniojo desniojo kampo koordinate x : ";
- cin >> angleCoordinates[3][0];
- cout << "Iveskite apatiniojo desniojo kampo koordinate y : ";
- cin >> angleCoordinates[3][1];
- if (checkAngleCoordinates() == false) {
- cout << "Fill in coordinates correctly please !" << endl;
- system("pause");
- }
- else {
- system("CLS");
- cout << "Your entered correct coordinates for rectangle !" << endl;
- system("pause");
- printSideValue();
- printBottomValue();
- printArea();
- system("pause");
- }
- }
- // Checking if values inserted correctly
- bool Rectangle::checkAngleCoordinates() {
- bool check = true;
- if (angleCoordinates[0][0] != angleCoordinates[1][0] & angleCoordinates[0][1] <= angleCoordinates[1][1]) {
- return false;
- }
- if (angleCoordinates[2][0] != angleCoordinates[3][0] & angleCoordinates[2][1] <= angleCoordinates[3][1]) {
- return false;
- }
- if (angleCoordinates[0][1] != angleCoordinates[2][1] & angleCoordinates[2][0] <= angleCoordinates[0][0]) {
- return false;
- }
- if (angleCoordinates[1][1] != angleCoordinates[3][1] & angleCoordinates[3][0] <= angleCoordinates[1][0]) {
- return false;
- }
- return check;
- }
- //Calculations
- //Getters
- double Rectangle::getBottomValue() {
- double bottomValue = sqrt(pow(angleCoordinates[3][0] - angleCoordinates[1][0], 2) + pow(angleCoordinates[3][1] - angleCoordinates[1][1], 2));
- return bottomValue;
- }
- double Rectangle::getSideValue() {
- double sideValue = sqrt(pow(angleCoordinates[0][0] - angleCoordinates[1][0], 2) + pow(angleCoordinates[0][1] - angleCoordinates[1][1], 2));
- return sideValue;
- }
- double Rectangle::getArea() {
- return area;
- }
- // Setters
- void Rectangle::setArea() {
- area = pow(getSideValue()) + pow(getBottomValue());
- }
- // Printing values
- void Rectangle::printAngleCoordinates() {
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 2; j++) {
- cout << angleCoordinates[i][j];
- }
- cout << endl;
- }
- }
- void Rectangle::printBottomValue() {
- cout << "Bottom value side is : " << getBottomValue() << endl;
- }
- void Rectangle::printSideValue() {
- cout << "Side value is : " << getSideValue() << endl;
- }
- void Rectangle::printArea() {
- cout << "Area value is : " << getArea() << endl;
- }
- void Rectangle::printCounter() {
- cout << "Your object number is : " << getCount() << endl;
- }
- // OPERATOR OVERLOAD
- void Rectangle::operator++() {
- /*
- for (int i = 0; i < 4; i++){
- for (int j = 0; j < 2; j++)
- {
- ++angleCoordinates[i][j];
- }
- }
- */
- area++;
- }
- Rectangle operator+(Rectangle op1, Rectangle op2) {
- Rectangle temp;
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 2; j++){
- temp.angleCoordinates[i][j] = op1.angleCoordinates[i][j] + op2.angleCoordinates[i][j];
- }
- }
- temp.setArea();
- return temp;
- }
- Rectangle Rectangle::operator= (Rectangle op1) {
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 2; j++) {
- angleCoordinates[i][j] = op1.angleCoordinates[i][j];
- }
- }
- setArea();
- return *this;
- }
- bool Rectangle:: operator==(Rectangle op1) {
- if (getArea() == op1.getArea()) return true;
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement