Forum » Advanced Programming » Tafel class
What else?
Berichten: 1180
avatar
Online Stuur privebericht
Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

/**
 * @author Patrick rennings
 * @copyright 2010
 */

class Tafel {
    
    
    protected 
$iCount;
    protected static 
$iMaxOutPut;
    protected 
$MathOutPut;
    
    public function 
__construct $Count$MaxOutPut NULL)
    {
        
        if ( !
is_int $Count ) OR empty ( $Count ) )
        {
                
            
$this->iCount 1;
                
        }
        else
        {
            
            
$this->iCount $Count;
            
        }
        if ( !
is_int $MaxOutPut ) OR empty ( $MaxOutPut ) AND empty ( self::$iMaxOutPut ) )
        {

            
self::$iMaxOutPut 10;
                
        }
        else
        {
            
            
self::$iMaxOutPut $MaxOutPut;
            
        }
  
        
$this->Math$this->iCountself::$iMaxOutPut );
                
    }
    
    private function 
Math $CalcNum$MaxOutPut )
    {
        
        
$sArrayMath = array ( );
        
        for ( 
$iMath 1$iMath <= $MaxOutPut$iMath++ )
        {
            
            
$sArrayMath[] = $iMath ' x ' $CalcNum ' = ' $iMath $CalcNum;
            
        }
        
        
$this->MathOutPut $sArrayMath;
        
    }
    
    public function 
ResultMath ( )
    {
        
        return 
$this->MathOutPut;
        
    }
    
}

$Math = new Tafel (4,20);

foreach ( 
$Math->ResultMath() AS $Calculation )
{
    
    echo 
$Calculation '  ';
    
}

$Math2 = new Tafel (5);

foreach ( 
$Math2->ResultMath() AS $Calculation )
{
    
    echo 
$Calculation '  ';
    
}

?>


Alles werkt, behalve de static variable, als ik de waarde = NULL meegeef aan $MaxOutPut wordt hij automatisch 10, maar als ik hem niet meegeef gaat hij mekkere dat er niks in staat,

Hoe kan ik er een check inbouwen dat wanneer de static variable is gevuld dat hij die gewoon pakt wanneer er geen nieuwe gedefinieerd is?

UPDATE:

zo werkt hij naar mijn zin
Comments?

Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php

/**
 * @author Patrick rennings
 * @copyright 2010
 */

class Tafel {
    
    
    protected 
$iCount;
    protected static 
$iMaxOutPut;
    protected 
$MathOutPut;
    
    public function 
__construct $Count$MaxOutPut NULL)
    {
        
        if ( !
is_int $Count ) OR empty ( $Count ) )
        {
                
            
$this->iCount 1;
                
        }
        else
        {
            
            
$this->iCount $Count;
            
        }
        
        if ( ( !
is_int $MaxOutPut ) OR empty ( $MaxOutPut ) ) AND empty ( self::$iMaxOutPut ) )
        {

            
self::$iMaxOutPut 10;
                
        }
            
        elseif ( empty ( 
self::$iMaxOutPut ) OR ! empty ( $MaxOutPut ) )
        {
                
            
self::$iMaxOutPut $MaxOutPut;
            
        }
  
        
$this->Math$this->iCountself::$iMaxOutPut );
                
    }
    
    private function 
Math $CalcNum$MaxOutPut )
    {
        
        
$sArrayMath = array ( );
        
        for ( 
$iMath 1$iMath <= $MaxOutPut$iMath++ )
        {
            
            
$sArrayMath[] = $iMath ' x ' $CalcNum ' = ' $iMath $CalcNum;
            
        }
        
        
$this->MathOutPut $sArrayMath;
        
    }
    
    public function 
ResultMath ( )
    {
        
        return 
$this->MathOutPut;
        
    }
    
}

$Math = new Tafel (4,20);

foreach ( 
$Math->ResultMath() AS $Calculation )
{
    
    echo 
$Calculation '  ';
    
}

$Math2 = new Tafel (5);

foreach ( 
$Math2->ResultMath() AS $Calculation )
{
    
    echo 
$Calculation '  ';
    
}

?>

Laatst gewijzigd door Patrick op 2010-04-04 12:15:05
04-04-2010 11:08
Dit topic is 138 keer bekeken door 11 verschillende leden
Reacties op: "Tafel class"
1
Webdeveloper & Programmeu
Berichten: 1001
avatar
Offline Stuur privébericht
Ik heb je script is bekeken en ik heb zelf ook er een gemaakt.
Hij is een stukje korter geworden.
Ben benieuwd of hier mensen zijn die het willen beoordelen?

class.table.php
Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?PHP
// Class Table maken.
class Table
{
    
// Variabel decaleren.
    
private $MathOutPut;
    
    
// Gegevens door sturen.
    
public function __construct($iTable$iMax)
    {
        
// Checken of de inkomende gegevens bestaan.
        
if ( !is_int $iTable ) or empty ( $iTable ) ) 
        { 
            
$iCount 7;
        } 
        else 
        {
            
$iCount $iTable;
        }
         
        if ( !
is_int $iMax ) or empty ( $iMax ) ) 
        {
            
$MaxOutPut 10;
        }
        else
        {
            
$MaxOutPut $iMax;
        }
        
        
// Math functie oproepen.
        
$this->Math$iCount$MaxOutPut );
    }
    
    
// Berekenen van de getallen.
    
private function Math$CalcNum$MaxOutPut )
    {
        
// Array maken.
        
$sArrayMath = array();
        
        
// Gegevens in array plaatsen.
        
for($i 0$i <= $MaxOutPut$i++)
        {
            
$sArrayMath[] = $i .' x '$CalcNum .' = '$i $CalcNum;
        }
        
        
// Hele array in de output plaatsen.
        
$this->MathOutPut $sArrayMath;
    }
    
    
// Weergeven van de tafel.
    
public function showTable()
    {
        
// Output terug sturen zodat hij kan worden weergeven.
        
return $this->MathOutPut;    
    }
}


Weergeven:
tafel.php
Code | Selecteer Alles
minimaliseren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?PHP
include "class.table.php";

if(
$_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['verzenden']))
{
    
$tafel = new Table($_POST['tafel'], $_POST['maximaal']);

    echo 
'<ul>';
        foreach ( 
$tafel->showTable() AS $Calculation 
        { 
            echo 
'<li>'$Calculation '</li>'
        }
    echo 
'</ul>';
}
?>
<form method="post">
    <p>Getal voor de tafel van, standaard 7:<input name="tafel" type="text" /></p>
    <p>Maximum aantal keer, standaard 10:<input name="maximaal" type="text" /></p>
    <p><input name="verzenden" type="submit" value="Verzenden" /></p>
</form>
27-04-2010 10:50
Reageer op: "Tafel class"
1
Je kan niet reageren omdat je niet bent ingelogd. Inloggen of Aanmelden