473,800 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to add date in c++ program

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

Oct 27 '05 #1
2 5797
pradeep wrote:
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>>(ist ream &in, date &d)
{
// read values from 'in'
// store them in d

return in;
}

ostream &operator<<(ost ream &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

Oct 27 '05 #2

pradeep wrote:
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

Oct 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3922
by: Raskolnikow | last post by:
Hi! I have some beginner questions about C++, so please be gentle if the things I ask are trivial. What I want to do is a program that - changes the current (system) date, - calls an external program and - resets the system date again (after a delay).
4
5392
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
2
2191
by: msaccess | last post by:
Dear knowledgeable folks, System: Windows XP and Access 2002. In my participants form, I have the following date fields: EnrollmentDate: the actual date that the participant officially began the program ActualExitDate: the actual date that the participant exited the program MaximumDate: =+547 547 days added to the EnrollmentDate, which is the maximum amount of time (18 months) that a
8
22493
by: Michael A. Covington | last post by:
Is there a way to make a C# program print the date on which it was compiled? Finding the file date of the executable is one way, but it's not foolproof. Thanks!
3
7458
by: gregmalenky | last post by:
Visual C# 2005 Express - I am creating a employee scheduling program for work. When I need to do is for the program to open with a start date of the previous sunday. I also want the ability to change the start date to create a new schedule - however, it must begin on a sunday. I want the sunday date to be locked in so it doesn't always show the current date when executed. Also for a prompt to appear if the user tries to use another day...
9
3229
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database and not the file itself. To do this I will need to have a File class property for Create time and date that will let me "set" the Create time and date of the file to my own chooseing. The VB file class does not appear to have the ability
13
2212
by: priyasmita_guha | last post by:
Here is a program- /* PROGRAM: To find the difference between two dates */ #include<dos.h> #include<stdio.h> #include<conio.h> #include<process.h> void valid_date(int,int,int); int getkey(void); void differ_dat(struct date *,struct date *); const int mth={31,28,31,30,31,30,31,31,30,31,30,31};
2
14005
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go into SQL view to change the date range. This is what I have so far: TRANSFORM Count(.ID) AS CountOfID SELECT ., Count(.ID) AS FROM
2
11384
by: mshroom12 | last post by:
I am having trouble with the following project on hand. I use Eclipse to do my work in Java. This is what I'm supposed to complete. Date Validation In this exercise you will write a program that checks to see if a date entered by the user is a valid date in the second millenium. A skeleton of the program is in Dates.java. Open this program and save it to your directory. As indicated by the comments in the program, fill in the following: ...
2
2363
by: samvb | last post by:
Hi, I have just finished a program that uses ms access and depends on system date to do certain things. just when i was testing it, a friend suggested that i change system date to see how it reacts. And it totally failed if the system date changes. I have written a small module that can save me from this errors upon the user's request i.e. the user clicks a button to reset the date using my program. during the reseting process, i fix any date...
0
9555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10514
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10287
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10260
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10042
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9099
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.