473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help! -Logbook ADT -This is due Monday (Missed a day due to sickness) OOP

I get 27 errors when I try to compile, none of which make sense to me, since the code looks good. I have my header file included, and all of my function definitions are in the class contained in the header. You can see an assignment sheet here .
I am not looking for someone to do it for me, but rather someone to point out the error causing code...This program is supposed to do what is described in the sheet linked above. And now for the code...

Logbook.cpp (The only source I am supposed to edit):
Expand|Select|Wrap|Line Numbers
  1. //Logbook.cpp
  2.  
  3. #include <iostream>
  4. #include "logbook.h"
  5. #include <windows.h>
  6.  
  7. void main()
  8. {
  9.    // Constructor for current time
  10.     Logbook::Logbook ()        // Creates a logbook
  11.     {
  12.  
  13.     SYSTEMTIME st; //structure to hold the system date
  14.     int NumberOfDays;
  15.     GetSystemTime (&st); //pull system date    
  16.  
  17.     logMonth = st.wMonth;
  18.     logYear = st.wYear;
  19.  
  20.     NumberOfDays= daysInMonth();
  21.  
  22.         for(int index = 0; index <= NumberOfDays; ++index)
  23.             entry[index]=0;
  24.     }
  25.  
  26.     //constructor for specific time
  27.     Logbook::Logbook ( int month, int year )
  28.     {
  29.         logMonth = month;
  30.         logYear = year;
  31.  
  32.         for(int index = 0; index <= NumberOfDays; ++index)
  33.             entry[index]=0;
  34.     }
  35.  
  36.     // Logbook marking operations
  37.     void Logbook::putEntry ( int day, int value ) // Store entry for day
  38.     {
  39.     if (day <= daysInMonth())               //make sure we're dealing with a valid day
  40.         entry[day] = value;                 //set the value for the day
  41.     }
  42.  
  43.  
  44.     int Logbook::getEntry ( int day ) const //returns entry for day
  45.     {
  46.         if (day <= daysInMonth())    //make sure the day is valid
  47.             return entry[day];             //return value            
  48.     }
  49.  
  50.  
  51.     // General operations
  52.     int Logbook::month () const                     // Return the month
  53.     {
  54.         return logMonth;
  55.     }
  56.  
  57.     int Logbook::year () const                      // Return the year
  58.     {
  59.         return logYear;
  60.     }
  61.  
  62.     int Logbook::daysInMonth () const               // Number of days in month
  63.     {
  64.         switch (logMonth)
  65.         {
  66.             //months with 30 days
  67.             case 4:
  68.             case 6:
  69.             case 9:
  70.             case 11: return 30;
  71.             break;
  72.  
  73.             //months with 31 days
  74.             case 1: 
  75.             case 3:
  76.             case 5:
  77.             case 6:
  78.             case 8:
  79.             case 19: return 31;
  80.             break;
  81.  
  82.             //month of February
  83.             case 2: if (logYear %100 ==0) 
  84.                         if (logYear % 400 ==0)
  85.                             return 29;
  86.                         return 28;
  87.  
  88.         }//end switch
  89.  
  90.     }
  91.  
  92.     // In-lab operations 
  93.     void Logbook::displayCalendar () const          // Display as calendar
  94.     {
  95.     int c, d;                        //loop counter and day variables
  96.  
  97.     //display month and year
  98.     cout << "\t\t\t  " << logMonth << " / " << logYear << endl << endl;
  99.  
  100.     //display days of the week
  101.     cout << "Sun      Mon      Tue      Wed      Thu      Fri      Sat\n\n";
  102.  
  103.     for (c = 0; c < dayOfWeek(1); c++) //blank in the first row until
  104.         cout << "         ";       //the first of the month
  105.  
  106.     for (c = 0; c < daysInMonth(); c++) //go through the days
  107.     {
  108.         if (c < 9) 
  109.             cout << " ";       //if it is a single digit pad with a blank space
  110.  
  111.         d = entry[c];
  112.         cout << ( c + 1) << " " << d;    //display date, entry
  113.  
  114.         if 
  115.             (d == 0) 
  116.                 d = 1;              //d wouldn't ever surpass zero
  117.         for (; d < 10000; d *= 10)      //pad with space until d is 6 digits long
  118.             cout << " ";
  119.  
  120.         cout << " ";                //spacing
  121.         if (dayOfWeek (c + 1) ==6)      //when Saturday is reached endline
  122.             cout << endl;
  123.     }
  124.  
  125.     }
  126.     void Logbook::putEntry ( int value )            // Store entry for today
  127.  
  128.         int Logbook::operator [] ( int day ) const      // Return entry for day
  129.     {
  130.             return getEntry(day);
  131.     }
  132.  
  133.     void operator += ( const Logbook &rightLogbook ) //combine logbooks
  134.     {
  135.         for (int i = 0; i < 32; i++)           //go through and add each entry
  136.         entry[i] += rightLogbook.entry[i];
  137.     }
  138.  
  139.  
  140.     // Facilitator (helper) function
  141.     int Logbook::leapYear () const                  // Leap year?
  142.     {
  143.         if( logYear % 400 ==0 || ( logYear % 100 != 0 && logYear % 4 == 0))
  144.             return 1;
  145.         else return 0;
  146.     }
  147.  
  148.     // In-lab facilitator function
  149.     int Logbook::dayOfWeek ( int day ) const        // Return day of the week
  150.     {
  151.         int dayCount = 1;                  //counter of days since 1901
  152.         int i;
  153.  
  154.         dayCount += (logYear - 1901);         //add the years since 1901
  155.  
  156.     for (i = 1901; i < logYear; i++)      //add leapyears since 1901
  157.         dayCount += (i %4 == 0 && i %100 != 0 || i %400 == 0)?1:0;
  158.  
  159.     for (i = 1; i < logMonth; i++)        //add the days to month
  160.         dayCount += daysInMonth(i);
  161.  
  162.     if (logMonth > 2 && leapYear())     //add for a leapyear
  163.         dayCount++;
  164.  
  165.     dayCount += day;                          //add the days
  166.  
  167.     dayCount %= 7;
  168.  
  169.     return int (dayCount);          //return the day of the week
  170.  
  171.     }
  172.  
  173. }
