0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

プログラミング言語化テスト

Last updated at Posted at 2023-05-31

大問1

以下のプログラムはPHPにて記載されたプログラムの一部である。
記載の内容を日本語に翻訳せよ

第1問

$a=2;

第2問

$a=["a"=>3];

第3問

$a = ad(1,2)

第4問

$a = new A();

第5問

a();

第6問

A::v();

第7問

$b->get()

第8問

a(a(1))

第9問

$a = c();
a(b(1), new A($a))

第10問

$users = User::all();

大問2

以下のプログラムはPHPにて記載されたプログラムのである。
echoされる結果を回答せよ

第1問

$a = 1;
$b = 2;
$c = compact("a", "b");
echo $c["a"].$c["b"];

第2問

$a = "a";
$b = "b";
$c = "c";

$x = function($a, $b) use ($c) {
    return $a.$b.$c;
};

echo $x($b, $a);

第3問

class MyClass {
    public static function sayHello($name) {
        echo "Hello, " . $name . "!";
    }
}
MyClass::sayHello("John");

第4問

class MyClass {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public static function sayHello() {
        echo "Hello, " . $this->name . "!";
    }
}

$myObject = new MyClass("John");
$myObject->sayHello();

第5問

class MyClass {
    private static $count = 0;

    public static function getCount() {
        return self::$count;
    }

    public static function incrementCount($cnt = 1) {
        self::$count += $cnt;
    }
}

MyClass::incrementCount();
MyClass::incrementCount(3);
MyClass::incrementCount(MyClass::getCount()+1);
echo "カウント: " . MyClass::getCount();

第6問

function createMultiplier($factor) {
    return function($number) use ($factor) {
        return $number * $factor;
    };
}

echo createMultiplier(2)(10);

第7問

function processNumbers($numbers, $callback) {
    foreach ($numbers as $number) {
        $result = $callback($number);
        echo $result . ",";
    }
}

$numbers = [1, 2, 3, 4, 5];

$x = function($number) {
    return $number * 2;
};

processNumbers($numbers, $x);

第8問

function c($factor) {
    return function($number) use ($factor) {
        return $number * $factor;
    };
}

$x = c(2);
$a = $x(10);
echo $a * 2;

第9問

class Animal {
    protected $name;
    
    public function __construct($name) {
        $this->name = $name;
    }
    
    public function eat() {
        echo $this->name . " is eating.\n";
    }
}

class Dog extends Animal {
    public function bark() {
        echo $this->name . " is barking.\n";
    }
}

$animal = new Animal("Generic Animal");
$animal->eat();

$dog = new Dog("Fido");
$dog->eat();
$dog->bark();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?