Qbasicnews.com
February 26, 2020, 01:04:43 AM
 Pages: [1] 2
 Author Topic: Making a calendar in Qbasic  (Read 10222 times)
New Member

Posts: 21

 « on: February 01, 2005, 11:14:07 AM »

Hi.

Yesterday, my class was given the assignment to make a calendar in Qbasic. The goal of the calendar is for the user to input a date (month, day, year) and then the program prints out the month containing that date. It can be any day of any month, of any year.

The only problem is... I have no idea what to do. I'm not very good in programming (I'm a B- student) so I'm kind of stuck whereas others are being successful.

Anyways, we were given this equation to help us find any date in history:

N = D + 2*M + INT(3*(M+1)/5 + Y + INT(Y/4) - INT(Y/100) + INT(Y/400)+2

Obviously d is the day, m is the month, and y is the year.

We were also told that when we found N, we should mod it by 7, and the result would the day of the week. For example, if N mod 7=0, then the day would be Saturday. If N mod 7=1, then the day would be Sunday. 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday

And for months, January and Feburary use 13, 14 (respectively) for the month number, plus they use the previous year. For example, if the input is 2,13, 2001 (Feb, 13th, 2001) then the program would need to use 14, 13, 2000.

The program prints out the calendar in question, and then allows the user to go again.

As you can guess, I'm extremely confused and have no idea where to start. I don't expect anyone to do the project for me, but I'd greatly appreciate it if somebody could give me a push in the right direction.

Thank you.

EDIT- I neglected to mention that I can design the calendar just fine. It's the whole science behind the dates and whatnot that's got me completely confused. Thanks again.
 Logged
Member

Posts: 75

 « Reply #1 on: February 01, 2005, 04:19:17 PM »

This is just a f.y.i. type thing.
For what it's worth, the formula you were given doesn't actually work all that well.
(I don't know if your instructor is aware of that or not. :roll: )
I discovered this while designing a calendar of my own.
I can't recall just where the problem was, but I remember it was off so far that it made a BIG difference in a short while.
 Logged

Ralph
Ancient Guru

Posts: 544

 « Reply #2 on: February 01, 2005, 04:40:42 PM »

I tried the following program, using the data posted by Blader, and it works well:
Code:

CLS
'This program correctly reports the day of the week for Feb 1 of the years
'1980, 2004, 2005, 2098 and 2099
INPUT "Enter the date you want to know the day for, as mm/dd/yyyy ", NDate\$
M = VAL(MID\$(NDate\$, 1, 2)) + 12
D = VAL(MID\$(NDate\$, 4, 2))
Y = VAL(MID\$(NDate\$, 7, 4)) - 1

N = D + 2 * M + INT(3 * (M + 1) / 5) + Y + INT(Y / 4) - INT(Y / 100) + INT(Y / 400) + 2

DOW = N MOD 7
IF DOW = 0 THEN D\$ = "Saturday"
IF DOW = 1 THEN D\$ = "Sunday"
IF DOW = 2 THEN D\$ = "Monday"
IF DOW = 3 THEN D\$ = "Tuesday"
IF DOW = 4 THEN D\$ = "Wednesday"
IF DOW = 5 THEN D\$ = "Thursday"
IF DOW = 6 THEN D\$ = "Friday"
PRINT "For the date entered, "; NDate\$; ", the day is "; D\$
END
 Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
na_th_an
*/-\*

Posts: 8244

 « Reply #3 on: February 01, 2005, 05:05:22 PM »

If you do his homework, he won't learn. You are not helping him at all.

It's not me, it's on the rules of this site.
 Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Member

Posts: 75

 « Reply #4 on: February 01, 2005, 09:52:34 PM »

Ralph,

I think it was an earlier year that I used, but I'm not positive.
I just remember it was off. I'll have to see if I can find it again so I can see just what it was that it had a problem with.
 Logged

Moneo
Na_th_an

Posts: 1971

 « Reply #5 on: February 02, 2005, 12:13:19 AM »

Ralph,

What inspired you to add 12 to the month, and subtract 1 from the year?
*****
 Logged
Nemesis
Forum Regular

Posts: 118

 « Reply #6 on: February 02, 2005, 12:14:28 AM »

Quote from: "na_th_an"
If you do his homework, he won't learn. You are not helping him at all.

It's not me, it's on the rules of this site.

Ummm... how do you know this?
Actually, he might have learned alot, now that he sees how the formula was actually put to use in a programming language.

Just some thoughts

Cya!

Nemesis
 Logged
Ralph
Ancient Guru

Posts: 544

 « Reply #7 on: February 02, 2005, 12:49:26 AM »

na_th_an:
Sorry, I just thought he needed to understand how to use the formula he received from his teacher.  My thoughts and intention were not to do his homework for him.  But, I'll think more about your remark the next time I think of helping out with a homework problem.

Moneo:
Quote

And for months, January and Feburary use 13, 14 (respectively) for the month number, plus they use the previous year. For example, if the input is 2,13, 2001 (Feb, 13th, 2001) then the program would need to use 14, 13, 2000.

so, it isn't too hard to see that a whole year has been subtracted and made up by adding 12 months.

Nemesis:
I sure hope you're right!  After all, if the OP doesn't learn from understanding the formula, he will have missed out on that part of the problem.  And, the rest of the problem remains, the actual creation of the proper calender month, plus the screen presentation and printout coding which, I would think, is still a substantial part of the problem he has to resolve.
 Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
rtrussell
New Member

Posts: 8

 « Reply #8 on: February 05, 2005, 02:03:57 PM »

>so, it isn't too hard to see that a whole year has been subtracted

I think you misunderstood.  It's only January and February that
need to be modified (to become months 13 and 14 respectively),
the other months retain their usual ordinal numbers.  The reason
for this is to make February (which is the odd one out) the 'last'
of the months, for example so leap years work correctly.

If you're interested in more calendar functions in BASIC (and you
free version of BBC BASIC for Windows and looking in the DATELIB
library.  Most of the functions there could be relatively easily
converted to QBASIC:

Richard.[/quote]
 Logged

url=http://www.bbcbasic.org/][size=18]Visit www.bbcbasic.org for BBC BASIC[/size][/url]
Ralph
Ancient Guru

Posts: 544

 « Reply #9 on: February 05, 2005, 05:23:54 PM »

I guess that our friend, Blader, the original poster, has some more work to do!  I just tested the program (and Blader's formula) for January of various years.  If I had tested for October, I guess I would have gotten an error!

But I, personally, am not interested in calender-making; I only thought of helping Blader get on the right road.
 Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Mac
Senior Member

Posts: 243

 « Reply #10 on: February 07, 2005, 03:18:33 PM »

The original question was

Yesterday, my class was given the assignment to make a calendar in Qbasic. The goal of the calendar is for the user to input a date (month, day, year) and then the program prints out the month containing that date. It can be any day of any month, of any year.

Wouldn't you simply take the month (1-12) and print "January", etc.?

Mac
 Logged
rtrussell
New Member

Posts: 8

 « Reply #11 on: February 07, 2005, 05:16:04 PM »

Quote from: "Mac"

Wouldn't you simply take the month (1-12) and print "January", etc.?

Er, I think the idea was to print out a calendar for the whole month, not just the name of the month!

Richard.
 Logged

url=http://www.bbcbasic.org/][size=18]Visit www.bbcbasic.org for BBC BASIC[/size][/url]
Mac
Senior Member

Posts: 243

 « Reply #12 on: February 07, 2005, 06:25:37 PM »

Quote from: "rtrussell"

Er, I think the idea was to print out a calendar for the whole month, not just the name of the month!

Richard.

Urk! Duhhh! Thanks! I get it now.

Mac
 Logged
New Member

Posts: 21

 « Reply #13 on: February 07, 2005, 06:28:13 PM »

I appreciate all your help, and I was eventually to figure out a lot of it on my own (hurray!). But I've reached yet another road block. My program can take any date of any month of any year, and tell you what day it is/was. It can also print out a spiffy calendar after telling you what the input date was.

But what I don't understand is how I can print the dates in the calendar, and then shift them for any month. For example, January of 2005 began on a Saturday, but Feburary started on a Tuesday. I don't understand how I'm supposed to print the numbered dates inside the calendar, and then shift them for each month.

Here's my coding so far:

Code:
CLS

INPUT "Enter a date"; d
INPUT "Enter a month"; m
INPUT "Enter a year"; y

IF m = 1 THEN

m = 13
y = y - 1

END IF

IF m = 2 THEN

m = 14
y = y - 1

END IF

n = d + 2 * m + INT(3 * (m + 1) / 5) + y + INT(y / 4) - INT(y / 100) + INT(y / 400) + 2

x = n MOD 7

IF x = 0 THEN

PRINT "Saturday"

END IF

IF x = 1 THEN

PRINT "Sunday"

END IF

IF x = 2 THEN

PRINT "Monday"

END IF

IF x = 3 THEN

PRINT "Tuesday"

END IF

IF x = 4 THEN

PRINT "Wednesday"

END IF

IF x = 5 THEN

PRINT "Thursday"

END IF

IF x = 6 THEN

PRINT "Friday"

END IF

calendar2

a\$ = INPUT\$(1)

CLS

SUB calendar2

CLS

LOCATE 4, 7: PRINT "Sunday"
LOCATE 4, 17: PRINT "Monday"
LOCATE 4, 27: PRINT "Tuesday"
LOCATE 4, 36: PRINT "Wednesday"
LOCATE 4, 47: PRINT "Thursday"
LOCATE 4, 57: PRINT "Friday"
LOCATE 4, 67: PRINT "Saturday"

FOR x = 5 TO 30                           'creates left border
LOCATE x, 5
PRINT CHR\$(219)
NEXT x

FOR x = 5 TO 30                           'creates right border
LOCATE x, 75
PRINT CHR\$(219)
NEXT x

FOR x = 5 TO 75                           'creates top border
LOCATE 5, x
PRINT CHR\$(219)
NEXT x

FOR x = 5 TO 75                           'creates bottom border
LOCATE 30, x
PRINT CHR\$(219)
NEXT x

'creates five rows
r = 5
DO
FOR x = 5 TO 75
LOCATE r, x
PRINT CHR\$(219)
NEXT x
r = r + 5
LOOP UNTIL r = 30

c = 5                                     'creates seven columns
DO
FOR x = 5 TO 30
LOCATE x, c
PRINT CHR\$(219)
NEXT x
c = c + 10
LOOP UNTIL c = 75

END SUB

Any and all help will be greatly appreciated. Thank you.
 Logged
Meg
Ancient QBer

Posts: 483

 « Reply #14 on: February 07, 2005, 06:37:34 PM »

well, imagine a marker which has an x and y value (x for the column, i.e. DAY.. and y for the row, i.e. WEEK on the calendar).

increase X until it hits the right side of the screen, at which point you add 1 to the Y value (week) and reset the X value to 1.

so..if the first day of the month is, say, a thursday, start your X at the thursday column.

Code:

X = 01 02 03 04 05 06 07
Sa Su Mo Tu We Th Fr

so the pseudo code looks something like this:

Code:

set x to starting day
set y to 1
set currentday to 1

start loop
print currentday at position (x,y)
increase x by 1
if x = 8 then {set x to 1, increase y by 1} 'start a new week
increase currentday by 1
end loop when currentday = last day of the month

Incidentally, FYI:

Code:

c = 5
DO
c = c + 10
LOOP UNTIL c = 75

can be rewritten:

Code:
FOR c = 5 TO 75 STEP 10
NEXT c

*peace*

Meg.
 Logged
 Pages: [1] 2