SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 5 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 17 Dec 2017 My Price 10.00

function given for each class and your main function

I need help with this assignment. Thank you.

 

  1. Modify the Shapes.cpp file attached by writing code for each member function given for each class and your main function.. Do not modify the declaration section given for each class at all.
  2. The Rectangle.class is the base class and contains two protected data members to store a sideA and sideB.
  3. The Rectangle class constructor will accept two arguments which will contain a value for each side of the rectangle (sideA and sideB).  Assign a value to sideA and sideB using the value of the two parameters.
  4. Code getSideA and getSideB member functions to return back the value of the associated data member.
  5. Code the setSideA and setSideB member functions to assign the value passed to the function to the associated data member. Make sure within the member function that the value assigned is not zero or less. If the value passed to the parameter is zero or less assign the side to a default value of 1.
  6. Code the computePerimeter member function to compute and return back the perimeter of a Rectangle. This formula is given in the hyperlink for step 1.
  7. Code the computeArea memberr function to compute and return back the area of a Rectangle. This formula is given in the hyperlink for step 1.
  8. Overload the increment operator to increment (add to) the value stored in sideA and sideB by one.
  9. Overload the decrement operator to decrement (subtract from) the value stored in sideA and sideB by one.
  10. Overload the equality operator (==) to test two Rectangle objects for equality. This function should return back true if the two Rectangle objects are equal and false if the two Rectangle objects are not equal. The two Rectangle objects are equal if both the value of the sideA data members are equal and the value of the sideB data members are equal.
  11. Code the Square class to inherit from the Rectangle class. The inheritance will be public. No additional data members should be added to the Square class because it will inherit the data members from the Rectangle class. Other than what is already contained in the Shapes.cpp file (see step1), no additional member functions should be added to the Square class because it will inherit or override the member functions from the Rectangle class.
  12. The setSideA member function will override this same function from the parent class. Within this function assign the value of the data members sideA and sideB to the argument of this function. This means both data members will be assigned the same value because sideA and sideB of a square are equal.  Make sure within the member function that the value assigned is not zero or less. If the value passed to the parameter (the argument) is zero or less assign both sides to a default value of 1.
  13. The setSideB member function will override this same function from the parent class. Within this function assign the value of the data members sideA and sideB to the argument of this function. This means both data members will be assigned the same value because sideA and sideB of a square are equal. Make sure within the member function that the value assigned is not zero or less. If the value passed to the parameter (the argument) is zero or less assign both sides to a default value of 1.
  14. The Square class constructor will accept one argument which will contain a value for each side of the square (sideB will be assigned the same value as sideA). Use a base/member initialization list to call the Rectangle constructor to assign values for sideA and sideB of the Square. Keep in mind that sideA and sideB of a square are equal.
  15. The main function will be used to test your class hierarchy. 
  16. Test the Square class first. Prompt the user to enter in the side length of a square. Instantiate a Square object using the data entered in by the user. Call the displayData function passing it the Square object to display the values for this square.
  17. Use the overloaded increment operator with the Square object from the above step. You have to use the prefix increment operator in order for your program to compile and run. Call the displayData function passing it the Square object to display the new values for this square.
  18. Test the Rectangle class second. Prompt the user to enter in the first side length of a rectangle (sideA). Prompt the user to enter in the second side length of a rectangle (sideB). Instantiate a Rectangle object using the data entered in by the user. Call the displayData function passing it the Rectangle object to display the values for this rectangle.
  19. Use the overloaded decrement operator with the Rectangle object from the above step.  You have to use the prefix decrement operator in order for your program to compile and run. Call the displayData function passing it the Rectangle object to display the new values for this rectangle.
  20. Use the overloaded == operator to display a message indicating whether the Rectangle object and the Square object from the above steps are the same or different. 
  21. Make sure the output matches the image output.png.output.PNG
    #include <iostream>
    #include <iomanip>
    using namespace std;


    /******************Rectangle Class****************************/
    //class declaration section
    class Rectangle {
    protected:
        //data members    
        int sideA;
        int sideB;
    public:
        Rectangle(int, int);
        void setSideA(int);
        void setSideB(int);
        int getSideA();
        int getSideB();
        int computePerimeter();
        int computeArea();
        void operator++(); //overloaded increment operator
        void operator--(); //overloaded decrement operator
        bool operator==(Rectangle &); //overloaded is equal to operator
    };


    /******************Square Class****************************/
    //class declaration section
    class Square
    {
    public:
        Square(int); //constructor
        void setSideA(int);
        void setSideB(int);
    };



    void displayData(Rectangle); // function prototype

    int main()
    {



    }

    /****************************************************************************/
    /* Because of inheritance and polymorphism the displayData function can be
       passed either a Rectangle object or a Square object to display each
       object's data.                                                           */
    void displayData(Rectangle shape)
    {
        cout << "\nThe length of side A is " << shape.getSideA() << endl;
        cout << "The length of side B is " << shape.getSideB() << endl;
        cout << "The perimeter is " << shape.computePerimeter() << endl;
        cout << "The area is " << shape.computeArea() << endl << endl;
    }


Attachments:

Answers

(5)
Status NEW Posted 17 Dec 2017 02:12 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)