c++ Class and function

Discussion in 'C++' started by necko, Apr 27, 2012.

  1. necko

    necko New Member

    Joined:
    Mar 10, 2012
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Hello to all programmer :))

    can you help me in this problem please :))?? Using function and Class

    Im beginner in c++ language

    Thank You for those who help me :))

    ______________________________________________________________
    Design and implement a class DayType that implements the day of the week in a program. The class should store the day such as Sun for "Sunday". The program should be able to perform the following operaions on a object of type DayType:


    1. Set the day.
    2. Print the day.
    3. Return the day.
    4. Return the next day.
    5. Return the previous day.
    6. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday, and we add 13 days, the day to be returned is Monday.

    Write the definions if the function to implement the operations of the class DayType as defined in #1. Also, write a program to test various operation on this class
    _______________________________________________________________


    Thank You for all those who help me :))
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    A simple idea might be to use an array of strings and an integer as your private data.

    Code:
    const std::string DOW[] = { "Sunday", "Monday", ... };  // 0-6
    
    class DayType {
       private : int curday;
    };
    the current day, if you need to return a string, would be something like DOW[curday];

    next day and prev day would be curday + 1 and curday - 1 respectively. However, you need to check boundaries; for example, with prev day, if it's currently sunday or 0, you wouldn't want -1 but 6. The opposite would be true of next day.

    to calculate some day in the future, just add it to the current day... something like DOW[(curday + future_day) % 7]. No check for days in the month, leap year, or such.

    Hope that helps
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice