Monday, August 31, 2015

Basic Math Operations Using Classes in C++

In this article I would like to share with you a basic math operations using classes in C++. In basic mathematics there are four operations addition, subtraction, multiplication and division. In our example I am using classes, attributes and method to solve the problem. The code is very easy to understand and use a good way to learn object oriented programming using 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 math {

     private:
       int x,y;
       int sum,divide;

     public:
       int process_data();
       int display();
 };


 int math :: process_data()
 {
    cout << "\n \t Basic Math Operations";
    cout << "\n\n";
    cout<<"Enter x value: ";
cin>>x;
cout<<"Enter y value: ";
cin>>y;

    sum    = x + y;
    divide = x - y;

    cout<<"\n sum        = "<<sum
        <<"\n difference = "<<divide
   <<"\n quotient   = "<<x/y
   <<"\n product    = "<<x*y
   <<"\n remainder  = "<<x%y
        <<"\n";
    cout << "\n\n";
    system("pause");
 }

 int math :: display()
  {
      int basic;
      basic = process_data();
  }

  main() {
      math value;
      value.display();
  }



No comments:

Post a Comment