In c and without using switch statements write a program whi
In c++ (and without using switch statements), write a program which will do the following. It will ask the user for the name of a month. It will call a function which will accept the name of the month as a parameter and return the number of days in that month. If the name of the month is not valid, it will throw an exception. The main function of the program will print the number which was returned by the function, or if there is an exception thrown the main function will catch it and display a message saying invalid month name. The main function will use a loop to accept one month name after another until the user enters the control-d character.
Solution
#include<conio.h>
#include<iostream.h>
void main()
{
int year,month;
clrscr();
cout<<\"Enter year:=\";
cin>>year;
cout<<\"Enter month:=\";
cin>>month;
cout<<\"\ \ ==========================================\ \ \";
if(year<=9999 && year>=1100)
{
if((year%400==0)||((year%100!=0)&&(year%4==0)))
{
cout<<year<<\" :: is a leap year with 366 days\ \";
if(month==1)
{
cout<<\"January\ Days: 31\";
}
else if(month==2)
{
cout<<\"February\ Days: 29\";
}
else if(month==3)
{
cout<<\"March\ Days: 31\";
}
else if(month==4)
{
cout<<\"April\ Days: 30\";
}
else if(month==5)
{
cout<<\"May\ Days: 31\";
}
else if(month==6)
{
cout<<\"June\ Days: 30\";
}
else if(month==7)
{
cout<<\"July\ Days: 31\";
}
else if(month==8)
{
cout<<\"August\ Days: 31\";
}
else if(month==9)
{
cout<<\"September\ Days: 30\";
}
else if(month==10)
{
cout<<\"October\ Days: 31\";
}
else if(month==11)
{
cout<<\"November\ Days: 30\";
}
else if(month==12)
{
cout<<\"December\ Days: 31\";
}
else
{
cout<<\"Invalid month...please enter form 1 to 12\";
}
}
else
{
cout<<year<<\":: with 365 days\ \";
if(month==1)
{
cout<<\"January\ Days: 31\";
}
else if(month==2)
{
cout<<\"February\ Days: 28\";
}
else if(month==3)
{
cout<<\"March\ Days: 31\";
}
else if(month==4)
{
cout<<\"April\ Days: 30\";
}
else if(month==5)
{
cout<<\"May\ Days: 31\";
}
else if(month==6)
{
cout<<\"June\ Days: 30\";
}
else if(month==7)
{
cout<<\"July\ Days: 31\";
}
else if(month==8)
{
cout<<\"August\ Days: 31\";
}
else if(month==9)
{
cout<<\"September\ Days: 30\";
}
else if(month==10)
{
cout<<\"October\ Days: 31\";
}
else if(month==11)
{
cout<<\"November\ Days: 30\";
}
else if(month==12)
{
cout<<\"December\ Days: 31\";
}
else
{
cout<<\"Invalid month...please enter form 1 to 12\";
}
}
}
else
{
cout<<\"Invalid year..Please enter year between 1100 to 9999\";
}
getch();
}


