fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class dateType
  7. {
  8. public:
  9. dateType();
  10. ~dateType();
  11. bool Checkdate();
  12. bool isLeapYear();
  13. void setDate();
  14. void setMonth (int m);
  15. int getMonth();
  16. void setDay(int d);
  17. int getDay();
  18. void setYear (int y);
  19. int getYear();
  20. void Num_Month();
  21. void Num_DayPassed();
  22. void Num_RemainingYear();
  23. void printdate();
  24.  
  25. private:
  26. int month;
  27. int day;
  28. int year;
  29. };
  30. dateType::dateType()
  31. {
  32. cout<<"Object Created\n";
  33. }
  34. bool dateType::Checkdate()
  35. {
  36.  
  37. if(year>=1900 && year<=9999)
  38. {
  39. if(month>=1&&month<=12)
  40. {
  41. if((day>=1&&day<=31)&&(month==1 ||month==3||month ==5||month==7||month ==8||month==10||month==12 ))
  42. cout<<"Date is Valid.\n";
  43. else if((day>=1 && day<=30) && (month==4 || month==6 || month==9 || month==11))
  44. cout<<"Date is valid.\n";
  45. else if((day>=1&&day<=28)&&(month==2))
  46. cout<<"Date is Valid\n";
  47. else
  48. printf("Invalid Date.\n");
  49. }
  50. else
  51. {
  52. cout<<"Invalid Month.\n";
  53. }
  54. }
  55. else
  56. {
  57. cout<<"Invalid Year.\n";
  58. }
  59.  
  60. }
  61. bool dateType::isLeapYear()
  62. {
  63.  
  64. if (year % 4 == 0)
  65. {
  66. if (year % 100 == 0)
  67. {
  68. if (year % 400 == 0)
  69. cout << year << " is a leap year.\n";
  70. else
  71. cout << year << " is not a leap year.\n";
  72. }
  73. else
  74. cout << year << " is a leap year.\n";
  75. }
  76. else
  77. cout << year << " is not a leap year.\n";
  78.  
  79. }
  80.  
  81. void dateType::setDate()
  82. {
  83. cout<<"Enter Month: ";
  84. cin>>month;
  85. cout<<endl;
  86. cout<<"Enter Date: ";
  87. cin>>day;
  88. cout<<endl;
  89. cout<<"Enter Year: ";
  90. cin>>year;
  91. cout<<endl;
  92. }
  93.  
  94. void dateType::setMonth (int m)
  95. {
  96. month = m;
  97. }
  98. int dateType::getMonth()
  99. {
  100. return month;
  101. }
  102. void dateType::setDay(int d)
  103. {
  104. day=d;
  105. }
  106. int dateType::getDay()
  107. {
  108. return day;
  109. }
  110. void dateType:: setYear (int y)
  111. {
  112. year=y;
  113. }
  114. int dateType::getYear()
  115. {
  116. return year;
  117. }
  118. void dateType::Num_Month()
  119. {
  120.  
  121.  
  122. if (month ==4||month==6||month==9||month==11)
  123. {day=30;
  124. cout<<"Number of days in a month: "<<day<<endl;
  125. }
  126. else if (month ==2)
  127. {
  128. day=29;
  129. cout<<"Number of days in a month: "<<day<<endl;
  130. }
  131. else
  132. {
  133. day=31;
  134. cout<<"Number of days in a month: "<<day<<endl;
  135. }
  136.  
  137. }
  138. void dateType::Num_DayPassed()
  139. {
  140. int sum;
  141. int yy = 365;
  142.  
  143. if (month ==1)
  144. {
  145. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  146. day=31;
  147. sum=day-yy;
  148. }
  149. else if (month==2)
  150. {
  151. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  152. day=60;
  153. sum=day-yy;
  154. }
  155. else if (month==3)
  156. {
  157. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  158. day=91;
  159. sum=day-yy;
  160. }
  161. else if (month==4)
  162. {
  163. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  164. day=121;
  165. sum=day-yy;
  166. }
  167. else if (month==5)
  168. {
  169. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  170. day=152;
  171. sum=day-yy;
  172. }
  173. else if (month==6)
  174. {
  175. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  176. day=182;
  177. sum=day-yy;
  178. }
  179. else if (month==7)
  180. {
  181. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  182. day=213;
  183. sum=day-yy;
  184. }
  185. else if (month==8)
  186. {
  187. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  188. day=244;
  189. sum=day-yy;
  190. }
  191. else if (month==9)
  192. {
  193. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  194. day=274;
  195. sum=day-yy;
  196. }
  197. else if (month==10)
  198. {
  199. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  200. day=305;
  201. sum=day-yy;
  202. }
  203. else if (month==11)
  204. {
  205. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  206. day=335;
  207. sum=day-yy;
  208. }
  209. else if (month==12)
  210. {
  211. cout<<"Number of days Passed in the Year: "<<sum<<endl;
  212. day=366;
  213. sum=day-yy;
  214. }
  215.  
  216. }
  217. void dateType::Num_RemainingYear()
  218. {
  219.  
  220. }
  221. void dateType:: printdate()
  222. {
  223. cout<<"Month: "<<month<<endl;
  224. cout<<"Date: "<<day<<endl;
  225. cout<<"Year: "<<year<<endl;
  226.  
  227. }
  228.  
  229. dateType::~dateType()
  230. {
  231. cout<<"Object Deleted";
  232. }
  233. int main()
  234. {
  235. dateType dt;
  236.  
  237. dt.setDate();
  238. dt.printdate();
  239. dt.Checkdate();
  240. dt.isLeapYear();
  241. dt.Num_Month();
  242. dt.Num_DayPassed();
  243.  
  244.  
  245. return 0;
  246. }
Success #stdin #stdout 0s 16072KB
stdin
Standard input is empty
stdout
Object Created
Enter Month: 
Enter Date: 
Enter Year: 
Month: -1752190480
Date: 32767
Year: 0
Invalid Year.
0 is a leap year.
Number of days in a month: 31
Object Deleted