We can easily use structures to **create a fractional calculator** than can **solve fractional numbers in C++**. It is just an easy approach through structures, we can easily create a simple calculator in C++, but for a **fractional calculator** it is a little bit different approach. The code of our **fractional calculator** is given below:

- // Fractional Calculator in C++
- #include<iostream>
- using namespace std;
- struct fraction
- {
- int n,d;
- int n1,d1;
- };
- int main()
- {
- char p;
- fraction opr;
- cout<<“enter nomerator of first fraction : “; cin>>opr.n;
- cout<<endl;
- cout<<“enter demonerator of first fraction”; cin>>opr.d;
- cout<<endl;
- cout<<“enter operation : “; cin>>p;
- cout<<endl;
- cout<<“enter nomerator of second fraction : “; cin>>opr.n1;
- cout<<endl;
- cout<<“enter denomerator of second fraction : “; cin>>opr.d1;
- cout<<endl;
- if(p==‘+’)
- {
- int z = (opr.n * opr.d1 + opr.d * opr.n1 );
- int y = (opr.d * opr.d1);
- cout<<z<<“/”<<y<<endl;
- }
- if(p==‘-‘)
- {
- int a = (opr.n * opr.d1 – opr.d * opr.n1 );
- int b = (opr.d * opr.d1);
- cout<<a<<“/”<<b<<endl;
- }
- return 0;
- }

Now lets explain the above **code of Fractional Calculator**. First of all We defined a structure named as “fraction” which contains the variables for numerators and denominators in it, then we used it in the main() function by defining a variable of type “ fraction ”. Then we asked the user to enter the numbers and an operator to be performed by the program, we simply used “ if “ statements for performing the arithmetic operations, and hence it is our **fractional calculator**. So i think creating a calculator in C++ in not a big deal, we just have to use simplest conditional operators.