Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,932 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,851 people online right now. Registration is fast and FREE... Join Now!




DayOfTheWeek

 
Reply to this topicStart new topic

DayOfTheWeek

ITChief
15 Mar, 2008 - 05:56 PM
Post #1

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions
Write a program that contains a class that implements the days of the week. The program should be able to perform the following on an object of a class.
1. Set the day
2. Print the day to the computer monitor(not the printer)
3. Return the day

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

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

Call these functions setDay, printDay and getDay.

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

DayOfTheWeekHEA~1

cpp

#include <string>
using std::string;
class DayOfTheWeek
{
private:
string day
string hour

public:
void setday(string, string);
void printday();
string getday();
};

DayOfTheWeekIMP
#include <iostream>
#include <string>
#include "DayOfTheWeek.h"

using manespace std;

void DayOfTheWeek::setdayinfo(string day, string hour)
{
Monday = mon;
Tuesday = tues;
Wednesday = weds;
Thursday = thurs;
Friday = fri;
Saturday = sat;
Sunday = sun;
}
void DayOfTheWeek::printDay()
{
cout << "Day: " << day << endl;
cout << "Hour: " << hour << endl;
}
string DayOfTheWeek::getday()
{
return day;
}

*edit: Please use code tags in the future, thanks! code.gif

This post has been edited by Martyr2: 15 Mar, 2008 - 07:55 PM
User is offlineProfile CardPM
+Quote Post

Topher84
RE: DayOfTheWeek
15 Mar, 2008 - 06:24 PM
Post #2

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
whats the problem?
User is offlineProfile CardPM
+Quote Post

ITChief
RE: DayOfTheWeek
15 Mar, 2008 - 06:31 PM
Post #3

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions
QUOTE(Topher84 @ 15 Mar, 2008 - 07:24 PM) *

whats the problem?


Does this even make any sense to you?
User is offlineProfile CardPM
+Quote Post

ITChief
RE: DayOfTheWeek
15 Mar, 2008 - 06:44 PM
Post #4

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions
QUOTE(Topher84 @ 15 Mar, 2008 - 07:24 PM) *

whats the problem?


Trying to write a program that displays the days of the week. I'm I on the right track with this one?

I'm I on the right track with this code?
User is offlineProfile CardPM
+Quote Post

Topher84
RE: DayOfTheWeek
15 Mar, 2008 - 06:55 PM
Post #5

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
I have a degree in CS so obviously this does make sense.. now I am asking what is the specific problem that you are having with your code? there is no need to get defensive with it.. if you want help you need to give a little more information behind what the problem is and we will gladly help you....

also.. post your code in the code tags for easier readability please.

This post has been edited by Topher84: 15 Mar, 2008 - 07:03 PM
User is offlineProfile CardPM
+Quote Post

ITChief
RE: DayOfTheWeek
15 Mar, 2008 - 07:02 PM
Post #6

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions
QUOTE(Topher84 @ 15 Mar, 2008 - 07:55 PM) *

I have a degree in CS so obviously this does make sense.. now I am asking what is the specific problem that you are having with your code? there is no need to get defensive with it.. if you want help you need to give a little more information behind what the problem is and we will gladly help you....

also.. post your code in the code tags for easier readability please.


I'm just learning how to use this website. Sorry that I quoted what you said. Where is the code tags located? Are the member variables in place and what do you see wrong if any with my code?
User is offlineProfile CardPM
+Quote Post

Topher84
RE: DayOfTheWeek
15 Mar, 2008 - 07:04 PM
Post #7

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
when you hit reply.. there is text in the background of the reply box that tells you how to post your code.. just look in the background where you type
User is offlineProfile CardPM
+Quote Post

ITChief
RE: DayOfTheWeek
15 Mar, 2008 - 07:19 PM
Post #8

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions
QUOTE(Topher84 @ 15 Mar, 2008 - 08:04 PM) *

when you hit reply.. there is text in the background of the reply box that tells you how to post your code.. just look in the background where you type


Write a program that contains a class that implements the days of the week. The program should be able to perform the following on an object of a class.
1. Set the day
2. Print the day to the computer monitor(not the printer)
3. Return the day

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

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

Call these functions setDay, printDay and getDay.

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

DayOfTheWeekHEA~1

#include <string>
using std::string;
class DayOfTheWeek
{
private:
string day
string hour

public:
void setday(string, string);
void printday();
string getday();
};

DayOfTheWeekIMP
#include <iostream>
#include <string>
#include "DayOfTheWeek.h"

using namespace std;

void DayOfTheWeek::setdayinfo(string day, string hour)
{
Monday = mon;
Tuesday = tues;
Wednesday = weds;
Thursday = thurs;
Friday = fri;
Saturday = sat;
Sunday = sun;
}
void DayOfTheWeek::printDay()
{
cout << "Day: " << day << endl;
cout << "Hour: " << hour << endl;
}
string DayOfTheWeek::getday()
{
return day;
}

I'm I missing anything within this code?
User is offlineProfile CardPM
+Quote Post

Topher84
RE: DayOfTheWeek
15 Mar, 2008 - 08:27 PM
Post #9

D.I.C Head
Group Icon

Joined: 4 Jun, 2007
Posts: 232


Dream Kudos: 25
My Contributions
You are pretty far off but heading in the right direction probably...

Class Header
CODE

#pragma once
#include <iostream>
#include <string>

using namespace std;

class DaysOfWeek
{
public:
    private:
        string day;    //Day of the week
        string hour;   //Hour of the week

    public:
        DaysOfWeek(void);         //Constructor
          ~DaysOfWeek(void);        //Destructor
        string getHour();         //Get the hour of the week
        void   setHour(string);   //Set the hour of the week
        string getDay();          //Get the day of the week
        void   setDay(string);    //Set the day of the week
        void   printday();        //Print the day and hour of the week
};


Class Definition
CODE

#include "DaysOfWeek.h"

DaysOfWeek::DaysOfWeek(void)
{
    day  = "default";
    hour = "default";
}

DaysOfWeek::~DaysOfWeek(void)
{
}

string DaysOfWeek::getHour()
{
    string tempHour;

    cout << "Enter Hour: ";
    cin  >> tempHour;

    return tempHour;
}

void DaysOfWeek::setHour(string HourOfWeek)
{
    hour = HourOfWeek;
}

string DaysOfWeek::getDay()
{
    string tempDay;

    cout << "Enter Day: ";
    cin  >> tempDay;

    return tempDay;
}

void DaysOfWeek::setDay(string DayOfWeek)
{
    day = DayOfWeek;
}

void DaysOfWeek::printday()
{
    cout << "The Day Is : " << day << endl;
    cout << "The Hour Is: " << hour << endl << endl;
}


Main File
CODE

#include "DaysOfWeek.h"

using namespace std;

int main()
{
    string HourOfDay = "";         //Hour of day
    string DayOfWeek = "";         //Day of week

    DaysOfWeek DayOne;             //Day 1
    DaysOfWeek DayTwo;             //Day 2

    HourOfDay = DayOne.getHour();  //Get the day of day 1
    DayOne.setHour(HourOfDay);     //Set the day of day 1

    DayOfWeek = DayOne.getDay();   //Get the hour of day 1
    DayOne.setDay(DayOfWeek);      //Set the hour of day 1

    HourOfDay = DayTwo.getHour();  //Get the day of day 2
    DayTwo.setHour(HourOfDay);     //Set the day of day 2

    DayOfWeek = DayTwo.getDay();   //Get the hour of day 2
    DayTwo.setDay(DayOfWeek);      //Set the hour of day 2

    DayOne.printday();             //Display information on day 1

    DayTwo.printday();             //Display information on day 2
    
    return 0;
}


You can do the error checking and the day of the week thing where MOnday = mon and whatnot yourself.. this is 98% of your program.. I hope your prof gives me an A smile.gif
User is offlineProfile CardPM
+Quote Post

ITChief
RE: DayOfTheWeek
15 Mar, 2008 - 08:51 PM
Post #10

New D.I.C Head
*

Joined: 15 Mar, 2008
Posts: 17


My Contributions
QUOTE(Topher84 @ 15 Mar, 2008 - 09:27 PM) *

You are pretty far off but heading in the right direction probably...

Class Header
CODE

#pragma once
#include <iostream>
#include <string>

using namespace std;

class DaysOfWeek
{
public:
    private:
        string day;    //Day of the week
        string hour;   //Hour of the week

    public:
        DaysOfWeek(void);         //Constructor
          ~DaysOfWeek(void);        //Destructor
        string getHour();         //Get the hour of the week
        void   setHour(string);   //Set the hour of the week
        string getDay();          //Get the day of the week
        void   setDay(string);    //Set the day of the week
        void   printday();        //Print the day and hour of the week
};


Class Definition
CODE

#include "DaysOfWeek.h"

DaysOfWeek::DaysOfWeek(void)
{
    day  = "default";
    hour = "default";
}

DaysOfWeek::~DaysOfWeek(void)
{
}

string DaysOfWeek::getHour()
{
    string tempHour;

    cout << "Enter Hour: ";
    cin  >> tempHour;

    return tempHour;
}

void DaysOfWeek::setHour(string HourOfWeek)
{
    hour = HourOfWeek;
}

string DaysOfWeek::getDay()
{
    string tempDay;

    cout << "Enter Day: ";
    cin  >> tempDay;

    return tempDay;
}

void DaysOfWeek::setDay(string DayOfWeek)
{
    day = DayOfWeek;
}

void DaysOfWeek::printday()
{
    cout << "The Day Is : " << day << endl;
    cout << "The Hour Is: " << hour << endl << endl;
}


Main File
CODE

#include "DaysOfWeek.h"

using namespace std;

int main()
{
    string HourOfDay = "";         //Hour of day
    string DayOfWeek = "";         //Day of week

    DaysOfWeek DayOne;             //Day 1
    DaysOfWeek DayTwo;             //Day 2

    HourOfDay = DayOne.getHour();  //Get the day of day 1
    DayOne.setHour(HourOfDay);     //Set the day of day 1

    DayOfWeek = DayOne.getDay();   //Get the hour of day 1
    DayOne.setDay(DayOfWeek);      //Set the hour of day 1

    HourOfDay = DayTwo.getHour();  //Get the day of day 2
    DayTwo.setHour(HourOfDay);     //Set the day of day 2

    DayOfWeek = DayTwo.getDay();   //Get the hour of day 2
    DayTwo.setDay(DayOfWeek);      //Set the hour of day 2

    DayOne.printday();             //Display information on day 1

    DayTwo.printday();             //Display information on day 2
    
    return 0;
}


You can do the error checking and the day of the week thing where MOnday = mon and whatnot yourself.. this is 98% of your program.. I hope your prof gives me an A smile.gif


Thanks for your help Topher.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:38PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month