0

I need help with this assignment. I got some done for the input validation but im having problems to understand classes. Ill provide the code below.

Design a class called Date that has integer data members to store month, day, and year.
The class should have a three-parameter default constructor that allows the date to be set
at the time a new Date object is created. If the user creates a Date object without passing
any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001
(i.e., January 1, 2001) should be used. The class should have member functions to print the
date in the following formats:
3/15/10
March 15, 2010
15 March 2010
Demonstrate the class by writing a program that uses it.
Input Validation: Only accept values between 1 and 12 for the month, between 1 and
31 for the day, and between 1950 and 2020 for the year.

#include <iostream>
 #include <cmath>
 using namespace std;


 class date
 {  private:
       int day;
	private:
       int month;
	private:
       int year;

  
};

 int main()
 {
	 int day;
	 int month;
	 int year;

    cout<< "Please enter a day from 1-31"<< endl;
	cin>> day;
	if ((day < 1) || (day > 31))
	{
		day = 1;

	}

	cout<< "Please enter a month from 1 - 12"<< endl;
	cin>> month;
	if ((month < 1 ) || (month > 12));{
		month = 1;	}
	cout<< "Please enter a year from 1950 -2020"<< endl;
	cin>> year;

	if ((year < 1950) || (year > 2020)){
		year = 2001;


	}          
  
    

   system("pause");

   return 0;
   
 }
2
Contributors
1
Reply
17
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
0

First of all you don't have to repeat private before each object. The access modifier is good until you change it to something else

class date
 {
  private:
       int day;
       int month;
       int year;
};

Next, you need to provide the three public constructors that are in your assignment.

You will also have to give the class public set/put methods so that the day,month and year can be changed outside the class.

Add a public method to print the date in the specified formats.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.