Code.GeekInterview.com
 
 

Java Code Base

 
Code Samples Java
 

Find your day from your DOB


Code ResourceAuthor: venki_madesh  

Difficulty Level:

Published: 6th Nov 2006   Read: 35132 times  

Filed in: Java
Add Comment


 

 

Sponsored Links


 

 

hi. this code is very usefull to find ur week day of ur date of birth or any date.... and it is useful for calculate the date after adding or subtract another date.

 


Sample Code
  1.  
  2. #include<iostream.h>
  3. class date
  4. {
  5.         public:
  6.         int d,m,y,n1,n2;
  7.         void getDate();                    //get the date
  8.         void putDate();                    //print the result
  9.         void addDate();                    //add the date
  10.         void subDate();                    //sub the date
  11.         void swapDate();                   // swap the date
  12.         void diffDate();                   //diff the date
  13.         void dayDate();                                           // find the day
  14. };
  15. date ven,d1,d2,d3,t,g;// create object
  16. void date::swapDate() //Swap the bigger date
  17. {
  18.         if ((d1.y<d2.y)||((d1.y==d2.y)&&(d1.m<d2.m))||((d1.y==d2.y)&&(d1.m==d2.m)&&(d1.d<d2.d)))
  19.         {
  20.                 t=d1;
  21.                 d1=d2;
  22.                 d2=t;
  23.         }
  24. }
  25. void date::getDate()
  26. {
  27.         cout<<"Enter the year:"<<endl;
  28.         cin>>y;
  29.         cout<<"Enter the month:"<<endl;
  30.         a:
  31.         cin>>m;
  32.         if(m>12)
  33.         {
  34.                 cout<<"Enter the correct month:"<<endl;        //check the month
  35.                 goto a;
  36.         }
  37.         cout<<"Enter the date:"<<endl;
  38.         b:
  39.         cin>>d;
  40.         if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)        //check the date
  41.         {
  42.                 if(d>31)
  43.                 {
  44.                         cout<<"Enter the correct date:"<<endl;
  45.                         goto b;
  46.                 }
  47.         }
  48.         else if(m==4||m==6||m==9||m==11)
  49.         {
  50.                 if(d>30)
  51.                 {
  52.                         cout<<"Enter the correct date:"<<endl;
  53.                         goto b;
  54.                 }
  55.         }
  56.         else if(m==2)
  57.         {
  58.                 if((y%4)==0)
  59.                 {
  60.                         if(d>29)
  61.                         {
  62.                                 cout<<"Enter the correct date:"<<endl;
  63.                                 goto b;
  64.                         }
  65.                 }
  66.                 else
  67.                 {
  68.                         if(d>28)
  69.                         {
  70.                                 cout<<"Enter the correct date:"<<endl;
  71.                                 goto b;
  72.                         }
  73.                 }
  74.         }
  75. }
  76. void date::putDate()
  77. {
  78.         cout<<"------------------"<<endl;
  79.         cout<<"Date==>"<<d<<":"<<m<<":"<<y<<endl;
  80.         cout<<"------------------"<<endl;
  81. }
  82. void date::addDate()
  83. {
  84.         int f=0;
  85.         cout<<"Enter the Number to add the date:"<<endl;
  86.         cin>>n1;
  87.         d=d+n1;
  88.         while(f==0)
  89.         {
  90.                 if((m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&(f==0))
  91.                 {
  92.                         if(d>31)
  93.                         {
  94.                                 d=d-31;
  95.                                 m++;
  96.                                 if(m>12)
  97.                                 {
  98.                                         y=y+1;
  99.                                         m=m-12;
  100.                                 }
  101.                         }
  102.                         else
  103.                                 f=1;
  104.                 }
  105.                 else if((m==4||m==6||m==9||m==11)&&(f==0))
  106.                 {
  107.                         if(d>30)
  108.                         {
  109.                                 d=d-30;
  110.                                 m++;
  111.                         }
  112.                         else
  113.                                 f=1;
  114.                 }
  115.                 else
  116.                 {
  117.                         if(m==2&&f==0)
  118.                         {
  119.                                 if((y%4)==0)
  120.                                 {
  121.                                         if(d>29)
  122.                                         {
  123.                                                 d=d-29;
  124.                                                 m++;
  125.                                         }
  126.                                         else
  127.                                                 f=1;
  128.                                 }
  129.                                 else
  130.                                 {
  131.                                         if(d>28)
  132.                                         {
  133.                                                 d=d-28;
  134.                                                 m++;
  135.                                         }
  136.                                         else
  137.                                                 f=1;
  138.                                 }
  139.                         }
  140.                 }
  141.         }
  142. }
  143. void date::subDate()                  // subtract the date
  144. {
  145.         int f=0;
  146.         cout<<"Enter the number to sub the date:"<<endl;
  147.         cin>>n2;
  148.         d=d-n2;
  149.         while(f==0)
  150.         {
  151.                 if((m==5||m==7||m==10||m==12)&&(f==0))
  152.                 {
  153.                         if(d<1)
  154.                         {
  155.                                 d=d+30;
  156.                                 m--;
  157.                         }
  158.                         else
  159.                                 f=1;
  160.                 }
  161.                 else if ((m==1||m==2||m==4||m==6||m==8||m==9||m==11)&&(f==0))
  162.                 {
  163.                         if(d<1)
  164.                         {
  165.                                 d=d+31;
  166.                                 m--;
  167.                                 if(m==0)
  168.                                 {
  169.                                         m=m+12;
  170.                                         y=y-1;
  171.                                 }
  172.                         }
  173.                         else
  174.                                 f=1;
  175.                 }
  176.                 else
  177.                 {
  178.                         if((m==3)&&(f==0))
  179.                         {
  180.                                 if((y%4)==0)
  181.                                 {
  182.                                         if(d<1)
  183.                                         {
  184.                                                 d=d+29;
  185.                                                 m--;
  186.                                         }
  187.                                         else
  188.                                                 f=1;
  189.                                 }
  190.                                 else
  191.                                 {
  192.                                         if(d<1)
  193.                                         {
  194.                                                 d=d+28;
  195.                                                 m--;
  196.                                         }
  197.                                         else
  198.                                                 f=1;
  199.                                 }
  200.                         }
  201.                 }
  202.         }
  203. }
  204. int dayd;
  205. void date::diffDate() // fint the difference of the two date
  206. {
  207.  
  208.         int f=0,count=0;
  209.         dayd=0;
  210.         while(f==0)
  211.         {
  212.                 a:
  213.                 if((d1.y==d2.y)&&(d1.m==d2.m)&&(d1.d==d2.d)&&(f==0))
  214.                 {
  215.         dayd=count;
  216.                         f=1;
  217.                 }
  218.                 d2.d++;
  219.                 count++;
  220.                 if(((d2.m==4)||(d2.m==6)||(d2.m==9)||(d2.m==11))&&(f==0))
  221.                 {
  222.                         if(d2.d>30)
  223.                         {
  224.                                 d2.d=1;
  225.                                 d2.m++;
  226.                         }
  227.                         else
  228.                                 goto a;
  229.                 }
  230.                 else if (((d2.m==1)||(d2.m==3)||(d2.m==5)||(d2.m==7)||(d2.m==8)||(d2.m==10)||(d2.m==12))&&(f==0))
  231.                 {
  232.                         if(d2.d>31)
  233.                         {
  234.                                 d2.d=1;
  235.                                 d2.m++;
  236.                                 if(d2.m>12)
  237.                                 {
  238.                                         d2.m=1;
  239.                                         d2.y++;
  240.                                 }
  241.                         }
  242.                         else
  243.                                 goto a;
  244.                 }
  245.                 else
  246.                 {
  247.                         if((d2.m==2)&&(f==0))
  248.                         {
  249.                                 if((d2.y%4)==0)
  250.                                 {
  251.                                         if(d2.d>29)
  252.                                         {
  253.                                                 d2.d=1;
  254.                                                 d2.m++;
  255.                                         }
  256.                                         else
  257.                                                 goto a;
  258.                                 }
  259.                                 else
  260.                                 {
  261.                                         if(d2.d>28)
  262.                                         {
  263.                                                 d2.d=1;
  264.                                                 d2.m++;
  265.                                         }
  266.                                         else
  267.                                                 goto a;
  268.                                 }
  269.                         }
  270.                 }
  271.         }
  272. }
  273. void date::dayDate()
  274. {
  275.         int temp;
  276.         cout<<" The day is  ";
  277.         temp=dayd;
  278.         temp=temp%7;
  279.         switch(temp)
  280.         {
  281.                 case 0:
  282.                         cout<<"Friday";
  283.                         break;
  284.                 case 1:
  285.                         cout<<"Saturday";
  286.                         break;
  287.                 case 2:
  288.                         cout<<"Sunday";
  289.                         break;
  290.                 case 3:
  291.                         cout<<"Monday";
  292.                         break;
  293.                 case 4:
  294.                         cout<<"Tuesday";
  295.                         break;
  296.                 case 5:
  297.                         cout<<"Wednesday";
  298.                         break;
  299.                 case 6:
  300.                         cout<<"Thursday";
  301.                         break;
  302.         }
  303. }
  304. void main()
  305. {
  306.         int o;
  307.         char ch='y';
  308.         while(ch=='y')
  309.         {
  310.                 cout<<"select any one:"<<endl;
  311.                 cout<<endl<<"1:add"<<endl<<"2:sub"<<endl<<"3.difference"<<endl<<"4.find the day"<<endl;
  312.                 cin>>o;
  313.                 switch(o)
  314.                 {
  315.                         case 1:
  316.                                 ven.getDate();
  317.                                 ven.putDate();
  318.                                 ven.addDate();
  319.                                 ven.putDate();
  320.                                 break;
  321.                         case 2:
  322.                                 ven.getDate();
  323.                                 ven.putDate();
  324.                                 ven.subDate();
  325.                                 ven.putDate();
  326.                                 break;
  327.                         case 3:
  328.                                 d1.getDate();
  329.                                 d2.getDate();
  330.                                 d1.putDate();
  331.                                 d2.putDate();
  332.                                 d3.swapDate();
  333.                                 g.diffDate();
  334.                                 cout<<"The date difference is:"<<dayd<<endl;
  335.                                 break;
  336.                         case 4:
  337.                                 d1.getDate();
  338.                                 d2.d=15;
  339.                                 d2.y=1947;
  340.                                 d2.m=8;
  341.                                 d1.putDate();
  342.                                 d3.swapDate();
  343.                                 g.diffDate();
  344.                                 g.dayDate();
  345.                                 break;
  346.                 }
  347.                 cout<<endl<<"if you want to continue:"<<endl;
  348.                 cin>>ch;
  349.                 if(ch=='n')
  350.                 {
  351.                         cout<<"                                                 "<<endl;
  352.                         cout<<"===============OK..............BYE==============="<<endl;
  353.                 }
  354.         }
  355. }
  356.  
  357.  
Copyright GeekInterview.com


Next Article: Find Character/Number Functions


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Comments

It's great!
Comment posted by: Gilson on 2006-11-09T01:02:57
this is a progrm i searched and tryed 4 a long time, but i cant do it, so this is very useful 4 me, thank u very much and plz post many good programs like this
Comment posted by: Vinodh.R on 2006-11-09T12:53:35
hey Mr.venki iam very thankful to 'U', that program was so simple and easy to use!, by means of this many pple would be pleased to see there day of which they where born!!! :)
Comment posted by: varunkumar.s on 2006-11-10T07:12:26
Good
Comment posted by: Binisten on 2006-11-08T07:59:58
Hey venki_madesh ,this is very nice cpp program ... i hope u have good knowledge in CPP and other programs.really i appreciate the way developed this code ... i wish u have to submit more codes in different language mainly i prefer u to submit same code in C#. thank u Venkii... all the best for future life....
Comment posted by: Binisten on 2006-11-08T07:59:11
hey really it super.. try to avoid more if and use function to reduce number of lines....
Comment posted by: binish k - the king on 2006-11-11T03:55:50
hi venki_madesh...i m paul here...i really like ur pgm vry much...i m doing my ms in city coll of new york its in uk...me and my friends doing a project in bussiness intelligence v hv some doubt regarding tht so v may contact u soon...keep posting cintinue ur gud work...bye tc...
Comment posted by: Paul Watson on 2006-11-11T11:28:17
hi venki_madesh...i m paul here...i really like ur pgm vry much...i m doing my ms in city coll of new york its in uk...me and my friends doing a project in bussiness intelligence v hv some doubt regarding tht so v may contact u soon...keep posting cintinue ur gud work...bye tc...
Comment posted by: Paul Watson on 2006-11-11T11:29:40
hi venkat.....
its simply cool da...
good....
Comment posted by: Jawahar on 2006-12-03T22:45:56
hi venkat

nice program really superb .... keep doin da .... u hav a good knowlege in oops concepts... congrats ..........all the best
Comment posted by: Franklin Daniel on 2006-12-04T11:53:15
great
Comment posted by: binishkaspar on 2006-11-11T04:46:32
how to use it
Comment posted by: bismi_be2004 on 2007-03-28T03:21:52

Popular Coders

# Coder NameHits
1. srinivasaraobora130662
2. iamdvr97658
3. venki_madesh35133
4. Raju18462
5. parmod kumar duhan15745
6. Kiran.jakkaraju14049
7. chowsys7451
8. Venkateswara Rao6471
9. ashish.cns6346
10. Vamshidhar Matam5426

Active Coders

Refined Tags