WeixiangYan/CodeTransOcean huggingface dataset:
Task: Variable-length quantity







Python: def tobits(n, _group=8, _sep='_', _pad=False):
    'Express n as binary bits with separator'
    bits = '{0:b}'.format(n)[::-1]
    if _pad:
        bits = '{0:0{1}b}'.format(n,
                                  ((_group+len(bits)-1)//_group)*_group)[::-1]
        answer = _sep.join(bits[i:i+_group]
                                 for i in range(0, len(bits), _group))[::-1]
        answer = '0'*(len(_sep)-1) + answer
    else:
        answer = _sep.join(bits[i:i+_group]
                           for i in range(0, len(bits), _group))[::-1]
    return answer

def tovlq(n):
    return tobits(n, _group=7, _sep='1_', _pad=True)

def toint(vlq):
    return int(''.join(vlq.split('_1')), 2)    

def vlqsend(vlq):
    for i, byte in enumerate(vlq.split('_')[::-1]):
        print('Sent byte {0:3}: {1:
Task: Variable-length quantity








VB: Module Module1

    Function ToVlq(v As ULong) As ULong
        Dim array(8) As Byte
        Dim buffer = ToVlqCollection(v).SkipWhile(Function(b) b = 0).Reverse().ToArray
        buffer.CopyTo(array, 0)
        Return BitConverter.ToUInt64(array, 0)
    End Function

    Function FromVlq(v As ULong) As ULong
        Dim collection = BitConverter.GetBytes(v).Reverse()
        Return FromVlqCollection(collection)
    End Function

    Iterator Function ToVlqCollection(v As ULong) As IEnumerable(Of Byte)
        If v > Math.Pow(2, 56) Then
            Throw New OverflowException("Integer exceeds max value.")
        End If

        Dim index = 7
        Dim significantBitReached = False
        Dim mask = &H7FUL << (index * 7)
        While index >= 0
            Dim buffer = mask And v
            If buffer > 0 OrElse significantBitReached Then
                significantBitReached = True
                buffer >>= index * 7
                If index > 0 Then
                    buffer = buffer Or &H80
                End If
                Yield buffer
            End If
            mask >>= 7
            index -= 1
        End While
    End Function

    Function FromVlqCollection(vlq As IEnumerable(Of Byte)) As ULong
        Dim v = 0UL
        Dim significantBitReached = False

        Using enumerator = vlq.GetEnumerator
            Dim index = 0
            While enumerator.MoveNext
                Dim buffer = enumerator.Current
                If buffer > 0 OrElse significantBitReached Then
                    significantBitReached = True
                    v <<= 7
                    v = v Or (buffer And &H7FUL)
                End If

                index += 1
                If index = 8 OrElse (significantBitReached AndAlso (buffer And &H80) <> &H80) Then
                    Exit While
                End If
            End While
        End Using

        Return v
    End Function

    Sub Main()
        Dim values = {&H7FUL << 7 * 7, &H80, &H2000, &H3FFF, &H4000, &H200000, &H1FFFFF}
        For Each original In values
            Console.WriteLine("Original: 0x{0:X}", original)

            REM collection
            Dim seq = ToVlqCollection(original)
            Console.WriteLine("Sequence: 0x{0}", seq.Select(Function(b) b.ToString("X2")).Aggregate(Function(a, b) String.Concat(a, b)))

            Dim decoded = FromVlqCollection(seq)
            Console.WriteLine("Decoded: 0x{0:X}", decoded)

            REM ints
            Dim encoded = ToVlq(original)
            Console.WriteLine("Encoded: 0x{0:X}", encoded)

            decoded = FromVlq(encoded)
            Console.WriteLine("Decoded: 0x{0:X}", decoded)

            Console.WriteLine()
        Next
    End Sub

End Module
Task: Variable-length quantity




Go: package main

import (
    "fmt"
    "encoding/binary"
)

func main() {
    buf := make([]byte, binary.MaxVarintLen64)
    for _, x := range []int64{0x200000, 0x1fffff} {
        v := buf[:binary.PutVarint(buf, x)]
        fmt.Printf("%d encodes into %d bytes: %x\n", x, len(v), v)
        x, _ = binary.Varint(v)
        fmt.Println(x, "decoded")
    }
}
Task: Sudan function



C#: 

using System;

namespace Sudan
{
  class Sudan
  {
  	static int F(int n,int x,int y) {
  		if (n == 0) {
    		return x + y;
  		}
 
  		else if (y == 0) {
    		return x;
  		}
 
  		return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
	}
    
    static void Main(string[] args)
    {
      Console.WriteLine("F(1,3,3) = " + F(1,3,3));    
    }
  }
}









Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function

C: 

#include <stdio.h>

int F(int n,int x,int y) {
  if (n == 0) {
    return x + y;
  }
 
  else if (y == 0) {
    return x;
  }
 
  return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
}

int main() {
  printf("F1(3,3) = %d",F(1,3,3));
  return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function


C++: 

#include <iostream>
using namespace std;

int F(int n,int x,int y) {
  if (n == 0) {
    return x + y;
  }
 
  else if (y == 0) {
    return x;
  }
 
  return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
}

int main() {
  cout << "F(1,3,3) = "<<F(1,3,3)<<endl;
  return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function




Go: package main

import "fmt"

func F(n, x, y int) int {
    if n == 0 {
        return x + y
    }
    if y == 0 {
        return x
    }
    return F(n-1, F(n, x, y-1), F(n, x, y-1)+y)
}

func main() {
    for n := 0; n < 2; n++ {
        fmt.Printf("Values of F(%d, x, y):\n", n)
        fmt.Println("y/x    0   1   2   3   4   5")
        fmt.Println("----------------------------")
        for y := 0; y < 7; y++ {
            fmt.Printf("%d  |", y)
            for x := 0; x < 6; x++ {
                fmt.Printf("%4d", F(n, x, y))
            }
            fmt.Println()
        }
        fmt.Println()
    }
    fmt.Printf("F(2, 1, 1) = %d\n", F(2, 1, 1))
    fmt.Printf("F(3, 1, 1) = %d\n", F(3, 1, 1))
    fmt.Printf("F(2, 2, 1) = %d\n", F(2, 2, 1))
}








Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function





Java: 

public class Main {

  private static int F(int n,int x,int y) {
  	if (n == 0) {
    	return x + y;
  	}
 
 	 else if (y == 0) {
    	return x;
  	}
 
  	return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
 }

  public static void main(String[] args) {
    System.out.println("F(1,3,3) = " + F(1,3,3));
  }
}







Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function







Python: 

def F(n,x,y):
  if n==0:
    return x + y
  elif y==0:
    return x
  else:
    return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y)
    
    
print("F(1,3,3) = ", F(1,3,3))





Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function








VB: Function F(n As Integer, x As Integer, y As Integer) As Integer 
  
  If n = 0 Then Return x + y 
  If y = 0 Then Return x 
  Return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y) 
  
End Function

Public Sub Main() 
  
  Dim n, x, y As Integer

  For n = 0 To 1 
    Print " Values of F(" & n & ", x, y):" 
    Print " y/x    0   1   2   3   4   5" 
    Print String(29, "-") 
    For y = 0 To 6 
      Print y; "  | "; 
      For x = 0 To 5 
        Print Format$(F(n, x, y), "####"); 
      Next 
      Print 
    Next 
    Print 
  Next 
  
  Print "F(2,1,1) = "; F(2, 1, 1) 
  Print "F(3,1,1) = "; F(3, 1, 1) 
  Print "F(2,2,1) = "; F(2, 2, 1)
  
End




Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function

C: 

#include <stdio.h>

int F(int n,int x,int y) {
  if (n == 0) {
    return x + y;
  }
 
  else if (y == 0) {
    return x;
  }
 
  return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
}

int main() {
  printf("F1(3,3) = %d",F(1,3,3));
  return 0;
}
Task: Sudan function



C#: 

using System;

namespace Sudan
{
  class Sudan
  {
  	static int F(int n,int x,int y) {
  		if (n == 0) {
    		return x + y;
  		}
 
  		else if (y == 0) {
    		return x;
  		}
 
  		return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
	}
    
    static void Main(string[] args)
    {
      Console.WriteLine("F(1,3,3) = " + F(1,3,3));    
    }
  }
}
Task: Sudan function


C++: 

#include <iostream>
using namespace std;

int F(int n,int x,int y) {
  if (n == 0) {
    return x + y;
  }
 
  else if (y == 0) {
    return x;
  }
 
  return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
}

int main() {
  cout << "F(1,3,3) = "<<F(1,3,3)<<endl;
  return 0;
}
Task: Sudan function





Java: 

public class Main {

  private static int F(int n,int x,int y) {
  	if (n == 0) {
    	return x + y;
  	}
 
 	 else if (y == 0) {
    	return x;
  	}
 
  	return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y);
 }

  public static void main(String[] args) {
    System.out.println("F(1,3,3) = " + F(1,3,3));
  }
}
Task: Sudan function







Python: 

def F(n,x,y):
  if n==0:
    return x + y
  elif y==0:
    return x
  else:
    return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y)
    
    
print("F(1,3,3) = ", F(1,3,3))
Task: Sudan function








VB: Function F(n As Integer, x As Integer, y As Integer) As Integer 
  
  If n = 0 Then Return x + y 
  If y = 0 Then Return x 
  Return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y) 
  
End Function

Public Sub Main() 
  
  Dim n, x, y As Integer

  For n = 0 To 1 
    Print " Values of F(" & n & ", x, y):" 
    Print " y/x    0   1   2   3   4   5" 
    Print String(29, "-") 
    For y = 0 To 6 
      Print y; "  | "; 
      For x = 0 To 5 
        Print Format$(F(n, x, y), "####"); 
      Next 
      Print 
    Next 
    Print 
  Next 
  
  Print "F(2,1,1) = "; F(2, 1, 1) 
  Print "F(3,1,1) = "; F(3, 1, 1) 
  Print "F(2,2,1) = "; F(2, 2, 1)
  
End
Task: Sudan function




Go: package main

import "fmt"

func F(n, x, y int) int {
    if n == 0 {
        return x + y
    }
    if y == 0 {
        return x
    }
    return F(n-1, F(n, x, y-1), F(n, x, y-1)+y)
}

func main() {
    for n := 0; n < 2; n++ {
        fmt.Printf("Values of F(%d, x, y):\n", n)
        fmt.Println("y/x    0   1   2   3   4   5")
        fmt.Println("----------------------------")
        for y := 0; y < 7; y++ {
            fmt.Printf("%d  |", y)
            for x := 0; x < 6; x++ {
                fmt.Printf("%4d", F(n, x, y))
            }
            fmt.Println()
        }
        fmt.Println()
    }
    fmt.Printf("F(2, 1, 1) = %d\n", F(2, 1, 1))
    fmt.Printf("F(3, 1, 1) = %d\n", F(3, 1, 1))
    fmt.Printf("F(2, 2, 1) = %d\n", F(2, 2, 1))
}
Task: Sudan function






PHP: #Aamrun , 11th July 2022

<?php
function F(int $n,int $x,int $y) {
  if ($n == 0) {
    return $x + $y;
  }
 
  else if ($y == 0) {
    return $x;
  }
 
  return F($n - 1, F($n, $x, $y - 1), F($n, $x, $y - 1) + $y);
}
echo "F(1,3,3) = " . F(1,3,3); 
?>






Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Sudan_Function is

   function F (N, X, Y : Natural) return Natural
   is (if    N = 0 then X + Y
       elsif Y = 0 then X
       else  F (N => N - 1,
                X => F (N, X, Y - 1),
                Y => F (N, X, Y - 1) + Y));

begin
   Put_Line ("F0 (0, 0) = " & F (0, 0, 0)'Image);
   Put_Line ("F1 (1, 1) = " & F (1, 1, 1)'Image);
   Put_Line ("F1 (3, 3) = " & F (1, 3, 3)'Image);
   Put_Line ("F2 (1, 1) = " & F (2, 1, 1)'Image);
   Put_Line ("F2 (2, 1) = " & F (2, 2, 1)'Image);
   Put_Line ("F3 (1, 1) = " & F (3, 1, 1)'Image);
end Sudan_Function;
Task: Sudan function






PHP: #Aamrun , 11th July 2022

<?php
function F(int $n,int $x,int $y) {
  if ($n == 0) {
    return $x + $y;
  }
 
  else if ($y == 0) {
    return $x;
  }
 
  return F($n - 1, F($n, $x, $y - 1), F($n, $x, $y - 1) + $y);
}
echo "F(1,3,3) = " . F(1,3,3); 
?>
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() );
    }
}









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

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);











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


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"










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




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)
}








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





Java: public class MyClass{

  
  private int variable;  

  
  public MyClass(){
    
  }

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







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







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  





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








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




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

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);
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() );
    }
}
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"
Task: Classes





Java: public class MyClass{

  
  private int variable;  

  
  public MyClass(){
    
  }

  
  public void someMethod(){
   this.variable = 1;
  }
}
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
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