Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program that calculates areas of rectangle, triangle and square with the following conditions.

0 votes
asked Jul 7, 2019 by anonymous
Write a program that calculates areas of rectangle, triangle and square with the following conditions. For each of these shapes you need to create classes, i.e. you should have three classes rectangle, triangle and square. Objects of these classes should be possible to initialize using constructor. If one is not passing arguments to the constructor during the object initialization, default values of the object sides (height, width, side) should be 0. Friend function should be able to calculate and print area of the shapes, if no shape is initialized using the non-zero values, it should not print anything for that particular shape.

2 Answers

0 votes
answered Aug 20, 2019 by SWEngineer (300 points)
Maybe you share what you already programmed, before expecting other people to do your homework ?
0 votes
answered Aug 24, 2019 by Biswadeep Datta (220 points)
b=int(input("Enter the base of triangle"))

h=int(input("Enter the height of triangle"))

s=int(input("Enter the sides of square"))

b1=int(input("Enter the breadth of rectangle"))

h1=int(input("Enter the height of rectangle"))

arear=b1*h1

areas=s*s

areat= 1/2*b*h

print("The area of rectangle is")

print(arear)

print("The area of square is")

print(areas)

print("The area of triangle is")

print(areat)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...