For this program you are going to make TWO calculators: A Law of Cosines calculator and a Quadratic Equation Solver. You can put both interfaces on the same spreadsheet tab and both functions on the same script page.
INPUTS:
A user will enter a side, angle and side.
The user will click a button to actuate the program.
OUTPUTS:
The length of the third side will be displayed.
CRITERIA & CONSTRAINTS:
Your program should have an impressive interface. (colors and graphics)
The angle entered will be in degrees but GAS only works with Radians so in your program you will need to convert it to radians to use it in your math.
Create a function called lawofcosines( )
Create a variable called sheet to get the active sheet.
Create a variable called side1 and use the .getValue on the sheet to hold the value the user enters.
Do this also for variables angle and side2.
Create a variable called final_side and calculate it.
You will have to use Math.pow( ), Math.sqrt( ) and Math.cos( ).
You will need to convert the angle input to radians. You can do that like this: angle*Math.PI/180
In your last line of your function print the final_side variable back to your output box on your spreadsheet. Of course you will have this function run when a button is pressed on your spreadsheet interface.
INPUTS:
A user will enter a,b and c.
The user will click a button to actuate the program.
OUTPUTS:
If nothing has been entered for (a), an output statement will say "Please enter a,b and c."
There will be three other possible output statements:
"The roots are complex"
There is only one real root: (print the root)
There are two real roots: (print the roots)
CRITERIA & CONSTRAINTS:
Your program should have an impressive interface. (colors and graphics)
In your program you will have to check the discriminant (stuff under the radical), to see if it is less than, equal to or greater than 0. If it is less than zero, the roots are complex. If it equals zero, there is only one root. If it is greater than zero, there are two real roots.
Create a function called quadratic( )
Create a variables called sheet to get the active sheet.
Create variables called a,b and c and use the .getValue on the sheet to hold the values the user enters.
Create a variable called discriminant and calculate it.
Create variables called root1 and root2 and calculate them.
Create a variable called statement and set it equal to an empty string.
Create an if - else if - else if - else statement.
First check if a==0. If it does set statement to "Enter a,b and c on the left!"
Next check if discriminant<0. If it does set statement to "The roots are complex!"
Next check if discriminant==0. If it does set statement to "There is only one real root:\n"+root1.toFixed(2);
The \n will cause a line break in your text. The .toFixed(2) on the variable root1 will cut it off at the hundredths place.
In the final else, which means that discriminant>0, set statement to "There are two real roots:\n"+root1.toFixed(2)+ " and " + root2.toFixed(2);
In your last line of your function print the statement variable back to your output box on your spreadsheet. Of course you will have this function run when a button is pressed on your spreadsheet interface.