Write and test a program to calculate the dayand number(from 1 to 365 in a regul
ID: 3617387 • Letter: W
Question
Write and test a program to calculate the dayand number(from 1 to 365 in a regular year, or from 1 to 366in a leap year), when a date is input. input month(1 to 12 allowed), day of month(1 to 31 allowed)and year(4-digit number) output: month/day/year is day number(--------------)? (day number) output: the year(-----------) is (or is not) a leap year (year) precessing requirements -use a switch statement testing t= (month - 1), with casesordered from 11 to 1, to add the number od days in month t to theday number. Do not use breaks between cases, because if you are inmonth 7, foe example, you need to add the days in all the months6,5,4,3,2 and 1 to the day of the month in month 7 Do atleast the following and make sure the program works forthese cases a january date, a february date in leap year, a june date in leap year, an october date in a non leap year cases with bad input to demonstrate your input checks andwork Write and test a program to calculate the dayand number(from 1 to 365 in a regular year, or from 1 to 366in a leap year), when a date is input. input month(1 to 12 allowed), day of month(1 to 31 allowed)and year(4-digit number) output: month/day/year is day number(--------------)? (day number) output: the year(-----------) is (or is not) a leap year (year) precessing requirements -use a switch statement testing t= (month - 1), with casesordered from 11 to 1, to add the number od days in month t to theday number. Do not use breaks between cases, because if you are inmonth 7, foe example, you need to add the days in all the months6,5,4,3,2 and 1 to the day of the month in month 7 Do atleast the following and make sure the program works forthese cases a january date, a february date in leap year, a june date in leap year, an october date in a non leap year cases with bad input to demonstrate your input checks andworkExplanation / Answer
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int days,month,year;
int day;
for(;;)
{
cout<<" Enter the day : ";
cin>>days;
if(days>0&&days<=31)
break;
else
cout<<" Invalid day:(1-31 only) ";
}
for(;;)
{
cout<<" Enter the month : ";
cin>>month;
if(month>0&&month<=12)
break;
else
cout<<" Invalid Month:(1-12 only) ";
}
for(;;)
{
cout<<" Enter the year : ";
cin>>year;
if(year>=1900&&year<=2010)
break;
else
cout<<" Invalid year:(1900-2010 only) ";
}
day=days;
if(year%4==0)
day++;
for(intv=1;v<month;v++)
{
switch(v)
{
case 1:
{
day+=31;
break;
}
case 2:
{
day+=28;
break;
}
case 3:
{
day+=31;
break;
}
case 4:
{
day+=30;
break;
}
case 5:
{
day+=31;
break;
}
case 6:
{
day+=30;
break;
}
case 7:
{
day+=31;
break;
}
case 8:
{
day+=31;
break;
}
case 9:
{
day+=30;
break;
}
case 10:
{
day+=31;
break;
}
case 11:
{
day+=30;
break;
}
case 12:
{
day+=31;
break;
}
}
}
cout<<" There are total : "<<day<<" Days From(1-1-"<<year<<") to("<<days<<"-"<<month<<"-"<<year<<")";
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.