![]() |
|
#1
|
|||
|
|||
I need help with three C++ assignments asap pleaseOkay, I'm having a hard time with the three assignments I have left to do. I've been working on these for a week now and I'm getting no where. I asked the prof but she said to use the examples from the book which can help to some point but at the same time confuse me even more. The examples from the book didn't help much and I'm not entirely sure I'm doing it right since I can't get the programs to run. Can anyone help me on what I'm doing wrong and what I should be doing if I'm not already? To avoid confusing of what I'm doing the assignment is: Construct a Time class contaning interger data members, seconds, minutes, and hours. Have the class contain two constructors. The first should be default constructor having the prototype time(int, int, int), which uses default values 0 for each data member. The second constructor should accept a long integer representing a total number of seconds and disassemble the long integer into hours, minutes, and seconds. The final function member should display the class data members. and this is what I have done:
CPP / C++ / C Code:
This program I'm supposed to write a C++ program named larger() that returns the later of any two dates passed to it and this is what I have: CPP / C++ / C Code:
The result is supposed to display 11/3/2005 since it's the most recent date. The last problem I'm working on I'm supposed to add an addition to a program given to me. The assignment is.. Add to the program I provided you another member function named convrt() that does the following: The function should access the month, year, and day data members and should display and then return an integer that is calculated as year * 10000 + month * 100 + day. For example, if the Date is 2/1/2007, the return value is 20070102. This is what I have done so far: CPP / C++ / C Code:
I'm not sure what to do. Am I supposed to use a loop statement? I know I'm supposed to use year * 10000 + month * 100 + day someplace but I don't know where or how to do it. These problems are really confusing to me and I hope I'm not confusing anyone else. If I left anything out please let me know. I'm doing my best to understand this programming stuff. I really need help if anyone can. |
|||
|
#2
|
|||
|
|||
Re: I need help with three C++ assignments asap pleaseQuote:
Why not take them one at a time? Maybe getting the first one going will help you see how to approach the others. To have reasonable expectations of getting meaningful help with fewest iterations, I respectfully suggest that, instead of saying, "I can't get...," you do the following: Post the first one. Tell us what happened when you compiled the program. Paste compiler messages into your post. Paste the entire message (don't edit; don't paraphrase). If there are lots and lots of messages, then just post the first ten or so. Sometimes fixing the first ones will cause other messages to go away, or at least give you some clues to fixing the others. If it compiles without any messages (no errors; no warnings), then tell us what happened when you try to execute it. If the assignment is to write a class, don't you need to write a main() function that instantiates class objects and tests whatever methods were assigned? Show us what input you gave it (if any) and tell us exactly what happened. Tell us what you expected to happen, and ask specific questions about what you don't understand about the difference between what you expected to see and what you saw. Tell us what compiler you are using. Sometimes it makes a difference to people who want to help. The idea is that maybe we can walk you through it. I know (believe me, I know) that compiler messages aren't always very clear, especially when you are just getting starting, but if we see what you are seeing, we might be able to elucidate. Regards, Dave No one was born knowing this stuff, you know. ---davekw7x |
|
#3
|
|||
|
|||
Re: I need help with three C++ assignments asap pleaseQuote:
The part that your comment says that you added, the "convrt" operation, seems rather ill-conceived. For one thing, you don't define a "convrt" operation in your class definition. You just lumped it on at the end. Also, we don't usually instantiate instances of the class in a class member operation. You see, in the case of a non-static member, you are not able to invoke the operation until you have a class instance (an object of the type defined by the class) and we reserve the "right" to instantiate objects of the type to its constructor(s) and externals who need to use the type. Also, naming an operation "convrt" is just plain stupid. If you're going to "convert" a date from something to something else, at least spell out the word convert. You gain nothing by saving the "e" in typing. Also, we try to be to be explicit when naming things such that we provide clarity and remove doubts whenever possible. The notion that the "convert" operation converts to a "int" is made solely by its return type. Since we can not overload convert based solely on its return type, we further breakdown the innate polymorphic reasons for using C++. In other words, if Date::convert would ever want to return a "long" we'd be "stuck." Note that many class libraries return long when converting a Date type to an integral type. Additionally, you may want to consider a different naming scheme, such as: Date::toLong() or Date::toInt() or something along those lines. Another choice might be to overload a convert operation: CPP / C++ / C Code:
...returning the "result" as an argument, which demonstrates the polymorphism mentioned earlier. If you want to "test" the conversion functionality, instantiate a Date object in main or some function called by main and invoke the Date::convert operation. Don't try to create Date objects inside of one of its member operations. Another naming "gotcha" is to use the class name in a non-ctor/cctor/dtor member operation. We don't use Date::showDate() because Date::show() already tells us all that it is going to be shown. Of course, "show" is rather ambiguous. Better might be Date::toStdOut() or something like it. Better yet is to write streaming I/O operations that you can invoke directly with stream operators. Things like: Date( int mm, int dd, int yyyy ) {...} ...do not do anything explicit in terms of ensuring that the data is valid. For example, there is nothing in your code that keeps the user from entering a -2934829 for the month, 100 for the day and a 1 for the year (or billions upon billions of other "bad date" combinations). You need to validate your input so that you don't end up with garbage. The same can be said for your Time class: CPP / C++ / C Code:
...what prevents the following input: ss = 1928174, mm = 72, hr = -1? Is that going to translate to a valid time? Some of the features of a well-rounded date class are missing. Granted, you want to start slowly adding the basics and add more features as you progress, but since I'm "here," I'll mention a few of them: One would expect that the Date would also be able to tell me things like what day of the week it is. It would also be reasonable to assume that it could tell me what day of the year it is in terms of 1-365 (or 366 if a leap year). The notion of having an args ctor with the following bounding constraints seems rather poorly considered: Date(int = 7, int = 4, int = 2006); ...since this date is in the past, when it is ever going to be useful on a wide enough scale as to be criteria for default values if the user doesn't care to explicitly enter one of them? Better is to write a no-args ctor that produces a Date object initialized to the "now" date. With some minor changes, I was able to get your code to compile and run, though I did not implement the changes that I recommend here. CPP / C++ / C Code:
Output: Code:
...in order to determine whether a date is greater-than, less-than or equal-to another Date, I'd say that it should sound a lot like we need some comparison operators in our class. Something like: CPP / C++ / C Code:
:davis: |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ student needs helps ASAP | silverneon | C++ Forum | 10 | 06-Mar-2007 15:14 |
| Array 1 dimensional help please asap | lion123 | C Programming Language | 10 | 18-Feb-2005 21:53 |
| Need Help ASAP | yeshwanth | C++ Forum | 0 | 04-Oct-2004 01:22 |
| Need Help With My Project | spring200301016 | Computer Programming Advertisements & Offers | 1 | 28-Mar-2004 03:44 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The