473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DayFinder Source Code!

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!

Jul 23 '05 #1
1 1552
* 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>
<iostream.h> is not a standard header. Use <iostream> instead.

#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.

while(1)
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]

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tim Zhao | last post by:
I downloaded the PHP 5 source code from www.php.net web site. It is a tar compressed file. I used WinZip to unzip it. Now I got a whole bunch of files. But I do not know to read these files. Do...
9
by: FISH | last post by:
Ever have one of those days when you're not sure if it's you who's gone mad, or the rest of the world? I have an Open Source project on SourceForge for communication with YSMG - Yahoo's IM...
2
by: Greg Strong | last post by:
Hello All, I've written code in a test database with test data. Everything seems to be working except compact database in VB code per http://www.mvps.org/access/general/gen0041.htm. The reason I...
8
by: ben | last post by:
i have a bit of code, that works absolutely fine as is, but seems over complicated/long winded. is there anyway to shorten/simplify it? the code is below. description of it: it's like strcpy in...
15
by: Fady Anwar | last post by:
Hi while browsing the net i noticed that there is sites publishing some software that claim that it can decompile .net applications i didn't bleave it in fact but after trying it i was surprised...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
64
by: Bayazee | last post by:
hi can we hide a python code ? if i want to write a commercial software can i hide my source code from users access ? we can conver it to pyc but this file can decompiled ... so ...!! do you...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.