the user will input the month of birth, date of birth and the year of birth
Program using turbo c++ an out put will be the zodiac sign and your age plus the day of birth?
Here are the type declarations and functions needed. I think you can handle writing the user-interface to get input and figure out how to determine the current date for inclusion in the getAge() function. Merry Christmas :
enum Day_of_Week
{
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
};
enum Month
{
January, February, March, April, May, June,
July, August, September, October, November, December
};
enum Zodiac_Sign
{
Capricorn, Aquarius, Pisces, Aries, Taurus, Gemini,
Cancer, Leo, Virgo, Libra, Scorpio, Sagittarius
};
enum Zodiac_Sign getZodiacSign(enum Month month, int day)
{
enum Zodiac_Sign sign;
switch (month)
{
case January :
if (day %26lt;= 19)
sign = Capricorn;
else
sign = Aquarius;
break;
case February :
if (day %26lt;= 18)
sign = Aquarius;
else
sign = Pisces;
break;
case March :
if (day %26lt;= 20)
sign = Pisces;
else
sign = Aries;
break;
case April :
if (day %26lt;= 19)
sign = Aries;
else
sign = Taurus;
break;
case May :
if (day %26lt;= 20)
sign = Taurus;
else
sign = Gemini;
break;
case June :
if (day %26lt;= 20)
sign = Gemini;
else
sign = Cancer;
break;
case July :
if (day %26lt;= 22)
sign = Cancer;
else
sign = Leo;
break;
case August :
if (day %26lt;= 22)
sign = Leo;
else
sign = Virgo;
break;
case September :
if (day %26lt;= 22)
sign = Virgo;
else
sign = Libra;
break;
case October :
if (day %26lt;= 22)
sign = Libra;
else
sign = Scorpio;
break;
case November :
if (day %26lt;= 21)
sign = Scorpio;
else
sign = Sagittarius;
break;
case December :
if (day %26lt;= 21)
sign = Sagittarius;
else
sign = Capricorn;
break;
}
return sign;
}
int getAge(int birth_year, int birth_month, int birth_day)
{
int age;
int year, month, day;
// I'm not going to populate year/month/day ... I'll leave that for you to determine
// today's date.
age = (year - birth_year);
if (month %26lt; birth_month)
{
// Our birth month is later in the year.
age--;
}
else if (month == birth_month)
{
if (day %26lt; birth_day)
{
// Currently our birth month, but our birth day is later in the month.
age--;
}
}
return age;
}
// Now the day of the week ... that's trickier. This should work for 1900-2099 :
enum Day_of_Week getDayofWeek(int year, enum Month month, int day)
{
int day_of_week;
bool is_leap_year;
is_leap_year = (((year % 4) == 0) %26amp;%26amp; (year != 1900));
day_of_week = ((year % 100) + ((year % 100) / 4));
day_of_week += day;
if (year %26gt;= 2000)
{
day_of_week--;
}
switch (month)
{
case January :
if (is_leap_year)
day_of_week += 0;
else
day_of_week += 1;
break;
case February :
if (is_leap_year)
day_of_week += 3;
else
day_of_week += 4;
break;
case March :
day_of_week += 4;
break;
case April :
day_of_week += 0;
break;
case May :
day_of_week += 2;
break;
case June :
day_of_week += 5;
break;
case July :
day_of_week += 0;
break;
case August :
day_of_week += 3;
break;
case September :
day_of_week += 6;
break;
case October :
day_of_week += 1;
break;
case November :
day_of_week += 4;
break;
case December :
day_of_week += 6;
break;
}
day_of_week %= 7;
return (enum Day_of_Week)day_of_week;
}
Reply:#include %26lt;dos.h%26gt;
#include %26lt;bool.h%26gt;
#include %26lt;ctype.h%26gt;
#include %26lt;conio.h%26gt;
#include %26lt;string.h%26gt;
#include %26lt;iostream.h%26gt;
struct DATE
{
DATE();
DATE(char*);
unsigned int day,month,year,l,count,
cday,cmonth,cyear,
dday,dyear;
char zodiac[12];
BOOL IsDate(char*);
void GetCurDate(unsigned int*,unsigned int*,unsigned int*);
BOOL FindDffrnce();
void FindZodiac();
BOOL Flag;
unsigned int dm(unsigned int);
};
// the constructor
DATE::DATE(char *newdate)
{
day = month = year = count = 0;
Flag = IsDate(newdate);
GetCurDate(%26amp;cday,%26amp;cmonth,%26amp;cyear);
if( cyear %26lt; year )
Flag = FALSE;
}
BOOL DATE::IsDate(char *newdate)
{
l = strlen(newdate);
unsigned long int number = 0;
int tn = 0;
if(l%26lt;6 || l%26gt;10) // format : DD/MM/YYYY or D/M/YY
return FALSE;
for(int i=0;i%26lt;l;i++)
{
if( (int)newdate[i] %26lt; 48 %26amp;%26amp; (int)newdate[i] %26gt; 57 )
if( newdate[i] != '/' %26amp;%26amp; newdate[i] != '.' )
return FALSE;
if(newdate[i] == '/' || newdate[i] == '.')
{// No month cannot have more than 31 days
if(count == 0 %26amp;%26amp; number %26gt; 31)
return FALSE;
if( count == 0 )
tn = number;
// There are 12 months :
if(count == 1 %26amp;%26amp; number %26gt; 12)
return FALSE;
// February cannot have more than 28 days:
if( count == 1 %26amp;%26amp; number == 2 %26amp;%26amp; tn %26gt; 28 )
return FALSE;
if( count == 1 ) // The months 4,6,9,11 cannot have more than 30 days
if( number == 4 || number == 6 || number == 9 || number == 11 )
if( tn %26gt; 30 )
return FALSE;
if( count == 0 )// allocate the days
day = number;
else if( count == 1 ) // allocate the month
month = number;
// the year never enters this loop!
if( !number )
return FALSE;
else number = 0; // back to ZERO
count++;
}
else
number = ((number*10)+(newdate[i]-48));
}
if( count %26lt; 2 )
return FALSE;
else
year = number; // year is never gone inside the main loop
return TRUE;
}
// gets today's date from the computer's BIOS
void DATE::GetCurDate(unsigned int* a,unsigned int* b,unsigned int* c)
{
struct date d;
getdate(%26amp;d);
*a = d.da_day;
*b = d.da_mon;
*c = d.da_year;
}
BOOL DATE::FindDffrnce()
{
if( !Flag )
return FALSE;
unsigned long int tot = 0;
unsigned int t1 = 0,t2 = 0;
dyear = cyear-year-1;
/* total days in input date */
t1 += day;
t1 += dm(month);
if( !(year%4) %26amp;%26amp; month%26gt;3 )
{
t1++;
t1 = 366-t1;
}
else
t1 = 365-t1;
/* total days in current date */
t2 += cday;
t2 += dm(cmonth);
if( !(cyear%4) %26amp;%26amp; cmonth%26gt;2 )
t2++;
tot = (t1+t2);
if( tot %26gt;= 365 )
{
dyear++;
tot -= 365;
}
dday = tot;
return TRUE;
}
void DATE::FindZodiac()
{
if(( day %26gt;= 20 %26amp;%26amp; month == 1 ) || ( day %26lt;= 18 %26amp;%26amp; month == 2 ) )
strcpy(zodiac,"Aquarius");
else if(( day %26gt;= 19 %26amp;%26amp; month == 2 ) || ( day %26lt;= 20 %26amp;%26amp; month == 3 ) )
strcpy(zodiac,"Pisces");
else if(( day %26gt;= 21 %26amp;%26amp; month == 3 ) || ( day %26lt;= 20 %26amp;%26amp; month == 4 ) )
strcpy(zodiac,"Aries");
else if(( day %26gt;= 21 %26amp;%26amp; month == 4 ) || ( day %26lt;= 20 %26amp;%26amp; month == 5 ) )
strcpy(zodiac,"Taurus");
else if(( day %26gt;= 21 %26amp;%26amp; month == 5 ) || ( day %26lt;= 20 %26amp;%26amp; month == 6 ) )
strcpy(zodiac,"Gemini");
else if(( day %26gt;= 21 %26amp;%26amp; month == 6 ) || ( day %26lt;= 20 %26amp;%26amp; month == 7 ) )
strcpy(zodiac,"Cancer");
else if(( day %26gt;= 21 %26amp;%26amp; month == 7 ) || ( day %26lt;= 20 %26amp;%26amp; month == 8 ) )
strcpy(zodiac,"Leo");
else if(( day %26gt;= 21 %26amp;%26amp; month == 8 ) || ( day %26lt;= 20 %26amp;%26amp; month == 9 ) )
strcpy(zodiac,"Virgo");
else if(( day %26gt;= 21 %26amp;%26amp; month == 9 ) || ( day %26lt;= 20 %26amp;%26amp; month == 10 ) )
strcpy(zodiac,"Libra");
else if(( day %26gt;= 21 %26amp;%26amp; month == 10 ) || ( day %26lt;= 20 %26amp;%26amp; month == 11 ) )
strcpy(zodiac,"Scorpio");
else if(( day %26gt;= 21 %26amp;%26amp; month == 11 ) || ( day %26lt;= 20 %26amp;%26amp; month == 12 ) )
strcpy(zodiac,"Sagittarius");
else
strcpy(zodiac,"Capricorn");
}
unsigned int DATE::dm(unsigned int d)
{
unsigned int retval = 0;
for(int i=1;i%26lt;=d;i++)
{
if( i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
retval+=31;
else if( i == 4 || i == 6 || i == 9 || i == 11 )
retval+=30;
else if( i == 2 )
retval +=28;
}
return retval;
}
main()
{
redo:
clrscr();
textmode(C80);
cout%26lt;%26lt;"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ...
cout%26lt;%26lt;"º RAHUL'S DATE %26amp; ZODIAC Calculator º\n";
cout%26lt;%26lt;"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ...
cout%26lt;%26lt;" Enter : 'quit' to exit\n\n\n";
cout%26lt;%26lt;" Enter you birth-day : ";
char date[20];
cin%26gt;%26gt;date;
if( !strcmp(strlwr(date),"quit"))
return 0;
DATE d(date);
if( d.Flag == FALSE )
{
cout%26lt;%26lt;"You have input an Invalid date...\nTry Again\n\n";
getch();
goto redo;
}
d.FindDffrnce();
cout%26lt;%26lt;"\nYour age is "%26lt;%26lt;d.dyear%26lt;%26lt;" years and "%26lt;%26lt;d.dday%26lt;%26lt;" day";
if( d.day )
cout%26lt;%26lt;"s";
d.FindZodiac();
cout%26lt;%26lt;"\n\nYour Zodiac Sign is "%26lt;%26lt;d.zodiac;
getch();
cout%26lt;%26lt;"\n\nContinue...?\n\n";
if( tolower(getch()) == 'y' )
goto redo;
return TRUE;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment