Improve the class example for several languages.
Fix numerous inaccuracies in index.html (where it exists) and eliminate unnecessary differences between the example code being wrapped.
This commit is contained in:
parent
2f3bf144c6
commit
34c97ffdbd
23 changed files with 154 additions and 412 deletions
|
|
@ -1,14 +1,7 @@
|
|||
/* File : example.c */
|
||||
/* File : example.cxx */
|
||||
|
||||
#include "example.h"
|
||||
#include <math.h>
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
int Shape::get_nshapes() {
|
||||
return nshapes;
|
||||
}
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
/* Move the shape to a new location */
|
||||
void Shape::move(double dx, double dy) {
|
||||
|
|
@ -18,22 +11,18 @@ void Shape::move(double dx, double dy) {
|
|||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
void Circle::set_radius( double r ) {
|
||||
radius = r;
|
||||
}
|
||||
|
||||
double Circle::area(void) {
|
||||
double Circle::area() {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter(void) {
|
||||
double Circle::perimeter() {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
double Square::area(void) {
|
||||
double Square::area() {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter(void) {
|
||||
double Square::perimeter() {
|
||||
return 4*width;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,9 @@ public:
|
|||
}
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
virtual double area() = 0;
|
||||
virtual double perimeter() = 0;
|
||||
static int nshapes;
|
||||
static int get_nshapes();
|
||||
};
|
||||
|
||||
class Circle : public Shape {
|
||||
|
|
@ -21,10 +20,8 @@ private:
|
|||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { }
|
||||
~Circle() { }
|
||||
void set_radius( double r );
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
class Square : public Shape {
|
||||
|
|
@ -32,7 +29,6 @@ private:
|
|||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { }
|
||||
~Square() { }
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ print " Created square\n";
|
|||
|
||||
# ----- Access a static member -----
|
||||
|
||||
print "\nA total of " . Shape::get_nshapes() . " shapes were created\n";
|
||||
print "\nA total of " . Shape::nshapes() . " shapes were created\n";
|
||||
|
||||
# ----- Member data access -----
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ $s = NULL;
|
|||
# the square.
|
||||
$o = NULL;
|
||||
|
||||
print Shape::get_nshapes() . " shapes remain\n";
|
||||
print Shape::nshapes() . " shapes remain\n";
|
||||
print "Goodbye\n";
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue