Thread: (Date dt)??? I'm lost...

  1. #1
    Registered User
    Join Date
    Jun 2006

    Unhappy (Date dt)??? I'm lost...

    Hi all!

    OK, so here is my question (code is below): class name for the below project is Date. In the below functions that return a boolean and a string, what is (Date dt)? I'm used to seeing parameter syntax as (datatype dataname). What the heck is Date doing where the data type normally goes? Where did this "dt" come from? It kind of fell out of the sky, there is no earlier reference to it in the data declaration, and it is in the method declaration section as :

    bool Date::isWeekday(Date dt);
    string Date::NameOfDay(Date dt);

    Would someone explain to me what this is and what is does in the program? I'm so lost and frustrated, and my professor thinks I'm a dummy, but the text does not explain at all!

    bool Date::isWeekday(Date dt)
        int day;
    	day = dt.dayOfWeek();
    	if(day >= 2 && day <= 6)
    		return true;
    		return false;
      string Date::nameOfDay(Date dt)
        int day;
    	day = dt.dayOfWeek();
    		case 0:
    			return "Satruday";
    		case 1:
    			return "Sunday";
    		case 2:
    			return "Monday";
    		case 3:
    			return "Tuesday";
    		case 4:
    			return "Wednesday";
    		case 5:
    			return "Thursday";
    		case 6:
    			return "Friday";

  2. #2
    Registered User
    Join Date
    Jun 2006

    One more thing....

    Is this creating an object "dt" of the type "Date"? Can objects be created w/in parameter/argument in this manner? If it is an object of type "Date", I don't see any initial values...

    Thanks again,


  3. #3
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    A class is a data type, only it is defined by a programmer,and
    consists of data (ints, chars,floats,other class types etc), and
    methods to manipulate that data. You declare an instance of
    a class just as you would declare an int, and you can pass that
    instance to a function just as you would as normal. The
    isWeekday and nameOfDay functions are part of the Date class
    (member functions). Notice that dayOfWeek is as well: this line
    demonstrates how member functions are called:

    day = dt.dayOfWeek();

    Notice the '.' - that means that the dayOfWeek function is being
    called against the class instance dt. General form:

    class_instance.member_function (args);

    The strange thing about this code is that because isWeekday and
    nameOfDay are member functions, they are called against
    instances of a class, but they are taking a class of the same type
    and returning information about that instance, as opposed to the
    instance it's being called against.

    That's poor design, judging by what the functions do.
    Last edited by Richie T; 06-24-2006 at 11:55 AM.
    No No's:
    fflush (stdin); gets (); void main ();

    Example of fgets (); The FAQ, C/C++ Reference

    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition

    ASCII stupid question, get a stupid ANSI

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    dt is an object of type date.


    The first line reads bool Date::isWeekday(Date dt)

    This defines a function named isWeekday belonging to the Date class. This function returns a bool and accepts a Date object as a parameter. The parameter has been named dt. When this function is called, a Date object must be passed. That object will be recognized inside the function as having the name dt.

    This is procedural programming. You may want to take a look at the functions tutorial on this website.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. CDate Class - handle date manipulation simply
    By LuckY in forum C++ Programming
    Replies: 5
    Last Post: 07-16-2003, 08:35 AM