The class dateType in my program was designed to implement the date in a program.
However, the function and constructor don’t check whether the date is valid before storing. … rewrite the definition of the function setDate and constructor so that the values for month, day, year are checked before storing…

I understand the validation would be a display of the entered date so the user can verify it is correct.

We are also asked to add a function member isLeapYear, to check if the year is a leap year.

I will use the function for leap year test
(year % 400 = = 0 || (year % 100! = =0 && year % 4 = =0)).

This is what I understand of simple class
class dateType
{
//THE CONSTRUCTOR

public:
dateType();
dateType(int newMonth, int newDay, int newYear);

// get methods
int getYear() const;
int getMonth() const;
int getDay() const;

private:
int year;
int month;
int day;
};

1. Does this declare a data type or variable?
2. What is public/private (I understand access control, but not understanding the benefits of using private)?
3. I understand const = = constant, but don’t understand the results of using ?
4. Is there a difference between a class declaration and definition?

Thanks for your help

Danni

I understand the validation would be a display of the entered date so the user can verify it is correct.

That's probably not a good assumption. More likely is that you're required to programmatically evaluate the date and determine if it's valid.

1. Does this declare a data type or variable?

A class definition introduces a data type.

2. What is public/private (I understand access control, but not understanding the benefits of using private)?

Then you don't understand access control. Think of it like this: the bank doesn't let you log into their system with full access because there's high risk of either someone breaking all kinds of stuff accidentally, or doing unscrupulous things like adding a few zeros to the end of their balance. You should have similar concerns with the classes you write.

3. I understand const = = constant, but don’t understand the results of using ?

It's another form of access control, except at the code level. const is a way of protecting yourself by disabling write access to an object.

4. Is there a difference between a class declaration and definition?

Yes. A class declaration only brings the name of a class into scope. A definition, on the other hand, provides enough information for objects to be created and used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.