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));
#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
Comments
Leave a comment