Hey guys have this program t it seems to have two errors and I couldn\'t fix the
ID: 3558313 • Letter: H
Question
Hey guys have this program t it seems to have two errors and I couldn't fix them. I need Your help please!
Here's the program,
//Header file dateType.h
int tmain(int argc, char** argv);
#include "stdafx.h"
#ifndef H_dateType
#define H_dateType
//Header file section
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
//Declare class name
class dateType
{
//Declare variables
public:
void setDate ( const int, const int, const int ) ;
void setMonth( const int month );
void setDay( const int day );
void setYear ( const int year ) ;
void getDate( int& month, int& day, int& year );
int getDay() const;
int getMonth() const;
int getYear()const;
int getDayslnMonth () const;
int getDaysPassed () const;
int getDaysRemaining () const;
void addDays ();
bool isLeapYear() const;
void printDate ()const;
dateType (int month = 1, int day = 1, int year = 1900);
private:
int dMonth;
int dDay;
int dYear;
}; // End class definition dateType
#endif
//Start function setDate
void dateType::setDate( const int month, const int day,
const int year )
{
setYear ( year ) ;
setMonth( month );
setDay( day );
}// End function setDate
//Start function setMonth
void dateType::setMonth( const int month )
{
//Check for validity of the month and assign
if ( month >=1 && month <=12 )
dMonth = month;
else
dMonth = 1;
}//End function setMonth
//Start. function setDay
void dateType::setDay( const int day )
{
int days[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31,
30, 31, 30, 31 };
//Check if it is leap year or not
if ( isLeapYear() )
days[ 1 ]++;
// Check for validity of the day and assign
if ( day >= 1 && day <= days[ dMonth - 1 ] )
dDay = day;
else
dDay = 1;
}//End function setbay
//Start function setYear
void dateType::setYear( const int year )
{
//Get the current date
char dateStr[ 9 ];
_strdate_s( dateStr);
//Extract year from the date
int thisYear = 2000 + (dateStr[ 6 ] - 48 ) * 10
+ dateStr[ 7 ] - 48;
//Check for validity of the year and assign
if ( ( year >= 1900 ) && ( year <= thisYear ) )
dYear=year;
else
dYear = 1900;
} // End function setYear
//Start function getDate
void dateType::getDate( int & month, int & day, int & year )
{
month = dMonth;
day = dDay;
year = dYear;
} //End function getDate
//Start function getDay
int dateType:: getDay () const
{
return dDay;
} //End function getDay
//Start function getMonth
int dateType::getMonth()const
{
return dMonth;
} //End function getMonth
//Start function getYear
int dateType:: getYear () const
{
return dYear;
} //End function getYear
//Start function getDayslnflonth
int dateType:: getDayslnMonth()const
{
int days[ 12 ] = { 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
if ( isLeapYear() )
days[ 1 ]++;
return days[ dMonth - 1 ];
} //End function getDayslnNonth
//Start function getDaysPassed
int dateType::getDaysPassed () const
{
int days[ 12 ] ={ 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
if ( isLeapYear() )
days[ 1 ]++;
int m = dMonth-1;
int daysPassed = 0;
while ( m> 0 )
{
daysPassed += days[ m - 1 ];
m--;
} //End while
daysPassed += dDay;
return daysPassed;
} //End function getDaysPassed
//Start function getDaysRemaining
int dateType:: getDaysRemaining () const
{
int daysRemaining = 365;
if ( isLeapYear() )
daysRemaining++;
daysRemaining -= getDaysPassed ();
return daysRemaining;
} //End function getDaysRemained
//Start function addDays
void dateType:: addDays ()
{
int d;
//Prompt and read the input from the user
cout << " Enter number of days to be added : ";
cin >> d;
while ( d > 0 )
{
//Add the days in case days are less
if ( d <= ( getDayslnMonth() - dDay ) )
{
dDay += d;
break;
}//End if
// add the days read from user to the date by subtracting days and advancing to next month
d -= getDayslnMonth() - dDay;
dDay = 0;
//Advance to next mont
dMonth++;
// check for advancement of an year
if ( dMonth > 12 )
{
dMonth = 1;
dYear++;
} //End if
} //End while
} //End function addDays
//Start function printDate
void dateType::printDate()const
{
cout <<" "<<dMonth << "-" << dDay << "-" <<dYear;
} //End function printDate
//Start constructor dateType
dateType::dateType( int month, int day, int year )
{
setDate ( month, day, year );
} //End constructor dateType
bool dateType::isLeapYear() const
{
//check for the leap year and print the result
if ( dYear % 400 == 0 ||
( dYear % 100 !=0 && dYear % 4 == 0 ) )
return true;
else
return false;
system("pause");
return 0;
} // end function isLeapYear
and Here Are the errors:
1) Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
-- My subsystem is console not windows but i keep getting this messege.
2) Error 2 error LNK1120: 1 unresolved externals.
-- I'm not sure how to solve this issue.
I really appreciate your Help!!
Explanation / Answer
Corrected and well-indented code : http://ideone.com/ddGsDJ Please ask if you have any more doubts. Do rate soon. Thanks :)