I seem to be having a validation error I believe with my code. The application is supposed to create a Date instance based on whether the inputs are valid. Here is the code files.
class Date
{
private:
string month;
int day;
int year;
bool isValidMonth(string);
bool isValidYear(int);
bool isValidDay(int);
public:
Date(string&,int& ,int&); // constructor
void getDate();
};
This is the test.cpp where the main function is located and the call are happening. this file is not yet complete due to the inconsistencies in my Date.cpp, I choose not to move on into it.
include <iostream>
using namespace std;
#include "Date.h"
#include <string>
#include <algorithm>
void setDateValues(string&, int&, int&);
int main()
{
string mth;
int day, yr;
setDateValues(mth, day, yr);
Date D1(mth, day, yr);
cout << "Date is:\n";
D1.getDate();
This is my Date.cpp file where the class implementation
int dayscount = 0; //global to save index of month match
Date::Date(string& newmonth, int& newday, int& newyear) //my constructor
{
if (isValidMonth(newmonth))
{
if (isValidDay(newday))
{
if (isValidYear(newyear))
{
month = newmonth;
day = newday;
year = newyear;
}
}
}
else
month = monthStr[0];
day = 1;
year = 2001;
}
//working on getting the three validation functions
//need to create the print function
// mdy1, mdy2, ymd1, ymd2
void Date::getDate() //pass an arguement that indicates the desired format
{
cout << month << "/" << day << "/" << year << endl;
}
bool Date::isValidMonth(string inputmonth)
{
for (int x = 0; x <= 11; x++)
if (inputmonth.compare(monthStrAbbrev[x])==0)
{
dayscount = x;
return true;
}
else
return false;
}
bool Date::isValidDay(int d)
{
if (d < 0 || d > monthDays[dayscount])
return false;
else
return true;
}
bool Date::isValidYear(int y)
{
if (y < MIN_YEAR || y > MAX_YEAR)
return false;
else
return true;
}