Thread: Please Help not sure whats wrong

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    6

    Please Help not sure whats wrong

    I am doing an assignment that is for the days of the week. This is what I am supposed to do, STEP 1: Create the Project and Main Class



    1. Create a new console application project and name it "Week1Lab_YourName".
    2. Create a new class called DayOfTheWeek. The class should have a data member that can store the day of the week, such as Mon for Monday, Tues for Tuesday, and so on.

    STEP 2: Create the Member Functions



    1. Create the necessary member functions that will perform the required operations outlined in the lab summary above.

    Call these functions setDay(), printDay(), and getDay().
    Function setDay(string) takes a string parameter (for example, Monday, Tuesday, etc.) and stores the value in the day attribute.
    Function printDay() prints the value of the day attribute on console output.
    Function getDay() returns the value of the day attribute.
    STEP 3: Create a Main() Program



    1. Write a main program that will instantiate two objects of the class DayOfTheWeek. Use these objects to test the various operations on this class, using the examples in the lectures and reading to perform the required operations.

    STEP 4: Build and Test



    1. Build your project (compile your program).
    2. Eliminate all syntax errors.
    3. Run the program.
    4. Verify results of program execution and correct any logic errors discovered.

    This is what I have:

    Code:
    #include <string>
    #include "DayOfTheWeek.h"
    using std::string;
    class DayOfTheWeek
    {
    private:
    	string day;
    
    public:
    	void SetDay(string);
    	void PrintDay(string);
    	string GetDay();
    };
    
    MAIN
    #include <string>
    #include "DayOfTheWeek.h"
    
    using namespace std;
    
    int Main()
    {
    	DayOfTheWeek day;
    	day.GetDay ("mon");
    	cout << DayOfTheWeek.PrintDay << endl;
    }
    
    void DayOfTheWeek::SetDay(string day)
    {
    	string Monday = "mon";
    	string Tuesday = "tues";
    	string Wednesday = "wed";
    	string Thursday = "thurs";
    	string Friday = "fri"; 
    	string Saturday = "sat";
    	string Sunday = "sun"; 
    }
    void DayOfTheWeek::PrintDay(string day)
    { 
    	cout << "Today is  " << day << endl;
    
    }
    
    string DayOfTheWeek::GetDay()
    {
    	string day = "Monday";
    	return day;
    }
    If I build it I get: fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

    If I add the #include "stdafx.h" it tells me: fatal error C1083: Cannot open include file: 'DayOfTheWeek.h': No such file or directory

    What am I doing wrong?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    First thing, turn OFF the pre-compiled header stuff. It is not necessary for student projects.

    Something like
    Project->settings->compiler->pre-processor->pre-compiled headers.
    There should be an OFF option.

    Next, you need to split your source code into 3 files.
    Code:
    //!! This is DayOfTheWeek.h
    #include <string>
    ////#include "DayOfTheWeek.h"
    using std::string;
    class DayOfTheWeek
    {
    private:
    	string day;
    
    public:
    	void SetDay(string);
    	void PrintDay(string);
    	string GetDay();
    };
    Code:
    //!! This is main.cpp
    #include <string>
    #include "DayOfTheWeek.h"
    
    using namespace std;
    
    int Main()
    {
    	DayOfTheWeek day;
    	day.GetDay ("mon");
    	cout << DayOfTheWeek.PrintDay << endl;
    }
    Code:
    //!! This is DayOfTheWeek.cpp
    #include "DayOfTheWeek.h"
    void DayOfTheWeek::SetDay(string day)
    {
    	string Monday = "mon";
    	string Tuesday = "tues";
    	string Wednesday = "wed";
    	string Thursday = "thurs";
    	string Friday = "fri"; 
    	string Saturday = "sat";
    	string Sunday = "sun"; 
    }
    void DayOfTheWeek::PrintDay(string day)
    { 
    	cout << "Today is  " << day << endl;
    
    }
    
    string DayOfTheWeek::GetDay()
    {
    	string day = "Monday";
    	return day;
    }
    The TWO source files (.cpp) should be added to the project source files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Salem View Post
    First thing, turn OFF the pre-compiled header stuff. It is not necessary for student projects.
    Or you can add
    #include "stdafx.h"
    at the beginning of all your source files.
    It's your choice.

    You can read a little more about recompiled headers using google, if you want. They won't help you that much in such a small project, but they can certainly be helpful and is a good thing to learn eventually.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    6
    Thank you for your help Salem and Elysia. It has been about 6 months since my last programming class so I was happy to get as far as I did. I am realizing this isn't like riding a bike, if you don't use it that often you forget alot. But I still get fatal error C1083: Cannot open include file: 'DayOfTheWeek.h': No such file or directory. I have it in there but not sure where it is wrong at.
    Last edited by iamnewtothis; 03-03-2011 at 04:17 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It means the compiler cannot find the file "DayOfTheWeek.h", which you are telling the compiler to include into the source file. This is not a standard header. This is some manual header someone has defined.
    Do you see the file anywhere?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM