Professional Documents
Culture Documents
Lab 02
Lab 02
Here, the variables patientNumber and diagnosis of the Patient class are hidden
using the private keyword, while the member functions are made accessible using
the public keyword.
Types of C++ Access Modifiers
public
private
protected
Getter in C++:
Getter is a member function that helps to get the value of a private data member. It
allows access to private members to get read by external code but not allowing
them to modify it directly.
Setter in C++:
Setter is a member function that helps to set the value of a private data member. It
allows controlled access to private members and can provide a constraint on the
input or validation before a value is set.
Example:
Output:
Introduction to constructor:
C++ Constructors
A constructor is a special type of member function that is called automatically
when an object is created.
In C++, a constructor has the same name as that of the class, and it does not have a
return type. For example,
Here, the function Wall() is a constructor of the class Wall. Notice that the
constructor has the same name as the class, does not have a return type, and
is public
Types of constructors:
C++ Default Constructor
C++ Parameterized Constructor
C++ Copy Constructor