Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please,Need to build a c++ program using visual studio Using DateClassDriver.txt

ID: 3711086 • Letter: P

Question

Please,Need to build a c++ program using visual studio Using DateClassDriver.txt and DateHeader.txt . The specifications are on the picture. Thank you!

DateClassDriver.txt
// DateClass.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "Date.h" #include <iostream>
using namespace std;
int main() { Date date01; // create with default constructor Date date02(24, 33, 93); // invalid month and day values Date date03(9, 17, -51); // invalid year value Date date04(12, 25, 14); // 2000 year range - 2014 Date date05(10, 31, 31); // 1900 year range - 1931 Date date06(4, 31, 11); // invalid day value for April Date date07(2, 29, 3); // 2003 is not a leap year Date date08(2, 29, 1900); // 1900 is not a leap year Date date09(2, 29, 2000); // 2000 is a leap year Date* date10; // pointer to Date class type
cout << endl;
date01.displayDate(); date02.displayDate(); date03.displayDate(); date04.displayDate(); date05.displayDate(); date06.displayDate(); date07.displayDate(); date08.displayDate(); date09.displayDate();
date10 = new Date(2, 29, 2004); // create new instance of Date class date10->displayDate(); // display function for class referenced with class pointer ->
date01.setDate(2, 29, 12); date01.displayDate();
date01.setDate(2, 29, 11); date01.displayDate();
date01.setDate(11, 30, 14); date01.displayDate();
cout << endl; system("pause"); return 0; }

DateHeader. Txt #pragma once
class Date { public: // public member functions Date(); // default constructor (no parameters) Date(int, int, int); // constructor with month day year parameters - check for validity
void setDate(int mm, int dd, int yyyy); void Date::setDefaultDate(); // set month day year values to default date ( 1/01/1970)
int getMonth() const; // return current month value int getDay() const; // return current day value int getYear() const; // return current 4-digit year value
void displayDate() const; // display current date value in mm/dd/yyyy format
private: // private data members bool validMonth() const; // check for valid month range bool validDay() const; // check for valid day range bool validYear(); // check for valid year value (must be >= zero) bool validDate(); // check for valid month, day, and year
int month; // current month value int day; // current day value int year; // current year value }; #pragma once
class Date { public: // public member functions Date(); // default constructor (no parameters) Date(int, int, int); // constructor with month day year parameters - check for validity
void setDate(int mm, int dd, int yyyy); void Date::setDefaultDate(); // set month day year values to default date ( 1/01/1970)
int getMonth() const; // return current month value int getDay() const; // return current day value int getYear() const; // return current 4-digit year value
void displayDate() const; // display current date value in mm/dd/yyyy format
private: // private data members bool validMonth() const; // check for valid month range bool validDay() const; // check for valid day range bool validYear(); // check for valid year value (must be >= zero) bool validDate(); // check for valid month, day, and year
int month; // current month value int day; // current day value int year; // current year value };

Explanation / Answer

//Application Date Program

//#include "stdafx.h"

//#include "Date.h"

#include <iostream>

#include <map>

#include <sstream>

using namespace std;

//DateHeader. Txt

//#pragma once

class Date

{

public: // public member functions

Date(); // default constructor (no parameters)

Date(int, int, int); // constructor with month day year parameters - check for validity

void setDate(int mm, int dd, int yyyy);

void setDefaultDate(); // set month day year values to default date ( 1/01/1970)

int getMonth() const; // return current month value

int getDay() const; // return current day value

int getYear() const; // return current 4-digit year value

void displayDate(); // display current date value in mm/dd/yyyy format

private:

// private data members

bool validMonth() const; // check for valid month range

bool validDay() const; // check for valid day range

bool validYear(); // check for valid year value (must be >= zero)

bool validDate(); // check for valid month, day, and year

int month; // current month value

int day; // current day value

int year; // current year value

};

Date :: Date()

{

month = 1;

day=01;

year=1970;

}

Date :: Date(int lmonth,int lday ,int lyear)

{

month = lmonth;

day = lday;

year=lyear;

}

void Date :: setDate(int mm, int dd, int yyyy)

{

month = mm;

day = dd;

year=yyyy;

}

void Date ::setDefaultDate() // set month day year values to default date ( 1/01/1970)

{

month = 1;

day=01;

year=1970;

  

}

int Date :: getMonth() const // return current month value

{

return month;

}

int Date ::getDay() const // return current day value

{

return day;

}

int Date ::getYear() const // return current 4-digit year value

{

return year;

}

void Date ::displayDate() // display current date value in mm/dd/yyyy format

{

stringstream ss;

ss << getYear();

string str="20";

if(getYear() <= 99 && getYear() > 0)

str += ss.str();

else

str = ss.str();

  

string error="";   

if(!validMonth() )

error = "Invalid month value ";

  

if(!validDay())

{

if(error != "")

error += "and day value";

else

error = "Invalid day value ";

}

  

if(!validYear())

{

if(error != "")

error += "and year value ";

else

error = "Invalid year value";

}

  

if(validDate())

cout << getMonth() << "/" <<getDay() << "/"<<str <<endl;

else

cout << error << endl;

/* else if(!getMonth() && !getDay() && !getYear())

{

cout << "Invalide month value and day "<<endl;

}

  

*/   

}

bool Date :: validMonth() const // check for valid month range

{

if(month >=1 && month <=12)

{

return true;

}

return false;

}

bool Date :: validDay() const // check for valid day range

{

  

map<int,int> daymap;

daymap[1]=31;

daymap[3]=31;

daymap[4]=30;

daymap[5]=31;

daymap[6]=30;

daymap[7]=31;

daymap[8]=31;

daymap[9]=30;

daymap[10]=31;

daymap[11]=30;

daymap[12]=31;

  

if(month == 2 && (year%4 == 0))

{

daymap[2]=29;

}

else

{

daymap[2]=28;

}

  

if(daymap[month] < day)

return false;

  

return true;

  

}

bool Date :: validYear() // check for valid year value (must be >= zero)

{

if(year <= 0)

return false;

return true;

}

bool Date ::validDate() // check for valid month, day, and year

{

if(validYear() && validDay() && validMonth())

return true;

return false;

}

int main()

{

Date date01; // create with default constructor

cout << "Date value "<<endl;

Date date02(24, 33, 93); // invalid month and day values

Date date03(9, 17, -51); // invalid year value

Date date04(12, 25, 14); // 2000 year range - 2014

Date date05(10, 31, 31); // 1900 year range - 1931

Date date06(4, 31, 11); // invalid day value for April

Date date07(2, 29, 3); // 2003 is not a leap year

Date date08(2, 29, 1900); // 1900 is not a leap year

Date date09(2, 29, 2000); // 2000 is a leap year

Date* date10; // pointer to Date class type

cout << endl;

date01.displayDate();

date02.displayDate();

date03.displayDate();

date04.displayDate();

date05.displayDate();

date06.displayDate();

date07.displayDate();

date08.displayDate();

date09.displayDate();

date10 = new Date(2, 29, 2004); // create new instance of Date class

date10->displayDate(); // display function for class referenced with class pointer ->

date01.setDate(2, 29, 12);

date01.displayDate();

date01.setDate(2, 29, 11);

date01.displayDate();

date01.setDate(11, 30, 14);

date01.displayDate();

  

cout << endl;

system("pause");

return 0;

}