C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 27th, 2007, 07:02 PM
bmn bmn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 40 bmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 51 m 48 sec
Reputation Power: 13
C++ Problems. Stuck... - URGENT! Needs to be done by Monday!

I am working on a program and I missed a very important day of class while I was puking my guts out. That class covered classes...this is my first OOP class in C++, and I am getting 27 errors...This is a logbook program. There is an assignment sheet here .

Anyway, I will post my code for my header file and .cpp file and the errors, and maybe somebody could help me work my way through this...I am stuck. I really don't know why I am getting these retarded errors.

the cpp file:
Code:
//Logbook.cpp

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

void main()
{
   // Constructor for current time
	Logbook::Logbook ()        // Creates a logbook
	{
	
	SYSTEMTIME st; //structure to hold the system date
	int NumberOfDays;
	GetSystemTime (&st); //pull system date	

	logMonth = st.wMonth;
	logYear = st.wYear;

	NumberOfDays= daysInMonth();

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

	//constructor for specific time
	Logbook::Logbook ( int month, int year )
	{
		logMonth = month;
		logYear = year;
		
		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 6:
			case 8:
			case 19: 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 << "\t\t\t  " << logMonth << " / " << logYear << endl << endl;

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

	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 operator += ( const Logbook &rightLogbook ) //combine logbooks
	{
		for (int i = 0; i < 32; i++)           //go through and add each entry
		entry[i] += rightLogbook.entry[i];
	}
 

    // 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;

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

	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

	}

}

Reply With Quote
  #2  
Old January 27th, 2007, 07:03 PM
bmn bmn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 40 bmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 51 m 48 sec
Reputation Power: 13
The header file:
Code:
//--------------------------------------------------------------------
//
//  Laboratory 1                                           logbook.h
//
//  Class declaration for the Logbook ADT
//
//--------------------------------------------------------------------

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
};



Errors:

Code:
------ Build started: Project: lab1, Configuration: Debug Win32 ------
Compiling...
Logbook.cpp
f:\c projects\112\lab1\logbook.cpp(9) : error C2143: syntax error : missing ';' before '{'
f:\c projects\112\lab1\logbook.cpp(15) : error C2065: 'logMonth' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(16) : error C2065: 'logYear' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(18) : error C3861: 'daysInMonth': identifier not found
f:\c projects\112\lab1\logbook.cpp(21) : error C2065: 'entry' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(25) : error C2144: syntax error : 'int' should be preceded by ')'
f:\c projects\112\lab1\logbook.cpp(25) : error C2059: syntax error : ')'
f:\c projects\112\lab1\logbook.cpp(26) : error C2143: syntax error : missing ';' before '{'
f:\c projects\112\lab1\logbook.cpp(27) : error C2065: 'month' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(28) : error C2065: 'year' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(30) : error C2065: 'NumberOfDays' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(36) : error C2601: 'Logbook::putEntry' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(43) : error C2601: 'Logbook::getEntry' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(51) : error C2601: 'Logbook::month' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(56) : error C2601: 'Logbook::year' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(61) : error C2601: 'Logbook::daysInMonth' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(92) : error C2601: 'Logbook::displayCalendar' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(126) : error C2144: syntax error : 'int' should be preceded by ';'
f:\c projects\112\lab1\logbook.cpp(126) : error C2761: 'putEntry' : member function redeclaration not allowed
f:\c projects\112\lab1\logbook.cpp(127) : error C2601: 'Logbook::operator []' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(132) : error C2601: 'operator +=' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(140) : error C2601: 'Logbook::leapYear' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(148) : error C2601: 'Logbook::dayOfWeek' : local function definitions are illegal
        f:\c projects\112\lab1\logbook.cpp(6): this line contains a '{' which has not yet been matched
f:\c projects\112\lab1\logbook.cpp(75) : error C2196: case value '6' already used
f:\c projects\112\lab1\logbook.cpp(96) : error C2065: 'cout' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(96) : error C2065: 'endl' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(132) : error C2805: binary 'operator +=' has too few parameters
f:\c projects\112\lab1\logbook.cpp(158) : error C2660: 'Logbook::daysInMonth' : function does not take 1 arguments
Build log was saved at "file://f:\c projects\112\LAB1\lab1\Debug\BuildLog.htm"
lab1 - 28 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Reply With Quote
  #3  
