This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -0,0 +1,58 @@
INTERFACE-ID. Shape.
PROCEDURE DIVISION.
METHOD-ID. perimeter.
DATA DIVISION.
LINKAGE SECTION.
01 ret USAGE FLOAT-LONG.
PROCEDURE DIVISION RETURNING ret.
END METHOD perimeter.
METHOD-ID. shape-area.
DATA DIVISION.
LINKAGE SECTION.
01 ret USAGE FLOAT-LONG.
PROCEDURE DIVISION RETURNING ret.
END METHOD shape-area.
END INTERFACE Shape.
CLASS-ID. Rectangle.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
INTERFACE Shape.
OBJECT IMPLEMENTS Shape.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 width USAGE FLOAT-LONG PROPERTY.
01 height USAGE FLOAT-LONG PROPERTY.
PROCEDURE DIVISION.
METHOD-ID. perimeter.
DATA DIVISION.
LINKAGE SECTION.
01 ret USAGE FLOAT-LONG.
PROCEDURE DIVISION RETURNING ret.
COMPUTE ret = width * 2.0 + height * 2.0
GOBACK
.
END METHOD perimeter.
METHOD-ID. shape-area.
DATA DIVISION.
LINKAGE SECTION.
01 ret USAGE FLOAT-LONG.
PROCEDURE DIVISION RETURNING ret.
COMPUTE ret = width * height
GOBACK
.
END METHOD shape-area.
END OBJECT.
END CLASS Rectangle.

View file

@ -0,0 +1,11 @@
(* Abstract type *)
Object = POINTER TO ABSTRACT RECORD END;
(* Integer inherits Object *)
Integer = POINTER TO RECORD (Object)
i: INTEGER
END;
(* Point inherits Object *)
Point = POINTER TO RECORD (Object)
x,y: REAL
END;

View file

@ -0,0 +1,15 @@
(* Abstract method of Object *)
PROCEDURE (dn: Object) Show*, NEW, ABSTRACT;
(* Implementation of the abstract method Show() in class Integer *)
PROCEDURE (i: Integer) Show*;
BEGIN
StdLog.String("Integer(");StdLog.Int(i.i);StdLog.String(");");StdLog.Ln
END Show;
(* Implementation of the abstract method Show() in class Point *)
PROCEDURE (p: Point) Show*;
BEGIN
StdLog.String("Point(");StdLog.Real(p.x);StdLog.Char(',');
StdLog.Real(p.y);StdLog.String(");");StdLog.Ln
END Show;

View file

@ -0,0 +1,38 @@
using System.Console;
namespace RosettaCode
{
abstract class Fruit
{
abstract public Eat() : void;
abstract public Peel() : void;
virtual public Cut() : void // an abstract class con contain a mixture of abstract and implemented methods
{ // the virtual keyword allows the method to be overridden by derivative classes
WriteLine("Being cut.");
}
}
interface IJuiceable
{
Juice() : void; // interfaces contain only the signatures of methods
}
class Orange : Fruit, IJuiceable
{
public override Eat() : void // implementations of abstract methods need to be marked override
{
WriteLine("Being eaten.");
}
public override Peel() : void
{
WriteLine("Being peeled.");
}
public Juice() : void
{
WriteLine("Being juiced.");
}
}
}