Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

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!

Search

.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);
 
 
LATEST TUTORIALS
APPROVED BY CLIENTS