我现在在线搜索了大约两个小时,我无法弄清楚这段代码有什么问题。我收到了这个错误。
1> DateAssignment.obj:错误LNK2019:未解析的外部符号" public:void __thiscall DayCalculator :: getDate(void)" (?getDate @ DayCalculator @@ QAEXXZ)在函数_main中引用 1> DateAssignment.obj:错误LNK2019:未解析的外部符号" public:void __thiscall DayCalculator :: print(void)" (?print @ DayCalculator @@ QAEXXZ)在函数_main
中引用-DayCalculator.h -
#pragma once
using namespace std;
class DayCalculator
{
public:
void getDate();
bool checkLeapYear();
int calcDayOfYear();
void print();
};
-DateAssignment.cpp -
#include "stdafx.h"
#include "DayCalculator.h"
DayCalculator DayCalc;
int main(int argc, char* argv[])
{
DayCalc.getDate();
DayCalc.print();
return 0;
}
-DayCalculator.cpp -
#include "stdafx.h"
#include "DayCalculator.h"
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string date = "01-01-0001";
int day, month, year;
/*
* - Get an int input in the form dd-mm-yyyy and break the string into three substrings
*day, month, and year.
* - Local string 's' is used temporarily to hold substrings of the input as stringstream
*is used to convert them into integers.
*/
void getDate()
{
string s;
cout << "Enter the date in the form dd-mm-yyyy(including dashes and zeros): ";
cin >> date;
s = date.substr(0,1);
stringstream(s) >> day;
s = date.substr(3,4);
stringstream(s) >> month;
s = date.substr(6,9);
stringstream(s) >> year;
}
/*
* - Check if the specified year is a leap year, if so, February has 29 days as opposed to 28.
*/
bool checkLeapYear()
{
if(year%4 == 0 && year%100 != 0)
return true;
else
return false;
}
/*
* - Calculate the number of days in each month of the specified year.
*/
int calcDayOfYear()
{
int dayOfYear;
switch(month)
{
case 1:
dayOfYear = day;
break;
case 2:
dayOfYear = day + 31;
break;
case 3:
dayOfYear = day + 59;
break;
case 4:
dayOfYear = day + 90;
break;
case 5:
dayOfYear = day + 120;
break;
case 6:
dayOfYear = day + 151;
break;
case 7:
dayOfYear = day + 181;
break;
case 8:
dayOfYear = day + 212;
break;
case 9:
dayOfYear = day + 243;
break;
case 10:
dayOfYear = day + 273;
break;
case 11:
dayOfYear = day + 304;
break;
case 12:
dayOfYear = day + 334;
break;
default:
dayOfYear = -1;
break;
}
if(dayOfYear < 0 || dayOfYear > 366)
{
return -1;
}
else if(dayOfYear > 59 && checkLeapYear() == true)
{
if(dayOfYear == 60 && month == 2)
return 60;
else
return dayOfYear+1;
}
else
return day;
}
/*
* - Output in the form ddd.
*/
void print()
{
cout << "The day is " + calcDayOfYear();
}