write a calculator program in c++. The calculator will allow the user to perform
ID: 3855087 • Letter: W
Question
write a calculator program in c++. The calculator will allow the user to perform the following operations(please follow instruction below)
writ a program to Get the area of a square
writ a program to Get the exponent of 2 integers
writ a program to Get the quotient of 2 integers
Get the real division of 2 integers
Get the remainder of 2 integers
Multiplication
Subtraction
Additiorn
Convert from decimal to bases 2-16
Get Factorial
Find out if an integer is even or odd
Get the area of a circle
Get the area of a right lisosceles triangle
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 n must determine if the user has made a legal option (i.e. one on the menu). If they entered an illegal option, you must n ntered an illegal option, you must notify the user that it is an illegal choice, redisplay the menu, and get the user r's new choice. The user cannot leave the menu function until they enter a legal option (The user's choice to quit is a legal option). When a legal choice is entere choice must be returned to the main function When the user's choice is returned to the main function the first thing you must determine is whether the user wants to quit, if so, quit (the main funct tion should return a value, so you can return that value). Otherwise, you must determine how many parameters must be passed to the required function. Some require only 1 integer (conversions, factorial , and the area of a circle or square) the others require 2 (all of the user's choices must be integers) t use any global variables (except for the assignment of the output file name). About half the external You may not use any global variables (except for the assignment of the o functions must return the result of the operations the function). Your program must print out the result presented as a loop. until the user decides to quit. the remaining operations can be printed in s to the console and to an external file. Your main function must be Once it completes the operation, it must again present the menu and perform all of the operations,
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class Calculator
{
public:
int a,b,ch;
int exponent;
float base, result = 1;
int dividend, divisor, quotient, remainder;
int first, second;
unsigned long long factorial = 1;
float area;
void Calculate()
{
do
{
cout<<" 1.Get the area of a square 2.Get the exponent of 2 integers 3.Get the quotient of 2 integers 4.division of 2 integers 5.remainder of 2 integers 6.Multiplication 7.Subtraction 8.Addition 9.decimal to bases 2-16 10.Factorial 11.even or odd 12.area of a circle 13.area of a right lisosceles triangle 14.Quit";
cout<<" Enter your choice ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter length of a side of square :";
cin>>a;
cout<<"Area = "<<a*a;
break;
case 2:
cout << "Enter base and exponent respectively: ";
cin >> base >> exponent;
cout << base << "^" << exponent << " = ";
while (exponent != 0) {
result *= base;
--exponent;
}
cout << result;
break;
case 3:
cout<<"Enter dividend: ";
cin>>dividend;
cout<<"Enter divisor: ";
cin>>divisor;
// Computes quotient
quotient = dividend / divisor;
cout<<"Quitionent is "<<quotient;
break;
case 4:
cout<<"Enter dividend: ";
cin>>dividend;
cout<<"Enter divisor: ";
cin>>divisor;
cout<<"Result is "<<dividend / divisor;;
break;
case 5:
cout<<"Enter dividend: ";
cin>>dividend;
cout<<"Enter divisor: ";
cin>>divisor;
cout<<"Result is "<<dividend % divisor;;
break;
case 6:
cout<<"Enter First value: ";
cin>>first;
cout<<"Enter Second value: ";
cin>>second;
cout<<"Result is "<<first * second;;
break;
case 7:
cout<<"Enter First value: ";
cin>>first;
cout<<"Enter Second value: ";
cin>>second;
cout<<"Result is "<<first - second;;
break;
case 8:
cout<<"Enter First value: ";
cin>>first;
cout<<"Enter Second value: ";
cin>>second;
cout<<"Result is "<<first + second;;
break;
case 9:
break;
case 10:
cout << "Enter a positive integer: ";
cin >> a;
for(int i = 1; i <=a; ++i)
{
factorial *= i;
}
cout << "Factorial of " << a << " = " << factorial;
break;
case 11:
cout << "Enter an integer: ";
cin >> a;
if ( a % 2 == 0)
cout << a << " is even.";
else
cout << a << " is odd.";
break;
case 12:
cout<< " Enter radius of circle : ";
cin>>a;
area = 3.14*a*a;
cout<<"Area of circle : "<<area;
break;
case 13:
cout<< " Enter the base of Right Angle Triangle : ";
cin>>a;
cout<< " Enter the height of Right Angle Triangle : ";
cin>>b;
area = 0.5 * a * b;
printf(" Area of Right Angle Triangle : %f", area);
}
}while(ch!=14);
}
};
int main()
{
Calculator obj;
obj.Calculate();
}
Output:
1.Get the area of a square
2.Get the exponent of 2 integers
3.Get the quotient of 2 integers
4.division of 2 integers
5.remainder of 2 integers
6.Multiplication
7.Subtraction
8.Addition
9.decimal to bases 2-16
10.Factorial
11.even or odd
12.area of a circle
13.area of a right lisosceles triangle
14.Quit
Enter your choice 1
Enter length of a side of square :4
Area = 16
1.Get the area of a square
2.Get the exponent of 2 integers
3.Get the quotient of 2 integers
4.division of 2 integers
5.remainder of 2 integers
6.Multiplication
7.Subtraction
8.Addition
9.decimal to bases 2-16
10.Factorial
11.even or odd
12.area of a circle
13.area of a right lisosceles triangle
14.Quit
Enter your choice
2.Get the exponent of 2 integers 3.Get the quotient of 2 integers 4.division of 2 integers 5.remainder of 2 integers 6.Multiplication 7.Subtraction 8.Addition 9.decimal to bases 2-16 10.Factorial 11.even or odd 12.area of a circle 13.area of a right lisosceles triangle 14.Quit Enter your choice 1 Enter length of a side of square :4 Area = 16 1.Get the area of a square 2.Get the exponent of 2 integers 3.Get the quotient of 2 integers 4.division of 2 integers 5.remainder of 2 integers 6.Multiplication 7.Subtraction 8.Addition 9.decimal to bases 2-16 10.Factorial 11.even or odd 12.area of a circle 13.area of a right lisosceles triangle 14.Quit Enter your choice
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.