Classes & Objects
In this Lab, you will learn:
➢ To define a class of your own and use it to create an object. ➢ To create constants variables and use it and how to write default constructors.
1. Create class Date with the following capabilities:
a. Output the date in multiple formats, such as
June 14, 1992
b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. [Hint: To convert the string representation of the month to a numeric value, compare strings using the equals method. For example, if s1 and s2 are strings, the method call s1.equals( s2 ) returns true if the strings are identical and otherwise returns false.]
2. Create a class Enrollment containing private data members: firstName, lastName, address, enrolDate. enrolDate is a final object of class Date, which contains private data members month, day and year. Enrollment constructor’s public member functions are the constructor that receives four parameters: firstName, lastName, address, enrolDate. Print function that prints the four parameters, set and get functions for every attribute. Use this pointer in set functions. Create a main program and instantiate one object of class Date called enroll (27, 9, 1995), and an object of class Enrollment: student1 (“Ryan”, “Haddad”, “Beirut”, enroll) to test your program.