PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/pike/class/runme.pike

#
Unknown | 53 lines | 37 code | 16 blank | 0 comment | 0 complexity | 789168f7f9a8fb84cb2a3e9d1365aa77 MD5 | raw file
 1import .example;
 2
 3int main()
 4{
 5    // ----- Object creation -----
 6
 7    write("Creating some objects:\n");
 8    Circle c = Circle(10.0);
 9    write("    Created circle.\n");
10    Square s = Square(10.0);
11    write("    Created square.\n");
12
13    // ----- Access a static member -----
14
15    write("\nA total of " + Shape_nshapes_get() + " shapes were created\n");
16
17    // ----- Member data access -----
18
19    // Set the location of the object
20
21    c->x_set(20.0);
22    c->y_set(30.0);
23
24    s->x_set(-10.0);
25    s->y_set(5.0);
26
27    write("\nHere is their current position:\n");
28    write("    Circle = (%f, %f)\n", c->x_get(), c->y_get());
29    write("    Square = (%f, %f)\n", s->x_get(), s->y_get());
30
31    // ----- Call some methods -----
32
33    write("\nHere are some properties of the shapes:\n");
34    write("   The circle:\n");
35    write("        area      = %f.\n", c->area());
36    write("        perimeter = %f.\n", c->perimeter());
37    write("   The square:\n");
38    write("        area      = %f.\n", s->area());
39    write("        perimeter = %f.\n", s->perimeter());
40
41    write("\nGuess I'll clean up now\n");
42
43    /* See if we can force 's' to be garbage-collected */
44    s = 0;
45    
46    /* Now we should be down to only 1 shape */
47    write("%d shapes remain\n", Shape_nshapes_get());
48    
49    /* Done */
50    write("Goodbye\n");
51    
52    return 0;
53}