Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- class Calc
- {
- private:
- double m_nValue2;
- double m_nValue;
- public:
- Calc(double nValue) { m_nValue = nValue; };
- double Add(double nValue) { m_nValue += nValue; return m_nValue;};
- double Subtract(double nValue) { m_nValue -= nValue; return m_nValue;};
- double Multiply(double nValue) { m_nValue *= nValue; return m_nValue;};
- double Divide(double nValue) { m_nValue /= nValue; return m_nValue;};
- double Modulus(double nValue) { m_nValue = fmod(m_nValue,nValue); return m_nValue;};
- double Power(double nValue) { m_nValue = pow(m_nValue,nValue); return m_nValue;};
- double Reciprocal() { m_nValue = 1/m_nValue; return m_nValue;};
- double NthRoot(double index, double guess, double pc)
- {
- double result = guess;
- double result_next;
- do
- {
- result_next = (1/index)*((index-1)*result+(m_nValue)/(pow(result,(index-1))));
- result = result_next;
- pc--;
- }while(pc>1);
- m_nValue = result;
- return m_nValue;
- };
- double Factorial()
- {
- double result = m_nValue;
- double result_next;
- double pc = m_nValue;
- do
- {
- result_next = result*(pc-1);
- result = result_next;
- pc--;
- }while(pc>2);
- m_nValue2 = m_nValue;
- m_nValue = result;
- return m_nValue;
- }
- double Factorial2(int nValue)
- {
- double result = nValue;
- double result_next;
- double pc = nValue;
- do
- {
- result_next = result*(pc-1);
- result = result_next;
- pc--;
- }while(pc>2);
- nValue = result;
- return nValue;
- }
- double DoubleFactorial()
- {
- double result=m_nValue;
- double result_next;
- double pc = m_nValue;
- do
- {
- result_next = result*(pc-2);
- result = result_next;
- pc--;
- pc--;
- }while(pc>2);
- m_nValue2 = m_nValue;
- m_nValue = result;
- return m_nValue;
- }
- double Gamma()
- {
- double result = Factorial()/m_nValue2;
- m_nValue = result;
- return m_nValue;
- }
- double Tetrate(double pc)
- {
- double result = m_nValue;
- double result_next;
- do
- {
- result_next = pow(result,m_nValue);
- result = result_next;
- pc--;
- }while(pc>1);
- m_nValue = result;
- return m_nValue;
- }
- double EvaluateBinomialCoefficient(double nValue)
- {
- double result;
- result = (Factorial2(m_nValue))/(Factorial2(nValue)*Factorial2((m_nValue - nValue)));
- m_nValue = result;
- return m_nValue;
- }
- double GetValue() { return m_nValue;};
- double SetValue(double nValue) { m_nValue = nValue;};
- };
- int main()
- {
- double start;
- unsigned int operation;
- double operand;
- double operand2;
- double iterations;
- cout<<"What shall be your starting value?";
- cin>>start;
- Calc cCalc(start);
- do
- {
- cout<<"Select an operation, please.\n\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus\n6. Exponentiation\n7. Tetration\n8. Reciprocal\n9. Nth Root\n10. Factorial\n11. Double Factorial\n12. Gamma Function\n13. Evaluate Binomal Coefficient\n14. Set Value\n15. Show Value\n\n";
- cin>>operation;
- cin.ignore();
- cout<<setprecision(15);
- switch(operation)
- {
- case 1:
- cout<<"Select an addend, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Add(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 2:
- cout<<"Select an minuend, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Subtract(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 3:
- cout<<"Select an multiplicand, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Multiply(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 4:
- cout<<"Select a divisor, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Divide(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 5:
- cout<<"Select a divisor, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Modulus(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 6:
- cout<<"Select a exponent, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Power(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 7:
- cout<<"Select a number to tetrate to, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Tetrate(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 8:
- cout<<"Select a number to take the reciprocal of, please.\n";
- cin>>operand;
- cin.ignore();
- cCalc.Reciprocal();
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 9:
- cout<<"Select an index, please.";
- cin>>operand;
- cin.ignore();
- cout<<"Select a guess for the root, please.";
- cin>>operand2;
- cin.ignore();
- cout<<"How many iterations of the algorithm?\n";
- cin>>iterations;
- cin.ignore();
- cCalc.NthRoot(operand,operand2,iterations);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 10:
- cCalc.Factorial();
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 11:
- cCalc.DoubleFactorial();
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 12:
- cCalc.Gamma();
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 13:
- cout<<"Choose an operand, please.";
- cin>>operand;
- cCalc.EvaluateBinomialCoefficient(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 14:
- cout<<"Which number would you like to set the calculator to?\n";
- cin>>operand;
- cin.ignore();
- cCalc.SetValue(operand);
- cout<<cCalc.GetValue()<<"\n";
- break;
- case 15:
- cout<<cCalc.GetValue()<<"\n";
- break;
- default:
- cout<<"Sorry, but that isn't a feature yet.";
- break;
- }
- }while(1==1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement