Sort by

recency

|

1186 Discussions

|

  • + 0 comments

    Here is HackerRank Day 12 Inheritance solution - https://programmingoneonone.com/hackerrank-day-12-inheritance-30-days-of-code-solution.html

  • + 0 comments

    python code

    class Person: def init(self, firstName, lastName, idNumber): self.firstName = firstName self.lastName = lastName self.idNumber = idNumber def printPerson(self): print("Name:", self.lastName + ",", self.firstName) print("ID:", self.idNumber) class Student(Person): def init(self,firstName,lastName,idNumber,scores): super().init(firstName,lastName,idNumber) self.scores=scores def calculate(self): m=sum(self.scores)/len(self.scores) if m>=90: return 'O' elif m>=80: return 'E' elif m>=70: return 'A' elif m>=55: return "P" elif m>=40: return 'D' else: return 'T' line = input().split() firstName = line[0] lastName = line[1] idNum = line[2] numScores = int(input()) # not needed for Python scores = list( map(int, input().split()) ) s = Student(firstName, lastName, idNum, scores) s.printPerson() print("Grade:", s.calculate())

  • + 0 comments

    Given code has compliation error C#:

    Solution.cs(91,21): error CS0019: Operator '+' cannot be applied to operands of type 'string' and 'void'

    Please fix it, we cannot edit these code. thanks!

  • + 0 comments

    If this is your first time with cpp classes I recommend you these 2 videos:

    Constructor video

    Inheritance video

    For constructors with inheritance you can do something like this:

    child (dataType inheritedParam1, dataType Param2) : father (inheritedParam1) {
    	m_variable = Param2;
    }
    
  • + 0 comments

    import java.util.Scanner;

    class Person { String firstName; String lastName; int id;

    public Person(String firstName, String lastName, int id) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.id = id;
    }
    

    }

    class Student extends Person { private int[] testScores;

    public Student(String firstName, String lastName, int id, int[] testScores) {
        super(firstName, lastName, id);
        this.testScores = testScores;
    }
    
    public char calculate() {
        int sum = 0;
        for (int score : testScores) {
            sum += score;
        }
        int avg = sum / testScores.length;
    
        if (avg >= 90) return 'O';
        else if (avg >= 80) return 'E';
        else if (avg >= 70) return 'A';
        else if (avg >= 55) return 'P';
        else if (avg >= 40) return 'D';
        else return 'T';
    }
    

    }

    public class Solution { public static void main(String[] args) { Scanner scn = new Scanner(System.in); String firstName = scn.next(); String lastName = scn.next(); int id = scn.nextInt(); int numScores = scn.nextInt(); int[] scores = new int[numScores];

        for (int i = 0; i < numScores; i++) {
            scores[i] = scn.nextInt();
        }
    
        Student std = new Student(firstName, lastName, id, scores);
        System.out.println("Name: "+lastName+", "+firstName);
        System.out.println("ID: "+id);
        System.out.println("Grade: "+std.calculate());
        scn.close();
    }
    

    }