Here is what is required:
Create a new console application project and name it "Week1Lab_YourName".

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 etc...

STEP 2: Create the member functions


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

Call these functions setDay, printDay and getDay.

STEP 3: Create a main() program


Write a main program that will instantiate two objects of the class DayOfTheWeek. Use these objects to test the various operations on this class.

Here is what I have so far, it does not compile. I'm sure it is a simple amatuer mistake but I am an amatuer trying to learn. Thanks in advance for any help.

#include <iostream>
#include <string>

using namespace std;

class dayOfTheWeek
{
public:
	dayOfTheWeek(void);         //Constructor
	~dayOfTheWeek(void);        //Destructor
	void getDay(string&, string&);          
	void setDay(string, string);    
    void printday(string, string);        
		
private:
	string mon;
	string tues;

};


dayOfTheWeek::dayOfTheWeek()
{
    mon = "";
	tues = "";
}
dayOfTheWeek::~dayOfTheWeek()
{
}

void dayOfTheWeek::setDay(string monday, string tuesday)
{
    mon = monday;
	tues = tuesday;
}
void dayOfTheWeek::getDay(string &monday, string &tuesday)
{
    monday = mon;
	tuesday = tues;
}

void dayOfTheWeek::printday(string monday, string tuesday)
{
	monday = mon;
	tuesday = tues;

    cout << "The value of the object " << monday << " is : " << mon << endl;
	cout << "the value of the object " << tuesday << " is : " << tues << endl;

}

int main()
{
    dayOfTheWeek DayOne;             
    dayOfTheWeek DayTwo;
	
	DayOne.setDay(monday, tuesday); 
	DayTwo.setDay(monday, tuesday);

	string localMon = "";
	string localTues = "";

	DayOne.getDay(localMon);
	DayTwo.getDay(localTues);  

    DayOne.printday(localMon);  
	DayTwo.printday(localTues);             
    
    return 0;
}

Delete your variables mon and tues and simply have a string dayofweek; member Then your (non-default) constructor only has to take 1 argument a string holding the day, so e.g., dayOfTheWeek(string dotw) and within the constructor set dayofweek = dotw;

Another hint, getters should "get" the value of the variable so they are not void functions. EDIT: I missed how you set them up in their definitions with passing in the local variables by value. I would still change them to return the dayofweek string above...

That helped considerable but I can't figure out these errors. Updated code

#include <iostream>
#include <string>

using namespace std;

class dayOfTheWeek
{
public:
	dayOfTheWeek(string);         //Constructor
	~dayOfTheWeek();        //Destructor
	string getDay(void);          
	void setDay(string);    
    void printday(string);        
		
private:
	string dayOfWeek;
	

};


dayOfTheWeek::dayOfTheWeek(string dotw)
{
	
    dayOfWeek = dotw;
	
}
dayOfTheWeek::~dayOfTheWeek()
{
}

void dayOfTheWeek::setDay(string dotw)
{
    dayOfWeek = dotw;
	cout << "Enter Day: " ;
		cin >> dotw;
	cout << endl;

}
string dayOfTheWeek::getDay(void)
{
    return dayOfWeek;
}

void dayOfTheWeek::printday(string dotw)
{
	dayOfWeek = dotw;

    cout << "The value of the object " << dotw << " is : " << dayOfWeek << endl;
	

}

int main()
{
	string localDayOfWeek = "";
    dayOfTheWeek DayOne(string);             
    dayOfTheWeek DayTwo(string);
	
	DayOne.setDay("Monday");
	DayOne.getDay(localDayOfWeek);
	DayOne.printday(localDayOfWeek);  
	         
    DayTwo.setDay("Tuesday");
	DayTwo.getDay(localDayOfWeek); 
	DayTwo.printday(localDayOfWeek);     
    return 0;
}

I have the same error for every instance od setDay, getDay and printDay....6 in all. It reads:
Error 1 error C2228: left of '.setDay' must have class/struct/union

Your code seems to contain a lot of errors.

You want to create a class called DayOfTheWeek that represents a day of the week. It looks like you have tried to store the actual data in a string object that you made private. That's an idea that could work. (The assignment would like you to store things like "Mon" it seems. You could also consider using an enumeration for this) You made 2 variables for 2 days (mon, tues) which makes no sense to me and is probably not what you wanted either. After all, it can only be 1 day at a time. (If you'd like to have a variable for each day, you could use the datatype "bool")A single datamember would be sufficient. If you'd use an enum to represent a day, your code could look like this at this point:

#include <string>

class dayOfTheWeek
{
    public:
        enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, Undefined};
        
        dayOfTheWeek();
        dayOfTheWeek(Day _day);
    
    private:
        Day day;
};

//Default constructor.
dayOfTheWeek::dayOfTheWeek() : day(Undefined)
{
}

//Constructor to set the day directly.
dayOfTheWeek::dayOfTheWeek(Day _day) : day(_day)
{
}

As you can see I added 2 constructors instead of only a default one. Also the way of initializing the data members might be unknown to you, if you'd like to know more you could search for "initialization section".

On the next question it asks you to create the following: setDay, printDay and getDay. This is where the main issue lies in your code. Some terms that might help you on finding awnsers: "Accessor / mutator functions", "scope" and "const correctness". (last one not really crucial for a properly working progream) Also note I did not add a deconstructor, but it's good practice to do so. (even though not needed here)

Instead of explaining things i'll show an example program that you could use to create more specific questions:

//File: daysOfTheWeek.h

//Following lines are to prevent multiple includes.
#ifndef DAYS_OF_THE_WEEK_H
#define DAYS_OF_THE_WEEK_H

#include <iostream>
#include <string>

//no "using namespace std" in the headerfile! forces users of the class to be in that namespace aswell.

class dayOfTheWeek
{
    public:
        enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, Undefined};

        dayOfTheWeek();
        dayOfTheWeek(Day _day);

        Day getDay() const;
        void setDay(Day _day);

        void printDay(std::ostream& out) const;
        std::string toString() const;

    private:
        Day day;
};

#endif
//File: daysOfTheWeek.cpp
#include "daysOfTheWeek.h"

//Default constructor.
dayOfTheWeek::dayOfTheWeek() : day(Undefined)
{
}

//Constructor to set the day directly.
dayOfTheWeek::dayOfTheWeek(Day _day) : day(_day)
{
}

//Returns the day as a Day type.
dayOfTheWeek::Day dayOfTheWeek::getDay() const
{
    return day;
}

//Sets the day.
void dayOfTheWeek::setDay(Day _day)
{
    day = _day;
}

//Prints the day to the outstream 'out'. If too advanced,
//remove the argument and use cout.
void dayOfTheWeek::printDay(std::ostream& out) const
{
    out << toString();
}

std::string dayOfTheWeek::toString() const
{
    switch(day)
    {
        case Monday:        return "Monday";        break;
        case Tuesday:       return "Tuesday";       break;
        case Wednesday:     return "Wednesday";     break;
        case Thursday:      return "Thursday";      break;
        case Friday:        return "Friday";        break;
        case Saturday:      return "Saturday";      break;
        case Sunday:        return "Sunday";        break;
        default:            return "Undefined";     break;
    }
}
//File: main.cpp

#include <iostream>
#include "daysOfTheWeek.h"

//No real issue to use it here.
using namespace std;

int main(int argc, char *argv[])
{
    dayOfTheWeek dayOne;
    dayOfTheWeek dayTwo;

    //Setting the days, could have done this in the
    //above 2 constructors aswell.
	dayOne.setDay(dayOfTheWeek::Monday);
	dayTwo.setDay(dayOfTheWeek::Tuesday);

    //could just use toString, but just to show printDay
	cout << "The days are: ";
	dayOne.printDay(cout);
	cout << " and ";
	dayTwo.printDay(cout);
	cout << ".\n";

    return 0;
}

