6. write a program that takes m from user and print its month calendar of year 2013 for example
February 2009
S M Tu W Th F S
2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
23 24 25 26 27 28
Please do not expect us to do your homework for you.
Be specific about what you have tried, where you are stuck, which errors the compiler gives you, etc.
People will be more inclined to help you out if you do so.
#include <iostream>
//EXAMPLE:
//#define MIN_DEC_2012 // Take a calendar and define these as spaces after start.
//#define MAX_DEC_2012 // For example: there are 6 blank spaces until day 1 so
// MIN_DEC_2012=6.
// Also, MAX_DEC_2012=6 because there are 6 spaces after 31.
#define MIN_JAN_2013 2 //31 days
#define MIN_FEB_2013 5 //31 days
#define MIN_MAR_2013 5 //30 days
#define MIN_APR_2013 1 //30 days
#define MIN_MAY_2013 3 //31 days
#define MIN_JUN_2013 6 //29 days
#define MIN_JUL_2013 1 //31 days
#define MIN_AUG_2013 4 //31 days
#define MIN_SEP_2013 0 //30 days
#define MIN_OCT_2013 2 //31 days
#define MIN_NOV_2013 5 //30 days
#define MIN_DEC_2013 //there isnt a december on the indian calendar.
//find one on your own
#define MAX_JAN_2013 2
#define MAX_FEB_2013 6
#define MAX_MAR_2013 0
#define MAX_APR_2013 4
#define MAX_MAY_2013 1
#define MAX_JUN_2013 0
#define MAX_JUL_2013 3
#define MAX_AUG_2013 0
#define MAX_SEP_2013 5
#define MAX_OCT_2013 2
#define MAX_NOV_2013 0
#define MAX_DEC_2013 //there isnt a december on the indian calendar.
//find one on your own
void InterpretMonth (int month);
void InterpretMonth (int month)
{
int i;
std::cout<<"F o r t h e y e a r 2 0 1 3"<<std::endl<<std::endl;
std::cout<<"| S | M | T | W | T | F | S |"<<std::endl;
std::cout<<"+---+---+---+---+---+---+---+"<<std::endl;
if(month==1)
{
for(i=1;i<=MIN_JAN_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=31;i++)
{
if(i==5||i==12||i==19||i==26)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_JAN_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==2)
{
for(i=1;i<=MIN_FEB_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=31;i++)
{
if(i==2||i==9||i==16||i==23||i==30)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_FEB_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==3)
{
for(i=1;i<=MIN_MAR_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=30;i++)
{
if(i==2||i==9||i==16||i==23||i==30)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_MAR_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==4)
{
for(i=1;i<=MIN_APR_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=30;i++)
{
if(i==6||i==13||i==20||i==27)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_APR_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==5)
{
for(i=1;i<=MIN_MAY_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=31;i++)
{
if(i==4||i==11||i==18||i==25)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_MAY_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==6)
{
for(i=1;i<=MIN_JUN_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=29;i++)
{
if(i==1||i==8||i==15||i==22||i==29)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
}
elseif(month==7)
{
for(i=1;i<=MIN_JUL_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=31;i++)
{
if(i==6||i==13||i==20||i==27)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_JUL_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==8)
{
for(i=1;i<=MIN_AUG_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=31;i++)
{
if(i==3||i==10||i==17||i==24||i==31)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
}
elseif(month==9)
{
for(i=1;i<=MIN_SEP_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=30;i++)
{
if(i==7||i==14||i==21||i==28)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_SEP_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==10)
{
for(i=1;i<=MIN_OCT_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=31;i++)
{
if(i==5||i==12||i==19||i==26)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
for(i=0;i<=MAX_OCT_2013;i++)
{
std::cout<<"| ";
}
}
elseif(month==11)
{
for(i=1;i<=MIN_NOV_2013;i++)
{
std::cout<<"| ";
}
for(i=1;i<=30;i++)
{
if(i==2||i==9||i==16||i==23||i==30)
{
if(i<10)
{
std::cout<<"| "<<i<<" |"<<std::endl;
}
else
{
std::cout<<"| "<<i<<"|"<<std::endl;
}
}
else
{
if(i<10)
{
std::cout<<"| "<<i<<" ";
}
else
{
std::cout<<"| "<<i;
}
}
}
}
else
{
std::cout<<std::endl<<"IN THE INDIAN MONTH, THE CALENDAR ENDS ON NOVEMBER."<<std::endl;
}
}
main()
{
int month;
std::cout<<"What month would you like us to print out? ";
std::cin>>month;
std::cout<<std::endl<<std::endl;
if(month>0 && month<13)
{
InterpretMonth(month);
}
else
{
std::cout<<"Out of range!";
}
}
DO NOT USE THIS CODE: 1. It is extensive. and repetitive. 2. It is very long, complicated and takes up a lot of memory. USE THIS CODE ONLY AS AN EXAMPLE.
oh well i m sorry i havent used this forum before my friend provided me the address. i didn't have any idea that we are suppose to post our programs as well i m not asking for my homework
Please edit your post so it uses code tags. Select your code, then press the <> button on the right under formatting.
With your code there a couple of things you can do to start with.
Create an array of all the month names. Use an array index variable to access them with a for loop. This is much better than lots of else-if statements.
With the starting day, you need to calculate this. Start with a year that you know what day was 1 Jan. Calc the number of days since then to the start of the month, taking into account leap years. Remeber to make use of functions.