Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with this task. We are using Visual Studio You are to write a ‘calcu

ID: 3920313 • Letter: P

Question

Please help with this task. We are using Visual Studio

You are to write a ‘calculator’ program. The calculator will allow the user to perform the following operations:

*Addition *Get the exponent of 2 integers

*Subtraction *Factorial (integer)

*Multiplication (integer) *Get the area of a circle

*Multiplication (real)) *Get the area of a right triangle

*Division (integer) *Get the area of a square

*Division (real) *Get the area of an isosceles triangle

*Modulus Arithmetic (integer) *Find out how many characters are in a string

*Find out if an integer is even or odd *Compare two strings to find out of they the same

*Convert From decimal to any base between binary to hexadecimal * Concatenate two string

ALL of these operations MUST be done in separate functions (i.e. NOT in the main function).

You must present the options to the user (also in a separate function). One of the options in the menu must be the option to quit. If that is the option, the program must end as soon as it returns to the main function. If that is not the option, you must determine if the user has made a legal option (i.e. one on the menu). If they entered an illegal option, you must notify the user that it is an illegal choice, redisplay the menu, and get the user’s new choice.

Explanation / Answer

code for calculator:

Comments in the program specify the function

code here:

#include <iostream>
using namespace std;
int main()
{

char oper = 0;

cout << "--------------CALCULATOR------------"; << endl;

cout<< "------Menu-----"<< endl;
cout <<" 1.Addition" << endl;
cout <<" 2.Substraction" << endl;
cout <<" 3.Multiplication(integer)" << endl;
cout <<" 4.Multiplication (real))" << endl;
cout <<" 5.Division (integer)" << endl;
cout <<" 6.Division (real) " << endl;
cout <<" 7.Modulus Arithmatic" << endl;
cout <<" 8.Find out if an integer is even or odd" << endl;
cout <<" 9.Get the exponent of 2 integers" << endl;
cout <<" 10.Factorial (integer)" << endl;
cout <<" 11.Get the area of a circle" << endl;
cout <<" 12.Get the area of a right triangle" << endl;
cout <<" 13.Get the area of a square" << endl;
cout <<" 14.Get the area of an isosceles triangle" << endl;
cout <<" 15.Find out how many characters are in a string" << endl;
cout <<" 16.Compare two strings to find out of they the same" << endl;
cout <<" 17.Concatenate two string" << endl;
cout <<" 18.Convert From decimal to any base between binary to hexadecimal" << endl;
cout <<" 19. Quit";
cout << endl << "Enter the operation to perform, choose one from this list: +,-,/,* ";
cout << "Enter your operation:";
cin >> oper;
cin.ignore();

switch(oper)
{
    case 1:
       add();
       braek;

   case 2:
      sub();
      break;

   case 3:
       multi();
       braek;

   case 4:
      multr();
      break;

   case 5:
       divi();
       braek;

   case 6:
      divr();
      break;

   case 7:
       modu();
       braek;

   case 8:
      evenodd();
      break;

case 9:
      expo();
      break;

case 10:
      fact();
      break;

case 11:
      areac();
      break;

case 12:
      areat();
      break;

case 13:
      areas();
      break;

case 14:
      areai();
      break;

case 15:
      charcount();
      break;

case 16:
      comp();
      break;
case 17:
      con();
      break;


   case 18:
       fDeci();
       braek;

   case 19:
      exit(0);
      break;

///Output starts here
cout << endl << "Your answer is: " << solution << endl << "Press Enter to exit." << endl;
return 0;
}//end main

void expo()
{

    int exp;
    float base, res= 1;

    cout << "Enter base and exponent here: ";
    cin >> base >> exp;

    cout << base << "^" << exponent << " = ";

    while (exp != 0) {
        res *= base;
        --exp;
    }

    cout << res;

}

//User need to enter positive numbers only

void fact()
{
    unsigned int a;             
    unsigned long long fact = 1;

    cout << "Enter a positive integer: ";
    cin >> n;

    for(int i = 1; i <=a; ++i)
    {
        fact *= i;
    }

    cout << "Factorial of " << n << " = " << fact;


}


area circle
void areac()
{
float rad,area;
cout<< " Enter radius of circle : ";
cin>>rad;
area = 3.14*rad*rad;
cout<<"Area of circle : "<<area;
  

}
//area triangle
void areat()
{
   double a,b, ar;
   cout<<"Enter two sides of right anglr triangle:";
   cin>>a>>b;
   ar=0.5*a*b;
   cout<<"Area of right angle triangle:"<< ar <<endl;

}
//area square
void areas()
{
int s;
cout << "Input length of side of square: " << endl;
cin >> s;

int area = s * s;

cout << "area of square is: " << area << endl;


}

//area isoscalus
void areai()
{
int x, y, z;
float area, s;
printf("Enter the sides of a triangle: ");

scanf("%d%d%d", &a, &b, &c);
if ((x + y > z && x + z > y && y + z > x) && (x > 0 && y > 0 && z > 0)) {
if (x == y || y == z || x == z) {
   s = (x + y + z) / 2.0;
   area = sqrt((s * (s - x) * (s - y) * (s - z)));
   printf(" Area of an isosceles triangle is: %2f ", area);
} else {
   printf(" Triangle is not an isosceles ");
}
} else {
printf(" Triangle formation not possible ");
}

}

// modulus arithmatic
void modu()
{
int a,b,c;
cout << "Enter two no. to find modular arithmatic like a mod b:" << endl;
cin >> a>> b;
c=a%b;
cout << "Answer: << c;
}
//charactor count from string
void charcount()
{
char s1[50];
int i;
int l = 0; // letters
int n = 0; // numerical characters
int o1 = 0; // other characters
int total; // total of all characters

cout << "Enter your string:";
cin >> s;
cout << endl;

i = 0;
while (s1[i] !=0)

if (( s[i] >= 'a' && s1[i] <= 'z') || (s[i] <= 'A' && s1[i] >= 'Z'))
{
l++;
i++;
}

else
if (( s1[i] >= '!' && s1[i] <= ')'))
{
o1++;
}

else
if (( s1[i] >= '0' && s1[i] <= '9'))
{
n++;
}

total = l + n + o1;

cout << "Your string has " << total << " total characters" << endl;
cout << l << " letters " << endl;
cout << n << " numerical characters " << endl;
cout << o1 << " other characters " << endl;

}
//no. odd or even
void evenodd()
{
int k;

    cout << "Enter an integer: ";
    cin >> k;

    if ( k % 2 == 0)
        cout << k << " is even.";
    else
        cout << k << " is odd.";


}

void deci()
{
    int Num = 282, b = 16;
    char res[100];
    cout << "Equivalent of << Num<<" in base << b<< is:<< fDeci(res, b, Num);
}

char Val(int n)
{
    if (n >= 0 && n <= 9)
        return (char)(n + '0');
    else
        return (char)(n - 10 + 'A');
}

void rev(char *str)
{
    int l = strlen(str);
    int i;
    for (i = 0; i < l/2; i++)
    {
        char t = str[i];
        str[i] = str[l-i-1];
        str[l-i-1] = t;
    }
}

//actual conversion funtion decimal to any base
char* fDeci(char res[], int b, int Num)
{
    int i = 0;

    while (Num > 0)
    {
        res[i++] = Val(Num % base);
        Num /= b;
    }
    res[i] = '';

    // Reverse the result
    rev(res);

    return res;
}
//concatination of string
void con()
{
     string str1, str2, r;

    cout << "Enter string s1: ";
    getline (cin, str1);

    cout << "Enter string s2: ";
    getline (cin, str2);

    r = str1 + str2;

    cout << "concatinated String = "<< r;
}
//addition
void add()
{
   int a,b,c;
   cout << "Enter two integer for addition:" << endl;
   cin<< a<<b;
   c=a+b;

   cout<< "Addition of two no. is:"<<c;
}

//substraction
void sub()
{

int a,b,c;
   cout << "Enter two integer for substraction:" << endl;
   cin<< a<<b;
   c=a-b;

   cout<< "substraction of two no. is:"<<c;

}

//multiplication interger
void multi()
{

int a,b,c;
   cout << "Enter two integer for Multiplication:" << endl;
   cin<< a<<b;
   c=a*b;

   cout<< "Multiplication of two no. is:"<<c;
}

//Multipication real no.
void multr()
{

double a,b,c;
   cout << "Enter two real no. for Multiplication:" << endl;
   cin<< a<<b;
   c=a*b;

   cout<< "Multiplication of two no. is:"<<c;

}

//Division integer
void divi()
{

int a,b,c;
   cout << "Enter two integer for division:" << endl;
   cin<< a<<b;
   c=a/b;

   cout<< "division of two no. is:"<<c;

}

// Division real no.
void divr()
{
double a,b,c;
   cout << "Enter two real no. for division:" << endl;
   cin<< a<<b;
   c=a/b;

   cout<< "division of two no. is:"<<c;

}

//Compare two strings to find out of they the same
void Comp()
{

        char s1[90], s2[90];
   cout<<"Enter first string : ";
   gets(s1);
   cout<<"Enter second string : ";
   gets(s2);
   if(strcmp(s1, s2)==0)
   {
       cout<<"Both the strings are equal";
   }
   else
   {
       cout<<"Both the strings are not equal";
   }
}