Project

Project Description

Using the raspberry pi we created a web server where on the pi and then using php scripting what was created was a simple calculator that would ask the user for inputs consisting of two numbers and then outputing the result both in input box and as text on the web page.  The operations that were created were those for addition, subtraction, multiply, division, exponential power, square root, sine, cosine, and tangent.

Team Members

Keven Deng, Michael Alvarez

My contribution to the project was that I provided funding for the project and I coded the script for the inputs and the buttons that will calculate the operation which is the first script. I also helped my team member in explaning what should happen with the second script to output the operation in a text format on the webpage.

PHP Script

code part 1code part 2code part 3

Web Server with Script working for addition, power, and cosine

screen1screen2screen3

Video of the simple calculator script running

The Actual PHP script

Keven Deng contribution PHP Script

<html>
<head>
<title>Calculator</title>
</head>
<body>

<!–background color–>
<body bgcolor=”#2EEEF7″>
<!–First php scripting code to ask user for input and pick operation from user input–>
<?php
/*the following uses the get function to get the operation,
the first number, second number, and the result
*/
$op = $_GET[‘submit’];//operation
$num1 = $_GET[‘num1’];//!st number
$num2 = $_GET[‘num2’];//2nd number
$result = $_GET[‘result’];//result

//switch function is used to select the operands
switch($op)
{
//addition
case ‘plus’ : $result=$num1+$num2;
break;
//subtraction
case ‘subtract’ : $result=$num1-$num2;
break;
//multiplication
case ‘multiply’ : $result=$num1*$num2;
break;
//division
case ‘divide’ : $result=$num1/$num2;
break;
//power
case ‘x^y’ : $result=pow($num1,$num2);
break;
//square root
case ‘sqrt’ : $result= sqrt($num1);
break;
//sine
case ‘Sine’ : $result= sin($num1);
break;
//cosine
case ‘Cosine’ : $result= cos($num1);
break;
//tangent
case ‘Tangent’ : $result= tan($num1);
break;

}//end of switch

//creation of asking user for inputs and buttons for operands
//echo <<<buttons_input is just the creation of a long string
echo <<<buttons_input
<h1>Simple Calculator</h1>
<html>
<head>
<title>Calculator</title>
</head>
<body>

<!–background color–>
<body bgcolor=”#2EEEF7″>
<!–First php scripting code to ask user for input and pick operation from user input–>
<?php
/*the following uses the get function to get the operation,
the first number, second number, and the result
*/
$op = $_GET[‘submit’];//operation
$num1 = $_GET[‘num1’];//!st number
$num2 = $_GET[‘num2’];//2nd number
$result = $_GET[‘result’];//result

//switch function is used to select the operands
switch($op)
{
//addition
case ‘plus’ : $result=$num1+$num2;
break;
//subtraction
case ‘subtract’ : $result=$num1-$num2;
break;
//multiplication
case ‘multiply’ : $result=$num1*$num2;
break;
//division
case ‘divide’ : $result=$num1/$num2;
break;
//power
case ‘x^y’ : $result=pow($num1,$num2);
break;
//square root
case ‘sqrt’ : $result= sqrt($num1);
break;
//sine
case ‘Sine’ : $result= sin($num1);
break;
//cosine
case ‘Cosine’ : $result= cos($num1);
break;
//tangent
case ‘Tangent’ : $result= tan($num1);
break;

}//end of switch

//creation of asking user for inputs and buttons for operands
//echo <<<buttons_input is just the creation of a long string
echo <<<buttons_input
<h1>Simple Calculator</h1>
*Note*
<br>//new line
sqrt, sine, cosine, and tangent uses the
first number entered to perform operation
<br><br>

<form method=”GET” action=”index.php”>//outputs the same page
enter the first number
//creates a input to ask user for first number
<input type=”text” name=”num1″ value= “$num1″><br/>
enter the second number
//creates a input to ask user for second number
<input type=”text” name=”num2″ value= “$num2″><br/>
result
//creates a input to display result
<input type=”text” name=”result” value= “$result”><br/>
<br>Basic</br>
//creation of buttons for operands of +,-,*,/,x^y,sqrt,sin,cos,tan
<input type=”submit” name=”submit” value=”plus”>
<input type=”submit” name=”submit” value=”subtract”>
<input type=”submit” name=”submit” value=”multiply”>
<input type=”submit” name=”submit” value=”divide”>
<br>Exponential</br>
<input type=”submit” name=”submit” value=”x^y”>
<input type=”submit” name=”submit” value=”sqrt”>
<br>Trigonometry</br>
<input type=”submit” name=”submit” value=”Sine”>
<input type=”submit” name=”submit” value=”Cosine”>
<input type=”submit” name=”submit” value=”Tangent”>
</form>//end of form
buttons_input

?><!–end of first script–>

Leave a Reply

Your email address will not be published. Required fields are marked *