1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <iostream>
using namespace std;
void add(int a, int b)
{
int res1;
res1=a+b;
cout<<"The answer is: "<<res1;
}
void sub(int a, int b)
{
int res2;
res2=a-b;
cout<<"The answer is: "<<res2;
}
void mult(int a, int b)
{
int res3;
res3=a*b;
cout<<"The answer is: "<<res3;
}
void div(int a, int b)
{
int res4;
res4=a/b;
cout<<"The answer is: "<<res4;
}
void squ(int a, int b)
{
int res5;
int res6;
res5=a*a;
cout<<"The square of the first number is: "<<res5;
res6=b*b;
cout<<"The square of the second number is: "<<res6;
}
void cub(int a, int b)
{
int res7;
int res8;
res7=a*a*a;
cout<<"The cube of the first number is: "<<res7;
res8=b*b*b;
cout<<"The cube of the second number is: "<<res8;
}
int main(int argc, char** argv) {
int a;
int b;
char op;
cout<<"Enter the first number: ";
cin>>a;
cout<<"Enter the operator (+,-,*,/,^(square) and #(cube): ";
cin>>op;
cout<<"Enter the second number: ";
cin>>b;
switch (op)
{
case '+':
add(a,b);
break;
case 'x':
case '*':
mult (a,b);
break;
case '-':
sub(a,b);
break;
case '/':
div(a,b);
break;
case '^':
squ(a,b);
break;
case '#':
cub(a,b);
break;
default:"Invalid input";
}
return 0;
}
|