Exercise 2: Students Average Marks

Let's calculate a student's average marks by using Classes.

Problem Statement

In this exercise, you have to write a class Student that contains the following data members and member functions and perform the following operations:

  • Private data members:

    • float data members: mark1 and mark2.

    • int data member rollno,

  • Public member functions:

    • Default constructor: Takes no parameters and initializes mark numbers to 0 and the roll no to 1.

    • Parameterized constructor: Takes the three private data members as arguments and sets them to given values.

    • GetMarks(int marknumber) function: Returns mark1 if marknumber equals 1 and mark2 otherwise.

    • calc_average() function: Take the two marks entered and return their average.

Sample input

Create a free account to access the full course.

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