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 - // Gail Sears
-
/*This program allows the user to add trucks to their
-
inventory. It also allows them to add and remove donations
-
from the truck chosen. It also display a chart of
-
what trucks are in inventory, with the name of the
-
truck and the amount of donations in each one.
-
*/
-
#include <iostream.h>
-
#include <iomanip.h>
-
#include <stdlib.h>
-
#include <conio.h>
-
#include <string.h>
-
#include <ctype.h>
-
-
#define max_trucks 500
-
#define max_cap 250
-
-
class OIL_TANK
-
{
-
private:
-
int ID_NUM;
-
int TRUCK_CAP;
-
int DON_ON_HAND;
-
static int NUM_TRUCKS;
-
-
public:
-
OIL_TANK (int id, int don= 0);
-
~ OIL_TANK ();
-
int ADD_DONATIONS (int amt);
-
int REMOVE_DONATIONS (int amt);
-
inline int GET_ID_NUM (){return ID_NUM;}
-
inline int GET_TRUCK_NAME () (return MERS/GOODWILL;)
-
inline int GET_CAP () {return TRUCK_CAP;}
-
inline int GET_CONT() {return DON_ON_HAND;}
-
static int TOTAL_TRUCKS ();
-
};
-
int OIL_TANK::NUM_TRUCKS = 0;
-
-
OIL_TANK::OIL_TANK (int id, int don)
-
{
-
ID_NUM = id;
-
DON_ON_HAND = don;
-
TRUCK_CAP = 250;
-
++NUM_TRUCKS;
-
}
-
int OIL_TANK::ADD_DONATIONS (int amt)
-
{
-
if (DON_ON_HAND + amt > TRUCK_CAP)
-
return -1;
-
else
-
return DON_ON_HAND += amt;
-
}
-
int OIL_TANK::REMOVE_DONATIONS (int amt)
-
{
-
if (DON_ON_HAND - amt < 0)
-
return -1;
-
else
-
return DON_ON_HAND -= amt;
-
}
-
-
OIL_TANK::~OIL_TANK ()
-
{
-
delete [] TRUCK_NAME;
-
}
-
int OIL_TANK::TOTAL_TRUCKS()
-
{
-
return NUM_TRUCKS;
-
}
-
OIL_TANK* create_truck();
-
void display (OIL_TANK&);
-
-
void main ()
-
{
-
int don_amt,
-
result,
-
count = 0,
-
choice;
-
char select = ' ';
-
char answer = ' ';
-
-
OIL_TANK* truck_table[max_trucks];
-
do
-
{
-
cout << "\n\n WELCOME TO THE MERS/GOODWILL TRUCK INVENTORY\n";
-
cout << "\n\nPlease choose a number from the menu below.\n";
-
cout << "\nl. Add a truck to inventory.";
-
cout << "\n2. Add donations to a truck.";
-
cout << "\n3. Remove donations from a truck.";
-
cout << "\n4. Display the trucks in inventory.";
-
cout << "\n5. Quit the Program.";
-
cout << "\n\nPlease enter your selection now: ";
-
cin >> select;
-
clrscr ();
-
switch (select)
-
{
-
case '1':
-
cout << "\nDo you want to add a truck to inventory? (Y/N): ";
-
cin >> answer;
-
while (toupper(answer) == 'Y' && count < max_trucks)
-
{
-
truck_table [count] = create_truck();
-
++count;
-
cout << "\nDo you want to add a truck to inventory? (Y/N): ";
-
cin >> answer;
-
}
-
break ;
-
case '2':
-
cout << "\nTo which truck would you like to add donations?(truck_num): ";
-
cin >> choice;
-
if (choice < 1 || choice > count)
-
{
-
cout << "\n\nINVALID ENTRY!!! ";
-
break;
-
}
-
else
-
{
-
cout << "n\nPlease enter the amount of donations to add: ";
-
cin >> don_amt;
-
result = truck_table[choice - 1]->ADD_DONATIONS (don_amt);
-
if (result < 0)
-
cout<< "\nERROR Truck capacity is not large enough!!!\n";
-
else
-
cout << "\nDonations Added!!! ";
-
break;
-
}
-
case '3':
-
cout << "\nFrom which truck would you like to remove donations? (truck_num): ";
-
cin >> choice;
-
if (choice < 1 || choice > count)
-
{
-
cout << "\n\nINVALID ENTRY!!! ";
-
break;
-
}
-
else
-
cout << "\nPlease enter the amount of donations to remove: ";
-
cin >> don_amt;
-
result = truck_table[choice - 1]->REMOVE_DONATIONS (don_amt);
-
if (result < 0)
-
cout <<"\nERROR Truck does not have enough donations in it!!!\n";
-
else
-
cout << "\nDonations Removed!!! ";
-
-
break;
-
-
case '4':
-
for (int x = 0; x < count; ++x)
-
display(*truck_table[x]);
-
break;
-
}
-
-
}
-
while (select != '5');
-
cout << "\n\n\n\n THANK YOU";
-
cout << "\n\n GOODBYE";
-
for (int x = 0; x < count; ++x)
-
delete truck_table[x];
-
}
-
OIL_TANK* create_truck()
-
{
-
int id_num,
-
donations = 0;
-
char name [80];
-
OIL_TANK* tankptr;
-
cout << "\nPlease enter the truck number: ";
-
cin >> id_num;
-
cin.ignore(81, '\n');
-
cout << "\nPlease enter the truck name: ";
-
cin.getline(name, 80);
-
cout << "\nPlease enter the amount of donations in truck: ";
-
cin >> donations;
-
cin.ignore(81, '\n');
-
clrscr();
-
tankptr = new OIL_TANK (id_num, donations);
-
cout << "\n\n\Trucks in inventory: " << tankptr->TOTAL_TRUCKS();
-
return tankptr;
-
}
-
void display (OIL_TANK& tank)
-
{
-
cout << "\nTruck ID " << tank.GET_ID_NUM();
-
cout << "\nName of Truck: " << tank.GET_NAME();
-
cout << "\nTruck Capacity: " << tank.GET_CAP();
-
cout << "\nDonations on Hand: " << tank.GET_CONT();
-
}
The following code in conjunction with: - #include<ctime>
-
time_t t = time(NULL);
-
cout<<ctime(&t);
-
//prints Mon Apr 12 12:30:00 2010 //there are ways of changing the format
-
12 1664
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?
yes or somewhere I can enter it, how do I code that in?
Why not write your own Date class?
i dont know how to add it
You prompt for the date and then enter it. - string s;
-
cout<<"enter current date";
-
getline(cin,s);
-
//type June 14 2010 which will appear on the screen and will be the content of s.
-
cout<<s;//prints June 14 2010 to screen.
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
You already have an OIL_TANK class so why not a Date class? - int main()
-
{
-
Date dt;
-
-
dt.GetDate();
-
-
//etc...
-
}
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.
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.
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.
The following code in conjunction with: - #include<ctime>
-
time_t t = time(NULL);
-
cout<<ctime(&t);
-
//prints Mon Apr 12 12:30:00 2010 //there are ways of changing the format
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
|
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...
| |