Ask Experts Questions for FREE Help !
Ask
    JPKrouse's Avatar
    JPKrouse Posts: 1, Reputation: 1
    New Member
     
    #1

    Jan 14, 2011, 10:31 PM
    C++ help with passing between functions.
    I am trying to write a program that contains a class that implements the days of the week.
    I got to a point and now I am a bit stuck.

    I have changed it so many time I am starting to confuse myself.. ANY help would be appreciated!
    my code is:
    #include <iostream>
    #include <string>
    #include <cstring>

    using namespace std;

    class DayOfTheWeek
    {
    private:
    string dayName;
    int result;

    public:
    int toNum(string day)
    {
    if (dayName == "Monday") return 0;
    if (dayName == "Tuesday") return 1;
    if (dayName == "Wednesday") return 2;
    if (dayName == "Thursday") return 3;
    if (dayName == "Friday") return 4;
    if (dayName == "Saturday") return 5;
    return 6;
    }
    string toName(int I)
    {
    switch (I)
    {
    case 0: return "Monday";break;
    case 1: return "Tuesday"; break;
    case 2: return "Wednesday"; break;
    case 3: return "Thursday"; break;
    case 4: return "Friday";break;
    case 5: return "Saturday";break;
    default: return "Sunday";break;
    }
    }
    void setDay (string day)
    {
    dayName = day;

    }
    string printDay()
    {
    cout << dayName;
    }
    string getDay()
    {
    return dayName;
    }
    string plusOneDay(string day)
    {

    /*char Monday[] = "0";
    int result;
    result = atoi("Monday");
    */

    return toNum();
    }
    string minusOneDay()
    {
    }
    string addDays()
    {
    }
    };

    int main()
    {
    DayOfTheWeek monday;
    monday.setDay("Monday");
    monday.toNum(dayName);
    cout << Monday.toNum();

    cout << "monday object is set to " <<monday.getDay() <<endl;
    //cout << "The day after monday is " <<monday.plusOneDay() << endl;
    //cout << "The day before monday is" <<monday.minusOneDay() << endl;
    cout << "The value for monday object is still " <<monday.getDay() <<endl;
    //cout << "Monday plus 3 = " <<monday.addDays(3) <<endl;
    //cout << "Monday minus 3 = " <<monday.addDays(-3) <<endl;

    cin.ignore(2);

    return 0;
    }

    essentially, I want it to set the day as Monday and be able to add a day, and subtract a day and have the right day come to the output (ie Tuesday for add a day,etc.. )
    Also, I need to be able to add a number to the day and have the output come out correct for the right day of the week.
    I was trying to make the Monday object into an int using the toNum() function, and then back again to string to display the name with the toName() function.
    In the plusOneDay() function I was trying to make the value from ToNum() add with the number for the current day of the week (monday).

    I deleted the code from the other functions,so this is very incomplete.
    can anyone give me any guideance if I'm going about this all wrong?

Check out some similar questions!

How to solve trig functions applications for advanced functions? [ 2 Answers ]

A point on the ocean rises and falls as wave pass Suppose that a wave passes every 4 s, and the height of each wave from the crest to the trough in 0.5 m. a) how do we graph the height of the point relative to tis average height for a complete cycle, starting at the crest of a wave. And how do...

Composition Functions and Inverse Functions [ 3 Answers ]

Wow! These things are boogers! :eek: any way to make these things easier?

2weeks late & passing passing clots [ 1 Answers ]

My period is weeks late and yesterday I had some bad cramping. I had some light bleeding & then I passed to large clots. I have never had any clots this size before. I am still bleeding. Is this just a late period or am I having a miscarriage ?

Passing from HD to new HD [ 1 Answers ]

I have an 160g Hard Drive. However, I bought a new 500g HD. How can I pass the stuff from the old to the new? Please be specific. I have little experience on this thing about the slave and such. Appreciate the help!

Passing over [ 8 Answers ]

My brother passed over, nearly 12 years ago from a heart condition, it was very quick and painless by all accounts, when I'm feeling sad or lonely I talk to my brother and feel he is answering me, what I would like to know is,if this is actually happening or is my imagination running away with me?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search