Exercise 2: Students Average Marks
Calculate a student's average marks by using classes.
We'll cover the following
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
andmark2
.int
data member:rollno
Public member functions:
Default constructor: Takes no parameters and initializes mark numbers to
0
and the roll no to1
.Parameterized constructor: Takes the three
private
data members as arguments and sets them to given values.GetMarks(int marknumber)
function: Returnsmark1
ifmarknumber
equals1
andmark2
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