C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how to add date in c++ program

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
pradeep
Guest





PostPosted: Thu Oct 27, 2005 12:25 pm    Post subject: how to add date in c++ program Reply with quote



hi!
i want to know how define a datatype to input date by user and store it.

Back to top
Jonathan Mcdougall
Guest





PostPosted: Thu Oct 27, 2005 1:05 pm    Post subject: Re: how to add date in c++ program Reply with quote



pradeep wrote:
Quote:
hi!
i want to know how define a datatype to input date by user and store it.

This can be failry simple or very complex, depending on what you mean
by "date", "input" and "store". A simple implementation could be

class date
{
public:
// constructors
// member functions to set and get date values

private:
int day_;
int month_;
int year_;
};

istream &operator>>(istream &in, date &d)
{
// read values from 'in'
// store them in d

return in;
}

ostream &operator<<(ostream &out, date &d)
{
// send all the data from 'd' to out
}

1) how do you want to represent the date (timestamp, d/m/y, a class
from another library, etc.)?
2) what can the user do with a date object (arithmetic, comparisons,
validation, etc.)?
3) what is the input format (fixed (25/12/2005), variable ("December
25, 2005", "Christmas 2005"), etc.)? How do you validate it? Do you use
locales?
4) what is the output format (is screen output (for humans) different
from "storage" (xml file, binary file))?

As you can see, sky is the limit.


Jonathan


Back to top
dinakar_desai@yahoo.com
Guest





PostPosted: Fri Oct 28, 2005 1:02 am    Post subject: Re: how to add date in c++ program Reply with quote




pradeep wrote:
Quote:
hi!
i want to know how define a datatype to input date by user and store it.

define it as class and use it.
class date {
int month;
int day;
int year;
public:
some methods to deal with date.
};

HTH
../dinakar


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.