#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,672
    Rep Power
    171

    Calculating area of rectangle or circle procedure based method


    Hi

    I have never done it. Would you please give me some tips on how to do it in procedure based method and NOT oop.

    Thanks
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    How to calculate the area of a rectangle or a circle? I sure hope it's something more complicated than that.

    Details. You've been here long enough to know that we need them.
  4. #3
  5. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    Originally Posted by requinix
    I sure hope it's something more complicated than that.
    didn't you go to school?

    Maybe you've forgotten that PHP can do basic maths just by writing +,-,* and / ?

    Maybe you don't know how to get the value of pi?

    PHP has a built in function which returns the value of pi (to some approximation, limited by variable length)...it's called [PHPNET="pi"]pi()[/PHPNET] for some reason.

    There's also the constant, M_PI, and a few derivatives should you need them

    Then, just remember that in PHP * means multiply and / means divide,

    eg

    $area_of_rectangle = $length * $width;

    and

    $area_of_circle = pi() * $radius * $radius;

    or

    $area_of_circle = pi() * pow($radius,2);
    Last edited by Northie; September 23rd, 2013 at 03:38 AM.
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,672
    Rep Power
    171
    I am gonna blame it on my English.
    A 6 year old can do this.
  8. #5
  9. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    Originally Posted by English Breakfast Tea
    I am gonna blame it on my English.
    A 6 year old can do this.
    So what was the original problem?
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  10. #6
  11. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,672
    Rep Power
    171
    Originally Posted by Northie
    So what was the original problem?
    The upload dynamic size for 3d images (cone, pyramid and cylender) and need to calculate the volume depending on the size and shape.
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Using procedural programming, you'd probably have one function for each shape.

    Like for example

    PHP Code:
    <?php

    function volume_cone($radius$height) {
        
    $base_area M_PI $radius $radius;
        return (
    1/3) * $base_area $height;
    }
    You might also write down the calculations directly if you only need them once. But personally, I'd hide low-level math like this from the actual code.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo