0% found this document useful (0 votes)
33 views

Lab 6 Section C 17

The document provides instructions for students to implement various methods for a Date class as part of an object-oriented programming lab assignment. It describes the private data members and public methods declared in a Date.h header file. It then instructs students to write code in a Date.cpp file to implement constructor, setter, getter, comparison and display methods for the class. Finally, it provides directions for writing test code in an operator_class.cpp file to create Date objects using the different constructors and call methods on those objects to validate the Date class implementation.

Uploaded by

CodingWithSaani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Lab 6 Section C 17

The document provides instructions for students to implement various methods for a Date class as part of an object-oriented programming lab assignment. It describes the private data members and public methods declared in a Date.h header file. It then instructs students to write code in a Date.cpp file to implement constructor, setter, getter, comparison and display methods for the class. Finally, it provides directions for writing test code in an operator_class.cpp file to create Date objects using the different constructors and call methods on those objects to validate the Date class implementation.

Uploaded by

CodingWithSaani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 6

Object Oriented Programming | Section C17 | 21 Nov. 2022

Part 1
You are given a “Date.h” file, which contains the following information:
 Four private data members
o Integer type day to store the information related a day
o Integer type month to store the information related a month
o Integer type year to store the information related a year
o String type month_name to store the information related a month_name
 In order to set the values of private data member, we have following public function
members:
o setday to set the value of day private data member
o setmonth to set the value of moth private data member
o setyear to set the value of year private data member
o setmonth_name to set value of the month_name private data member
 Now in order to get the values of private data member, we have following public
function members:
o getday to get the value of day private data member
o getmonth to get the value of moth private data member
o getyear to get the value of year private data member
o getmonth_name to get value of the month_name private data member
 To check that whether the given values for the day, month, year and month_name
are valid or not, “Date.h” contains the following public member functions:
o isValid_day which validates that whether the given value for the day private
data member is valid or not.
o isValid_month which validates that whether the given value for the month
private data member is valid or not.
o isValid_year which validates that whether the given value for the year private
data member is valid or not.
o isValid_month_name which validates that whether the given value for the
month_name private data member is valid or not.
 To copy the content of a Date object into another Date object we have the following
method:
o copyDate which is used to copies the data of one available Data object to
another Date object.
 “Date.h” file has another method called display which displays the date into following
formate:
o year:month:day – month_name
 If someone wants to check the date for that we do have checkDate method.
 Now we have four constructors in “Date.h” file.
o Date() default constructor
o Date() constructor which takes all the parameters i.e. day, month, year and
month_name
o Date() constructor which also takes all the parameters i.e. day, month, year
and month_name but with default values.
o Date() constructor which takes an object of Date class.
 At the end we have a Date destructor which is used to free the memory from date
object.
Part 2
Now as you have enough knowledge about the “Date.h” file’s private date members, public
constructors and public member functions, you have to perform the following task inside
“Date.cpp” file as your graded lab.
1. Implement the default constructor for Date object.
2. Implement the parameterized constructor for Date object.
3. Implement the parameterized constructor for Date object with default values.
4. Implement the constructor for Date object which will take Data object as parameter.
5. Provide the implementation for setday method.
a. In order to check whether the given value for the day is valid or not, provide
the implementation isValid_day method as well and before setting the day’
value make sure that given value is not invalid. To understand what can be the
valid values for a day in month please use your common sense.
6. Provide the implementation for setmonth method.
a. In order to check whether the given value for the month is valid or not,
provide the implementation isValid_month method as well and before setting
the month’ value make sure that given value is not invalid. To understand what
can be the valid values for a month in year please use your common sense.
7. Provide the implementation for setyear method.
a. In order to check whether the given value for the year is valid or not, provide
the implementation isValid_year method as well and before setting the year’
value make sure that given value is not invalid. Valid values for the year are
between 1990 and 2022.
8. Provide the implementation for setmonth_name method.
a. In order to check whether the given value for the month_name is valid or not,
provide the implementation isValid_month_name method as well and before
setting the month_name’ value make sure that given value is not invalid. To
understand what can be the valid values for a month_name in a year please
use your common sense.
9. Now to get the values of the private data members day, month, year and
month_name, provide the implementations for the following methods.
a. getday which will return the day’s value.
b. getmonth which will return the month’s value.
c. getyear which will return the year’s value.
d. getmonth_name which will return the month_name’s value.
10. Here please note an important point that you cannot get any of the data member’s
value without getter methods.
11. Next please provide the implementation for the copyDate method which actually
copies the content of available date object to current date object.
a. Hint: You will get the available date object from Date constructor which will
have data object as its parameter.
12. To check the date, please provide implementation for the checkDate method.
13. To display the data in following format, please provide the implementation for the
display method.
a. year:month:day – month_name
14. To clear the content of date object from the memory provide the implementation for
the Date destructor.

Part 3
Now till this point we have completed our work with “Date.cpp” file. Now inside the
operator_class.cpp file, do the following.
1. Create the objects of Date class using all of its four constructors, which means you
will create four different Date class objects.
2. After creating the first object, which will be with default constructor do the following:
a. Call all the setter methods to set the values of day, month, year and
month_name with this object.
b. Make sure all these data members must have valid values.
c. Call the checkDate and display methods with this object. Now how you are
going to get values of data members please read point # 10 of Part 2.
3. Your next task is to use the object with parameterized constructor. Now as you have
provided values for the data members as parameters of this object’s constructor, so
use your brilliance to figure how you are going to assign these values to data
members of Date class while making sure that these values are also valid.
a. Hint: Values can only be set to data member using setter methods i.e. setday
4. Object with parametrized constructor which you have created in step 3 of Part 3, now
use this object to the call the checkDate and display methods. Before doing this step,
make sure the read the point # 10 of part 2.
5. After completing the first 4 steps of the part 3, now it’s time to create the object with
constructor with default values. Now here you might be wondering that what will be
the default values for the day, month and month_name please use something called
brain. I am sure, after constraining for a while you will figure it out. To understand
what can be default value for year, please read Point 7-a of Part 2.
6. Next task is to assign values to day, month, year and month_name which we have
provided as parameters of this object’s constructor. Important thing to understand
here is that at the time of this object creation, all the default values will be assigned
to the date members of the Date class, but later on if you want to assign a new value
by using this object, you can call the setter methods i.e. setday
7. Please remember, values to data members can only be assigned by using the setter
methods i.e. setday even if you have provided the values via parameterized
constructor.
8. Now it’s time to call checkDate and display method with object you have created in
step 6 of part 3.
9. In this step you have to create the object which will take a date object as a
parameter. After creating this object do the following:
a. Use the copyDate method (point 11 part 2) to assign the date members’ values
of date object which you have passed as parameter at the time of creation of
object to current date object’s data members.
b. After assigning the values if you want to change the values you can always call
the setter method i.e. setday
c. Now at the end make sure to call checkDate and display methods with this
object.
10. Call the destructors for all four Date objects.
11. Zip your program with your group number and upload on your Student Portal.

----------Good Luck----------

You might also like