4/01/2009

C++ Program To Perform Arithmetic Operation Using Class And Object


/* C++ Program To Perform Arithmetic Operation Using Class And Object */

#include <iostream>

using namespace std;

class arithmetic
{
    float a,b,sum,div,mul,diff;
public:
    void getdata();
    void putdata();
};
void arithmetic::getdata()
{
    cout<<"Enter The Value For Two Numbers:"<<endl;
    cin>>a>>b;
}
void arithmetic::putdata()
{
    sum=a+b;
    cout<<"Sum Of Two Numbers:"<<sum<<endl;
    diff=a-b;
    cout<<"Difference Of Two Numbers:"<<diff<<endl;
    mul=a*b;
    cout<<"Product Of Two Numbers:"<<mul<<endl;
    div=a/b;
    cout<<"Division Result:"<<div<<endl;

}

int main()
{
    arithmetic a;
    a.getdata();
    a.putdata();

    return 0;
 }
Out Put:
Enter The Value For Two Numbers:
21
7
Sum Of Two Numbers:28
Difference Of Two Numbers:14
Product Of Two Numbers:147
Division Result:3

No comments:

Post a Comment