logbook.h:
Expand|Select|Wrap|Line Numbers
  1. //--------------------------------------------------------------------
  2. //
  3. //  Laboratory 1                                           logbook.h
  4. //
  5. //  Class declaration for the Logbook ADT
  6. //
  7. //--------------------------------------------------------------------
  8.  
  9. class Logbook
  10. {
  11.   public:
  12.  
  13.     // Constructor
  14.     Logbook ( int month, int year );        // Create a logbook
  15.  
  16.     // Logbook marking operations
  17.     void putEntry ( int day, int value );   // Store entry for day
  18.     int getEntry ( int day ) const;         // Return entry for day
  19.  
  20.     // General operations
  21.     int month () const;                     // Return the month
  22.     int year () const;                      // Return the year
  23.     int daysInMonth () const;               // Number of days in month
  24.  
  25.     // In-lab operations
  26.     void displayCalendar () const;          // Display as calendar
  27.     Logbook ();                             // Default constructor
  28.     void putEntry ( int value );            // Store entry for today
  29.     int operator [] ( int day ) const;      // Return entry for day
  30.     void operator += ( const Logbook &rightLogbook );
  31.                                             // Combine logbooks
  32.   private:
  33.  
  34.     // Facilitator (helper) function
  35.     int leapYear () const;                  // Leap year?
  36.  
  37.     // In-lab facilitator function
  38.     int dayOfWeek ( int day ) const;        // Return day of the week
  39.  
  40.     // Data members
  41.     int logMonth,     // Month covered by logbook
  42.         logYear,
  43.         entry [32];   // Logbook entries
  44. };