Old January 27th, 2007, 08:54 PM
bmn bmn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 40 bmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 51 m 48 sec
Reputation Power: 13
Did I mention I have to do this by monday? I am totally stumped.

Reply With Quote
  #4  
Old January 28th, 2007, 06:15 AM
Paul820 Paul820 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Location: United Kingdom
Posts: 428 Paul820 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 7 h 55 m 4 sec
Reputation Power: 12
Why have you got all your functions inside main()?, functions don't go inside main, they go below main().
__________________
USE CODE TAGS: Highlight the code, click on the # button.

Reply With Quote
  #5  
Old January 28th, 2007, 08:17 AM
prongs_386 prongs_386 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 35 prongs_386 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 50 m 22 sec
Reputation Power: 11
as Paul said... put all your logbook:: stuff outside of the void main function.

What you probably missed in the OOP class is that you define the class as you have done, but then you make a new object of the class you defined. You can do this just like declaring an int or double etc.
so inside main you could have
Code:
logbook MyLogBook();

and then use the functions of log book like this...
Code:
MyLogBook.PutEntry();

Reply With Quote
  #6  
Old January 28th, 2007, 01:23 PM
bmn bmn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 40 bmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 51 m 48 sec
Reputation Power: 13
Thanks!

Reply With Quote
  #7  
Old January 28th, 2007, 06:45 PM
bmn bmn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 40 bmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 51 m 48 sec
Reputation Power: 13
Ok, I am to the point of having 6 errors, which I can't find a source for...

errors:
Code:
------ Build started: Project: lab1, Configuration: Debug Win32 ------
Compiling...
Logbook.cpp
f:\c projects\112\lab1\logbook.cpp(139) : error C2805: binary 'operator +=' has too few parameters
f:\c projects\112\lab1\logbook.cpp(141) : error C3861: 'daysInMonth': identifier not found
f:\c projects\112\lab1\logbook.cpp(143) : error C2065: 'logMonth' : undeclared identifier
f:\c projects\112\lab1\logbook.cpp(143) : error C2248: 'Logbook::logMonth' : cannot access private member declared in class 'Logbook'
        f:\c projects\112\lab1\logbook.h(41) : see declaration of 'Logbook::logMonth'
        f:\c projects\112\lab1\logbook.h(10) : see declaration of 'Logbook'
f:\c projects\112\lab1\logbook.cpp(144) : warning C4390: ';' : empty controlled statement found; is this the intent?
f:\c projects\112\lab1\logbook.cpp(150) : error C2065: 'entry' : undeclared identifier
Build log was saved at "file://f:\c projects\112\LAB1\lab1\Debug\BuildLog.htm"
lab1 - 5 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Code:
Code:
#include<iostream>
#include "logbook.h"
#include <windows.h>

using namespace std;


// Constructor for current time
	Logbook::Logbook ()        // Creates a logbook
	{
	
		SYSTEMTIME st; //structure to hold the system date
		int NumberOfDays;
		GetSystemTime (&st); //pull system date	

		logMonth = st.wMonth;
		logYear = st.wYear;

		NumberOfDays= daysInMonth();

		for(int index = 0; index <= NumberOfDays; ++index)
			entry[index]=0;
	}
		//constructor for specific time
	Logbook::Logbook ( int month, int year )
	{
		int NumberOfDays;

		logMonth = month;
		logYear = year;
		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 << "\t\t\t  " << logMonth << " / " << logYear << endl << endl;

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

		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 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;
}

Reply With Quote
  #8  
Old January 28th, 2007, 10:50 PM
bmn bmn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 40 bmn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 51 m 48 sec
Reputation Power: 13
I finally figured it out. It was, of course, stupid typos.

Reply With Quote
  #9  
Old July 10th, 2017, 02:52 AM
buzzwind55 buzzwind55 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2017
Posts: 1 buzzwind55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 55 sec
Reputation Power: 0
Logbook

how to solve? can show us how?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ - I am a n00b compared to everyone here, but some help would be great - OOP


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap