473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How do I add the date to it?

I am wanting to add the date to this program, how do I do it? What I mean is everytime I get into to it I want to be able to enter the days date, help please...Thanks

Expand|Select|Wrap|Line Numbers
  1. // Gail Sears
  2. /*This program allows the user to add trucks to their
  3. inventory. It also allows them to add and remove donations
  4. from the truck chosen. It also display a chart of
  5. what trucks are in inventory, with the name of the
  6. truck and the amount of donations in each one.
  7. */
  8. #include <iostream.h>
  9. #include <iomanip.h>
  10. #include <stdlib.h>
  11. #include <conio.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. #define max_trucks 500
  16. #define max_cap 250
  17.  
  18. class OIL_TANK
  19. {
  20. private:
  21. int ID_NUM;
  22. int TRUCK_CAP;
  23. int DON_ON_HAND;
  24. static int NUM_TRUCKS;
  25.  
  26. public:
  27. OIL_TANK (int id, int don= 0);
  28. ~ OIL_TANK ();
  29. int ADD_DONATIONS (int amt);
  30. int REMOVE_DONATIONS (int amt);
  31. inline int GET_ID_NUM (){return ID_NUM;}
  32. inline int GET_TRUCK_NAME () (return MERS/GOODWILL;)
  33. inline int GET_CAP () {return TRUCK_CAP;}
  34. inline int GET_CONT() {return DON_ON_HAND;}
  35. static int TOTAL_TRUCKS ();
  36. };
  37. int OIL_TANK::NUM_TRUCKS = 0;
  38.  
  39. OIL_TANK::OIL_TANK (int id, int don)
  40. {
  41. ID_NUM = id;
  42. DON_ON_HAND = don;
  43. TRUCK_CAP = 250;
  44. ++NUM_TRUCKS;
  45. }
  46. int OIL_TANK::ADD_DONATIONS (int amt)
  47. {
  48.     if (DON_ON_HAND + amt > TRUCK_CAP)
  49. return -1;
  50. else
  51.     return DON_ON_HAND += amt;
  52. }
  53. int OIL_TANK::REMOVE_DONATIONS (int amt)
  54. {
  55.     if (DON_ON_HAND - amt < 0)
  56. return -1;
  57.     else
  58.         return DON_ON_HAND -= amt;
  59. }
  60.  
  61. OIL_TANK::~OIL_TANK ()
  62. {
  63. delete [] TRUCK_NAME;
  64. }
  65. int OIL_TANK::TOTAL_TRUCKS()
  66. {
  67. return NUM_TRUCKS;
  68. }
  69. OIL_TANK* create_truck();
  70. void display (OIL_TANK&);
  71.  
  72. void main ()
  73. {
  74.     int don_amt,
  75.     result,
  76.     count = 0,
  77.     choice;
  78.     char select  = ' ';
  79.     char answer = ' ';
  80.  
  81. OIL_TANK* truck_table[max_trucks];
  82. do
  83. {
  84. cout << "\n\n        WELCOME TO THE MERS/GOODWILL TRUCK INVENTORY\n";
  85. cout << "\n\nPlease choose a number from the menu below.\n";
  86. cout << "\nl. Add a truck to inventory.";
  87. cout << "\n2. Add donations to a truck.";
  88. cout << "\n3. Remove donations from a truck.";
  89. cout << "\n4. Display the trucks in inventory.";
  90. cout << "\n5. Quit the Program.";
  91. cout << "\n\nPlease enter your selection now: ";
  92. cin >> select;
  93. clrscr ();
  94. switch (select)
  95. {
  96. case '1':
  97. cout << "\nDo you want to add a truck to inventory? (Y/N): ";
  98. cin >> answer;
  99. while (toupper(answer) == 'Y' && count < max_trucks)
  100. {
  101. truck_table [count] = create_truck();
  102. ++count;
  103. cout << "\nDo you want to add a truck to inventory? (Y/N): ";
  104. cin >> answer;
  105. }
  106. break ;
  107. case '2':
  108. cout << "\nTo which truck would you like to add donations?(truck_num): ";
  109. cin >> choice;
  110. if (choice < 1 || choice > count)
  111. {
  112. cout << "\n\nINVALID ENTRY!!! ";
  113. break;
  114. }
  115. else
  116. {
  117. cout << "n\nPlease enter the amount of donations to add: ";
  118. cin >> don_amt;
  119. result = truck_table[choice - 1]->ADD_DONATIONS (don_amt);
  120. if (result < 0)
  121. cout<< "\nERROR Truck capacity is not large enough!!!\n";
  122. else
  123. cout << "\nDonations Added!!! ";
  124. break;
  125. }
  126. case '3':
  127. cout << "\nFrom which truck would you like to remove donations? (truck_num): ";
  128. cin >> choice;
  129. if (choice < 1 || choice > count)
  130. {
  131. cout << "\n\nINVALID ENTRY!!! ";
  132. break;
  133. }
  134. else
  135. cout << "\nPlease enter the amount of donations to remove: ";
  136. cin >> don_amt;
  137. result = truck_table[choice - 1]->REMOVE_DONATIONS (don_amt);
  138. if (result < 0)
  139. cout <<"\nERROR Truck does not have enough donations in it!!!\n";
  140. else
  141. cout << "\nDonations Removed!!! ";
  142.  
  143. break;
  144.  
  145. case '4':
  146. for (int x = 0; x < count; ++x)
  147. display(*truck_table[x]);
  148. break;
  149. }
  150.  
  151. }
  152. while (select != '5');
  153. cout << "\n\n\n\n                       THANK YOU";
  154. cout << "\n\n                       GOODBYE";
  155. for (int x = 0; x < count; ++x)
  156. delete truck_table[x];
  157. }
  158. OIL_TANK* create_truck()
  159. {
  160. int id_num,
  161. donations = 0;
  162. char name [80];
  163. OIL_TANK* tankptr;
  164. cout << "\nPlease enter the truck number: ";
  165. cin >> id_num;
  166. cin.ignore(81, '\n');
  167. cout << "\nPlease enter the truck name: ";
  168. cin.getline(name, 80);
  169. cout << "\nPlease enter the amount of donations in truck: ";
  170. cin >> donations;
  171. cin.ignore(81, '\n');
  172. clrscr();
  173. tankptr = new OIL_TANK (id_num, donations);
  174. cout << "\n\n\Trucks in inventory: " << tankptr->TOTAL_TRUCKS();
  175. return tankptr;
  176. }
  177. void display (OIL_TANK& tank)
  178. {
  179. cout << "\nTruck ID " << tank.GET_ID_NUM();
  180. cout << "\nName of Truck: " << tank.GET_NAME();
  181. cout << "\nTruck Capacity: " << tank.GET_CAP();
  182. cout << "\nDonations on Hand: " << tank.GET_CONT();
  183. }
