Compound data type: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 12: Line 12:
type Point is tagged private;
type Point is tagged private;


private
public
type Point is tagged record
type Point is tagged record
X : Integer := 0;
X : Integer := 0;

Revision as of 03:02, 24 February 2007

Task
Compound data type
You are encouraged to solve this task according to the task description, using any language you may know.

Create a structure Point(x,y)

Ada TODO

The parent package defines the Point type.

 package Shapes is
   type Point is tagged private;
 public
   type Point is tagged record
      X : Integer := 0;
      Y : Integer := 0;
   end record;
 end Shapes;

BASIC

Interpeter: QuickBasic 4.5, PB 7.1

TYPE Point
  x AS INTEGER
  y AS INTEGER
END TYPE

C

Compiler: GCC, MSVC, BCC, Watcom

Libraries: Standard

 typedef struct Point
 {
   int x;
   int y;
 } Point;

C++

Compiler: GCC, Visual C++, BCC, Watcom

 struct Point
 {
   int x;
   int y;
 };

C#

 struct Point
 {
   public int x, y;
   public Point(int x, int y) {
     this.x = x;
     this.y = y;
   }
 }

D TODO

Compiler: DMD,GDC

Forth TODO

Fortran TODO

Java

class Point
{
  public int x, y;
  public Point() { this(0); }
  public Point(int x0) { this(x0,0); }
  public Point(int x0, int y0) { x = x0; y = y0; }
}

JavaScript TODO


Perl TODO

Interpeter: Perl


PHP TODO