![]() |
|
#1
|
|||
|
|||
Write a program that implements a class called DateI have to write a program that implements a class called Date. i have the functions needed for it and the loops but I'm not sure how the main looks. Can someone please help with the main function.
Just in case you need to see the Assignment. its below; Overview For this assignment, you are to implement a class called Date. This class will be used to represent simple dates. Date class The following definition for the Date class should be placed at the top of the CPP file: CPP / C++ / C Code:
Data Members The Date class contains five data members that are not available to the outside world. They are: * an integer to hold the month number * an integer to hold the day number * an integer to hold the year number * an array of integer constants that represent the number of days in each month * an array of constant pointers to character constants that represent the names of each of the months in a year The two arrays both hold constant values but they cannot be initialized in the Date class definition because the definition is simply a pattern for what an object will "look like" when it is created. This means that there is no memory allocated for the class definition and therefore the two arrays must be initialized outside of the class definition. Place the following array declaration/initialization statements at the top of the CPP file after the closing curly brace for the class definition. CPP / C++ / C Code:
Note 1: The arrays hold thirteen thirteen items sp that the month number can be used as a direct subscript to access a value. For example, to access the number of days in March use the statement monthDays[3]. Note 2: The class disregards leap years. Constructor: Date( int monthVal, int dayVal, int yearVal ) The constructor for this class is used to initialize a Date object to a specific date. It takes three arguments: the initial month, the initial day, and the initial year. The passed in values should only be used if they are valid. The month value should be between 1 and 12, inclusive. If it is invalid, set the month to January. The day value should be between 1 and the maximum number of days in the current month, inclusive. If it is invalid, set the number of days to the maximum for the current month. The year value should be positive. If it is invalid, set the year to 2009. Note/Hint: think about calling the setDate method that is described next. Methods void setDate ( int monthVal, int dayVal, int yearVal ) This method sets the date for the current object. It takes three arguments: the value for the month, the value for the day, and the value for the year. The passed in values should only be used if they are valid. The month value should be between 1 and 12, inclusive. If it is invalid, set the month to January. The day value should be between 1 and the maximum number of days in the current month, inclusive. If it is invalid, set the number of days to the maximum for the current month. The year value should be positive. If it is invalid, set the year to 2009. void printToday() This method prints the current date in the Date object in the format "monthName day, year". For example, if the month value is 11, day is 30, and year is 1977, then this method will print "November 30, 1977". int daysPassed() This method calculates and returns the number of days that have passed from the beginning of the year up to and including the current date in the Date object. Hint: To get started, think about writing a loop that will add up the maximum number of days in each month up to the current month in the Date object. int daysLeft() This method calculates and returns the number of days that are left in the current year in the Date object. This will only count the days after the current date in the Date object. Hint: To get started, think about writing a loop that will add up the maximum number of days in each month AFTER the current month in the Date object through December. main This part of the assignment is going to use the Date class described above. Create four Date objects with the values: * November 13, 1975 for the first object * January 1, 2009 for the second object * December 31, 2005 for the third object * Your birth date for the fourth object For each of the objects, display the following: * the current date * the number of days that have passed in the current year * the number of days left in the current year Output The output for this assignment should resemble the following: Today is November 13, 1975 317 days have passed in the year There are 48 days left in the year Today is January 1, 2009 1 days have passed in the year There are 364 days left in the year Last edited by admin : 06-Dec-2009 at 17:09.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
|||
|
|||
Re: ClassesPerhaps something like this should do it?
CPP / C++ / C Code:
|
Recent GIDBlog
GID Spam Detector 1.1.0 by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Classes referencing one another | kuroi | C++ Forum | 9 | 09-Oct-2008 02:10 |
| Trouble with Classes Within Classes | jdbrine | C++ Forum | 2 | 29-Jun-2006 15:26 |
| Re: Derived FLTK Classes | cable_guy_67 | FLTK Forum | 0 | 26-Jun-2005 20:07 |
| Assistance with classes... | Bravebird | C++ Forum | 7 | 27-Apr-2005 13:17 |
| Fairly simple classes help please | sammacs | C++ Forum | 0 | 30-Nov-2004 09:58 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The