The code defines a struct Rectangle with width and height as its member variables. It also defines a constructor that takes two parameters w and h and initializes the width and height variables of the struct with those values.
It also defines a function areaOfRectangle() that calculates and prints the area of the rectangle. In themain() function, an object of the Rectangle struct is created with width 4 and height 6. Then, the areaOfRectangle() function is called on that object to print the area of the rectangle, which is 24.
#include<iostream> using namespace std; struct Rectangle { int width,height; Rectangle(int w,int h) { width=w; height=h; } void areaOfRectangle() { cout<<"Area of Rectangle is: "<<(width*height); } }; int main(void) { struct Rectangle rec=Rectangle(4,6); rec.areaOfRectangle(); return 0; }To download raw file Click Here
Area of Rectangle is: 24
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions