WeixiangYan/CodeTransOcean huggingface dataset:
Task: Classes




Go: package main

import "fmt"




type picnicBasket struct {
    nServings int 
    corkscrew bool
}


func (b *picnicBasket) happy() bool {
    return b.nServings > 1 && b.corkscrew
}









func newPicnicBasket(nPeople int) *picnicBasket {
    
    
    
    
    return &picnicBasket{nPeople, nPeople > 0}
}


func main() {
    var pb picnicBasket          
    pbl := picnicBasket{}        
    pbp := &picnicBasket{}       
    pbn := new(picnicBasket)     
    forTwo := newPicnicBasket(2) 
    
    forToo := &picnicBasket{nServings: 2, corkscrew: true}

    fmt.Println(pb.nServings, pb.corkscrew)
    fmt.Println(pbl.nServings, pbl.corkscrew)
    fmt.Println(pbp)
    fmt.Println(pbn)
    fmt.Println(forTwo)
    fmt.Println(forToo)
}
Task: Classes

C: #include <stdlib.h>

typedef struct sMyClass
{
  int variable;
} *MyClass;

MyClass  MyClass_new()
{
  MyClass pthis = malloc(sizeof *pthis);
  pthis->variable = 0;
  return pthis;
}

void MyClass_delete(MyClass* pthis)
{
  if (pthis)
  {
    free(*pthis);
    *pthis = NULL;
  }
}

void MyClass_someMethod(MyClass pthis)
{
  pthis->variable = 1;
}

MyClass obj = MyClass_new();
MyClass_someMethod(obj);
MyClass_delete(&obj);









COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Classes



C#: public class MyClass
{
    public MyClass()
    {
    }
    public void SomeMethod()
    {
    }
    private int _variable;
    public int Variable
    {
        get { return _variable; }
        set { _variable = value; }
    }
    public static void Main()
    {
        
        MyClass instance = new MyClass();
        
        instance.SomeMethod();
        
        instance.Variable = 99;
        
        System.Console.WriteLine( "Variable=" + instance.Variable.ToString() );
    }
}







COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Classes


C++: PRAGMA COMPILER g++
PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fpermissive

OPTION PARSE FALSE


'---The class does the declaring for you

CLASS Books 
	public: 
		const char* title;
		const char* author; 
		const char* subject; 
		int book_id; 
END CLASS


'---pointer to an object declaration (we use a class called Books) 
DECLARE Book1 TYPE Books
'--- the correct syntax for class
Book1  =  Books()


'--- initialize the strings const char* in c++
Book1.title = "C++ Programming to bacon "
Book1.author = "anyone"
Book1.subject ="RECORD Tutorial"
Book1.book_id = 1234567


PRINT "Book title   : " ,Book1.title FORMAT "%s%s\n"
PRINT "Book author  : ", Book1.author FORMAT "%s%s\n"
PRINT "Book subject : ", Book1.subject FORMAT "%s%s\n"
PRINT "Book book_id : ", Book1.book_id FORMAT "%s%d\n"








COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Classes





Java: public class MyClass{

  
  private int variable;  

  
  public MyClass(){
    
  }

  
  public void someMethod(){
   this.variable = 1;
  }
}





COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Classes







Python: class MyClass:
    name2 = 2 

    def __init__(self):
        
        self.name1 = 0 
  
    def someMethod(self):
        
        self.name1 = 1
        MyClass.name2 = 3
  
  
myclass = MyClass() 

class MyOtherClass:
    count = 0  
    def __init__(self, name, gender="Male", age=None):
        
        MyOtherClass.count += 1
        self.name = name
        self.gender = gender
        if age is not None:
            self.age = age
    def __del__(self):
        MyOtherClass.count -= 1

person1 = MyOtherClass("John")
print person1.name, person1.gender  
print person1.age                   
person2 = MyOtherClass("Jane", "Female", 23)
print person2.name, person2.gender, person2.age  



COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Classes








VB: Class NumberContainer
  Private TheNumber As Integer
  Sub Constructor(InitialNumber As Integer)
    TheNumber = InitialNumber
  End Sub

  Function Number() As Integer
    Return TheNumber
  End Function

  Sub Number(Assigns NewNumber As Integer)
    TheNumber = NewNumber
  End Sub
End Class


COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Classes




Go: package main

import "fmt"




type picnicBasket struct {
    nServings int 
    corkscrew bool
}


func (b *picnicBasket) happy() bool {
    return b.nServings > 1 && b.corkscrew
}









func newPicnicBasket(nPeople int) *picnicBasket {
    
    
    
    
    return &picnicBasket{nPeople, nPeople > 0}
}


func main() {
    var pb picnicBasket          
    pbl := picnicBasket{}        
    pbp := &picnicBasket{}       
    pbn := new(picnicBasket)     
    forTwo := newPicnicBasket(2) 
    
    forToo := &picnicBasket{nServings: 2, corkscrew: true}

    fmt.Println(pb.nServings, pb.corkscrew)
    fmt.Println(pbl.nServings, pbl.corkscrew)
    fmt.Println(pbp)
    fmt.Println(pbn)
    fmt.Println(forTwo)
    fmt.Println(forToo)
}






COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Classes






PHP: class MyClass {
    public static $classVar;
    public $instanceVar; // can also initialize it here
    function __construct() {
        $this->instanceVar = 0;
    }
    function someMethod() {
        $this->instanceVar = 1;
        self::$classVar = 3;
    }
}
$myObj = new MyClass();
Task: Classes






PHP: class MyClass {
    public static $classVar;
    public $instanceVar; // can also initialize it here
    function __construct() {
        $this->instanceVar = 0;
    }
    function someMethod() {
        $this->instanceVar = 1;
        self::$classVar = 3;
    }
}
$myObj = new MyClass();






Ada: package My_Package is
   type My_Type is tagged private;
   procedure Some_Procedure(Item : out My_Type);
    function Set(Value : in Integer) return My_Type;
private
   type My_Type is tagged record
      Variable : Integer := -12;
   end record;
end My_Package;
Task: Classes






PHP: class MyClass {
    public static $classVar;
    public $instanceVar; // can also initialize it here
    function __construct() {
        $this->instanceVar = 0;
    }
    function someMethod() {
        $this->instanceVar = 1;
        self::$classVar = 3;
    }
}
$myObj = new MyClass();




COBOL:        IDENTIFICATION DIVISION.
       CLASS-ID. my-class INHERITS base.
       
       
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS base.
     
           
           
           
           
     
           OBJECT.
               
               DATA DIVISION.
               WORKING-STORAGE SECTION.
               01  instance-variable PIC 9(8).
       
               
               
               01  a-property        PIC 9(8) PROPERTY.
               
               PROCEDURE DIVISION.
       
               METHOD-ID. some-method.
               PROCEDURE DIVISION.
                   
               END METHOD some-method.
           END OBJECT.
       END CLASS my-class.
       
       IDENTIFICATION DIVISION.
       PROGRAM-ID. example-class-use.
       
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           
           
           CLASS my-class
           PROPERTY a-property. 
                  
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       
       01  instance USAGE OBJECT REFERENCE my-class.
       
       PROCEDURE DIVISION.
       
           
           INVOKE my-class "new" RETURNING instance
           
           
           INVOKE instance "some-method"

           
           MOVE 5 TO a-property OF instance
           DISPLAY a-property OF instance
       
           GOBACK
           .
           
       END PROGRAM example-class-use.
Task: Long multiplication



C#: using System;
using static System.Console;
using BI = System.Numerics.BigInteger;

class Program {

  static decimal mx = 1E28M, hm = 1E14M, a;

  
  struct bi { public decimal hi, lo; }

  
  static bi set4sq(decimal a) { bi r; r.hi = Math.Floor(a / hm); r.lo = a % hm; return r; }

  
  static string toStr(bi a, bool comma = false) {
    string r = a.hi == 0 ? string.Format("{0:0}", a.lo) :
                           string.Format("{0:0}{1:" + new string('0', 28) + "}", a.hi, a.lo);
    if (!comma) return r;  string rc = "";
    for (int i = r.Length - 3; i > 0; i -= 3) rc = "," + r.Substring(i, 3) + rc;
    return r.Substring(0, ((r.Length + 2) % 3) + 1) + rc; }

  
  static decimal Pow_dec(decimal bas, uint exp) {
    if (exp == 0) return 1M; decimal tmp = Pow_dec(bas, exp >> 1); tmp *= tmp;
    if ((exp & 1) == 0) return tmp; return tmp * bas; }

  static void Main(string[] args) {
    for (uint p = 64; p < 95; p += 30) {        
      bi x = set4sq(a = Pow_dec(2M, p)), y;     
      WriteLine("The square of (2^{0}):                    {1,38:n0}", p, a); BI BS = BI.Pow((BI)a, 2);
      y.lo = x.lo * x.lo; y.hi = x.hi * x.hi;   
      a = x.hi * x.lo * 2M;                     
      y.hi += Math.Floor(a / hm);               
      y.lo += (a % hm) * hm;                    
      while (y.lo > mx) { y.lo -= mx; y.hi++; } 
      WriteLine(" is {0,75} (which {1} match the BigInteger computation)\n", toStr(y, true),
          BS.ToString() == toStr(y) ? "does" : "fails to"); } }

}









Ada: package Long_Multiplication is
   type Number (<>) is private;

   Zero : constant Number;
   One  : constant Number;

   function Value (Item : in String) return Number;
   function Image (Item : in Number) return String;

   overriding
   function "=" (Left, Right : in Number) return Boolean;

   function "+" (Left, Right : in Number) return Number;
   function "*" (Left, Right : in Number) return Number;

   function Trim (Item : in Number) return Number;
private
   Bits : constant := 16;
   Base : constant := 2 ** Bits;

   type Accumulated_Value is range 0 .. (Base - 1) * Base;
   subtype Digit is Accumulated_Value range 0 .. Base - 1;

   type Number is array (Natural range <>) of Digit;
   for Number'Component_Size use Bits; 

   Zero : constant Number := (1 .. 0 => 0);
   One  : constant Number := (0 => 1);

   procedure Divide (Dividend  : in     Number;
                     Divisor   : in     Digit;
                     Result    :    out Number;
                     Remainder :    out Digit);
end Long_Multiplication;
Task: Long multiplication

C: #include <stdio.h>
#include <string.h>


void longmulti(const char *a, const char *b, char *c)
{
	int i = 0, j = 0, k = 0, n, carry;
	int la, lb;

	
	if (!strcmp(a, "0") || !strcmp(b, "0")) {
		c[0] = '0', c[1] = '\0';
		return;
	}

	
	if (a[0] == '-') { i = 1; k = !k; }
	if (b[0] == '-') { j = 1; k = !k; }

	
	if (i || j) {
		if (k) c[0] = '-';
		longmulti(a + i, b + j, c + k);
		return;
	}

	la = strlen(a);
	lb = strlen(b);
	memset(c, '0', la + lb);
	c[la + lb] = '\0';

#	define I(a) (a - '0')
	for (i = la - 1; i >= 0; i--) {
		for (j = lb - 1, k = i + j + 1, carry = 0; j >= 0; j--, k--) {
			n = I(a[i]) * I(b[j]) + I(c[k]) + carry;
			carry = n / 10;
			c[k] = (n % 10) + '0';
		}
		c[k] += carry;
	}
#	undef I
	if (c[0] == '0') memmove(c, c + 1, la + lb);

	return;
}

int main()
{
	char c[1024];
	longmulti("-18446744073709551616", "-18446744073709551616", c);
	printf("%s\n", c);

	return 0;
}











Ada: package Long_Multiplication is
   type Number (<>) is private;

   Zero : constant Number;
   One  : constant Number;

   function Value (Item : in String) return Number;
   function Image (Item : in Number) return String;

   overriding
   function "=" (Left, Right : in Number) return Boolean;

   function "+" (Left, Right : in Number) return Number;
   function "*" (Left, Right : in Number) return Number;

   function Trim (Item : in Number) return Number;
private
   Bits : constant := 16;
   Base : constant := 2 ** Bits;

   type Accumulated_Value is range 0 .. (Base - 1) * Base;
   subtype Digit is Accumulated_Value range 0 .. Base - 1;

   type Number is array (Natural range <>) of Digit;
   for Number'Component_Size use Bits; 

   Zero : constant Number := (1 .. 0 => 0);
   One  : constant Number := (0 => 1);

   procedure Divide (Dividend  : in     Number;
                     Divisor   : in     Digit;
                     Result    :    out Number;
                     Remainder :    out Digit);
end Long_Multiplication;