The code works, I just want to see if someone can help me cut lines in main only.
#include <iostream>
#include <sstream>
#include <windows.h>
#include <time.h>
#include <string>
using namespace std;
struct tm * timeinfo; // Holds information about time in form of struct
class Date
{
public:
int m_nMonth;
int m_nDay;
int m_nYear;
// Allocate function
void setDate(int nMonth, int nDay, int nYear)
{
m_nMonth = nMonth;
m_nDay = nDay;
m_nYear = nYear;
}
// Display function
void displayDate()
{
cout << "Today's Date is: "
<< m_nMonth << "/"
<< m_nDay << "/"
<< m_nYear << endl;
}
};
int main()
{
Date cTodayDate; // Variable for class
time_t rawtime; // Variable of type time_t
string strMonth, strDay, strYear, dateTime; // Variables to hold strings
int nMonth, nDay, nYear; // Variables to hold actual
// numeric values
// Getting time from system
time ( &rawtime );
timeinfo = localtime ( &rawtime );
// Making timeinfo from struct to string:: Www Mmm dd hh:mm:ss yyyy
dateTime = asctime (timeinfo);
// Break down to get Month
strMonth.append(dateTime,4,3);
if(strMonth.compare("Jan") == 0)
nMonth = 1;
else if(strMonth.compare("Feb") == 0)
nMonth = 2;
else if(strMonth.compare("Mar") == 0)
nMonth = 3;
else if(strMonth.compare("Apr") == 0)
nMonth = 4;
else if(strMonth.compare("May") == 0)
nMonth = 5;
else if(strMonth.compare("Jun") == 0)
nMonth = 6;
else if(strMonth.compare("Jul") == 0)
nMonth = 7;
else if(strMonth.compare("Aug") == 0)
nMonth = 8;
else if(strMonth.compare("Sep") == 0)
nMonth = 9;
else if(strMonth.compare("Oct") == 0)
nMonth = 10;
else if(strMonth.compare("Nov") == 0)
nMonth = 11;
else if(strMonth.compare("Dec") == 0)
nMonth = 12;
else cout << "Error." << endl;
// Break down to get Day
strDay.append(dateTime,8,2);
istringstream ( strDay ) >> nDay;
// Break down to get Year
strYear.append(dateTime,20,4);
istringstream ( strYear ) >> nYear;
// Allocate in class
cTodayDate.setDate(nMonth, nDay, nYear);
// Display in class
cTodayDate.displayDate();
// Display for 4 seconds
Sleep(4000);
return 0;
}