此程序的目标是取1到365之间的整数并将其转换为月和日。防爆。 2 = 1月2日,365 = 12月31日。我以为我把所有内容都输入正确,我在正确的轨道上,但现在我有16个错误来自我的头文件中的12-14行,并且1个错误来自我的类文件。
我不确定它是否真的是标题,或者我是否在其他地方搞砸了。
HEADER FILE
#ifndef DAYOFYEAR_H
#define DAYOFYEAR_H
class DayOfYear
{
private:
int day;
public:
DayOfYear();
static int daysAtEndOfMonth[];
static string monthName[];
void print();
void setDay(int day) { this->day = day; };
};
#endif
类
#include "DayOfYear.h"
#include <iostream>
#include <string>
using namespace std;
DayOfYear::DayOfYear() {
}
int DayOfYear::daysAtEndOfMonth[] = {
31, 59, 90,
120, 151, 181,
212, 243, 273,
304, 334, 365
};
string DayOfYear::monthName[] = { "January", "February",
"March", "April",
"May", "June"
"July", "August",
"September", "October",
"November", "December"
};
void DayOfYear::print() {
int month = 0;
while (daysAtEndOfMonth[month] < day)
month = (month + 1) % 12;
if (month == 0) {
cout << "\nJanuary" << day << endl << endl;
}
else
{
cout << endl << monthName[month] << " " << day - daysAtEndOfMonth[month - 1]
<< "\n\n";
};
};
主要
#include <iostream>
#include <string>
#include "DayOfYear.h"
using namespace std;
int main() {
int day;
DayOfYear DayOfYearObj;
cout << "This program will convert an integer between 1 and 365 to a Month/Day format"
<< endl << endl;
cout << "Please enter an integer from 1 to 365:";
cin >> day;
//set day
DayOfYearObj.setDay(day);
//display
DayOfYearObj.print();
return 0;
}
答案 0 :(得分:2)
您的头文件需要excelApp.DisplayAlerts = false;
workBook = (Microsoft.Office.Interop.Excel._Workbook)(excelApp.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet));
//DataTable to Excel
foreach(DataTable table in dataSet.Tables)
{
workSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelApp.Worksheets.Add(Missing.Value, Missing.Value, Missing.Value, Missing.Value);
workSheet.Name = table.TableName;
for (int i = 0; i < table.Columns.Count; i++)
{
workSheet.Cells[1, (i + 1)] = table.Columns[i].ColumnName;
}
for (int i = 0; i < table.Rows.Count; i++)
{
for (int k = 0; k < table.Columns.Count; k++)
{
workSheet.Cells[(i + 2), (k + 1)] = table.Rows[i][k];
}
}
workBook.Worksheets.Add(workSheet);
}
//Trying to delete empty sheets
foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in workBook.Sheets)
{
excelApp.DisplayAlerts = false;
if (sheet.Cells.MaxRow == -1 && sheet.Cells.MaxColumn == -1)
{
sheet.Delete();
}
}
,您必须在头文件中引用#include <string>
。
(在{+ 1}}中,在C ++文件中使用std::string
已经足够糟糕了,它在头文件中更糟糕了 - 它将整个std命名空间带入< em>包含标题的每个文件。只需说不!)
其他评论:
using namespace std;
和daysAtEndOfMonth
应为monthName
。