I am having to write a program that has a user-defined class. In this program I need to convert an INT to a STRING. For example, if the program reads in the date "7/17/2009" it will need to be converted to "July 17, 2009", where all it does is take the month's number value and change it to the string equivalant.
Can somebody help me with the INT to STRING conversion? I can't quite grasp it.
Here is what I have thus far for the implementation of my class:
#include "testerResult.h"
#include <iostream>
#include <string>
using namespace std;
Date::Date()
{
month = 1;
day = 1;
year = 1800;
}
Date::Date(int m, int d, int y)
{
}
Date::Date(string m, int d, int y)
{
Date::convertMonthNumberToString(month);
month = m;
day = d;
year = y;
}
int Date::compareDates()
{
return 0;
}
string Date::convertMonthNumberToString(int month)
{
switch (month)
{
case 1: return "January";
case 2: return "February";
case 3: return "March";
case 4: return "April";
case 5: return "May";
case 6: return "June";
case 7: return "July";
case 8: return "August";
case 9: return "September";
case 10: return "October";
case 11: return "November";
case 12: return "December";
}
}
int Date::dayNumber()
{
return 0;
}
void Date::displayDate()
{
}
void Date::increment()
{
}
void Date::isLeapYear()
{
if((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
{
cout << "This is a Leap Year." << endl;
}
else
{
cout << "This is not a Leap Year." << endl;
}
}
void Date::isValidDate()
{
int d = 0;
int m = 0;
int y = 0;
if (d < 1 || d > 31)
{
cout << "Invalid Date." << endl;
}
else if (m < 1 || m > 12)
{
cout << "Invalid Date." << endl;
}
else if (y < 1800 || y > 2100)
{
cout << "Invalid Date." << endl;
}
else
{
cout << "Valid Date." << endl;
}
}
void Date::setDate(int m, int d, int y)
{
if(m < 1 || m >12) return;
month = m;
cout << m;
if(d < 1 || d > 31) return;
day = d;
cout << d;
if(y < 1800 || y > 2100) return;
year = y;
cout << y;
}
int Date::getDay() const
{
return day;
}
int Date::getMonth() const
{
return month;
}
int Date::getYear() const
{
return year;
}
int Date::getDate() const
{
return month;
return day;
return year;
}
I know this code is full of errors. I just need assistance with the 'convertMonthNumberToString' function.