Jan 28 '07 #1
8 3307
the errors (I fixed the switch error...but the others I still get):
Expand|Select|Wrap|Line Numbers
  1. ------ Build started: Project: lab1, Configuration: Debug Win32 ------
  2. Compiling...
  3. Logbook.cpp
  4. f:\c projects\112\lab1\logbook.cpp(9) : error C2143: syntax error : missing ';' before '{'
  5. f:\c projects\112\lab1\logbook.cpp(15) : error C2065: 'logMonth' : undeclared identifier
  6. f:\c projects\112\lab1\logbook.cpp(16) : error C2065: 'logYear' : undeclared identifier
  7. f:\c projects\112\lab1\logbook.cpp(18) : error C3861: 'daysInMonth': identifier not found
  8. f:\c projects\112\lab1\logbook.cpp(21) : error C2065: 'entry' : undeclared identifier
  9. f:\c projects\112\lab1\logbook.cpp(25) : error C2144: syntax error : 'int' should be preceded by ')'
  10. f:\c projects\112\lab1\logbook.cpp(25) : error C2059: syntax error : ')'
  11. f:\c projects\112\lab1\logbook.cpp(26) : error C2143: syntax error : missing ';' before '{'
  12. f:\c projects\112\lab1\logbook.cpp(27) : error C2065: 'month' : undeclared identifier
  13. f:\c projects\112\lab1\logbook.cpp(28) : error C2065: 'year' : undeclared identifier
  14. f:\c projects\112\lab1\logbook.cpp(30) : error C2065: 'NumberOfDays' : undeclared identifier
  15. f:\c projects\112\lab1\logbook.cpp(36) : error C2601: 'Logbook::putEntry' : local function definitions are illegal
  16.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  17. f:\c projects\112\lab1\logbook.cpp(43) : error C2601: 'Logbook::getEntry' : local function definitions are illegal
  18.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  19. f:\c projects\112\lab1\logbook.cpp(51) : error C2601: 'Logbook::month' : local function definitions are illegal
  20.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  21. f:\c projects\112\lab1\logbook.cpp(56) : error C2601: 'Logbook::year' : local function definitions are illegal
  22.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  23. f:\c projects\112\lab1\logbook.cpp(61) : error C2601: 'Logbook::daysInMonth' : local function definitions are illegal
  24.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  25. f:\c projects\112\lab1\logbook.cpp(92) : error C2601: 'Logbook::displayCalendar' : local function definitions are illegal
  26.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  27. f:\c projects\112\lab1\logbook.cpp(126) : error C2144: syntax error : 'int' should be preceded by ';'
  28. f:\c projects\112\lab1\logbook.cpp(126) : error C2761: 'putEntry' : member function redeclaration not allowed
  29. f:\c projects\112\lab1\logbook.cpp(127) : error C2601: 'Logbook::operator []' : local function definitions are illegal
  30.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  31. f:\c projects\112\lab1\logbook.cpp(132) : error C2601: 'operator +=' : local function definitions are illegal
  32.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  33. f:\c projects\112\lab1\logbook.cpp(140) : error C2601: 'Logbook::leapYear' : local function definitions are illegal
  34.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  35. f:\c projects\112\lab1\logbook.cpp(148) : error C2601: 'Logbook::dayOfWeek' : local function definitions are illegal
  36.         f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
  37. f:\c projects\112\lab1\logbook.cpp(75) : error C2196: case value '6' already used
  38. f:\c projects\112\lab1\logbook.cpp(96) : error C2065: 'cout' : undeclared identifier
  39. f:\c projects\112\lab1\logbook.cpp(96) : error C2065: 'endl' : undeclared identifier
  40. f:\c projects\112\lab1\logbook.cpp(132) : error C2805: binary 'operator +=' has too few parameters
  41. f:\c projects\112\lab1\logbook.cpp(158) : error C2660: 'Logbook::daysInMonth' : function does not take 1 arguments
  42. Build log was saved at "file://f:\c projects\112\LAB1\lab1\Debug\BuildLog.htm"
  43. lab1 - 28 error(s), 0 warning(s)
  44. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Jan 28 '07 #2
willakawill
1,646 1GB
Expand|Select|Wrap|Line Numbers
  1. #include<stdafx.h>
  2. #include<iostream>
  3. using namespace std;
  4. //Logbook.cpp
  5.  
  6. #include "logbook.h"
  7. #include <windows.h>
  8.  
  9. // Constructor for current time
  10.     Logbook::Logbook ()        // Creates a logbook
  11.     {
  12.  
  13.         SYSTEMTIME st; //structure to hold the system date
  14.         int NumberOfDays;
  15.         GetSystemTime (&st); //pull system date    
  16.  
  17.         logMonth = st.wMonth;
  18.         logYear = st.wYear;
  19.  
  20.         NumberOfDays= daysInMonth();
  21.  
  22.         for(int index = 0; index <= NumberOfDays; ++index)
  23.             entry[index]=0;
  24.     }
  25.         //constructor for specific time
  26.     Logbook::Logbook ( int month, int year )
  27.     {
  28.         logMonth = month;
  29.         logYear = year;
  30.  
  31.         for(int index = 0; index <= NumberOfDays; ++index)
  32.             entry[index]=0;
  33.     }
  34.  
  35.     // Logbook marking operations
  36.     void Logbook::putEntry ( int day, int value ) // Store entry for day
  37.     {
  38.         if (day <= daysInMonth())               //make sure we're dealing with a valid day
  39.             entry[day] = value;                 //set the value for the day
  40.     }
  41.  
  42.  
  43.     int Logbook::getEntry ( int day ) const //returns entry for day
  44.     {
  45.         if (day <= daysInMonth())    //make sure the day is valid
  46.             return entry[day];             //return value            
  47.     }
  48.  
  49.  
  50.     // General operations
  51.     int Logbook::month () const                     // Return the month
  52.     {
  53.         return logMonth;
  54.     }
  55.  
  56.     int Logbook::year () const                      // Return the year
  57.     {
  58.         return logYear;
  59.     }
  60.  
  61.     int Logbook::daysInMonth () const               // Number of days in month
  62.     {
  63.         switch (logMonth)
  64.         {
  65.             //months with 30 days
  66.             case 4:
  67.             case 6:
  68.             case 9:
  69.             case 11: return 30;
  70.             break;
  71.  
  72.             //months with 31 days
  73.             case 1: 
  74.             case 3:
  75.             case 5:
  76.             case 7:
  77.             case 8:
  78.             case 10:
  79.             case 12: return 31;
  80.             break;
  81.  
  82.             //month of February
  83.             case 2: if (logYear %100 ==0) 
  84.                         if (logYear % 400 ==0)
  85.                             return 29;
  86.                         return 28;
  87.  
  88.         }//end switch
  89.  
  90.     }
  91.  
  92.     // In-lab operations 
  93.     void Logbook::displayCalendar () const          // Display as calendar
  94.     {
  95.         int c, d;                        //loop counter and day variables
  96.  
  97.         //display month and year
  98.         cout << "\t\t\t  " << logMonth << " / " << logYear << endl << endl;
  99.  
  100.         //display days of the week
  101.         cout << "Sun      Mon      Tue      Wed      Thu      Fri      Sat\n\n";
  102.  
  103.         for (c = 0; c < dayOfWeek(1); c++) //blank in the first row until
  104.             cout << "         ";       //the first of the month
  105.  
  106.         for (c = 0; c < daysInMonth(); c++) //go through the days
  107.         {
  108.             if (c < 9) 
  109.                 cout << " ";       //if it is a single digit pad with a blank space
  110.  
  111.             d = entry[c];
  112.             cout << ( c + 1) << " " << d;    //display date, entry
  113.  
  114.             if 
  115.                 (d == 0) 
  116.                     d = 1;              //d wouldn't ever surpass zero
  117.             for (; d < 10000; d *= 10)      //pad with space until d is 6 digits long
  118.                 cout << " ";
  119.  
  120.             cout << " ";                //spacing
  121.             if (dayOfWeek (c + 1) ==6)      //when Saturday is reached endline
  122.                 cout << endl;
  123.         }
  124.  
  125.     }
  126.  
  127.     void Logbook::putEntry ( int value )  // Store entry for today
  128.     {
  129.     }
  130.  
  131.     int Logbook::operator [] ( int day ) const      // Return entry for day
  132.     {
  133.             return getEntry(day);
  134.     }
  135.  
  136.     void operator += ( const Logbook &rightLogbook ) //combine logbooks
  137.     {
  138.         for (int i = 0; i < 32; i++)           //go through and add each entry
  139.         entry[i] += rightLogbook.entry[i];
  140.     }
  141.  
  142.  
  143.     // Facilitator (helper) function
  144.     int Logbook::leapYear () const                  // Leap year?
  145.     {
  146.         if( logYear % 400 ==0 || ( logYear % 100 != 0 && logYear % 4 == 0))
  147.             return 1;
  148.         else return 0;
  149.     }
  150.  
  151.     // In-lab facilitator function
  152.     int Logbook::dayOfWeek ( int day ) const        // Return day of the week
  153.     {
  154.         int dayCount = 1;                  //counter of days since 1901
  155.         int i;
  156.  
  157.         dayCount += (logYear - 1901);         //add the years since 1901
  158.  
  159.         for (i = 1901; i < logYear; i++)      //add leapyears since 1901
  160.             dayCount += (i %4 == 0 && i %100 != 0 || i %400 == 0)?1:0;
  161.  
  162.         for (i = 1; i < logMonth; i++)        //add the days to month
  163.             dayCount += daysInMonth(i);
  164.  
  165.         if (logMonth > 2 && leapYear())     //add for a leapyear
  166.             dayCount++;
  167.  
  168.         dayCount += day;                          //add the days
  169.  
  170.         dayCount %= 7;
  171.  
  172.         return int (dayCount);          //return the day of the week
  173.  
  174.     }
  175.  
  176.     int main()
  177. {
  178.  
  179.     return 0;
  180.  
  181.  
  182. }
Down to just the 7 errors:
Expand|Select|Wrap|Line Numbers
  1. --------------------Configuration: Logbook - Win32 Debug--------------------
  2. Compiling...
  3. Logbook.cpp
  4. Logbook.cpp(33) : error C2065: 'NumberOfDays' : undeclared identifier
  5. Logbook.cpp(139) : error C2805: binary 'operator +=' has too few parameters
  6. Logbook.cpp(141) : error C2065: 'entry' : undeclared identifier
  7. Logbook.cpp(141) : error C2109: subscript requires array or pointer type
  8. Logbook.cpp(141) : error C2248: 'entry' : cannot access private member declared in class 'Logbook'
  9.             logbook.h(43) : see declaration of 'entry'
  10. Logbook.cpp(141) : error C2106: '+=' : left operand must be l-value
  11. Logbook.cpp(165) : error C2660: 'daysInMonth' : function does not take 1 parameters
  12. Error executing cl.exe.
  13.  
  14. Testall.exe - 7 error(s), 0 warning(s)
Jan 28 '07 #3
I love you (in a totally hetero way). GOD BLESS! THANKS!
Jan 28 '07 #4
I hope I can repay the favor sometime.
Jan 28 '07 #5
Of course, I don't know why I am getting those errors. I have seen an example, and my code looks allright.
Jan 29 '07 #6
I still get these:

Expand|Select|Wrap|Line Numbers
  1. ------ Build started: Project: lab1, Configuration: Debug Win32 ------
  2. Compiling...
  3. Logbook.cpp
  4. f:\c projects\112\lab1\logbook.cpp(139) : error C2805: binary 'operator +=' has too few parameters
  5. f:\c projects\112\lab1\logbook.cpp(141) : error C3861: 'daysInMonth': identifier not found
  6. f:\c projects\112\lab1\logbook.cpp(143) : error C2065: 'logMonth' : undeclared identifier
  7. f:\c projects\112\lab1\logbook.cpp(143) : error C2248: 'Logbook::logMonth' : cannot access private member declared in class 'Logbook'
  8.         f:\c projects\112\lab1\logbook.h(41) : see declaration of 'Logbook::logMonth'
  9.         f:\c projects\112\lab1\logbook.h(10) : see declaration of 'Logbook'
  10. f:\c projects\112\lab1\logbook.cpp(144) : warning C4390: ';' : empty controlled statement found; is this the intent?
  11. f:\c projects\112\lab1\logbook.cpp(150) : error C2065: 'entry' : undeclared identifier
  12. Build log was saved at "file://f:\c projects\112\LAB1\lab1\Debug\BuildLog.htm"
  13. lab1 - 5 error(s), 1 warning(s)
  14. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include "logbook.h"
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. // Constructor for current time
  9.     Logbook::Logbook ()        // Creates a logbook
  10.     {
  11.  
  12.         SYSTEMTIME st; //structure to hold the system date
  13.         int NumberOfDays;
  14.         GetSystemTime (&st); //pull system date    
  15.  
  16.         logMonth = st.wMonth;
  17.         logYear = st.wYear;
  18.  
  19.         NumberOfDays= daysInMonth();
  20.  
  21.         for(int index = 0; index <= NumberOfDays; ++index)
  22.             entry[index]=0;
  23.     }
  24.         //constructor for specific time
  25.     Logbook::Logbook ( int month, int year )
  26.     {
  27.         int NumberOfDays;
  28.  
  29.         logMonth = month;
  30.         logYear = year;
  31.         NumberOfDays= daysInMonth();
  32.  
  33.         for(int index = 0; index <= NumberOfDays; ++index)
  34.             entry[index]=0;
  35.     }
  36.  
  37.     // Logbook marking operations
  38.     void Logbook::putEntry ( int day, int value ) // Store entry for day
  39.     {
  40.         if (day <= daysInMonth())               //make sure we're dealing with a valid day
  41.             entry[day] = value;                 //set the value for the day
  42.     }
  43.  
  44.  
  45.     int Logbook::getEntry ( int day ) const //returns entry for day
  46.     {
  47.         if (day <= daysInMonth())    //make sure the day is valid
  48.             return entry[day];             //return value            
  49.     }
  50.  
  51.  
  52.     // General operations
  53.     int Logbook::month () const                     // Return the month
  54.     {
  55.         return logMonth;
  56.     }
  57.  
  58.     int Logbook::year () const                      // Return the year
  59.     {
  60.         return logYear;
  61.     }
  62.  
  63.     int Logbook::daysInMonth () const               // Number of days in month
  64.     {
  65.         switch (logMonth)
  66.         {
  67.             //months with 30 days
  68.             case 4:
  69.             case 6:
  70.             case 9:
  71.             case 11: return 30;
  72.             break;
  73.  
  74.             //months with 31 days
  75.             case 1: 
  76.             case 3:
  77.             case 5:
  78.             case 7:
  79.             case 8:
  80.             case 10:
  81.             case 12: return 31;
  82.             break;
  83.  
  84.             //month of February
  85.             case 2: if (logYear %100 ==0) 
  86.                         if (logYear % 400 ==0)
  87.                             return 29;
  88.                         return 28;
  89.  
  90.         }//end switch
  91.  
  92.     }
  93.  
  94.     // In-lab operations 
  95.     void Logbook::displayCalendar () const          // Display as calendar
  96.     {
  97.         int c, d;                        //loop counter and day variables
  98.  
  99.         //display month and year
  100.         cout << "\t\t\t  " << logMonth << " / " << logYear << endl << endl;
  101.  
  102.         //display days of the week
  103.         cout << "Sun      Mon      Tue      Wed      Thu      Fri      Sat\n\n";
  104.  
  105.         for (c = 0; c < dayOfWeek(1); c++) //blank in the first row until
  106.             cout << "         ";       //the first of the month
  107.  
  108.         for (c = 0; c < daysInMonth(); c++) //go through the days
  109.         {
  110.             if (c < 9) 
  111.                 cout << " ";       //if it is a single digit pad with a blank space
  112.  
  113.             d = entry[c];
  114.             cout << ( c + 1) << " " << d;    //display date, entry
  115.  
  116.             if 
  117.                 (d == 0) 
  118.                     d = 1;              //d wouldn't ever surpass zero
  119.             for (; d < 10000; d *= 10)      //pad with space until d is 6 digits long
  120.                 cout << " ";
  121.  
  122.             cout << " ";                //spacing
  123.             if (dayOfWeek (c + 1) ==6)      //when Saturday is reached endline
  124.                 cout << endl;
  125.         }
  126.  
  127.     }
  128.  
  129.     void Logbook::putEntry ( int value )  // Store entry for today
  130.     {
  131.     }
  132.  
  133.     int Logbook::operator [] ( int day ) const      // Return entry for day
  134.     {
  135.             return getEntry(day);
  136.     }
  137.  
  138.     void operator += ( const Logbook &rightLogbook ) //combine logbooks
  139.     {
  140.  
  141.         int NumberOfDays= daysInMonth();
  142.         if ((rightLogbook.daysInMonth() == NumberOfDays) &&
  143.         (logMonth == rightLogbook.logMonth));
  144.         {
  145.         int i = 0;
  146.  
  147.  
  148.  
  149.         for(int index = 0; index <= NumberOfDays; ++index)
  150.             entry[index]=0;
  151.         }
  152.     }
  153.  
  154.  
  155.     // Facilitator (helper) function
  156.     int Logbook::leapYear () const                  // Leap year?
  157.     {
  158.         if( logYear % 400 ==0 || ( logYear % 100 != 0 && logYear % 4 == 0))
  159.             return 1;
  160.         else return 0;
  161.     }
  162.  
  163.     // In-lab facilitator function
  164.     int Logbook::dayOfWeek ( int day ) const        // Return day of the week
  165.     {
  166.         int dayCount = 1;                  //counter of days since 1901
  167.         int i;
  168.  
  169.         dayCount +=(logYear - 1901);         //add the years since 1901
  170.  
  171.         for (i = 1901; i < logYear; i++)      //add leapyears since 1901
  172.             dayCount += (i %4 == 0 && i %100 != 0 || i %400 == 0)?1:0;
  173.  
  174.         //fix
  175.         for (i = 1; i < logMonth; i++)        //add the days to month
  176.             dayCount += daysInMonth();
  177.  
  178.         if (logMonth > 2 && leapYear())     //add for a leapyear
  179.             dayCount++;
  180.  
  181.         dayCount += day;                          //add the days
  182.  
  183.         dayCount %= 7;
  184.  
  185.         return int (dayCount);          //return the day of the week
  186.  
  187.     }
  188.  
  189.  
  190.  
  191.     int main()
  192. {  
  193.     return 0;
  194. }
