WeixiangYan/CodeTransOcean huggingface dataset:
Task: Arithmetic_Integer







Python: x = int(raw_input("Number 1: "))
y = int(raw_input("Number 2: "))

print "Sum: %d" % (x + y)
print "Difference: %d" % (x - y)
print "Product: %d" % (x * y)
print "Quotient: %d" % (x / y)     
                                   
print "Remainder: %d" % (x % y)    
print "Quotient: %d with Remainder: %d" % divmod(x, y)
print "Power: %d" % x**y


raw_input( )



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Arithmetic.

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 A      PIC S9(10).
       01 B      PIC S9(10).
       01 Result PIC S9(10).

       PROCEDURE DIVISION.
           DISPLAY "First number: " WITH NO ADVANCING
           ACCEPT A
           DISPLAY "Second number: " WITH NO ADVANCING
           ACCEPT B
           
*          
*          
*          
*          

           ADD A TO B GIVING Result
           DISPLAY "A + B = " Result

           SUBTRACT B FROM A GIVING Result
           DISPLAY "A - B = " Result

           MULTIPLY A BY B GIVING Result
           DISPLAY "A * B = " Result

*          
*          
*          
           DIVIDE A BY B GIVING Result
           DISPLAY "A / B = " Result

           COMPUTE Result = A ^ B
           DISPLAY "A ^ B = " Result
       
*          
           DISPLAY "A % B = " FUNCTION REM(A, B)

           GOBACK
           .
Task: Arithmetic_Integer








VB: START:
INPUT "Enter two integers (a,b):"; a!, b!
IF a = 0 THEN END
IF b = 0 THEN
    PRINT "Second integer is zero. Zero not allowed for Quotient or Remainder."
    GOTO START
END IF
PRINT
PRINT "             Sum = "; a + b
PRINT "      Difference = "; a - b
PRINT "         Product = "; a * b

PRINT "Integer Quotient = "; a \ b, , "* Rounds toward 0."
PRINT "       Remainder = "; a MOD b, , "* Sign matches first operand."
PRINT "  Exponentiation = "; a ^ b
PRINT
INPUT "Again? (y/N)"; a$
IF UCASE$(a$) = "Y" THEN CLS: GOTO START
CLS
END


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Arithmetic.

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 A      PIC S9(10).
       01 B      PIC S9(10).
       01 Result PIC S9(10).

       PROCEDURE DIVISION.
           DISPLAY "First number: " WITH NO ADVANCING
           ACCEPT A
           DISPLAY "Second number: " WITH NO ADVANCING
           ACCEPT B
           
*          
*          
*          
*          

           ADD A TO B GIVING Result
           DISPLAY "A + B = " Result

           SUBTRACT B FROM A GIVING Result
           DISPLAY "A - B = " Result

           MULTIPLY A BY B GIVING Result
           DISPLAY "A * B = " Result

*          
*          
*          
           DIVIDE A BY B GIVING Result
           DISPLAY "A / B = " Result

           COMPUTE Result = A ^ B
           DISPLAY "A ^ B = " Result
       
*          
           DISPLAY "A % B = " FUNCTION REM(A, B)

           GOBACK
           .
Task: Arithmetic_Integer




Go: package main

import "fmt"

func main() {
    var a, b int
    fmt.Print("enter two integers: ")
    fmt.Scanln(&a, &b)
    fmt.Printf("%d + %d = %d\n", a, b, a+b)
    fmt.Printf("%d - %d = %d\n", a, b, a-b)
    fmt.Printf("%d * %d = %d\n", a, b, a*b)
    fmt.Printf("%d / %d = %d\n", a, b, a/b)  
    fmt.Printf("%d %% %d = %d\n", a, b, a%b) 
    
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Arithmetic.

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 A      PIC S9(10).
       01 B      PIC S9(10).
       01 Result PIC S9(10).

       PROCEDURE DIVISION.
           DISPLAY "First number: " WITH NO ADVANCING
           ACCEPT A
           DISPLAY "Second number: " WITH NO ADVANCING
           ACCEPT B
           
*          
*          
*          
*          

           ADD A TO B GIVING Result
           DISPLAY "A + B = " Result

           SUBTRACT B FROM A GIVING Result
           DISPLAY "A - B = " Result

           MULTIPLY A BY B GIVING Result
           DISPLAY "A * B = " Result

*          
*          
*          
           DIVIDE A BY B GIVING Result
           DISPLAY "A / B = " Result

           COMPUTE Result = A ^ B
           DISPLAY "A ^ B = " Result
       
*          
           DISPLAY "A % B = " FUNCTION REM(A, B)

           GOBACK
           .
Task: Arithmetic_Integer






PHP: <?php
$a = fgets(STDIN);
$b = fgets(STDIN);

echo
    "sum:                 ", $a + $b, "\n",
    "difference:          ", $a - $b, "\n",
    "product:             ", $a * $b, "\n",
    "truncating quotient: ", (int)($a / $b), "\n",
    "flooring quotient:   ", floor($a / $b), "\n",
    "remainder:           ", $a % $b, "\n",
    "power:               ", $a ** $b, "\n"; // PHP 5.6+ only
?>
Task: Arithmetic_Integer






PHP: <?php
$a = fgets(STDIN);
$b = fgets(STDIN);

echo
    "sum:                 ", $a + $b, "\n",
    "difference:          ", $a - $b, "\n",
    "product:             ", $a * $b, "\n",
    "truncating quotient: ", (int)($a / $b), "\n",
    "flooring quotient:   ", floor($a / $b), "\n",
    "remainder:           ", $a % $b, "\n",
    "power:               ", $a ** $b, "\n"; // PHP 5.6+ only
?>






Ada: with Ada.Text_Io;
with Ada.Integer_Text_IO;

procedure Integer_Arithmetic is
   use Ada.Text_IO;
   use Ada.Integer_Text_Io;

   A, B : Integer;
begin
   Get(A);
   Get(B);
   Put_Line("a+b = " & Integer'Image(A + B));
   Put_Line("a-b = " & Integer'Image(A - B));
   Put_Line("a*b = " & Integer'Image(A * B));
   Put_Line("a/b = " & Integer'Image(A / B));
   Put_Line("a mod b = " & Integer'Image(A mod B)); 
   Put_Line("remainder of a/b = " & Integer'Image(A rem B)); 
   Put_Line("a**b = " & Integer'Image(A ** B));  

end Integer_Arithmetic;
Task: Arithmetic_Integer






PHP: <?php
$a = fgets(STDIN);
$b = fgets(STDIN);

echo
    "sum:                 ", $a + $b, "\n",
    "difference:          ", $a - $b, "\n",
    "product:             ", $a * $b, "\n",
    "truncating quotient: ", (int)($a / $b), "\n",
    "flooring quotient:   ", floor($a / $b), "\n",
    "remainder:           ", $a % $b, "\n",
    "power:               ", $a ** $b, "\n"; // PHP 5.6+ only
?>




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Arithmetic.

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 A      PIC S9(10).
       01 B      PIC S9(10).
       01 Result PIC S9(10).

       PROCEDURE DIVISION.
           DISPLAY "First number: " WITH NO ADVANCING
           ACCEPT A
           DISPLAY "Second number: " WITH NO ADVANCING
           ACCEPT B
           
*          
*          
*          
*          

           ADD A TO B GIVING Result
           DISPLAY "A + B = " Result

           SUBTRACT B FROM A GIVING Result
           DISPLAY "A - B = " Result

           MULTIPLY A BY B GIVING Result
           DISPLAY "A * B = " Result

*          
*          
*          
           DIVIDE A BY B GIVING Result
           DISPLAY "A / B = " Result

           COMPUTE Result = A ^ B
           DISPLAY "A ^ B = " Result
       
*          
           DISPLAY "A % B = " FUNCTION REM(A, B)

           GOBACK
           .
Task: Null object



C#: if (foo == null)
    Console.WriteLine("foo is null");









Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object

C: #include <stdio.h>

int main()
{
	char *object = 0;

	if (object == NULL) {
		puts("object is null");
	}
	return 0;
}











Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object


C++: #include <iostream>
#include <cstdlib>
if (object == 0) {
   std::cout << "object is null";
}










Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object




Go: package main

import "fmt"

var (
    s []int       
    p *int        
    f func()      
    i interface{} 
    m map[int]int 
    c chan int    
)

func main() {
    fmt.Println(s == nil)
    fmt.Println(p == nil)
    fmt.Println(f == nil)
    fmt.Println(i == nil)
    fmt.Println(m == nil)
    fmt.Println(c == nil)
}








Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object





Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }







Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object







Python: x = None
if x is None:
  print "x is None"
else:
  print "x is not None"





Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object








VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub




Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object

C: #include <stdio.h>

int main()
{
	char *object = 0;

	if (object == NULL) {
		puts("object is null");
	}
	return 0;
}
Task: Null object


C++: #include <iostream>
#include <cstdlib>
if (object == 0) {
   std::cout << "object is null";
}
Task: Null object





Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }
Task: Null object







Python: x = None
if x is None:
  print "x is None"
else:
  print "x is not None"
Task: Null object








VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub
Task: Null object




Go: package main

import "fmt"

var (
    s []int       
    p *int        
    f func()      
    i interface{} 
    m map[int]int 
    c chan int    
)

func main() {
    fmt.Println(s == nil)
    fmt.Println(p == nil)
    fmt.Println(f == nil)
    fmt.Println(i == nil)
    fmt.Println(m == nil)
    fmt.Println(c == nil)
}
Task: Null object



C#: if (foo == null)
    Console.WriteLine("foo is null");
Task: Null object

C: #include <stdio.h>

int main()
{
	char *object = 0;

	if (object == NULL) {
		puts("object is null");
	}
	return 0;
}









COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Null object



C#: if (foo == null)
    Console.WriteLine("foo is null");







COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Null object


C++: #include <iostream>
#include <cstdlib>
if (object == 0) {
   std::cout << "object is null";
}








COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Null object





Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }





COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Null object







Python: x = None
if x is None:
  print "x is None"
else:
  print "x is not None"



COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Null object








VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub


COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Null object




Go: package main

import "fmt"

var (
    s []int       
    p *int        
    f func()      
    i interface{} 
    m map[int]int 
    c chan int    
)

func main() {
    fmt.Println(s == nil)
    fmt.Println(p == nil)
    fmt.Println(f == nil)
    fmt.Println(i == nil)
    fmt.Println(m == nil)
    fmt.Println(c == nil)
}






COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Null object






PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Null object






PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";






Ada: with Ada.Text_Io;

if Object = null then
   Ada.Text_Io.Put_line("object is null");
end if;
Task: Null object






PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";




COBOL:        identification division.
       program-id. null-objects.
       remarks. test with cobc -x -j null-objects.cob

       data division.
       working-storage section.
       01 thing-not-thing      usage pointer.

      
      
      
      
      
       procedure division.
       call "test-null" using thing-not-thing omitted returning nothing
       goback.
       end program null-objects.

      
      
      
       identification division.
       program-id. test-null.

       data division.
       linkage section.
       01 thing-one            usage pointer.
       01 thing-two            pic x.

       procedure division using
           thing-one
           optional thing-two
           returning omitted.

       if thing-one equal null then
           display "thing-one pointer to null" upon syserr
       end-if

       if thing-two omitted then
           display "no thing-two was passed" upon syserr
       end-if
       goback.
       end program test-null.
Task: Chat server







Python: 

import socket
import thread
import time

HOST = ""
PORT = 4004

def accept(conn):
    
    def threaded():
        while True:
            conn.send("Please enter your name: ")
            try:
                name = conn.recv(1024).strip()
            except socket.error:
                continue
            if name in users:
                conn.send("Name entered is already in use.\n")
            elif name:
                conn.setblocking(False)
                users[name] = conn
                broadcast(name, "+++ %s arrived +++" % name)
                break
    thread.start_new_thread(threaded, ())

def broadcast(name, message):
    
    print message
    for to_name, conn in users.items():
        if to_name != name:
            try:
                conn.send(message + "\n")
            except socket.error:
                pass


server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.setblocking(False)
server.bind((HOST, PORT))
server.listen(1)
print "Listening on %s" % ("%s:%s" % server.getsockname())


users = {}
while True:
    try:
        
        while True:
            try:
                conn, addr = server.accept()
            except socket.error:
                break
            accept(conn)
        
        for name, conn in users.items():
            try:
                message = conn.recv(1024)
            except socket.error:
                continue
            if not message:
                
                del users[name]
                broadcast(name, "--- %s leaves ---" % name)
            else:
                broadcast(name, "%s> %s" % (name, message.strip()))
        time.sleep(.1)
    except (SystemExit, KeyboardInterrupt):
        break