How To Create A Multifunctional Calculator Using C++

[716 views]


In this tutorial we will learn how can we create a calculator using C++. This calculator is able to calculate Plus, Minus, Subtraction and Division. This is really useful to practice C++ program.

How To Create A Multi functional Calculator Using C++

The best part of this program is you will learn about Object Oriented Programming Concept in C++ and the use of switch statement in C++. In this program we use constructor, class and switch statement to make the program able to calculate user defined operator.

C++ Program To Create A Multifunctional Calculator

#include<iostream> class calc { public: calc() { char o; int a,b; cout<<"Enter first number"<<endl; cin>>a; cout<<"Enter Operator"<<endl; cin>>o; cout<<"Enter second number"<<endl; cin>>b; switch(o) { case '+': cout<<a<<"+"<<b<<"="<<a+b; break; case '-': cout<<a<<"-"<<b<<"="<<a-b; break; case '*': cout<<a<<"*"<<b<<"="<<a*b; break; case '/': cout<<a<<"/"<<b<<"="<<a/b; break; default: cout<<"Enter right operator"; break; } } }; int main() { calc obj; return 0; }

For Turbo C++

#include<iostream.h> #include<conio.h> class calc { public: calc() { char o; int a,b; cout<<"Enter first number"<<endl; cin>>a; cout<<"Enter Operator"<<endl; cin>>o; cout<<"Enter second number"<<endl; cin>>b; switch(o) { case '+': cout<<a<<"+"<<b<<"="<<a+b; break; case '-': cout<<a<<"-"<<b<<"="<<a-b; break; case '*': cout<<a<<"*"<<b<<"="<<a*b; break; case '/': cout<<a<<"/"<<b<<"="<<a/b; break; default: cout<<"Enter right operator"; break; } } }; int main() { clrscr(); calc obj; getch(); return 0; }

Output

Enter First Number 10 Enter Operator + Enter Second Number 20 10 + 20 = 30
        

Algorithm Logic Test

Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once. 



Need any help in Programming? Chat with Us

Comments



Online Compiler
Search
Algorithm Quiz

Only 5% Users were able to score above 75% in this Quiz. Can You Crack this?

Deals Ends in





Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    Simple Calculator using C++

    C++ code for Calculator

    calculator program in cpp