Write a menu-driven program that repeatedly allows the user to select one of the following tasks:

(Task 1) User enters the time of city A, time difference between cities A and B, and the program will output the equivalent time of city B.

Define and implement a class Time. Time difference is a positive value if time of city B is ahead of city A. It is a negative value if time of city B is behind city A.

Typical Sample Runs for Task 1 (user inputs in bold):
Enter hrs, mins and am/pm of time of city A: 2 10 pm
Enter time difference (in hrs) between cities A & B: 6
The equivalent time of city B is 8:10 pm.

Enter hrs, mins and am/pm of time of city A: 9 45 am
Enter time difference (in hrs) between cities A & B: -3
The equivalent time of city B is 6:45 am.

Im now doing on this and got stuck.
This is what i do. The code is below

How about something like that for the class prototype. Now try to figure out what the parameters for the methods mean, and try to implement them. Using this class in a program should be a piece of cake, if you got that done.

(Also note, that your code contains public data members. Don't do that! Data has to be private, especially since you may need to validate the parameters first. With public data, you're class would accept times such as 100.-23 FM.)

can someone help me.
I want the user to key in the time difference (in hrs) between cities A & B like and show the equivalent time of city B.

The user can key in any number in the time difference (in hrs) between cities A & B. ex negative or positive number.
thanks

01-10-2007

CodeMonkey

What do A and B refer to in your code?

01-11-2007

iMalc

So who wrote that newer piece of code?
It was clearly not written by the same person.

01-11-2007

anon

Well, this code looks very elegant, except that Time::print_A and Time::print_B are identical, Time::printSetup is unused (and not needed - and should be a private method anyway).

It looks as if you got some code from a solution to an earlier assignment (which you probably failed / stole from somebody), copied the print() function (because you have no idea what variables are and how classes work - that you make different instances of a class and call the same methods on them, not the other way round), and wrote a stupid driver program that doesn't take you one step closer to the solution.

Adding hours to a given time should be done by a class method, not in main.

Try harder.

01-11-2007

swgh

Gong is learning from the popular Detiel C++ programming books. I have done this assignment, and like anon said it's quite easy with the correct class. The book does tell you before this task how to set a class out correctly. After this he will have to do an assignment about a post office. Good luck gong.

01-11-2007

anon

If he's learning from a book, then I'm sorry for my harsh words.

But really, instead of struggling on without understanding the basics, find the place where things got confusing, reread, do the exercises and try out the new concepts with similar programs.