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

CIS3301 You are to write a calculator program in c++. The calculator will allow

ID: 3854684 • Letter: C

Question

CIS3301 You are to write a calculator program in c++. The calculator will allow the user to perform the following operations Get the area of a square Get the exponent of 2 integers 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 rightlisosceles 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.

Explanation / Answer

This  c++ program creates the following function.

in the main method, displays the menu for accepting user choice and calls the appropriate function according to the user input. if the user diaplay the illegal menu redisplay the menu. to exit from the program user has to chose exit from the given menu option.

// the caluculator program

#include<iostream.h>

#include<conio.h>

class calculator

{

int a,b,c,i,j,x,r;

float a1,b1;

public:

// constructor to initialies the values

calculator()

{

a=0;

b=0;

c=0;

}

// input function for accepting values

int input()

{

cin>>x;

return x;

}

// function for calculating area of circle

void area()

{

cout <<" Enter the Length of Side : ";

a = input();

b = a * a;

cout<<" Area of Square : "<< b;

}

// function for calculating exponent

void expo()

{

cout << "Enter base : ";

a= input();

cout<< "enter exponent :";

b = input();

cout << a << "^" << b << " = ";

while (b != 0) {

r *= b;

--a;

}

cout << r;

}

// function for finding quotient of the given two numbers

void quot()

{

cout << "Enter dividend: ";

a = input();

cout << "Enter divisor: ";

b = input();

r = a/ b;

cout << "Quotient = " << r << endl;

}

// function for dividing real numbers

void realdiv()

{

cout << "Enter dividend: ";

a1 = input();

cout << "Enter divisor: ";

b1 = input();

r = a1/ b1;

cout << "2 real number division = " << r << endl;

}

// function for finding reminder of division

void remindiv()

{

cout << "Enter dividend: ";

a = input();

cout << "Enter divisor: ";

b = input();

r = a% b;

cout << "reminder of 2 number division = " << r << endl;

}

// function for adding two numbers

void add()

{

cout << "Enter first number: ";

a = input();

cout << "Enter second number: ";

b = input();

r = a+b;

cout << "addition of two number is= " << r << endl;

}

// function for subtracting two numbers

void sub()

{

cout << "Enter first number: ";

a = input();

cout << "Enter second number: ";

b = input();

r = a-b;

cout << "subtraction of two number is= " << r << endl;

}

// function for multiplication

void mul()

{

cout << "Enter first number: ";

a = input();

cout << "Enter second number: ";

b = input();

r = a*b;

cout << "multiplication of two number is= " << r << endl;

}

// function for convert decimal to binary

void dtob()

{

long long binaryNumber = 0;

int remainder, i = 1, step = 1;

cout << "Enter decimal number: ";

a = input();

while (a!=0)

{

r= a%2;

a /= 2;

b += r*i;

i *= 10;

}

cout<< "Binary equivalent for the given number is "<<b;

}

// function for finding factorial

void fact()

{

cout << "Enter a positive integer: ";

a= input();

r = 1;

for(int i = 1; i <=a; ++i)

{

r *= i;

}

cout << "Factorial of " << a << " = " << r;

}

// function for find even or odd

void evenodd()

{

cout << "Enter an integer: ";

a=input();

if ( a % 2 == 0)

cout << a << " is even.";

else

cout << a << " is odd.";

}

void circlearea()

{

cout<< " Enter radius of circle : ";

a = input();

r = 3.14*a*a;

cout<<"Area of circle : "<<r;

}

// function for displaying right triangle

void rightlisosceles()

{

cout << "Enter number of rows: ";

r = input();

for(int i = 1; i <= r; ++i)

{

for(int j = 1; j <= i; ++j)

{

cout << "* ";

}

cout << " ";

}

}

};

void main()

{

calculator o1;

int m=0;

clrscr();

cout<<" IMPLEMENTATION OF mathematical operations ";

// display the menu item

do

{

clrscr();

cout<<" MENU ";

cout<<" 1.Area of square ";

cout<<" 2.Exponent of two numbers ";

cout<<" 3. Quotient of two numbers ";

cout<<" 4.division of real numbers ";

cout<<" 5.reminder of two numbers ";

cout<<" 6. addition of two numbers ";

cout<<" 7.subtraction of two numbers ";

cout<<" 8.multiplication of two numbers ";

cout<<" 9. converting decimal to binary";

cout<<" 10. factorial of given number ";

cout<<" 11. finding even or odd ";

cout<<" 12. finding area of circle ";

cout<<" 13. display rightlisosceles triangle ";

cout<<" 14.EXIT ";

cout<<" ENTER YOUR CHOICE : ";

cin>>m;

// for getting a choice from user

switch(m)

{

case 1: o1.area();

break;

case 2: o1.expo();

break;

case 3: o1.quot();

break;

case 4: o1.realdiv();

break;

case 5: o1.remindiv();

break;

case 6: o1.add();

break;

case 7: o1.sub();

break;

case 8: o1.mul();

break;

case 9: o1.dtob();

break;

case 10: o1.fact();

break;

case 11:o1.evenodd();

break;

case 12: o1.circlearea();

break;

case 13: o1.rightlisosceles();

break;

default :

cout<<" enter the menu option from 1 to 13 to perform the function."

}

}while(m!=14);

getch();

}