I need some help writing this program. I have to use a driver and this is my fir
ID: 3620807 • Letter: I
Question
I need some help writing this program. I have to use a driver and this is my first experience with it. I'm in intro to c++ so if any help is offered, can you please try to keep it as basic as possible. When I received help before, the help was to advanced for me. Here is my assignment:Write and test a series of functions, in order to practice procedural abstraction.
Each function should include documentation, proper types, variables and return.
1. Given three integers, determine if they are a Pythagorean Triple, that is,
they satisfy the equation a2 + b2 = c2. Return true or false.
2. Take an integer and return the order of magnitude of that number.
e.g. OoM(50) = 1, OoM(100) = 2, OoM(1200) = 3,
OoM(17545) = 4, OoM(299999) = 5 and so on.
3. Calculate the growth of a sum of money by compound interest:
Given principal (P), annual interest rate (r: a decimal: eg .085 for 8.5%),
a number representing the times per year to compound (n),
and a number of years (t), return the new value of the principal (A).
The formula is: A = P ( 1 + r/n ) nt
4. Write a function to answer questions of how many years it takes to
grow to a certain amount. You should use the function from #3.
Given a principal and a target amount, and an interest rate (eg. 8.5 for 8.5%),
determine how many years it would take, compounding monthly for the
original principal to grow larger than the target amount.
Notes
Your driver should call your function with various values and print
out the results of the function call.
Thanks, any help will be greatly appreciated.
Explanation / Answer
please rate - thanks if there is something you don't understand message me #include <iostream>#include <cmath>
using namespace std;
bool istriangle(int,int,int);
int OoM(int);
double growth(double,double,int,int);
int main()
{int a,b,c,n,t;
double P,r,wish;
cout<<"enter sides of a triangle: ";
cout<<"Enter side 1: ";
cin>>a;
cout<<"Enter side 2: ";
cin>>b;
cout<<"Enter side 3: ";
cin>>c;
if(istriangle(a,b,c)||istriangle(a,c,b)||istriangle(b,c,a))
cout<<"Triangle sides "<<a<<","<<b<<","<<c<<" is a Pythagorean Triple ";
else
cout<<"Triangle sides "<<a<<","<<b<<","<<c<<" is not a Pythagorean Triple ";
cout<<" Enter a number whos magnitude you want: ";
cin>>a;
cout<<"OoM("<<a<<") = "<<OoM(a)<<endl<<endl;
cout<<"Calculate money growth: ";
cout<<"Enter Principal: ";
cin>>P;
cout<<"Enter yearly interest rate (as a decimal): ";
cin>>r;
cout<<"Enter times per year to compound: ";
cin>>n;
cout<<"Enter number of years invested: ";
cin>>t;
cout<<"At rhe end of "<<t<<" years invested at "<<r*100<<"% ";
cout<<"If the money is compounded "<<n<<" times a year ";
cout<<"Your $"<<P<<" will grow to $"<<growth(P,r,n,t)<<endl<<endl;
cout<<"How much would you like your "<<P<<" to grow to at that rate? ";
cin>>wish;
t=0;
while(P<wish)
{t++;
P=growth(P,r,n,t);
}
cout<<"It will take "<<t<<" years to reach your goal of $"<<wish;
cout<<" you will then have $"<<P<<endl;
system("pause");
return 0;
}
bool istriangle(int a,int b,int c)
{if(a*a+b*b==c*c)
return true;
return false;
}
int OoM(int a)
{int n=0;
while(a>10)
{a/=10;
n++;
}
return n;
}
double growth(double P,double r,int n,int t)
{
return P*pow((1.+r/n),n*t);
}