Compound data type: Difference between revisions

From Rosetta Code
Content added Content deleted
(New page: {{task}} <div class="messagebox"> Create a structure Point(x,y) </div> ==BASIC== Category:BASIC '''Interpeter:''' QuickBasic 4.5, PB 7.1 TYPE Point x AS INTEGER y AS I...)
 
Line 4: Line 4:
Create a structure Point(x,y)
Create a structure Point(x,y)
</div>
</div>

==[[Ada|Ada TODO]]==
[[Category:Ada]]
The parent package defines the Point type.

package Shapes is
type Point is tagged private;

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


==[[BASIC]]==
==[[BASIC]]==

Revision as of 03:01, 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;
 private
   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