VB icon

Simplest Calendar Program

Email
Submitted on: 1/8/2015 11:35:00 AM
By: K. N. K. TEJA (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: C++ (general), Borland C++
Views: 652
 
     This is a 28 line calendar program. It prints any month entered after Jan, 1980. Simple program to show the power of calculations.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Simplest Calendar Program
//**************************************
iostream.h for cout,cin and,
conio.h for clrscr(), getch().
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Simplest Calendar Program
// Description:This is a 28 line calendar program. It prints any month entered after Jan, 1980. Simple program to show the power of calculations.
// By: K. N. K. TEJA (from psc cd)
//
// Inputs:The inputs of the program are the month and year numbers you want to print the calendar for.
//
// Returns:Program does not return anything but displays the calendar for the requested month
//
// Assumes:Nothing special
//
// Side Effects:No special side effects for the program.
//**************************************

#include<iostream.h>
#include<conio.h>
void main(){
 int i,cm,cy,d=2; //cm = current month, cy = current year. d=2 because 1st jan,1980 is tuesday.
 int m[12]={31,28,31,30,31,30,31,31,30,31,30,31}; //Array to hold no. of days in all months.
 clrscr();
 cout<<"Enter month and year:";
 cin>>cm>>cy;
 if(cm<1||cm>12||cy<1980){
cout<<"ERROR! Cannot display below 1980.";
return; //returns from main
 }
 m[1]=!(cy%4)+28; // !(cy%4) is true if cy is a leapyear
 for(i=1980;i<cy;i++){
d+=!(i%4)+365;
d%=7; //calculates the effective day.
 }
 for(i=2;i<=cm;i++)
d+=m[i-2];
 d%=7;
 cout<<"\nSu\tMo\tTu\tWe\tTh\tFr\tSa\n";
 for(i=0;i<d;i++)cout<<" \t";
 for(i=1;i<=m[cm-1];i++,d++){
cout<<i<<'\t';
if(!((d+1)%7))cout<<endl;
 }
 getch();
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.