Answer to Question #172402 in C++ for Panjumin

Question #172402

Define a Class to get length and breadth of a rectangle. Get length and breadth from the user, calculate and display its area.


1
Expert's answer
2021-03-17T20:18:43-0400
#include <iostream>

class Rectangle{
private:
    float length, breadth;
    
public:
    void GetDimensions(){
        std::cout << "Input length:";
        std::cin >> length;
        
        std::cout << "Input breadth:";
        std::cin >> breadth;
    }
    
    void DisplayArea(){
        float area = length * breadth;
        
        std::cout << "Area:" << area << "\n";
    }
};

int main(){
    Rectangle rectangle;
    
    rectangle.GetDimensions();
    rectangle.DisplayArea();
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS