Created a calculator in c++ using class concepts....

 Bibek Kumar Agrawal · November 24, 2015 hello friends i have created a calculator in c++ using the class concepts having 4 basic operation : 1.  Addition upto n terms 2. Subtraction upto n terms3. multiplication upto n terms.4.divisionplease give suggestion to improve the code....here's the code:  calculator.h#ifndef CALCULATOR_H#define CALCULATOR_Hclass calculator{    public:        int calc();        void switchcase(int);        void addition();        void subtraction();        void multiplication();        void division();    private:        int a,choice,n,b;        float res=0;        char ch;};#endif // CALCULATOR_Hcalculator.cpp#include #include #include "calculator.h"using namespace std;void calculator::addition(){    cout << "\n\tEnter The numbers you want to add : ";    cin >> n;    res=0;    for(int i=0; i> a;        res=res+a;    }    cout << "\nThe result is : " << res;}void calculator::subtraction(){    cout << "\n\tEnter the numbers you want to subtract : ";    cin >> n;    res=0;    for(int i=0; i> a;        if(i==0)        {            res=a;        }        else        {            res=res-a;        }    }    cout << "\nThe result is : " << res;}void calculator::multiplication(){    cout << "\n\tEnter the numbers you want to multiply : ";    cin >> n;    res=1;    for(int i=0; i> a;        res=res*a;    }    cout << "\nThe result is : " << res;}void calculator::division(){    cout << "\nEnter the first number : ";    cin >> a;    cout << "Enter the second number : ";    cin >> b;    res=a/b;    cout << "\nThe result is : " << a <<"/"<< b <<" = " <> choice;    switchcase(choice);    cout << "\n\n\tDo you want to continue? (Y/n) : ";    cin >> ch;    system("clear");  }while(ch=='y' || ch=='Y');}Main.cpp#include #include "calculator.h"using namespace std;int main(){    calculator obj;    obj.calc();    return 0;}

Replies

Nothing to see here.

C++

120,641 followers