Showing posts with label rectangle area solver. Show all posts
Showing posts with label rectangle area solver. Show all posts

Monday, August 31, 2015

Rectangle Area Solver Using Classes in C++

In this article I would like to share with you a sample program that will compute the area and base of the rectangle using Classes in C++. The code will give you a first hand experience how to create an object, methods and attributes in object oriented programming in C++.

If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at  my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

#include <iostream>

 using namespace std;

 class rectangle {
   private:
   float base,height;

   public:

   float area(float b,float h)
    {
       return(b*h);
    }

    float process_data();
    float display_data();
 };

 float rectangle :: process_data()
   {
    cout << "\n";
    cout<<"\t\t AREA OF A RECTANGLE\n";
    cout << "\n";
    cout<<"\nEnter Base   : ";
    cin>>base;

    cout<<"\nEnter Height : ";
    cin>>height;

    cout << "\n\n";
    cout<<"\nArea = "
        <<area(base,height)
        <<" Square Units\n";
    cout << "\n\n";
    system("pause");
   }

   float rectangle :: display_data()
   {
       float math;

       math = process_data();
   }

main() {
    rectangle number;
    number.display_data();
}