4 Replies - 9496 Views - Last Post: 22 July 2009 - 08:29 AM Rate Topic: -----

#1 ratheeshsuresh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-March 09

to write a c program to print the monthly calendar if the date is give

Post icon  Posted 12 March 2009 - 06:18 AM

send the program soon........
Is This A Good Question/Topic? 0
  • +

Replies To: to write a c program to print the monthly calendar if the date is give

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,440
  • Joined: 23-August 08

Re: to write a c program to print the monthly calendar if the date is give

Posted 12 March 2009 - 06:47 AM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 eeshan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 10-May 09

Re: to write a c program to print the monthly calendar if the date is give

Posted 10 May 2009 - 02:46 AM

View Postratheeshsuresh, on 12 Mar, 2009 - 05:18 AM, said:

send the program soon........


Here's the program that you require :
/*This program also includes a facility in which you can change the month or the year by using the arrow keys*/ :) :D :^:
#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<math.h>
#include<ctype.h>

int month (int a)
{
	int x;
	switch (a)
	{
		case 1  :
		case 3  :
		case 5  :
		case 7  :
		case 8  :
		case 10 :
		case 12 :	x=31;
					break;
		case 2  :	x=28;
					break;
		case 4  :
		case 6  :
		case 9  :
		case 11 :	x=30;
					break;
	}
	return x;
}

int calculate (int a, int b)
{
	int dc=0, i=1900, j=1;
	while (i<a)
	{
		if (i%4)
			dc+=365;
		else
			dc+=366;
		++i;
	}
	while (j<b)
	{
		dc+=month(j);
		++j;
	}
	if (((a%4)==0) && (b>2))
		dc+=1;
	return dc;
}

void output (int day, int month)
{
	int date=1, j, i;
	cout<<"\nSun\tMon\tTue\tWed\tThurs\tFri\tSat\n";
	for (j=1;date<=month;++j, date++)
	{
		if (j==1)
		{
			for (i=1;i<=day;i++)
				cout<<"  \t";
		}
		cout<<date<<"  \t";
		if ((day+j)%7==0)
			cout<<endl;
	}
}

void main()
{
	clrscr();
	int year, mon, k, l, day;
	cout<<"Enter month and year ";
	cin>>mon>>year;
	cal:
	clrscr();
	k=0;
	l=0;
	day=0;
	k=calculate(year, mon);
	k+=2;
	day=k%7;
	day=abs(day);
	char x;
	l=month(mon);
	if ((year%4==0) && (mon==2))
		l+=1;
	switch (mon)
	{
		case 1   :	cout<<"January "<<year<<": \n";break;
		case 2   :	cout<<"February "<<year<<":\n";break;
		case 3   :	cout<<"March "<<year<<": \n ";break;
		case 4   :	cout<<"April "<<year<<":\n ";break;
		case 5   :	cout<<"May "<<year<<":\n ";break;
		case 6   :  cout<<"June "<<year<<":\n ";break;
		case 7   :	cout<<"July "<<year<<":\n ";break;
		case 8   :	cout<<"August "<<year<<":\n ";break;
		case 9   :	cout<<"September "<<year<<":\n";break;
		case 10  :	cout<<"October "<<year<<":\n";break;
		case 11  :	cout<<"November "<<year<<":\n";break;
		case 12  :	cout<<"December "<<year<<":\n";break;
	}
	output(day, l);
	cout<<"\nPress :\n1.Up arrow key for the calendar for the same month but next year ";
	cout<<"\n2.Down arrow key for the calendar of the same month but previous year ";
	cout<<"\n3.Left arrow key for the calendar of the previous month of same year ";
	cout<<"\n4.Right arrow key for the calendar of the next month of same year ";
	cout<<"\n5.Enter key twice to exit ";
	x='\0';
	getch();
	x=getch();
	if ((toascii(x))==72)
	{
		year++;
		goto cal;
	}
	if ((toascii(x))==80)
	{
		year--;
		goto cal;
	}
	if ((toascii(x))==75)
	{
		mon--;
		goto cal;
	}
	if ((toascii(x))==77 && mon==12)
	{
		mon=1;
		year++;
		goto cal;
	}
	if ((toascii(x))==77)
	{
		mon++;
		goto cal;
	}
	if ((toascii(x))==13)
		exit(0);
}


This post has been edited by eeshan: 10 May 2009 - 02:50 AM

Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,902
  • Joined: 10-May 07

Re: to write a c program to print the monthly calendar if the date is give

Posted 10 May 2009 - 02:49 AM

eeshan : It's understandable that you are eager to help out, but we really ask that posters provide even a little bit of effort towards their projects or requests. Please read over the above post by JackOfAllTrades for a better description on our policy. If you have any questions regarding this policy, please feel free to create a post under Site Feedback

Thank you.
Was This Post Helpful? 0
  • +
  • -

#5 guppirulz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-July 09

Re: to write a c program to print the monthly calendar if the date is give

Posted 22 July 2009 - 08:29 AM

hey can any one give the same code for c language please
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1