Exercise 2: Students Average Marks

Calculate a student's average marks by using classes.

Problem statement

Write a class Student that contains the following data members and member functions, and performs 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: Takes the two marks entered and returns their average.

Sample input

Create a free account to access the full course.

Continue your learning journey with a 14-day free trial.

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