Exercise 2: 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 and mark2

  • And methods:

    • getMarks($marknumber), a method which should return mark1 if marknumber equals 1 and mark2 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!

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy