Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Class Shape

Class Shape

Scheduled Pinned Locked Moved C / C++ / MFC
help
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kumn1d
    wrote on last edited by
    #1

    This is the output I am supposed to get but I am getting errors please help me

    int main()
    {
    int size = 5;

    Shape\*\* shapes = new Shape\*\[size\];
    
    Point\* centre = new Point(5,5);
    Rectangle\* rectangle1 = new Rectangle(\*centre, 4, 3);
    shapes\[0\] = rectangle1;
    
    shapes\[1\] = new Rectangle (\*new Point(10, -10), 4, 4);
    
    Rectangle\* rectangle3 = new Square(\*new Point(-8.5,-10), 2.5);
    shapes\[2\] = rectangle3;
    
    Square\* square2 = new Square (\*new Point(-1,-1), 1.5);
    shapes\[3\] = square2;
    
    Circle\* circle = new Circle(\*new Point(100,100), 25.4);
    shapes\[4\] = circle;
    
    cout << "\\n11111111111111111111111111\\n";
    
    for (int i = 0; i < size; ++i)
    	shapes\[i\] -> display();
    
    cout << "\\n22222222222222222222222222\\n";
    
    cout << "\\nthe area of the first rectangle is: ";
    cout << rectangle1->area() << endl;
    
    cout << "It is a square, the area is: ";
    Square\* square = dynamic\_cast<Square\*> (rectangle3);
    cout << square->area() << endl;	
    
    cout << "the perimeter of the circle is: ";
    cout << circle->perimeter() << endl;	
    
    cout << "\\n33333333333333333333333333\\n";
    
    cout << "\\nThe four vertices of the first rectangle are: (clockwise from top-left)\\n";
    rectangle1->printFourVertices();
    
    cout << "\\nThe four vertices of the third rectangle are:\\n";
    rectangle3->printFourVertices();
    
    cout << "\\n44444444444444444444444444\\n";
    
    rectangle1->reflectX();
    
    shapes\[2\] -> translate(1.5, 3);
    
    shapes\[4\] -> translate(-100,-100);
    
    cout << "\\nAfter reflection and translation, here are the moved shapes:\\n" ;
    for (int i = 0; i < size; ++i)
    	shapes\[i\] -> display();
    
    cout << "\\n55555555555555555555555555\\n";
    
    cout << "\\nNow, the four vertices of the first rectangle are:\\n";
    rectangle1->printFourVertices();
    
    cout << "\\nNow, the four vertices of the third rectangle are:\\n";
    rectangle3->printFourVertices();
    
    cout << "\\n66666666666666666666666666\\n\\n";
    
    for (int i = 0; i < size; ++i)
    	cout << shapes\[i\] -> area() << endl;
    
    // From the following statements, understand how setLength() and setWidth()
    // work for rectangles and squares.
    
    cout << "\\n777777777777777777777777777\\n";
    
    shapes\[1\] -> display();
    dynamic\_cast<Rectangle\*> (shapes\[1\]) -> setLength(8.2);
    cout << "\\nAfter setLength(8.2), the rectangle is: ";
    shapes\[1\] -> dis
    
    A _ V D 4 Replies Last reply
    0
    • K kumn1d

      This is the output I am supposed to get but I am getting errors please help me

      int main()
      {
      int size = 5;

      Shape\*\* shapes = new Shape\*\[size\];
      
      Point\* centre = new Point(5,5);
      Rectangle\* rectangle1 = new Rectangle(\*centre, 4, 3);
      shapes\[0\] = rectangle1;
      
      shapes\[1\] = new Rectangle (\*new Point(10, -10), 4, 4);
      
      Rectangle\* rectangle3 = new Square(\*new Point(-8.5,-10), 2.5);
      shapes\[2\] = rectangle3;
      
      Square\* square2 = new Square (\*new Point(-1,-1), 1.5);
      shapes\[3\] = square2;
      
      Circle\* circle = new Circle(\*new Point(100,100), 25.4);
      shapes\[4\] = circle;
      
      cout << "\\n11111111111111111111111111\\n";
      
      for (int i = 0; i < size; ++i)
      	shapes\[i\] -> display();
      
      cout << "\\n22222222222222222222222222\\n";
      
      cout << "\\nthe area of the first rectangle is: ";
      cout << rectangle1->area() << endl;
      
      cout << "It is a square, the area is: ";
      Square\* square = dynamic\_cast<Square\*> (rectangle3);
      cout << square->area() << endl;	
      
      cout << "the perimeter of the circle is: ";
      cout << circle->perimeter() << endl;	
      
      cout << "\\n33333333333333333333333333\\n";
      
      cout << "\\nThe four vertices of the first rectangle are: (clockwise from top-left)\\n";
      rectangle1->printFourVertices();
      
      cout << "\\nThe four vertices of the third rectangle are:\\n";
      rectangle3->printFourVertices();
      
      cout << "\\n44444444444444444444444444\\n";
      
      rectangle1->reflectX();
      
      shapes\[2\] -> translate(1.5, 3);
      
      shapes\[4\] -> translate(-100,-100);
      
      cout << "\\nAfter reflection and translation, here are the moved shapes:\\n" ;
      for (int i = 0; i < size; ++i)
      	shapes\[i\] -> display();
      
      cout << "\\n55555555555555555555555555\\n";
      
      cout << "\\nNow, the four vertices of the first rectangle are:\\n";
      rectangle1->printFourVertices();
      
      cout << "\\nNow, the four vertices of the third rectangle are:\\n";
      rectangle3->printFourVertices();
      
      cout << "\\n66666666666666666666666666\\n\\n";
      
      for (int i = 0; i < size; ++i)
      	cout << shapes\[i\] -> area() << endl;
      
      // From the following statements, understand how setLength() and setWidth()
      // work for rectangles and squares.
      
      cout << "\\n777777777777777777777777777\\n";
      
      shapes\[1\] -> display();
      dynamic\_cast<Rectangle\*> (shapes\[1\]) -> setLength(8.2);
      cout << "\\nAfter setLength(8.2), the rectangle is: ";
      shapes\[1\] -> dis
      
      A Offline
      A Offline
      Afzaal Ahmad Zeeshan
      wrote on last edited by
      #2

      Do not repost questions, you have already posted the same question here, [Class shape and related functions](https://www.codeproject.com/Questions/1197886/Class-shape-and-related-functions). If someone is active to answer your question, they will do it. If there is no one, reposting the question doesn't help at all.

      The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

      1 Reply Last reply
      0
      • K kumn1d

        This is the output I am supposed to get but I am getting errors please help me

        int main()
        {
        int size = 5;

        Shape\*\* shapes = new Shape\*\[size\];
        
        Point\* centre = new Point(5,5);
        Rectangle\* rectangle1 = new Rectangle(\*centre, 4, 3);
        shapes\[0\] = rectangle1;
        
        shapes\[1\] = new Rectangle (\*new Point(10, -10), 4, 4);
        
        Rectangle\* rectangle3 = new Square(\*new Point(-8.5,-10), 2.5);
        shapes\[2\] = rectangle3;
        
        Square\* square2 = new Square (\*new Point(-1,-1), 1.5);
        shapes\[3\] = square2;
        
        Circle\* circle = new Circle(\*new Point(100,100), 25.4);
        shapes\[4\] = circle;
        
        cout << "\\n11111111111111111111111111\\n";
        
        for (int i = 0; i < size; ++i)
        	shapes\[i\] -> display();
        
        cout << "\\n22222222222222222222222222\\n";
        
        cout << "\\nthe area of the first rectangle is: ";
        cout << rectangle1->area() << endl;
        
        cout << "It is a square, the area is: ";
        Square\* square = dynamic\_cast<Square\*> (rectangle3);
        cout << square->area() << endl;	
        
        cout << "the perimeter of the circle is: ";
        cout << circle->perimeter() << endl;	
        
        cout << "\\n33333333333333333333333333\\n";
        
        cout << "\\nThe four vertices of the first rectangle are: (clockwise from top-left)\\n";
        rectangle1->printFourVertices();
        
        cout << "\\nThe four vertices of the third rectangle are:\\n";
        rectangle3->printFourVertices();
        
        cout << "\\n44444444444444444444444444\\n";
        
        rectangle1->reflectX();
        
        shapes\[2\] -> translate(1.5, 3);
        
        shapes\[4\] -> translate(-100,-100);
        
        cout << "\\nAfter reflection and translation, here are the moved shapes:\\n" ;
        for (int i = 0; i < size; ++i)
        	shapes\[i\] -> display();
        
        cout << "\\n55555555555555555555555555\\n";
        
        cout << "\\nNow, the four vertices of the first rectangle are:\\n";
        rectangle1->printFourVertices();
        
        cout << "\\nNow, the four vertices of the third rectangle are:\\n";
        rectangle3->printFourVertices();
        
        cout << "\\n66666666666666666666666666\\n\\n";
        
        for (int i = 0; i < size; ++i)
        	cout << shapes\[i\] -> area() << endl;
        
        // From the following statements, understand how setLength() and setWidth()
        // work for rectangles and squares.
        
        cout << "\\n777777777777777777777777777\\n";
        
        shapes\[1\] -> display();
        dynamic\_cast<Rectangle\*> (shapes\[1\]) -> setLength(8.2);
        cout << "\\nAfter setLength(8.2), the rectangle is: ";
        shapes\[1\] -> dis
        
        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        What kind of errors do you get ?

        L 1 Reply Last reply
        0
        • _ _Flaviu

          What kind of errors do you get ?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          See Afzaal's reply above.

          1 Reply Last reply
          0
          • K kumn1d

            This is the output I am supposed to get but I am getting errors please help me

            int main()
            {
            int size = 5;

            Shape\*\* shapes = new Shape\*\[size\];
            
            Point\* centre = new Point(5,5);
            Rectangle\* rectangle1 = new Rectangle(\*centre, 4, 3);
            shapes\[0\] = rectangle1;
            
            shapes\[1\] = new Rectangle (\*new Point(10, -10), 4, 4);
            
            Rectangle\* rectangle3 = new Square(\*new Point(-8.5,-10), 2.5);
            shapes\[2\] = rectangle3;
            
            Square\* square2 = new Square (\*new Point(-1,-1), 1.5);
            shapes\[3\] = square2;
            
            Circle\* circle = new Circle(\*new Point(100,100), 25.4);
            shapes\[4\] = circle;
            
            cout << "\\n11111111111111111111111111\\n";
            
            for (int i = 0; i < size; ++i)
            	shapes\[i\] -> display();
            
            cout << "\\n22222222222222222222222222\\n";
            
            cout << "\\nthe area of the first rectangle is: ";
            cout << rectangle1->area() << endl;
            
            cout << "It is a square, the area is: ";
            Square\* square = dynamic\_cast<Square\*> (rectangle3);
            cout << square->area() << endl;	
            
            cout << "the perimeter of the circle is: ";
            cout << circle->perimeter() << endl;	
            
            cout << "\\n33333333333333333333333333\\n";
            
            cout << "\\nThe four vertices of the first rectangle are: (clockwise from top-left)\\n";
            rectangle1->printFourVertices();
            
            cout << "\\nThe four vertices of the third rectangle are:\\n";
            rectangle3->printFourVertices();
            
            cout << "\\n44444444444444444444444444\\n";
            
            rectangle1->reflectX();
            
            shapes\[2\] -> translate(1.5, 3);
            
            shapes\[4\] -> translate(-100,-100);
            
            cout << "\\nAfter reflection and translation, here are the moved shapes:\\n" ;
            for (int i = 0; i < size; ++i)
            	shapes\[i\] -> display();
            
            cout << "\\n55555555555555555555555555\\n";
            
            cout << "\\nNow, the four vertices of the first rectangle are:\\n";
            rectangle1->printFourVertices();
            
            cout << "\\nNow, the four vertices of the third rectangle are:\\n";
            rectangle3->printFourVertices();
            
            cout << "\\n66666666666666666666666666\\n\\n";
            
            for (int i = 0; i < size; ++i)
            	cout << shapes\[i\] -> area() << endl;
            
            // From the following statements, understand how setLength() and setWidth()
            // work for rectangles and squares.
            
            cout << "\\n777777777777777777777777777\\n";
            
            shapes\[1\] -> display();
            dynamic\_cast<Rectangle\*> (shapes\[1\]) -> setLength(8.2);
            cout << "\\nAfter setLength(8.2), the rectangle is: ";
            shapes\[1\] -> dis
            
            V Offline
            V Offline
            Victor Nijegorodov
            wrote on last edited by
            #5

            kumn1d wrote:

            This is the output I am supposed to get but I am getting errors please help me

            What error? The compiler ones? - Then show us the errors. Or you meant the incorrect output? - Then try to debug your code.

            K 1 Reply Last reply
            0
            • K kumn1d

              This is the output I am supposed to get but I am getting errors please help me

              int main()
              {
              int size = 5;

              Shape\*\* shapes = new Shape\*\[size\];
              
              Point\* centre = new Point(5,5);
              Rectangle\* rectangle1 = new Rectangle(\*centre, 4, 3);
              shapes\[0\] = rectangle1;
              
              shapes\[1\] = new Rectangle (\*new Point(10, -10), 4, 4);
              
              Rectangle\* rectangle3 = new Square(\*new Point(-8.5,-10), 2.5);
              shapes\[2\] = rectangle3;
              
              Square\* square2 = new Square (\*new Point(-1,-1), 1.5);
              shapes\[3\] = square2;
              
              Circle\* circle = new Circle(\*new Point(100,100), 25.4);
              shapes\[4\] = circle;
              
              cout << "\\n11111111111111111111111111\\n";
              
              for (int i = 0; i < size; ++i)
              	shapes\[i\] -> display();
              
              cout << "\\n22222222222222222222222222\\n";
              
              cout << "\\nthe area of the first rectangle is: ";
              cout << rectangle1->area() << endl;
              
              cout << "It is a square, the area is: ";
              Square\* square = dynamic\_cast<Square\*> (rectangle3);
              cout << square->area() << endl;	
              
              cout << "the perimeter of the circle is: ";
              cout << circle->perimeter() << endl;	
              
              cout << "\\n33333333333333333333333333\\n";
              
              cout << "\\nThe four vertices of the first rectangle are: (clockwise from top-left)\\n";
              rectangle1->printFourVertices();
              
              cout << "\\nThe four vertices of the third rectangle are:\\n";
              rectangle3->printFourVertices();
              
              cout << "\\n44444444444444444444444444\\n";
              
              rectangle1->reflectX();
              
              shapes\[2\] -> translate(1.5, 3);
              
              shapes\[4\] -> translate(-100,-100);
              
              cout << "\\nAfter reflection and translation, here are the moved shapes:\\n" ;
              for (int i = 0; i < size; ++i)
              	shapes\[i\] -> display();
              
              cout << "\\n55555555555555555555555555\\n";
              
              cout << "\\nNow, the four vertices of the first rectangle are:\\n";
              rectangle1->printFourVertices();
              
              cout << "\\nNow, the four vertices of the third rectangle are:\\n";
              rectangle3->printFourVertices();
              
              cout << "\\n66666666666666666666666666\\n\\n";
              
              for (int i = 0; i < size; ++i)
              	cout << shapes\[i\] -> area() << endl;
              
              // From the following statements, understand how setLength() and setWidth()
              // work for rectangles and squares.
              
              cout << "\\n777777777777777777777777777\\n";
              
              shapes\[1\] -> display();
              dynamic\_cast<Rectangle\*> (shapes\[1\]) -> setLength(8.2);
              cout << "\\nAfter setLength(8.2), the rectangle is: ";
              shapes\[1\] -> dis
              
              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              There does not seem to be a Rectangle::printFourVertices() method. There is a redundant assignment operator in the Point::setX() method. Short of that, what's the issue? "I am getting errors" is meaningless.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              K 1 Reply Last reply
              0
              • D David Crow

                There does not seem to be a Rectangle::printFourVertices() method. There is a redundant assignment operator in the Point::setX() method. Short of that, what's the issue? "I am getting errors" is meaningless.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                K Offline
                K Offline
                kumn1d
                wrote on last edited by
                #7

                I corrected the entire code , but the only thing now I dont know is how to implement this Print four Vertices function . I want to know how to implement anf declare this function . Beside that , I corrected the rest of code

                D 1 Reply Last reply
                0
                • V Victor Nijegorodov

                  kumn1d wrote:

                  This is the output I am supposed to get but I am getting errors please help me

                  What error? The compiler ones? - Then show us the errors. Or you meant the incorrect output? - Then try to debug your code.

                  K Offline
                  K Offline
                  kumn1d
                  wrote on last edited by
                  #8

                  I corrected the entire code , but the only thing now I dont know is how to implement this Print four Vertices function .
                  I want to know how to implement anf declare this function . Beside that , I corrected the rest of code

                  1 Reply Last reply
                  0
                  • K kumn1d

                    I corrected the entire code , but the only thing now I dont know is how to implement this Print four Vertices function . I want to know how to implement anf declare this function . Beside that , I corrected the rest of code

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    How would you do it using pencil and paper? If you coded up everything that calculates said vertices, printing them should be a non-issue, yes?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups