Write a program that implements the week

I have most of the code but I keep getting the same errors and

Page 1 of 1

8 Replies - 3619 Views - Last Post: 12 March 2010 - 03:08 PM Rate Topic: -----

#1 Guest_DL*


Reputation:

Write a program that implements the week

Posted 11 March 2010 - 10:56 PM

I have a problem with finishing off the code that I have. I don't know how to use the enum function to get my days to calculate correctly. I keep getting these same 8 errors and I cannot find out what is wrong!
#pragma once //Lines of code that start with # are preprocessing devices.
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class DaysOfWeek
{
public:
        private:
                
			    string day;     //This sets the day of the week
                string hour;
				enum Days Day;

        public:
                enum Days {Mon, Tues, Wed, Thurs, Fri, Sat, Sun};
                DaysOfWeek(void); //This is the default constructor
                ~DaysOfWeek(void); // This is the Destructor pp.687
                string getHour();//Gets the specific hour
                void   setHour(string);//Sets the hour
                string getDay();//Gets the day in  string
                void   setDay(string);  //Sets the string
                void   printday();  //Print the day and hour of the week in a string
                
				


};              



DaysOfWeek::DaysOfWeek(void)// Set the day and hour to zero
{
        day  = "default";
         hour = "default";
}

DaysOfWeek::~DaysOfWeek(void)//sets the relation between the constuctor and destructor
{
}

string DaysOfWeek::getHour()// gets the hour
{
        string tempHour;
        
        cout << "Hello,Enter the Hour: ";
        cin  >> tempHour;

        return tempHour;
}

void DaysOfWeek::setHour(string HourOfWeek) // gets the hour of the week
{
        hour = HourOfWeek;
}

string DaysOfWeek::getDay()// gets the day and sets it
{
        string tempDay;
		string mon = Monday;
        string tues = Tuesday;
        string weds = Wednesday;
        string thurs = Thursday;
        string fri = Friday;
        string sat = Saturday;
        string sun = Sunday;
        
        cout << "Okay, Now enter Day: ";
        cin  >> tempDay;

        return tempDay;
}

void DaysOfWeek::setDay(string DayOfWeek)//Sets the day in sync with the week
{        			  day = DayOfWeek;
}

void DaysOfWeek::printday()//prints out the date and the time
{
        cout << "Today is: " << day << endl;
        cout << "The time is " << hour << endl << endl;
}




int main()//Main engine to output the program
{
        string HourOfDay = "";           
        string DayOfWeek = "";           

        DaysOfWeek DayOne;                    
        DaysOfWeek DayTwo;                     

        HourOfDay = DayOne.getHour();  
        DayOne.setHour(HourOfDay);      

        DayOfWeek = DayOne.getDay();  
        DayOne.setDay(DayOfWeek);        

        HourOfDay = DayTwo.getHour();  
        DayTwo.setHour(HourOfDay);      

        DayOfWeek = DayTwo.getDay();   
        DayTwo.setDay(DayOfWeek);         

        DayOne.printday();                   

        DayTwo.printday();                       
        
        return 0;
}




Is This A Good Question/Topic? 0

Replies To: Write a program that implements the week

#2 PlasticineGuy   User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Write a program that implements the week

Posted 11 March 2010 - 11:17 PM

Okay, so you're getting errors.

Which errors?
Was This Post Helpful? 0
  • +
  • -

#3 Martyn.Rae   User is offline

  • The programming dinosaur
  • member icon

Reputation: 547
  • View blog
  • Posts: 1,420
  • Joined: 22-August 09

Re: Write a program that implements the week

Posted 11 March 2010 - 11:30 PM

The errors are because you are assigning an undeclared variable to a string. You forgot to put the days of the week between double quotes.

Here is the corrected code for that section.

string DaysOfWeek::getDay()// gets the day and sets it 
{ 
        string tempDay; 
        string mon = "Monday"; 
        string tues = "Tuesday"; 
        string weds = "Wednesday"; 
        string thurs = "Thursday"; 
        string fri = "Friday"; 
        string sat = "Saturday"; 
        string sun = "Sunday"; 
         
        cout << "Okay, Now enter Day: "; 
        cin  >> tempDay; 
 
        return tempDay; 
} 



Fix that and your program will compile.
Was This Post Helpful? 0
  • +
  • -

#4 PlasticineGuy   User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Write a program that implements the week

Posted 11 March 2010 - 11:50 PM

The problem with that is that the initialised strings aren't used.
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Headz*


Reputation:

Re: Write a program that implements the week

Posted 12 March 2010 - 01:32 PM

View PostDL, on 11 March 2010 - 09:56 PM, said:

I have a problem with finishing off the code that I have. I don't know how to use the enum function to get my days to calculate correctly. I keep getting these same 8 errors and I cannot find out what is wrong!
#pragma once //Lines of code that start with # are preprocessing devices.
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class DaysOfWeek
{
public:
        private:
                
			    string day;     //This sets the day of the week
                string hour;
				enum Days Day;

        public:
                enum Days {Mon, Tues, Wed, Thurs, Fri, Sat, Sun};
                DaysOfWeek(void); //This is the default constructor
                ~DaysOfWeek(void); // This is the Destructor pp.687
                string getHour();//Gets the specific hour
                void   setHour(string);//Sets the hour
                string getDay();//Gets the day in  string
                void   setDay(string);  //Sets the string
                void   printday();  //Print the day and hour of the week in a string
                
				


};              



DaysOfWeek::DaysOfWeek(void)// Set the day and hour to zero
{
        day  = "default";
         hour = "default";
}

DaysOfWeek::~DaysOfWeek(void)//sets the relation between the constuctor and destructor
{
}

string DaysOfWeek::getHour()// gets the hour
{
        string tempHour;
        
        cout << "Hello,Enter the Hour: ";
        cin  >> tempHour;

        return tempHour;
}

void DaysOfWeek::setHour(string HourOfWeek) // gets the hour of the week
{
        hour = HourOfWeek;
}

string DaysOfWeek::getDay()// gets the day and sets it
{
        string tempDay;
		string mon = Monday;
        string tues = Tuesday;
        string weds = Wednesday;
        string thurs = Thursday;
        string fri = Friday;
        string sat = Saturday;
        string sun = Sunday;
        
        cout << "Okay, Now enter Day: ";
        cin  >> tempDay;

        return tempDay;
}

void DaysOfWeek::setDay(string DayOfWeek)//Sets the day in sync with the week
{        			  day = DayOfWeek;
}

void DaysOfWeek::printday()//prints out the date and the time
{
        cout << "Today is: " << day << endl;
        cout << "The time is " << hour << endl << endl;
}




int main()//Main engine to output the program
{
        string HourOfDay = "";           
        string DayOfWeek = "";           

        DaysOfWeek DayOne;                    
        DaysOfWeek DayTwo;                     

        HourOfDay = DayOne.getHour();  
        DayOne.setHour(HourOfDay);      

        DayOfWeek = DayOne.getDay();  
        DayOne.setDay(DayOfWeek);        

        HourOfDay = DayTwo.getHour();  
        DayTwo.setHour(HourOfDay);      

        DayOfWeek = DayTwo.getDay();   
        DayTwo.setDay(DayOfWeek);         

        DayOne.printday();                   

        DayTwo.printday();                       
        
        return 0;
}



I am still showing errors. These are the errors that are showing
dl_wk1\dl_wk1\wk1.cpp(30) : error C2535: 'DaysOfWeek::DaysOfWeek(void)' : member function already defined or declared
1> y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(21) : see declaration of 'DaysOfWeek::DaysOfWeek'
1>y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(36) : error C2535: 'DaysOfWeek::~DaysOfWeek(void)' : member function already defined or declared
1> y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(22) : see declaration of 'DaysOfWeek::~DaysOfWeek'
1>y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(40) : error C2535: 'std::string DaysOfWeek::getHour(void)' : member function already defined or declared
1> y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(23) : see declaration of 'DaysOfWeek::getHour'
1>y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(50) : error C2535: 'void DaysOfWeek::setHour(std::string)' : member function already defined or declared
1> y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(24) : see declaration of 'DaysOfWeek::setHour'
1>y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(55) : error C2535: 'std::string DaysOfWeek::getDay(void)' : member function already defined or declared
1> y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(25) : see declaration of 'DaysOfWeek::getDay'
1>y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(65) : error C2535: 'void DaysOfWeek::setDay(std::string)' : member function already defined or declared
1> y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(26) : see declaration of 'DaysOfWeek::setDay'
1>y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(70) : error C2535: 'void DaysOfWeek::printday(void)' : member function already defined or declared
1> y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(27) : see declaration of 'DaysOfWeek::printday'
1>y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(101) : fatal error C1075: end of file found before the left brace '{' at 'y:\d03141392\documents\visual studio 2005\projects\dl_wk1\dl_wk1\wk1.cpp(14)' was matched
1>Generating Code...
1>Build log was saved at "file://\\ilabss\home$\D03141392\Documents\Visual Studio 2005\Projects\DL_wk1\DL_wk1\Debug\BuildLog.htm"
1>DL_wk1 - 8 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Was This Post Helpful? 0

#6 eker676   User is offline

  • Software Engineer
  • member icon

Reputation: 379
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Write a program that implements the week

Posted 12 March 2010 - 01:41 PM

Take the code you quoted, put the days of the week in double quotes as Martyn said and it will compile.
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Guest*


Reputation:

Re: Write a program that implements the week

Posted 12 March 2010 - 02:52 PM

I did and I still got these errors!
#pragma once //Lines of code that start with # are preprocessing devices.
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

class DaysOfWeek
{
public:
        private:
                
                            string day;     //This sets the day of the week
                string hour;
                                enum Days Day;

        public:
                enum Days {Mon, Tues, Wed, Thurs, Fri, Sat, Sun};
                DaysOfWeek(void); //This is the default constructor
                ~DaysOfWeek(void); // This is the Destructor pp.687
                string getHour();//Gets the specific hour
                void   setHour(string);//Sets the hour
                string getDay();//Gets the day in  string
                void   setDay(string);  //Sets the string
                void   printday();  //Print the day and hour of the week in a string
                
                                


};              



DaysOfWeek::DaysOfWeek(void)// Set the day and hour to zero
{
        day  = "default";
         hour = "default";
}

DaysOfWeek::~DaysOfWeek(void)//sets the relation between the constuctor and destructor
{
}

string DaysOfWeek::getHour()// gets the hour
{
        string tempHour;
        
        cout << "Hello,Enter the Hour: ";
        cin  >> tempHour;

        return tempHour;
}

void DaysOfWeek::setHour(string HourOfWeek) // gets the hour of the week
{
        hour = HourOfWeek;
}
string DaysOfWeek::getDay()// gets the day and sets it 
{ 
        string tempDay; 
        string mon = "Monday"; 
        string tues = "Tuesday"; 
        string weds = "Wednesday"; 
        string thurs = "Thursday"; 
        string fri = "Friday"; 
        string sat = "Saturday"; 
        string sun = "Sunday"; 
         
        cout << "Okay, Now enter Day: "; 
        cin  >> tempDay; 
 
        return tempDay; 
} 
void DaysOfWeek::setDay(string DayOfWeek)//Sets the day in sync with the week
{                                 day = DayOfWeek;
}

void DaysOfWeek::printday()//prints out the date and the time
{
        cout << "Today is: " << day << endl;
        cout << "The time is " << hour << endl << endl;
}




int main()//Main engine to output the program
{
        string HourOfDay = "";           
        string DayOfWeek = "";           

        DaysOfWeek DayOne;                    
        DaysOfWeek DayTwo;                     

        HourOfDay = DayOne.getHour();  
        DayOne.setHour(HourOfDay);      

        DayOfWeek = DayOne.getDay();  
        DayOne.setDay(DayOfWeek);        

        HourOfDay = DayTwo.getHour();  
        DayTwo.setHour(HourOfDay);      

        DayOfWeek = DayTwo.getDay();   
        DayTwo.setDay(DayOfWeek);         

        DayOne.printday();                   

        DayTwo.printday();                       
        
        return 0;
}


Was This Post Helpful? 0

#8 sarmanu   User is offline

  • D.I.C Lover
  • member icon

Reputation: 967
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Write a program that implements the week

Posted 12 March 2010 - 02:56 PM

The above code compiled & looks correct to me, though I don't know why you put that #pragma once? What Compiler are you using?
EDIT: NVM, I see that you use MSVC 2005. Something is very weird. Take a look at your error description: http://msdn.microsof...y/45d5keht.aspx . This is not the case for that though ... I was able to compile your project using MSVC 2008 ...

This post has been edited by sarmanu: 12 March 2010 - 02:59 PM

Was This Post Helpful? 0
  • +
  • -

#9 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: Write a program that implements the week

Posted 12 March 2010 - 03:08 PM

compiles fine for me in VS 2008 , lose the #pragma once
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1