Write a Calculator class that can accept two values, then add them, subtract them, multiply them together, or divide them on request. For example: $calc = new Calculator( 3, 4 ); echo $calc- >add(); // Displays “7” echo $calc- >multiply(); // Displays “12”

Calculate.html
<HTML><BODY>
<FORM method=get action="Calculate.php">
Enter first value: <INPUT type=text name="a"><br>
Enter second value:<INPUT type=text name="b"><br>
<INPUT type=submit value=”Calculate”>
</FORM></BODY></HTML>
Calculate.php
<?php
class Calculate
      {public $a;
public $b;
function __construct($a,$b){
$this->a=$a;
$this->b=$b;
}
public function add()
         {
          $c=$this->a+$this->b;
echo"Addition = $c<br>";
         }
public function subtract()
         {
          $c=$this->a-$this->b;
echo"Subtract = $c<br>";
         }
public function multiply()
         {
          $c=$this->a*$this->b;
echo"Multiplication = $c<br>";
         }
public function div()
         {
          $c=$this->a/$this->b;
echo"Division = $c";
         } }
$x=$_GET['a'];
$y=$_GET['b'];
$calc=new Calculate($x,$y);
$calc->add();
$calc->subtract();
$calc->multiply();
$calc->div();?>

Comments

Popular posts from this blog

Create an XML file which gives details of books available in “ABC Bookstore” from following categories. 1)      Technical 2)      Cooking 3)      Yoga And elements in each category are in the following format.     …….     …….     ……. Save the file as “Book.xml” Create an application that reads “Book.xml” file into simple XML object. Display attributes and elements. (Hint:- Use simple_xml_load_file() function). 

Write a PHP program to create a simple calculator that can accept two numbers and perform operations like add, subtract, multiplication and divide (using Self Processing form)

Write an Ajax program to print the content of the myfile.dat. This code asks the user to click a button, fetches data from the server using Ajax techniques and displays that data in the same web page as the button without refreshing the page