0% found this document useful (0 votes)
15 views3 pages

# Define # Include # Include # Include Using Namespace Int Double Double Char Char While

This C++ program allows a user to perform various mathematical operations by selecting an operation code and entering numbers. It can calculate the absolute value, hypotenuse, square root, cosine, sine, tangent, addition, subtraction, multiplication, and division of numbers. The program uses the built-in constant M_PI and converts degrees to radians for trigonometric functions. It outputs the results to 15 decimal places of precision.

Uploaded by

mwaseem2011
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

# Define # Include # Include # Include Using Namespace Int Double Double Char Char While

This C++ program allows a user to perform various mathematical operations by selecting an operation code and entering numbers. It can calculate the absolute value, hypotenuse, square root, cosine, sine, tangent, addition, subtraction, multiplication, and division of numbers. The program uses the built-in constant M_PI and converts degrees to radians for trigonometric functions. It outputs the results to 15 decimal places of precision.

Uploaded by

mwaseem2011
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

# define _USE_MATH_DEFINES # include <iostream> # include <iomanip> # include <cmath> using namespace std; int main() { double number_1,

number_2, output; double PI = M_PI; char choice = '1'; char (choice == '*'); while(choice != 'e') {

// M_PI gives built in PI value

cout << endl << endl << "Choose an opration" << endl << "a for absolute" << endl << "h for hypotenuse" << endl << "r for square root" << endl << "c for cosine" << endl << "s for sine" << endl << "t for tangent" << endl << "+ for add" << endl << "- for substract" << endl << "* for multiplication" << endl << "/ for divide" << endl << "e for exit" << endl << "Enter opration: " ; cin >> choice; if(choice == 'a') { cout << "Enter number :"; cin>> number_1; output = abs(number_1); cout << "output:abs of" <<number_1 setprecision(15) << output << endl; }

<< "is" << fixed <<

else if(choice == 'h') { cout << "Enter number1 :"; cin>> number_1; cout << "Enter number 2:"; cin>> number_2; output = hypot(number_1,number_2); cout << "output : hypot of of" <<number_1 <<number_2 << "is" << fixed << setprecision(15) << output << endl; }

<< "and"

else if(choice == 'r') { cout << "Enter number :"; cin>> number_1; output = sqrt(number_1); //squre root function only users radians cout << "output:sqrt of" setprecision(15) << output << endl; } <<number_1 << "is" << fixed <<

else if(choice == 'c') { cout << "Enter number :"; cin>> number_1; number_1 = number_1*PI / 180.0; // degree to radians output = cos(number_1); // cos function only users radians cout << "output:cos of " <<number_1 << "is" << fixed << setprecision(15) << output << endl; } else if(choice == 's') { cout << "Enter number :"; cin>> number_1; number_1 = number_1*PI / 180.0; // degree to radians output = sin(number_1); // sin function only users radians cout << "output:sin of " <<number_1 << "is" << fixed << setprecision(15) << output << endl; } else if(choice == 't') { cout << "Enter number :"; cin>> number_1; number_1 = number_1*PI / 180.0; // degree to radians output = tan(number_1); // tangent function only users radians cout << "output:tan of " setprecision(15) << output << endl; } <<number_1 << "is" << fixed <<

"is" <<

else if(choice == '+') { cout << "Enter number1 :"; cin>> number_1; cout << "Enter number 2:"; cin>> number_2; output = number_1 + number_2; cout << "output : add of" <<number_1 fixed << setprecision(15) << output << endl; } else if(choice == '-') {

<< "and" <<number_2 <<

<<number_2 << " is " << }

cout << "Enter number1 :"; cin>> number_1; cout << "Enter number 2:"; cin>> number_2; output = number_1 - number_2; cout << "output : substraction of" <<number_1 fixed << setprecision(15) << output << endl;

<< " and "

else if(choice == '*') { cout << "Enter number1 :"; cin>> number_1;

" <<number_2 << " is " << }

cout << "Enter number 2:"; cin>> number_2; output = number_1 * number_2; cout << " output : multiplication of " <<number_1 fixed << setprecision(15) << output << endl;

<< " and

else if(choice == '/') { cout << "Enter number1 :"; cin>> number_1; cout << "Enter number 2:"; cin>> number_2; output = number_1 / number_2; cout << "output : divide of" <<number_1 fixed << setprecision(15) << output << endl; }

<< "and" <<number_2

<< "is" <<

} system ("pause"); return(0); }

You might also like