![]() |
|
#1
|
|||
|
|||
C++ program to calculate time remainingHi there. My nephew is taking a required course in C++. I, however, only know Visual Basic and am having a hard time helping him. I could use your help. Here is his assignment:
I noticed that when the code has :: it gives an emoticon. Sorry! For the assignment modify the three files that we used for the C++ example that involved time. Add the ability to create a deadline. Your software should provide the user with the capability of setting a deadline, inspecting a deadline, and calculating the amount of time remaining between the current time (the time defined already in the class) and the deadline. --------------------------------- Here are the given files: time2.cpp: CPP / C++ / C Code:
CPP / C++ / C Code:
timetest.txt: CPP / C++ / C Code:
Last edited by LuciWiz : 01-Dec-2008 at 12:31.
Reason: Please insert your C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: C++ program to calculate time remainingQuote:
Quote:
It is not clear whether the assignment is to add another class or add a data member to the existing class or to use the present classes and make two instances of Time objects: One would be "current time" and the other would be the "deadline." In any case you will have to subtract current time from the deadline to calculate the remaining time. Additional new features will be stuff to, somehow, read time information from the user and either use it in a constructor, or to have class functions that use this to update the fields in the Time objects. So: where would you like to start? I like to think about how the information, "current time" and "deadline time," can be used to calculate time remaining. One possibility: 1. Convert hours:minutes:seconds since midnight to seconds since midnight for both time values. 2. Subtract the "current" seconds from "deadline" seconds. 3. Convert the result back to hours:minutes:seconds. This immediately raises a question: Are we always going to assume that "current" time and "deadline" time are on the same day? If not, then we also have to take days into account. Since you didn't mention it, I will assume that they are both on the same day. My point is that when you write a program like this (or like anything else), think about what the program is supposed to do. It's embarrassing to spend lots of time on a program and then find that there are some basic limitations that keep it from doing what you had in mind (or discovering that what you had in mind simply isn't do-able with the structure given---what if the deadline is supposed to be next Tuesday?) Here's the "bottom-up" approach: Make sure you can enter data and do calculations: CPP / C++ / C Code:
A run: Code:
Regards, Dave Footnote: Instead of converting to seconds, you could do modulo-time subtraction: Subtract seconds. If the result is less than zero, then add 60 and set a "borrow" flag to 1, else set the "borrow" flag to zero. Subtract minutes and subtract the borrow flag. If the result is less than 0 , then add 60 and set the "borrow" flag to 1, else set the "borrow" flag to zero. Etc. If I were designing the classes, I probably would just keep everything in seconds and convert from/to hours:minutes:seconds as required for input/output operations. For many (most?) computers these days, the date/time inside the computer is maintained as number that counts the number of seconds from some arbitrary "time zero" known as the "epoch." |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Python - Need help with time card script/wage calculator | sigkill9 | Python Forum | 5 | 12-Mar-2008 22:01 |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 11:13 |
| Hard Time W/ Program | Kres10_98 | C++ Forum | 5 | 09-Aug-2007 10:57 |
| My randomly generated quote program | monalin | C++ Forum | 4 | 18-Oct-2005 17:18 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 08:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The