Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My Massive Packet
#1
So Basically I got this Huge packet from my comp sci teacher.  It has close to 50 practice programs for a competition that my school is going to at Western New England College.  So I need to do as many as possible to help my chances of going (We have 5 teams of 4 people each she has not told us how many teams she is allowed to bring).  I will start working on one and post the to be created program in this topic.  Feel free to help me if you wish but you of course do not have to.  Programs that we are allowed to use C++, Java, QBasic, and Visual Basic.  Please by no means do these have to be pretty or adhere to the standards of the industry they just have to work.  Any help with this is much appreciated.  Also note these are not the programs used in the competition (obviously).  I will post the first one later tonight (proly 11:00pm EST) or tommorow.
Reply
#2
I lost it lol when I find it ill be sure to post them.
Reply
#3
Found it left it in a class.  Anyway here is the fist problem.  Please try to explain how you solved especially if you figure it out and I have not.  This isn't to rip you of code I just haven't touched QB in awhile and need to relearn some things to say the least.

Problem 1: What time is it?

    Military personnel avoid confusion between morning and afternoon times, a.m. and p.m., by using a 24-hour clock rather than a 12-hour clock.  Time is measured sequentially in a 24-hour period and is expressed as a 4 digit number number between 0001 and 2400.  The first two digits represent the number of hours past midnight.  After noon, add 12 to the hour to convert from standard time to military time.  Note that one or more leading digits of 0 are used if the number of hours is less than 10.  The last two digits represent the number of minutes after the top the hour.  Some examples of standard to military time conversions are shown in the table below.

Standard Time                    Military Time     
12:01 a.m.                        0001 hours
9:00 a.m.                          0900 hours
11:30 a.m.                        1130 hours
1:00 p.m.                          1300 hours
5:45 p.m.                          1745 hours
10:59 p.m.                          2259 hours

    Your program will read pairs of times in military format and print the number of hours and minutes elapsed from the first time to the second time.  If the first time is later than the second time, then the second time represents a time from the next day.  The first line of the input file contains the number of pairs of time to be processed.  Each of the remaining lines of the input file contains two military times per line (hours, minutes, hours, minutes).  Your output should indicate the number of hours and number of minutes elapsed between the two times for each pair of times in the input file.

Remember C++, Java, and VisualBasic programs should read from a separate data file

QBasic should read from the DATA statements in the code

Sample Input:

C++/Java                        QBasic                            VisualBasic
2                                    DATA 2                          2
09 00 17 30                      DATA 09, 00, 17, 30          09, 00, 17, 30
18 25 09 00                      DATA 18, 25, 09, 00          18, 25, 09, 00

Sample OutPut: (display this to the screen do not put the output into a file)

8 hours 30 minutes
14 hours 35 minutes
Reply
#4
Hi.  I don't understand your data for QBasic.  When you show:
DATA 2
DATA  09, 00, 17, 30
DATA  18, 25, 09, 00
what does 2 mean?  Is it supposed to be 0200 hours?
What does 09 ,00 ,17, 30 mean?  Is it supposed to be 0900 hours and 1730 hours?
What does the last one mean"  Is it supposed to be 1825 hours and 0900 hours?

If my above interpretation is correct, shouldn't the first DATA statement be:
DATA 02, 00

Once the above has been clarified, we can proceed, but, not before!
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#5
Ralph,
The DATA 2 conforms to the specs which say: " The first line of the input file contains the number of pairs of time to be processed."

So it looks like the program would have to check that the number of pairs matches those in the subsequent DATA statments. This could get tricky to check, especially if they don't match.

To alleviate this problem, I susgest that the Qbasic program also receive a file as input instead of using DATA statements.

Regards..... Moneo
Reply
#6
Moneo:  Right!, my fault for not reading the whole, long explanation!  Here us my code for this problem.  Any questions, TIA?

Code:
'TimePast looks at the first data statemet and takes that number of
'subsequent pairs of data as military time in hours and minutes, then obtains
'and prints to screen the time elapsed from the first time to the second.
'If the first time is larger than the second one, assume the second time
'occurs the next day, by adding 24 hours to it.

CLS
'Read first data
READ PairNums

'Read data pairs and report time elapsed; if less pairs available than
'PairNums, report the error
ON ERROR GOTO PairErr:

FOR pair = 1 TO PairNums
  READ h1, m1: t1 = h1 * 60 + m1
  READ h2, m2: t2 = h2 * 60 + m2
  IF t1 < t2 THEN
    totMins = t2 - t1
  ELSE
    totMins = t2 + 24 * 60 - t1
  END IF
  hrs = INT(totMins / 60)
  min = totMins - hrs * 60
  PRINT hrs; "hours"; min; "minutes"
NEXT pair

END

PairErr:
  PRINT " Not enough time pairs!"
  END

'data statements:
DATA 2
DATA 09,00,17,30
DATA 18,25,09,00
DATA 18 25 09 00

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#7
Nice job, Ralph. It works.

A few comments:
There is an extra DATA statement at the end. Because of the number of data pairs, it is not needed nor processed for this version. But, this shows that the number of defined data pairs must match the number of data pairs in the DATA statements.

The values in each DATA statement should be validated as follows:
* Each DATA statement of data pairs must contain 4 values. as per the format shown in the sample program. Otherwise these data statements could be formatted as 1 or 2 values per DATA statement.
* Each of these values must be validated: no negatives, strictly numeric, and hours must be from 0 to 23, and minutes from 0 to 59.
* The DATA statement containing the single number of data pairs must itself be a positive value greater than zero.

All this extra validation would be required if the program is to be entirely bulletproof.

Regards..... Moneo

Reply
#8
Moneo, right, I had the last DATA line there only for a test, and forgot to delete it before posting here!  As to all your other comments, yep, this program is full of traps in the way the data is presented and processed.  I only took the problem as presented and gave it a "first shot" approach, which should work if all the DATA lines are correct.  Let's say it is now up to the OP to make this into a proper, bug-free program.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#9
You're right, Ralph. I addressed my last post to you, but the comments about data validation were really intended for the OP.

It's amazing how few programmers actually devote much time to data validation. They seem to adopt an attitude of 'Damn the torpedoes, full speed ahead."

Regards..... Moneo
Reply
#10
I'm sure most, if not all, professional programmers do care a lot about making their programs as user-friendly and bug- and fool-proof as they can.  But, most of us amateur programmers, like me, who can write code good enough to work if all the data is correct, usually don't go back and think of all the ways a program can fail, and add the additional code to take care of that sort of thing, as well as protecting the user against problems of all sorts, such as wrong type of data, proper user prompting, and so on.  I'm also sure that, atthe learning stage, as the OP obviously is, it should not be expected of him.  
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)