DayFinder Source Code!

A

AshifToday

i have made a day finder progra, its source code is here,
=========
/*
This program has been made by Ashif Zubair.
Roll # 1468, B.Sc.(Hons.) in C.S.
ALL RIGHTS ARE RESERVED TO ASHIF ZUBAIR.
PROGRAM OBJECTIVE :-
To display the day, when the user gives the date
range is between years 1900 - 2100
*/
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#define SECOND 1

int match(unsigned char [],unsigned char &);
void warning (void);

void main (void)
{
clrscr();
warning();
int count;
for(count = SECOND;count>=0;count--)
{
gotoxy(13,34);
cout<<" YOU WILL BE REDIRECTED IN SECONDS : "<<count;
delay(1000);
}

while(1)
{
clrscr();
unsigned int date,month,year,_date,_year,row=0,clm=0;
unsigned char letter,again,
jan_oct[7] = {'A','B','C','D','E','G','H'},//01_10
feb_mrh_nov[7] = {'D','E','G','B','C','H','A'},//02_03_11
apr_jul_janl[7]= {'B','C','H','E','G','A','D'},//04_07_(01L)
may[7] = {'G','A','B','H','D','E','C'},//05
june[7] = {'H','D','E','A','B','C','G'},//06
aug_febl[7] = {'E','G','A','C','H','D','B'},//08_(02L)
sep_dec[7] = {'C','H','D','G','A','B','E'},//09_12
day[7][7] = {
{'T','W','H','S','N','M','F'},//1
{'W','H','F','N','M','T','S'},//2
{'H','F','S','M','T','W','N'},//3
{'F','S','N','T','W','H','M'},//4
{'S','N','M','W','H','F','T'},//5
{'N','M','T','H','F','S','W'},//6
{'M','T','W','F','S','N','H'},//7
};
/*
T = TUESDAY, W = WEDNESDAY, H = THURSDAY, S = SATURDAY,
N = SUNDAY, M = MONDAY, F = FRIDAY .
*/
while(1)
{
clrscr();
cout<<"Enter The Information As Indicated In The Brckets \"[ -
]\"\n\nDo Not Use Decimal Point \"(.)\" Or Any Alphabet.\n\nAnd Remove
Any Leading \"0\".Thank You.\n\n\nPlease Enter Year = [1900 - 2100] ?
: ";
cin >> year;
_year = year;
if(year >=1900 && year<=2100)
break;
else
cout<<"\nInvalid Input! [1900 - 2100],Press any key to input
again..";
getch();
}
while(1)
{
clrscr();
cout<<"Enter The Information As Indicated In The Brckets \"[ -
]\"\n\nDo Not Use Decimal Point \"(.)\" Or Any Alphabet.\n\nAnd Remove
Any Leading \"0\".Thank You.\n\n\nEnter Month = [1 - 12] ? : ";
cin >>month;
if(month >=1 && month<=12)
break;
else
cout<<"\nInvalid Input! [1 - 12],Press any key to input again..";
getch();
}
while(1)
{
clrscr();
cout<<"Enter The Information As Indicated In The Brckets \"[ -
]\"\n\nDo Not Use Decimal Point \"(.)\" Or Any Alphabet.\n\nAnd Remove
Any Leading \"0\".Thank You.\n\n\nEnter Date = ? : ";
cin >>date;
_date = date;
if(month == 2)
{
if(year%4 != 0)
{
if(date >=1 && date <=28)
break;
else
{
cout<<"\nInvalid Input! [1 - 28] (Feburary, Non-Leap year). Press
any key to input again..";
getch();
continue;
}
}
else
{
if(date >=1 && date <=29)
break;
else
{
cout<<"\nInvalid Input! [1 - 29] (Feburary, Leap year). Press any
key to input again..";
getch();
continue;
}
}
}
else
{
switch(month)
{
case 4 :
case 6 :
case 9 :
case 11 :
if(date >=1 && date <=30)
break;
else
{
cout<<"\nInvalid Input! [1 - 30]. Press any key to input
again..";
getch();
continue;
}
default :
if(date >=1 && date <=31)
break;
else
{
cout<<"\nInvalid Input! [1 - 31]. Press any key to input
again..";
getch();
continue;
}
}
break;
}
}
clrscr();
cout<<"Your Entered Date [ Day / Month / Year ] : [ "<<_date<<" /
"<<month<<" / "<<_year<<" ]";
if(year % 4 == 0)
cout<<" Leap-Year";
else
cout<<" Non Leap-Year";
if(_year <=2000)
_year = _year % 1900;
else
_year = _year % 2000;
while(_year>27)
_year = _year - 28;
switch(_year)
{
case 0 :
case 6 :
case 17 :
case 23 :
if(year<2000)
letter = 'G';
else
letter = 'E';
break;
case 1 :
case 7 :
case 12 :
case 18 :
if(year<=2000)
letter = 'A';
else
letter = 'G';
break;
case 2 :
case 13 :
case 19 :
case 24 :
if(year<2000)
letter = 'B';
else
letter = 'A';
break;
case 3 :
case 8 :
case 14 :
case 25 :
if(year<2000)
letter = 'C';
else
letter = 'B';
break;
case 4 :
case 10 :
case 21 :
case 27 :
if(year<2000)
letter = 'D';
else
letter = 'H';
break;
case 5 :
case 11 :
case 16 :
case 22 :
if(year<2000)
letter = 'E';
else
letter = 'D';
break;
case 9 :
case 15 :
case 20 :
case 26 :
if(year<2000)
letter = 'H';
else
letter = 'C';
break;
}
if(year%4 == 0 && (month == 1 || month == 2))
{
if(month == 1)
clm = match(apr_jul_janl,letter);
else
clm = match(aug_febl,letter);
}
else
{
switch(month)
{
case 1 :
case 10:
clm = match(jan_oct,letter);
break;
case 2:
case 3:
case 11:
clm = match(feb_mrh_nov,letter);
break;
case 4 :
case 7 :
clm = match(apr_jul_janl,letter);
break;
case 5 :
clm = match(may,letter);
break;
case 6 :
clm = match(june,letter);
break;
case 8 :
clm = match(aug_febl,letter);
break;
case 9 :
case 12:
clm = match(sep_dec,letter);
break;
}
}
while(_date > 7)
_date = _date - 7;
for(row = 0; row<7; row++)
{
if(row+1 == _date)
break;
}
switch(day[row][clm])
{
case 'F' :
cout<<"\n\nThat Day Is";
textcolor(6);
cout<<" \"FRIDAY!\"";
break;
case 'S' :
cout<<"\n\nThat Day Is";
textcolor(6);
cout<<" \"SATURDAY!\"";
break;
case 'N' :
cout<<"\n\nThat Day Is";
textcolor(6);
cout<<" \"SUNDAY!\"";
break;
case 'M' :
cout<<"\n\nThat Day Is";
textcolor(6);
cout<<" \"MONDAY!\"";
break;
case 'T' :
cout<<"\n\nThat Day Is";
textcolor(6);
cout<<" \"TUESDAY!\"";
break;
case 'W' :
cout<<"\n\nThat Day Is";
textcolor(6);
cout<<" \"WEDNESDAY!\"";
break;
case 'H' :
cout<<"\n\nThat Day Is";
textcolor(6);
cout<<" \"THURSDAY!\"";
break;
}
cout<<"\n\nDo You Want To Do Again = [y/n] ? ";
cin >>again;
if(again == 'y' || again == 'Y')
continue;
else
break;
}
}
int match(unsigned char month[],unsigned char &letter)
{
int clm = 0;
for(clm = 0 ; clm < 7 ; clm++)
if(month[clm] == letter)
break;
return clm;
}

void warning(void)
{
gotoxy(13,16);
cout<<" WARNING!";
gotoxy(13,20);
cout<<"THIS PROGRAM IS PROTECTED BY THE LAWS AND COPYRIGHT";
gotoxy(13,22);
cout<<" AS STATED IN THE ABOUT SECTION IN SOURCE CODE";
gotoxy(13,24);
cout<<" ---------------------------------------------";
gotoxy(13,26);
cout<<" COPYRIGHT 2003 - 2004,\"ASHIF ZUBAIR\".";
gotoxy(13,28);
cout<<" ALL RIGHTS ARE RESERVED.";
}


================================

u can learn from this, the logic of finding any day from the given date!
 
A

Alf P. Steinbach

* AshifToday:
i have made a day finder progra, its source code is here,

It's a good idea to post code for comments, yes.

I hope you learn something from my comments below.

=========
/*
This program has been made by Ashif Zubair.
Roll # 1468, B.Sc.(Hons.) in C.S.
ALL RIGHTS ARE RESERVED TO ASHIF ZUBAIR.
PROGRAM OBJECTIVE :-
To display the day, when the user gives the date
range is between years 1900 - 2100
*/

#include <iostream.h>

#include <conio.h>
#include <dos.h>

Note: These are non-portable non-standard headers. Also, using screen-
oriented stuff make the program less usable. E.g., it cannot be used
in scripts.

#define SECOND 1

Plus points for using all uppercase for macro name.

Minus points for using a macro where a constant would be more appropriate.

int match(unsigned char [],unsigned char &);

void warning (void);

void main (void)

Error: this signature is not allowed in standard C++.

'main' must have return type 'int'.

{
clrscr();
warning();

Uh, starting off the program by giving the user a warning? :)

int count;
for(count = SECOND;count>=0;count--)
{
gotoxy(13,34);
cout<<" YOU WILL BE REDIRECTED IN SECONDS : "<<count;
delay(1000);
}

Preferably like this:

for( int count = ....

declaring the loop control variable in the loop head.

As it is 'count' is accessible later on.


Some compiler may issue a silly-warning for this construct; instead use

for( ;; )

{
clrscr();
unsigned int date,month,year,_date,_year,row=0,clm=0;
unsigned char letter,again,
jan_oct[7] = {'A','B','C','D','E','G','H'},//01_10
feb_mrh_nov[7] = {'D','E','G','B','C','H','A'},//02_03_11
apr_jul_janl[7]= {'B','C','H','E','G','A','D'},//04_07_(01L)
may[7] = {'G','A','B','H','D','E','C'},//05
june[7] = {'H','D','E','A','B','C','G'},//06
aug_febl[7] = {'E','G','A','C','H','D','B'},//08_(02L)
sep_dec[7] = {'C','H','D','G','A','B','E'},//09_12
day[7][7] = {
{'T','W','H','S','N','M','F'},//1
{'W','H','F','N','M','T','S'},//2
{'H','F','S','M','T','W','N'},//3
{'F','S','N','T','W','H','M'},//4
{'S','N','M','W','H','F','T'},//5
{'N','M','T','H','F','S','W'},//6
{'M','T','W','F','S','N','H'},//7
};

Have you considered e.g.

unsigned char const jan_oct[] = "ABCDEGH";

?

There's an extra zero byte at the end, but that shouldn't matter.

Anyway, 'const' would be nice here.¨
/*
T = TUESDAY, W = WEDNESDAY, H = THURSDAY, S = SATURDAY,
N = SUNDAY, M = MONDAY, F = FRIDAY .
*/
while(1)

See earlier comment.

[rest of code]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top