Jan 29 '07 #7
Motoma
3,237 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. ------ Build started: Project: lab1, Configuration: Debug Win32 ------
  2. Compiling...
  3. Logbook.cpp
  4. f:\c projects\112\lab1\logbook.cpp(139) : error C2805: binary 'operator +=' has too few parameters
  5. f:\c projects\112\lab1\logbook.cpp(141) : error C3861: 'daysInMonth': identifier not found
  6. f:\c projects\112\lab1\logbook.cpp(143) : error C2065: 'logMonth' : undeclared identifier
  7. f:\c projects\112\lab1\logbook.cpp(143) : error C2248: 'Logbook::logMonth' : cannot access private member declared in class 'Logbook'
  8.         f:\c projects\112\lab1\logbook.h(41) : see declaration of 'Logbook::logMonth'
  9.         f:\c projects\112\lab1\logbook.h(10) : see declaration of 'Logbook'
  10. f:\c projects\112\lab1\logbook.cpp(144) : warning C4390: ';' : empty controlled statement found; is this the intent?
  11. f:\c projects\112\lab1\logbook.cpp(150) : error C2065: 'entry' : undeclared identifier
  12. Build log was saved at "file://f:\c projects\112\LAB1\lab1\Debug\BuildLog.htm"
  13. lab1 - 5 error(s), 1 warning(s)
  14. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Just quickly:

Operator += is a binary operator; it takes two arguments, a left and a right element.
Operator += is not in the Logbook namespace, therefor you will need to reference daysInMonth() as Logbook::daysInMonth(). Same goes for logmonth.
Jan 29 '07 #8
Got it! (dances!)
Jan 29 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Alex Endl | last post by:
ok now that i know the random function, i made this guessing game. I get an error though, and Im new so im not to good at figuring out what its talking about. import random a =...
0
by: bill wilson | last post by:
Hi folks, I am new to php+mysql, can anyone help on this query? If we have a table id name 1 allen 2 bill 3 mark 15 david
0
by: KK | last post by:
Design Pattern help for this scenerio?. I need some expert advice on possible ways to design the classes for following scenerio. Subject domain has 3 types of identities. Lets say <IDType1>,...
0
by: MDOPro | last post by:
A pal needs help on this site greetings fellow newsgroupers. I recently found a site called Microsoft Forums. In a very short time I became very known to the site and its an excellent tool....
0
by: TN Bella | last post by:
Hi, I am trying to get my compare validator to fire properly...Since I have panels the validator wouldn't work properly, the app would fire right but would insert the data regardless and the...
2
by: Merdelus | last post by:
I'm a new visual basic learner, I need some help with this program below: create an application that either sums or averagethe rows or columns of a two dimensional array depending on user...
2
by: MK | last post by:
Hello, I am new to XML and PERL and I have a few questions the answers to which I need to complete a project. All your time and effort would be highly appreciated. I have to make a small HTML page...
0
by: shantanuaggarwal | last post by:
Hi,, I have one following question that whether attributes can help me in resolving this problem: I have one base class called Employee and I have 3 classes which inherit it: EmployeeA...
1
by: flavourofbru | last post by:
Hi, I am stuck at a major part of the code in VC++. My algorithm is as follows: f_name = load(filename); //this also loads a text file. The text files contains numbers sepearted by tab....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.