Apr 8 '10 #1

✓ answered by whodgson

The following code in conjunction with:
Expand|Select|Wrap|Line Numbers
  1. #include<ctime>
  2. time_t t = time(NULL);
  3.     cout<<ctime(&t);
  4. //prints Mon Apr 12 12:30:00 2010 //there are ways of changing the format
  5.  

12 1664
whodgson
542 512MB
So are you saying that every time the program is run you want a coded command
to provide the system date which will be printed to screen?
Apr 9 '10 #2
yes or somewhere I can enter it, how do I code that in?
Apr 9 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
Why not write your own Date class?
Apr 9 '10 #4
i dont know how to add it
Apr 9 '10 #5
jkmyoung
2,057 Expert 2GB
http://www.cppreference.com/wiki/c/date/time
http://www.cppreference.com/wiki/c/date/asctime

Note that time in seconds are returned so if you want it to print in a custom manner you can take a substring of the asctime.
Apr 9 '10 #6
whodgson
542 512MB
You prompt for the date and then enter it.
Expand|Select|Wrap|Line Numbers
  1. string s;
  2. cout<<"enter current date";
  3. getline(cin,s);
  4. //type June 14 2010 which will appear on the screen and will be the content of s.
  5. cout<<s;//prints June 14 2010 to screen.
Apr 10 '10 #7
ok I understand that part but now where do I put that, to return the correct date, how do I know the correct date is being entered and not any date being put in and the program taking it, again thanks for all the help
Apr 10 '10 #8
weaknessforcats
9,208 Expert Mod 8TB
You already have an OIL_TANK class so why not a Date class?

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     Date dt;
  4.  
  5.     dt.GetDate();
  6.  
  7.     //etc...
  8. }
I am sure you can write a Date class that holds a month, day and year and cna write a member function that stores the month day and year from the keyboard into the Date object.
Apr 10 '10 #9
whodgson
542 512MB
Yes but that will not necessarily guard against the entry of an incorrect date. I presume the date (and time) has to be entered by the system in this case.
Apr 11 '10 #10
weaknessforcats
9,208 Expert Mod 8TB
Here's where you earn you pay as a developer.

When you have the user enter a date, any old thing may be entered. So you need a) to have the user enter a monthn, day and year then b) you need to verify that what was entered is a valid date. So you call your nifty date validation function. If tyhe date is invalid, it does not get put in the Date object. Instead, the function fails and you test that in main() and ask for the user to try again.

Your date verification routine needs to a) insure the month is in the range 1-12. b) unsure that the days are possible for the month-that includes a 28 or 29 value for month 2. And that means you need to call a leap year caculation function that returns true of the year is a leap year and false otherwise. BTW: Leap years a divisible by 4 but not by 400. A yeat divisible by 4 and 400 is not a leap year.

All this means when you create your Date object that initializing the the date in the object to 0 month 0 days and 0 years is not correct since this is not a valid date. You Date constrcutor needs to set the object to a default date. Likemaybe it calls the operating system clock and parses out the current month, day and year.

Lastly, be sure this Date code is in a Date.h and a Date.cpp because I guarantee you will use this code all over the place forever.
Apr 11 '10 #11
whodgson
542 512MB
The following code in conjunction with:
Expand|Select|Wrap|Line Numbers
  1. #include<ctime>
  2. time_t t = time(NULL);
  3.     cout<<ctime(&t);
  4. //prints Mon Apr 12 12:30:00 2010 //there are ways of changing the format
  5.  
Apr 12 '10 #12
Yes Im wanting the user to be promted each time using the program to enter the date, not necessarily the time and of course I want it to recognize it and make sure the correct date is being entered each time. Thanks for alls help
Apr 12 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
4
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...
2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
9
by: Thomas R. Hummel | last post by:
Hello, I am importing data that lists rates for particular coverages for a particular period of time. Unfortunately, the data source isn't very clean. I've come up with some rules that I think...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
1
by: Liz Malcolm | last post by:
Hello and TIA. I have a DE form with an option group that if daily is selected todays date is used for start and end date, if weekly is selected Monday - Friday is used. I am trying to add a...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
3
by: JJ | last post by:
Here's the code. $link="http://xbox360cheat.org"; $close_date=$_POST; #last content change check if ($close_date == 0) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.