Create a class named Rectangle Solution

profileTopsolutions
 (Not rated)
 (Not rated)
Chat

Pseudo code

·        Create class Rectangle

o   Declare height as double

o   Declare width as double

o   Declare surfacearea as double

o   Rectangle()

§  Set height = 0

§  Set width = 0

§  Set computeSurfaceArea()

o   End

o   Rectangle(double p_height, double p_width)

§  Set height = p_height

§  Set width = p_width

§  Set computeSurfaceArea()

o   End

o   computeSurfaceArea()

§  Set surfaceArea = height * width

o   End

o   getHeight()

§  return height

o   End

o   getWidth()

§  return width

o   End

o   getSurfaceArea()

§  return surfaceArea

o   End

·        End class Rectanle

 

·        Create class Box

o   Declare depth as double

o   Box()

§  Set depth = 0

o   End

o   Box(double p_height, double p_width, double p_depth): Rectangle(p_height, p_width)

§  Set depth = p_depth

o   End

o   computeSurfaceArea()

§  return 2 * Rectangle::getSurfaceArea() + 2 * getWidth()* depth + 2 *getHeight()*depth

o   end

o   Getdepth()

§  return depth

o   End

o   Setdepth(double val)

§  depth = val

o   End

·        end class Box

 

 

 

Main method

1.      Create rectangle(10, 20) as Rectangle

2.      DISPLAY "Surface area of rectangle: " + rectangle.getSurfaceArea()

3.      Create box (10, 20, 5) as Box

4.      DISPLAY "Surface area of box: " + box.computeSurfaceArea()

End

 

 

Class Diagram

 

Rectangle

-height : double

-width : double

-surfaceArea:double

+Rectangle()

+Rectangle(double, double)

+computeSurfaceArea() : void

+ getHeight() : double

+ getWidth(): double

+ getSurfaceArea(): double

 

 

 

 

Box

-depth: double

+Box()

+ Box (double, double, double)

+computeSurfaceArea() : void

+Getdepth() : double

+Setdepth(double) : void

 

 

    • 11 years ago
    Complete A++ Solution
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      rectangleboxcomplete.zip
    • attachment
      rectanglebox.zip