-2

create a rectangle and find its area=w*h.create another rectangle with width and height as twice as the first rectangle and find its area using friend function in c++

5
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Lucaci Andrew
0

I'm quite sure that the people who help others here do not complete another persons homework for them.

I suggest you post what you have tried, with a little explanation of it.

0

I'd break this up into manageable pieces:

  • Define a function that will calculate (and return) an area given a width and height
  • Layout the main function to have the original width and height variables
  • call the area function with the original values
  • output the result
  • create new variables (height * 2, width * 2)
  • call the area function with the new variables
  • output the result
0

Here's the pseudocode.

class Rectangle
    int height, width
public
    Rectangle(initial_height, initial_width)
        height=initial_height
        width=initial_width
    end_Rectangle

    getArea()
        getArea=height*width
    end_getArea

end_class

main
    height=input height
    width=input width
    Rectangle rt(height, width)
    print Area=rt.getArea
end_main
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.