Monday, August 31, 2015

Area of the Triangle Using Classes in C++

In this article I would like to share with you again a program that I wrote that will solve the are of the triangle using classes in C++. The code is very easy to understand that teaches the fundamentals of object oriented programming in C++ programming language.

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 triangle {

      public:
            double b,h;
  };

 main()
{
    triangle values;

    cout<<"\n [ Area of a triangle ]"<<endl;
    cout << "\n\n";
    cout<<"Enter Base    : ";
    cin>>values.b;
    cout<<"Enter Height  : ";
    cin>>values.h;
    cout << "\n\n";
    cout<<"Area = "
        <<(values.b*values.h)/2
        <<" square units ";
    cout << "\n\n";
    system("pause");
}

No comments:

Post a Comment