HELP PLEASE WITH CODE

How do you insert void IO() code into the five different functions to make the menu work

1) Write a C++ Function float period(float length,float g) which returns the time?
Write a C++ Function float period(float length,float g) which returns the time, T, according to the formula below for one complete swing of a pendulum, where L is the length of the pendulum and g is the gravitational field strength:

T= 2pisqrt[L/g]


2) Write a C++ Function void sort3(void) which prompts the user to enter three integers, a,b,c and outputs their values in ascending order according to the following decision tree(click the link)

http://img809.imageshack.us/img809/9589/28769489.png


3) Write a C++ function void triplets(void) which computes and outputs the pythagorean triplets for the diophantine equation:

a^2+b^2=c^2, in the range 1<a,b,c<30.

4) Write a C++ function named quadratic which has parameters a,b, and c of type int which calculates only double real roots of quadratic equations according to the formula:

r1=-b+Sqrt(b^2-4ac)/(2a)), r2=-b- Sqrt(b^2-4ac)/(2a))

The two real roots are passed back to the caller via two parameters r1 and r2 of type float. When quadratic cannot calculate two real roots, it prints out the appropriate error message and returns -1 to the caller as a warning not to use the values of the roots. When it can calculate two real solutions, it returns 1 to the caller to indicate success.(better picture below of quadratic equation)

5) Write a recursive C++ Function unsigned long trib(int n) which returns the nth (1=<n=<38) tribonacci according to the recursive formula
T_1 = T_2 = T_3=1
T_n=T_n-1+T_n-2+T_n-3
And finally an interface to run the menu of all these functions
#include <iostream>
#include <math.h>

using namespace std;
static const float PI = (float)(2*acos(0.0));

float period(float length,float g)
{
return (float)(2*PI*sqrt(length/g));
}

int a=0;
int b =0;
int c =0;

typedef struct node
{
int* val1;
int* val2;
struct node* left;
struct node* right;
int isleaf;
int* ptrs[3];
}node;

//tree consturtcion
node node1 = {NULL,NULL,NULL,NULL,1, {&a,&b,&c } };
node node2 = {NULL,NULL,NULL,NULL,1, {&a,&c,&b } };
node node3 = {NULL,NULL,NULL,NULL,1, {&c,&a,&b } };
node node4 = {NULL,NULL,NULL,NULL,1, {&b,&c,&a } };
node node5 = {NULL,NULL,NULL,NULL,1, {&c,&b,&a } };
node node6 = {&a,&c,&node2,&node3,0, NULL };
node node7 = {NULL,NULL,NULL,NULL,1, {&b,&a,&c } };
node node8 = {&b,&c,&node4,&node5,0, NULL };
node node9 = {&b,&c,&node1,&node6,0, NULL };
node node10 = {&a,&c,&node7,&node8,0, NULL };
node node11 = {&a,&b,&node9,&node10,0, NULL };

void rsort( node* ptr )
{
if(ptr->isleaf ==1){
int i=0;
int value;
cout<<"printing the sorting order\n";
while(i < 3)
{
value = *(ptr->ptrs[i]);
cout<<value;
i++;
}
return;
}
if ( *(ptr->val1) < *(ptr->val2) ){

return rsort(ptr->left);
}
else{

return rsort(ptr->right);
}
}


int sort3(int vala,int valb, int valc)
{

a = vala;
b = valb;
c = valc;

rsort(&node11);
}




int main()
{
sort3(5,5,1);

return 0;


}
template <class T>
bool is_valid(const T& tMin, const T& tMax, const T& number)
{
return number <= tMax && number >= tMin ? true : false;
}

template <class T>
T get_number(const string& strPrompt, const T& tMin, const T& tMax)
{
bool bContinue = false;
cout << strPrompt;
T tRet;
do {
cin >> tRet;
bContinue = !is_valid(tMin, tMax, tRet);
if (bContinue) {
cout << "Range: " << tMin << " <= x <= " << tMax << endl;
}
} while(bContinue);
return tRet;
}

double get_base(double& a, double& b)
{
a = get_number("a: ", 1.0, 30.0);
b = get_number("b: ", 1.0, 30.0);
return sqrt(a * a + b * b);
}
int quadratic(int a, int b, int c, double &r1, double &r2)
{
if(pow(b,2)-4*a*c < 0)
{
cout << "Non real result"<<endl;
return -1;
}
else
{
r1= (-b + sqrt( pow(b,2) - 4*a*c)) /(2*a);

r2= (-b - sqrt(pow(b,2) - 4*a*c)) /(2*a);
return 1;
}
}

unsigned long trib( unsigned int n )
{
return ( ( n < 3 ) ? 1 : trib( n - 1 ) + trib( n - 2 ) + trib( n - 3 ) );
}
int main()
{
char letter; //Below begins the outputs to execute the functions

cout << "This program allows you to execute five functions.\n\n Options Menu:";
cout << "Enter 'a' to compute period.\n Enter 'b' to compute sort 3.\n Enter 'c' to compute triplets.\n Enter 'd' to compute a Quadratic Equation.\n Enter "e" to compute unsigned long.\n";
cout << "Enter the letter from the options menu for your desired function: ";
cin >> letter;

letter = toupper (letter);

while (!cin.eof())
{
switch(letter)
{
case 'A': periodIO();
break;
case 'B': sort3IO();
break;
case 'C': tripletsIO();
break;
case 'D': quadraticEquationIO();
break;
case 'E': unsignedLongIO();
break;

}

cout << "";
cin >> letter;
letter = toupper (letter);
}

return 0;
}
Last edited on
Topic archived. No new replies allowed.