You don't need parentheses when you call a default constructor (which is what you should do on lines 57-58

dayOfTheWeek DayOne;             
    dayOfTheWeek DayTwo;

You should also declare a default constructor, that is: dayOfTheWeek() up in your class declaration (next to the other dayOfTheWeek(string) one.

For your getDay method, you're not passing in a parameter (see your declaration in the public: section). Just leave it as getDay() which in reality is the same as getDay(void).

In the printDay you shouldn't be passing in a parameter either. Your printDay method has access to the private member dayOfWeek, so you can just print that out directly. Start to think in terms of the objects you are creating (DayOne and DayTwo) as having these methods and member variables intrinsic to themselves (so DayOne is carrying around it's own dayOfWeek string and DayTwo has it's own, and they are each able to use these class methods independently of each other).
I think that's all the major errors, there might be some minor ones around...

EDIT: You need to put {} after the declaration of your default
constructor, that way you don't have to put a full definition.
And with regards to your set function, you should probably do the data entry in main and pass that value through the set rather than passing it in and then overwriting it anyway.

commented: thanks! +1

Gonbe, a valiant effort! :) However, I think you have introduced a lot of concepts that may be unfamiliar to the OP at this stage. Beyond that, it's not normally the practice to give any OP an entire piece of code as it takes away from their learning rather than supplements it.

Thanks for all of the help. I appreciate the gentle nudges in the right direction as I do not want anyone to do my work for me. I will never learn anything that way. I have a feeling I will be working on this for a bit until I get it. Again thanks for the help

Here is what is required:
Create a new console application project and name it "Week1Lab_YourName".

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 etc...

STEP 2: Create the member functions


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

Call these functions setDay, printDay and getDay.

STEP 3: Create a main() program


Write a main program that will instantiate two objects of the class DayOfTheWeek. Use these objects to test the various operations on this class.

Here is what I have so far, it does not compile. I'm sure it is a simple amatuer mistake but I am an amatuer trying to learn. Thanks in advance for any help.

#include <iostream>
#include <string>

using namespace std;

class dayOfTheWeek
{
public:
	dayOfTheWeek(void);         //Constructor
	~dayOfTheWeek(void);        //Destructor
	void getDay(string&, string&);          
	void setDay(string, string);    
    void printday(string, string);        
		
private:
	string mon;
	string tues;

};


dayOfTheWeek::dayOfTheWeek()
{
    mon = "";
	tues = "";
}
dayOfTheWeek::~dayOfTheWeek()
{
}

void dayOfTheWeek::setDay(string monday, string tuesday)
{
    mon = monday;
	tues = tuesday;
}
void dayOfTheWeek::getDay(string &monday, string &tuesday)
{
    monday = mon;
	tuesday = tues;
}

void dayOfTheWeek::printday(string monday, string tuesday)
{
	monday = mon;
	tuesday = tues;

    cout << "The value of the object " << monday << " is : " << mon << endl;
	cout << "the value of the object " << tuesday << " is : " << tues << endl;

}

int main()
{
    dayOfTheWeek DayOne;             
    dayOfTheWeek DayTwo;
	
	DayOne.setDay(monday, tuesday); 
	DayTwo.setDay(monday, tuesday);

	string localMon = "";
	string localTues = "";

	DayOne.getDay(localMon);
	DayTwo.getDay(localTues);  

    DayOne.printday(localMon);  
	DayTwo.printday(localTues);             
    
    return 0;
}

Send your code to dreamincode.net and maybe some of their experts will help. By the way, are you a devry student in cis247c. I am in that class also. My name is bryant

commented: How frickin' rude: go to one site and ask people to send code elsewhere. Why not simply ask us to ignore you completely and avoid the middleman? -2
commented: Do not hijack another thread to ask your question. -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.