![]() |
|
#1
|
|||
|
|||
Write the declaration for a Date objectthe Question was:
a.Write the declaration for a Date object. The user should be able to instantiate an object as the following: Date date_1; //current date or Date date_2(01,02,2006); The Date object should contain the following functions: -Set the day, month and year. The values should be validated. (assume all months have 30 days) -Get a string format of the date: day, month and year of the object in one function. -Print the next date of the date object.. -Print the birth date in the format dd-mm-yyyy. -Calculate age member function that takes one object parameter of type Date and return the difference between the invoking object (current date) and the passed object (birth date) as a number of days. Test your class by creating 2 Date objects: today's date and your birth date, then write a menu that allows the user to use the above functions on your birth date i.e. the second date. ive start solve it: CPP / C++ / C Code:
but idont know if i should use pointer or array..? Last edited by admin : 26-Oct-2007 at 06:06.
Reason: Please insert your C/C++ example codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
|||
|
|||
Re: could anyone help me please?This is a simple way to convert it to a string using sprintf().
CPP / C++ / C Code:
Do you need to use an array or pointer for what? |
|
#3
|
|||
|
|||
Re: could anyone help me please?i'll be right back :shy:
|
|
#4
|
|||
|
|||
Re: could anyone help me please?ok, this is the final answer.. and i hope its good :/
CPP / C++ / C Code:
when i ask him to Get a string format he doesnt return anything.. is it the string library wrong? hope u test this program and tell me if i need to fix something or not.. |
|
#5
|
|||
|
|||
Re: could anyone help me please?fakepoo
Quote:
Quote:
i dont know, but i think there is way to acsess to the private varible by using pointer.. than u very much for ur help.. |
|
#6
|
|||
|
|||
Re: Write the declaration for a Date objectsprintf() is an old C function for formatting strings. Basically, if you had a variable called count that is of type int and you wanted to print a message that said "The count is X" where X is the value of count, you would have to use something like sprintf() when dealing with char*-type strings. Here are the basics:
sprintf( char* Destination, char* Format,[list of arguments, separated by commas) Destination - the string to print into. Format - the string containing the desired format. When creating the format string, you can put any text you want. At the place where you want to insert the value of a variable, you put a % sign followed by a specifier. The specifier depends on the variable data type. For an integer, the specifier is 'd'. So, for our example above, you would do it like this: CPP / C++ / C Code:
If you wanted to add more variables, then put another %[specifier] into the format string and the variable as an additional argument. For example: CPP / C++ / C Code:
For more information about using sprintf(), see: http://www.cplusplus.com/reference/c...o/sprintf.html and search "sprintf". Good luck! ~fakepoo |
|
#7
|
|||
|
|||
Re: Write the declaration for a Date objectQuote:
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The