Exercise 2: Students Average Marks
In this exercise, you have to calculate a student's average marks using the concept of Classes
We'll cover the following
Problem Statement #
Write a C++ class called Student
with
-
private
member variables:-
name
(string
type), -
mark1
andmark2
(float type)
-
And member functions:
-
GetMarks(int marknumber)
, a function which should returnmark1
ifmarknumber
equals 1 andmark2
otherwise. -
calc_average()
function should take the two marks entered and return their average.
Also define two constructors:
- A default constructor that takes no parameters and initializes mark numbers to zeros and the name to
null
. - A constructor that takes the three
private
variables and sets them to given values.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy