.Define a class Shape and create constant object from the class with at least one constant data member. Create object in main function from the class Shape. Also display state of the constant object in main( ) function
Define a class Shape and create constant object from the class with at least one constant data member. Create object in main function from the class Shape. Also display state of the constant object in main( ) function
Comment this code line by line in simple english
include <iostream>
using namespace std;
class Line {
public:
void setLength( double len );
double getLength( void );
Line();
private:
double length;
};
Line::Line(void) {
cout << "Object is being created" << endl;
}
void Line::setLength( double len ) {
length = len;
}
double Line::getLength( void ) {
return length;
}
int main() {
Line line;
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;
return 0;
}
Comment this code line by line in simple english
float Height(){
return sqrt(pow((float)(points2D[0]-points2D[2]),2)+pow((float)(points2D[1]-points2D[3]),2));
}
float Perimeter(){
return 2*(Length()+Height());
}
float Diagonal(){
return sqrt(pow((float)(points2D[0]-points2D[4]),2)+pow((float)(points2D[1]-points2D[5]),2));
}
};
int main (){
Rectangle rectangle;
rectangle.Input();
rectangle.Output();
system("pause");
return 0;
}
Comment this code line by line in simple english
int CD=(pow((float)(points2D[4]-points2D[6]),2)+pow((float)(points2D[5]-points2D[7]),2));
int ACDiagonal=(pow((float)(points2D[0]-points2D[4]),2)+pow((float)(points2D[1]-points2D[5]),2));
return ( ACDiagonal == (AB + BC)) && (ACDiagonal == (AD + CD));
}
void Output(){
if(IsRectangle()){
cout<<"\nIt is a rectangle.\n";
cout<<"Area: "<<Area()<<"\n";
cout<<"Length: "<<Length()<<"\n";
cout<<"Height: "<<Height()<<"\n";
cout<<"Perimeter: "<<Perimeter()<<"\n";
cout<<"Diagonal: "<<Diagonal()<<"\n";
}else{
cout<<"\nIt is not a rectangle.\n";
}
}
float Length(){
return sqrt(pow((float)(points2D[4]-points2D[2]),2)+pow((float)(points2D[5]-points2D[3]),2));
}
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));Comment this code line by line in simple english
float Beta(){
return 90-Alpha();
}
};
int main (){
RightAngleTriangle rightAngleTriangle;
rightAngleTriangle.Input();
rightAngleTriangle.Output();
system("pause");
return 0;
}Comment this code line by line in simple english
cout << "The length of Hypotenuse: " << Hypotenuse() << "\n";
cout << "The angle between Base and Hypotenuse: " << Alpha() << "\n";
cout << "The angle between Hypotenuse and Perpendicular: " << Beta() << "\n";
}else{
cout << "It is not a right angle triangle\n";
}
}
float Base(){
if(AC == (AB + BC)){
return sqrt(AB);
}
if(AB == (AC + BC)){
return sqrt(AC);
}
return sqrt(AC);
}
float Perpendicular(){
if(AC == (AB + BC)){
return sqrt(BC);
}
if(AB == (AC + BC)){
return sqrt(BC);
}
return sqrt(AB);
}
float Hypotenuse(){
return sqrt((Base()*Base() + Perpendicular()*Perpendicular()));
}
float Alpha(){
return (acos(Base()/Hypotenuse())* 180.0) / 3.14;
}Comment this code line by line in simple english
AC=(pow((float)(Point2DA[0]-Point2DC[0]),2)+pow((float)(Point2DA[1]-Point2DC[1]),2));
AB=(pow((float)(Point2DA[0]-Point2DB[0]),2)+pow((float)(Point2DA[1]-Point2DB[1]),2));
BC=(pow((float)(Point2DB[0]-Point2DC[0]),2)+pow((float)(Point2DB[1]-Point2DC[1]),2));
}
float Area(){
return abs((Point2DA[0]*(Point2DB[1]-Point2DC[1])+Point2DB[0]*(Point2DC[1]-Point2DA[1])+Point2DC[0]*(Point2DA[1]-Point2DB[1]))/2.0);
}
bool IsRightAngleTriangle(){
return (((AC == (AB + BC)) || (AB == (AC + BC) ) || (BC == (AC + AB))));
}
void Output(){
cout << "The area of triangle: " << Area() << "\n";
if(IsRightAngleTriangle()){
cout << "It is a right angle triangle\n";
cout << "The length of Base: " << Base() << "\n";
cout << "The length of Perpendicular: " << Perpendicular() << "\n";Comment this code line by line
Comment each line and said why we use
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <cmath>
using namespace std;
class RightAngleTriangle{
private:
vector<int> Point2DA, Point2DB, Point2DC;
float AC,AB,BC;
public:
RightAngleTriangle(){}
void Input(){
int X;
int Y;
cout<<"Enter X coordinate for point A: ";
cin>>X;
cout<<"Enter Y coordinate for point A: ";
cin>>Y;
Point2DA.push_back(X);
Point2DA.push_back(Y);
cout<<"Enter X coordinate for point B: ";
cin>>X;
cout<<"Enter Y coordinate for point B: ";
cin>>Y;
Point2DB.push_back(X);
Point2DB.push_back(Y);
cout<<"Enter X coordinate for point C: ";
cin>>X;
cout<<"Enter Y coordinate for point C: ";
cin>>Y;
Point2DC.push_back(X);
Point2DC.push_back(Y);