Addition program using class and object in C++

PROGRAM : 
#include <iostream>
#include <string.h>
using namespace std;
 
class addition
{
    private:
        int var1, var2, result;
    public:
        void getValue();
        int addOperation();
};
 
void addition :: getValue()
{
        cout << "Enter the first value : " << "\n";
        cin >> var1;
        cout << "Enter the second value : " << "\n";
        cin >> var2;
}
 
int addition :: addOperation()
{
        result = var1 + var2;
        return result;
}
 
int main(int argc, char *argv[])
{
        addition obj1;
        int output = 0;
        obj1.getValue();
        output = obj1.addOperation();
        cout << "Result : " << output << endl;
        return 0;
}
OUTPUT : 
Enter the first value : 
25
Enter the second value : 
30

Result : 55

No comments:

Post a Comment