This is for a class. Two of the files are provided, and I need to write the third.
I'm having trouble with a constructor in a class. The constructor is called with 'Logbook testLog(month,year)' and it saves the month and year correctly. The daysInMonth function works fine.
My problem is this: when I enter a value with the putEntry function, the days that are set to 0 only go up to the month's day. If the month is two, day one and two have a value of 0, and the rest are junk (something like 21345, I think the memory address.) I THINK it is the "Logbook::Logbook (int month, int year)" function, but I'm going to try something else as well.
#include "logbook.h"
#include <windows.h>
Logbook::Logbook ()
// Constructs an empty logbook for the specified month.
{
SYSTEMTIME st;
logMonth = st.wMonth;
logYear = st.wYear;
for (int day = 1 ; day <= daysInMonth() ; day++)
{
entry[day] = 0;
}
}
Logbook::Logbook (int month, int year)
// Constructs an empty logbook for the specified month.
{
logMonth = month;
logYear = year;
// make sure real month/year
int MAXDay = daysInMonth();
for ( day = 1 ; day <= daysInMonth() ; day++ )
{
entry[day] = 0;
}
}
incomplete for space... here is the rest of the code.
void Logbook::putEntry ( int day, int value )
int Logbook::getEntry ( int day ) const
int Logbook::month () const
int Logbook::year () const
int Logbook::operator [] ( int day ) const
void Logbook::operator += ( const Logbook &rightLogbook )
int Logbook::daysInMonth () const
If you need more code, please tell!
(I understand the concept of a class, but I think I'm missing something.)