Answer to Question #184071 in C++ for Bilal

Question #184071

Comment this code line by line in simple english


#include <iostream>
 
#include <vector>
 
#include <cmath>
 
 
using namespace std;
 
class Rectangle{
 
private:
 
    vector<int> points2D;
 
 
 
public:
 
 
    void Input(){
 
        for(int i=1;i<=4;i++){
 
            int x;
 
            int y;
 
            cout<<"Enter X"<<i<<": ";
 
            cin>>x;
 
            points2D.push_back(x);
 
            cout<<"Enter Y"<<i<<": ";
 
            cin>>y;
 
            points2D.push_back(y);
 
        }
 
 
    }
 
 
    float Area(){
 
        return Length()*Height();
 
    }
 
 
    bool IsRectangle(){
 
        int AB=(pow((float)(points2D[0]-points2D[2]),2)+pow((float)(points2D[1]-points2D[3]),2));
 
        int BC=(pow((float)(points2D[4]-points2D[2]),2)+pow((float)(points2D[5]-points2D[3]),2));
 
        int AD=(pow((float)(points2D[0]-points2D[6]),2)+pow((float)(points2D[1]-points2D[7]),2));
1
Expert's answer
2021-04-25T03:12:06-0400
#include <iostream>
 
#include <vector>
 
#include <cmath>
 
 
using namespace std;
 
class Rectangle{
 
private:
 
    vector<int> points2D;                     //declaration of points of rectangle in 2D Plane 
 
 
 
public:
 
 
    void Input(){
 
        for(int i=1;i<=4;i++){            //loop to accept and iterate over four points of rectangle
 
            int x;
 
            int y;
 
            cout<<"Enter X"<<i<<": ";               
 
            cin>>x;                          //initial starting point for rectangle
 
            points2D.push_back(x);           //passing of initial point to the function
 
            cout<<"Enter Y"<<i<<": ";
 
            cin>>y;                          //second point for rectangle
 
            points2D.push_back(y);            //passing of second point to the function
 
        }
 
 
    }
 
 
    float Area(){                        //function definition to compute the area of rectangle
 
        return Length()*Height();
 
    }
 
 
    bool IsRectangle(){                   //function to check whether the given points forms a rectangle
 
        int AB=(pow((float)(points2D[0]-points2D[2]),2)+pow((float)(points2D[1]-points2D[3]),2)); //checks the length AB
 
        int BC=(pow((float)(points2D[4]-points2D[2]),2)+pow((float)(points2D[5]-points2D[3]),2)); //checks the length BC
 
        int AD=(pow((float)(points2D[0]-points2D[6]),2)+pow((float)(points2D[1]-points2D[7]),2));  //checks the length AD

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS