HR30 Day 12: Inheritance

Jmnote (토론 | 기여)님의 2018년 8월 9일 (목) 20:19 판 (새 문서: ==개요== ;<nowiki>Day 12: Inheritance</nowiki> * https://www.hackerrank.com/challenges/30-inheritance/problem {{HR30 헤더}} {{HR30 10-19}} |} ==PHP== <source lang='php'> class S...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

Day 12: Inheritance
해커랭크 30 Days of Code
문제 풀이
10-19 Day e
HR30 Day 10: Binary Numbers

HR30 Day 11: 2D Arrays

HR30 Day 12: Inheritance

HR30 Day 13: Abstract Classes

HR30 Day 14: Scope

HR30 Day 15: Linked List

HR30 Day 16: Exceptions - String to Integer

HR30 Day 17: More Exceptions

HR30 Day 18: Queues and Stacks

HR30 Day 19: Interfaces

2 PHP

class Student extends person {
    private $testScores;
    public function __construct($first_name, $last_name, $identification, $scores) {
        parent::__construct($first_name, $last_name, $identification);
        $this->testScores = $scores;
    }
    function calculate() {
        $average = array_sum($this->testScores) / count($this->testScores);
        if( $average >= 90 ) return 'O';
        if( $average >= 80 ) return 'E';
        if( $average >= 70 ) return 'A';
        if( $average >= 55 ) return 'P';
        if( $average >= 40 ) return 'D';
        return 'T';
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}