Exercise 2: Students Average Marks
Let's calculate a student's average marks by using Classes.
We'll cover the following
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
andmark2
.int
data memberrollno
,
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: 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