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

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




return date problem

 
Reply to this topicStart new topic

return date problem

prescott2006
20 Jan, 2008 - 08:53 AM
Post #1

New D.I.C Head
*

Joined: 13 Nov, 2007
Posts: 3


My Contributions
Hello,newbie here,i wan 2 write a program 2 determine the day after sum day.Example:like we input monday,then we input 10 ,then d program wil cum out wf thursday.i hv ald write d code,but it hv error but i duno where r d error.i hv write d program in 3 document,they include a header file,a implementation file,a main program.Plz help me....thnx in advance.



[quote]
CODE

header file
_______________:
#include<iostream>
#include<string>

class dayType
{
public:
    void setDay(string day,int num);
    void printDay(string day,int num);
    void returnTheDay(string after);
    void returnNextDay(string day);
    void returnPreviousDay(string day);

private:
    int num;
};



CODE


implementation file
________________:
#include<iostream>
#include<string>
#include"day.h"

using namespace std;

void dayType::setDay(string day,int num)
{
    cout<<"Enter a day like 'sunday'/'monday'...etc ";
    cin>>day;
    cout<<endl;
    cout<<"Key in a number of day "
    cin>>num;
    cout<<endl;
}

void dayType::printDay(string day,int num)
{
    cout<<"Today is "<<day<<"after "<<num
        <<"the day is "<<after;
    cout<<endl;

}


void dayType::returnTheDay(string day)
{
    else if (day==sunday)
    {
        return 7;
    }
    else if (day==monday)
    {
        return 1;
    }
    else if (day==tuesday)
    {
        return 2;
    }
    else if (day==wednesday)
    {
        return 3;
    }
    else if (day==thursday)
    {
        return 4;
    }
    else if (day==friday)
    {
        return 5;
    }
    else if (day==saturday)
    {
        return 6;
    }
    
    after=day+num;

    switch(after)
    {
    case '1':
        cout<<"monday";
            cout<<end;
        break;
    case '2':
        cout<<"tuesday";
        cout<<endl;
        break;
    case '3':
        cout<<"wednesday";
        cout<<endl;
        break;
    case '4':
        cout<<"thursday";
        cout<<endl;
        break;
    case '5':
        cout<<"friday";
        cout<<endl;
    case '6':
        cout<<"saturday";
        cout<<endl;
    case '7':
        cout<<"sunday";
        cout<<endl;
    }
}

void dayType::returnNextDay(string day)
{
    if (day==sunday)
    {
        cout<<"The next day is monday ";
        cout<<endl;
    }
    if (day==monday)
    {
        cout<<"The next day is tuesday ";
        cout<<endl;
    }
    if (day==tuesday)
    {
        cout<<"The next day is wednesday ";
        cout<<endl;
    }
    if (day==wednesday)
    {
        cout<<"The next day is thursday ";
        cout<<endl;
    }
    if (day==thursday)
    {
        cout<<"The next day is friday ";
        cout<<endl;
    }
    if (day==friday)
    {
        cout<<"The next day is saturday ";
        cout<<endl;
    }
    if (day==saturday)
    {
        cout<<"The next day is sunday ";
        cout<<endl;
    }
}

void dayType::returnPreviousDay(string day)
{
    if (day==sunday)
    {
        cout<<"The previous day is saturday ";
        cout<<endl;
    }
    if (day==monday)
    {
        cout<<"The previous is sunday ";
        cout<<endl;
    }
    if (day==tuesday)
    {
        cout<<"The previous is monday ";
        cout<<endl;
    }
    if (day==wednesday)
    {
        cout<<"The previous is tuesday ";
        cout<<endl;
    }
    if (day==thursday)
    {
        cout<<"The previous is wednesday ";
        cout<<endl;
    }
    if (day==friday)
    {
        cout<<"The previous is thursday ";
        cout<<endl;
    }
    if (day==saturday)
    {
        cout<<"The next day is friday ";
        cout<<endl;

    }



CODE

main program
_____________:
#include<iostream>
#include<string>
#include"day.h"

using namespace std;

void dayType();

int main()

{
    setDay(string day,int num)
        cout<<endl;
    returnTheDay(string after)
        cout<<endl;
    printDay(string day,int num)
        cout<<endl;
    returnNextDay(string name)
        cout<<endl;
    returnPreviousDay(string day)
        cout<<endl;

    return 0;

}


Can u tell me where r d syntax error?i reali duno

This post has been edited by prescott2006: 20 Jan, 2008 - 09:28 AM
User is offlineProfile CardPM
+Quote Post

#include<wmx010>
RE: Return Date Problem
20 Jan, 2008 - 09:05 AM
Post #2

D.I.C Head
**

Joined: 19 Jan, 2008
Posts: 75



Thanked: 1 times
My Contributions
Your code is not understandable....

Post Your Code Like This:

CODE
code here


The first thing i noticed is that your code is filled with syntax errors...

This post has been edited by #include<wmx010>: 20 Jan, 2008 - 09:16 AM
User is offlineProfile CardPM
+Quote Post

yooxygen
RE: Return Date Problem
20 Jan, 2008 - 07:45 PM
Post #3

New D.I.C Head
*

Joined: 20 Jan, 2008
Posts: 15


My Contributions
CODE

header file:
______________________________________________
enum weekDayType{Sun, Mon, Tue, Wed, Thu, Fri, Sat};

class dayType
{
public:
    void print();
    weekDayType nextDay();
    weekDayType prevDay();
    void addDay(int nDays);

    void setDay(weekDayType d);
    weekDayType getDay();

    dayType();
    dayType(weekDayType d);

private:
    weekDayType weekDay;
};



CODE

impletation file:
_______________________________________________
#include <iostream>
#include "dayType.h"

using namespace std;

void dayType::print()
{
    switch(weekDay)
    {
    case Sun: cout<<"Sunday";
              break;
    case Mon: cout<<"Monday";
              break;
    case Tue: cout<<"Tuesday";
              break;
    case Wed: cout<<"Wednesday";
              break;
    case Thu: cout<<"Thursday";
              break;
    case Fri: cout<<"Friday";
              break;
    case Sat: cout<<"Saturday";
    }
}

weekDayType dayType::nextDay()
{
    return weekDayType((weekDay + 1) % 7);
}

weekDayType dayType::prevDay()
{
    if (weekDay == Sun)
        return Sat;
    else
        return weekDayType(weekDay - 1);
}


void dayType::addDay(int nDays)
{
    weekDay = weekDayType((weekDay + nDays) % 7);
}

void dayType::setDay(weekDayType d)
{
    weekDay = d;
}

weekDayType dayType::getDay()
{
    return weekDay;
}

dayType::dayType()
{
    weekDay = Sun;
}

dayType::dayType(weekDayType d)
{
    weekDay = d;
}



CODE

main program:
__________________________________________
#include <iostream>
#include "dayType.h"

using namespace std;

int main()
{
    dayType myDay(Mon);
    dayType tempDay;

    cout<<"Today: ";
    myDay.print();
    cout<<endl;

    tempDay.setDay(myDay.nextDay());

    cout<<"Next Day: ";

    tempDay.print();
    cout<<endl;

    tempDay.setDay(myDay.prevDay());

    cout<<"Previous Day: ";

    tempDay.print();
    cout<<endl;

    myDay.addDay(11);
    
    cout<<"After 11 Days: ";
    myDay.print();
    cout<<endl;

    return 0;
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 04:26PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

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