We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 12: Inheritance
Day 12: Inheritance
Sort by
recency
|
1183 Discussions
|
Please Login in order to post a comment
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:
import java.util.Scanner;
class Person { String firstName; String lastName; int id;
}
class Student extends Person { private int[] testScores;
}
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];
}
String calculate(){ int sum=0; for(int a:testScores){ sum+=a; } int avg=sum/testScores.length; if(avg>40){ if(avg<55) return "D"; if(avg<70) return "P"; if(avg<80) return "A"; if(avg<90) return "E"; else return "O"; } else{ return "T"; } }
Python Code: This is my solution: