Exercise: Students Average Marks
Calculate a student's average marks using the concept of classes.
We'll cover the following...
Problem Statement #
Write a class called student
with
-
private
member variables:-
name
, -
mark1
andmark2
-
-
And methods:
-
getMarks($marknumber)
, a method which should returnmark1
ifmarknumber
equals 1 andmark2
otherwise. -
calcAverage()
method should take the two marks entered and return their average.
-
Also define
- A constructor that takes the three
private
variables and sets them to given values.
Coding Challenge #
Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.
Good Luck!