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++

Recommended Answers

All 4 Replies

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.

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

Post some work/idea of yours.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.