//Programmer: Eric Barnes
//Date: 3/19/2014
//Class: Cs 53
//Filename: rw_calcfun.cpp
//Description: Function definitions for ralphs calculatior program
#include "rw_calc.h"
void greet()
{
cout << "Hello Ralph, welcome to your calculator program...again \n" << endl;
return;
}
void demand_x()
{
cout << "Choose a value for x before attempting calculations" << endl;
return;
}
int menu()
{
int selection;
cout << "\t\t MENU\n";
cout << "1. Enter a positive number x \n";
cout << "2. Factorial (of integer part of x)\n";
cout << "3. Nth Root of x\n";
cout << "4. Power of x, x^n\n";
cout << "5. Exp(x)\n";
cout << "6. Sinh(x) (hyperbolic sine)\n";
cout << "7. Quit\n";
cout << "Make your selection: ";
cin >> selection;
return selection;
}
float get_posnum(const string numname)
{
int in_num;
do
{
cout << "Enter the (positive) value of your " << numname <<" choice : ";
cin >> in_num;
if(in_num <= 0)
cout << "Not like that" << endl << endl;
}while(in_num <= 0);
return in_num;
}
int fact(const int x)
{
int result = 1;
for(int i = 1; i <= x; i++)
{
result *= i;
}
return result;
}
float pow(const float x, const int n)
{
int result = 1;
for(int i = 0; i < n; i++)
{
result *= x;
}
return result;
}
float nth_root(const float x, const int n)
{
float root = x;
for(int i = 0; i < ROOT_ITRS; i++)
{
root = ((n - 1)*root + x/pow(root, n-1))/n;
}
return root;
}
float exponential(const float x)
{
float exp = 1;
float num;
float den;
for(int i = 1; i <= EXP_TERMS; i++)
{
num = pow(x,i);
den = fact(i);
exp += num/den;
}
return exp;
}
float sinh(const float x)
{
return (exponential(x) - (1/exponential(x)))/2;
}
void goodbye()
{
cout << "Goodbye Ralph, better luck next time" << endl;
return;
}