- 1

C++ program that computes the area and perimeter of a rectangle using OOP.Your program should have a class Rectangle

please help

28th Jan 2018, 4:37 AM
Brian Simiyu
Brian Simiyu - avatar
2 Answers
0
#include<iostream.h> using namespacestd; class rectangle { int l,b; }d; int main() { float p,a; cout<<"enter the length and bredth of rectangle"; cin>>d.l>>d.b; p=2*(d.l+d.b); a=d.l*d.b; cout<<"perimeter="; cout<<p; cout<<"area="; cout<<a; return(0); }
28th Jan 2018, 7:23 AM
Ashmita Shrivastava
Ashmita Shrivastava - avatar
0
#include <iostream> using namespace std; struct Rectangle { float x, y; float area() const { return x*y; } float perimeter() const { return 2*(x+y); } }; int main() { float x, y; cout << "Enter the rectangle broadth and width: "; cin >> x >> y; Rectangle r{x, y}; cout << "Area: " << r.area() << endl; cout << "Perimeter: " << r.perimeter(); }
28th Jan 2018, 9:23 AM
Timon Paßlick