Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this problem from my c++ class and I need the answer in three source code

ID: 3667780 • Letter: I

Question

I have this problem from my c++ class and I need the answer in three source code:

"logbook.h" "logbook.cpp" "main.cpp"

The purpose of this homework is for you to explore how you can use C++ classes to implement an abstract data type (ADT). We use a monthly logbook as our example abstract data type. A monthly logbook consists of a set of entries, one for each day of the month. Depending on the logbook, these entries might denote a business’s daily receipts, the amount of time a person spent exercising, the number of cups of coffee consumed, and so forth. A typical logbook is shown below.         

           

The following is the definition of Logbook ADT.

Data Items

A set of integer values.

Structure

Each integer value is the logbook entry for a given day of the month. The number of logbook entries varies depending on the month for which data is being recorded. We will refer to this month as the logbook month.

Operations

Logbook ( int month, int year ) Requirements:

Month must specify a valid month.

Results:

Constructor. Creates an empty logbook for the specified month—that is, a logbook in which all the entries are zero.

void putEntry ( int day, int value ) Requirements:

Day is within the range of days in the logbook month.

Results:

Stores the value as the logbook entry for the specified day.

int getEntry ( int day ) Requirements:

Day is within the range of days in the logbook month.

Results:

Returns the logbook entry for the specified day.

int getMonth () const Requirements:

None

Results:

Returns the logbook month.

int getYear () const Requirements:

None

Results:

Returns the logbook year.

int getDaysInMonth () const Requirements:

None

Results:

Returns the number of days in the logbook month.

void displayCalendar () const Requirements:

Logbook month must occur in a year in the range 1901–2099.

Results:

Outputs a logbook using the calendar format shown below. Note that each calendar entry includes the logbook entry for the corresponding day.

2 / 2003

Sun        Mon      Tue        Wed      Thu        Fri         Sat

100

95 3 90       4 0         5 150     6 94       7 100     8 105

9 100      10 100 11 50        12 110 13 110 14 100 15 125

16 110 17 0          18 110 19 0         20 125 21 100 22 110

23 115    24 111 25 0        26 50     27 110 28 125

Explanation / Answer

//logbook.cpp

#include<iostream>
#include "logbook.h"
include <time.h>

using namespace std;


// Constructor for current time  

Logbook::Logbook ()        // Creates a logbook
   {

     
       int NumberOfDays;
     
   time_t theTime = time(NULL);
   struct tm *aTime = localtime(&theTime);
       logMonth = aTime->tm_mon + 1; // Month is 0 - 11, add 1 to get a jan-dec 1-12 concept
       logYear = aTime->tm_year + 1900; // Year is # years since 1900

       NumberOfDays= daysInMonth();

       for(int index = 0; index <= NumberOfDays; ++index)
           entry[index]=0;
   }

    // Logbook marking operations
   void Logbook::putEntry ( int day, int value ) // Store entry for day
   {
       if (day <= daysInMonth())               //make sure we're dealing with a valid day
           entry[day] = value;                 //set the value for the day
   }


   int Logbook::getEntry ( int day ) const //returns entry for day
   {
       if (day <= daysInMonth())    //make sure the day is valid
           return entry[day];             //return value          
   }
  

    // General operations
   int Logbook::month () const                     // Return the month
   {
       return logMonth;
   }

   int Logbook::year () const                      // Return the year
   {
       return logYear;
   }

   int Logbook::daysInMonth () const               // Number of days in month
   {
       switch (logMonth)
       {
           //months with 30 days
           case 4:
           case 6:
           case 9:
           case 11: return 30;
           break;

           //months with 31 days
           case 1:
           case 3:
           case 5:
           case 7:
           case 8:
           case 10:
           case 12: return 31;
           break;

           //month of February
           case 2: if (logYear %100 ==0)
                       if (logYear % 400 ==0)
                           return 29;
                       return 28;
      
       }//end switch

   }

    // In-lab operations
   void Logbook::displayCalendar () const          // Display as calendar
    {
       int c, d;                        //loop counter and day variables

       //display month and year
       cout << " " << logMonth << " / " << logYear << endl << endl;

       //display days of the week
       cout << "Sun      Mon      Tue      Wed      Thu      Fri      Sat ";

       for (c = 0; c < dayOfWeek(1); c++) //blank in the first row until
           cout << "         ";       //the first of the month

       for (c = 0; c < daysInMonth(); c++) //go through the days
       {
           if (c < 9)
               cout << " ";       //if it is a single digit pad with a blank space

           d = entry[c];
           cout << ( c + 1) << " " << d;    //display date, entry

           if
               (d == 0)
                   d = 1;              //d wouldn't ever surpass zero
           for (; d < 10000; d *= 10)      //pad with space until d is 6 digits long
               cout << " ";

           cout << " ";                //spacing
           if (dayOfWeek (c + 1) ==6)      //when Saturday is reached endline
               cout << endl;
       }

   }

   void Logbook::putEntry ( int value ) // Store entry for today
   {
   }
  
   int Logbook::operator [] ( int day ) const      // Return entry for day
   {
           return getEntry(day);
   }
  
   void Logbook::operator += ( const Logbook &rightLogbook ) //combine logbooks
   {
      
       int NumberOfDays= daysInMonth();
       if ((rightLogbook.daysInMonth() == NumberOfDays) &&
       (logMonth == rightLogbook.logMonth));
       {
       int i = 0;
      
      

       for(int index = 0; index <= NumberOfDays; ++index)
           entry[index]=0;
       }
   }

    // Facilitator (helper) function
   int Logbook::leapYear () const                  // Leap year?
   {
        if( logYear % 400 ==0 || ( logYear % 100 != 0 && logYear % 4 == 0))
           return 1;
       else return 0;
   }

    // In-lab facilitator function
   int Logbook::dayOfWeek ( int day ) const        // Return day of the week
   {
       int dayCount = 1;                  //counter of days since 1901
       int i;

       dayCount +=(logYear - 1901);         //add the years since 1901

       for (i = 1901; i < logYear; i++)      //add leapyears since 1901
           dayCount += (i %4 == 0 && i %100 != 0 || i %400 == 0)?1:0;

       //fix
       for (i = 1; i < logMonth; i++)        //add the days to month
           dayCount += daysInMonth();

       if (logMonth > 2 && leapYear())     //add for a leapyear
           dayCount++;

       dayCount += day;                          //add the days

       dayCount %= 7;

       return int (dayCount);          //return the day of the week

   }

   int main()
{
   return 0;
}

//logbook.h

#ifndef LOGBOOK_H
#define LOGBOOK_H
class Logbook
{
public:

    // Constructor
    Logbook ( int month, int year );        // Create a logbook

    // Logbook marking operations
    void putEntry ( int day, int value );   // Store entry for day
    int getEntry ( int day ) const;         // Return entry for day

    // General operations
    int month () const;                     // Return the month
    int year () const;                      // Return the year
    int daysInMonth () const;               // Number of days in month

    // In-lab operations
    void displayCalendar () const;          // Display as calendar
    Logbook ();                             // Default constructor
    void putEntry ( int value );            // Store entry for today
    int operator [] ( int day ) const;      // Return entry for day
    void operator += ( const Logbook &rightLogbook );
                                            // Combine logbooks
private:

    // Facilitator (helper) function
    int leapYear () const;                  // Leap year?

    // In-lab facilitator function
    int dayOfWeek ( int day ) const;        // Return day of the week

    // Data members
    int logMonth,     // Month covered by logbook
        logYear,
        entry [32];   // Logbook entries
};
#endif