使用图形的C中的日历计划程序如何启动

使用图形的C中的日历计划程序如何启动

本文介绍了使用图形的C中的日历计划程序如何启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#include<math.h>
#include<c:\tc\bin\calendar.c>

#define X getmaxx()/2
#define Y getmaxy()/2
#define PI 3.14
union REGS i,o;


int alarm_hr,alarm_min,alarm_sec,hr,min,sec;
char *alarm_time;
char *c_time;
char ch;
struct time t;
void main_menu();

void clock();
void clock_intro();
void clock_draw();
void drawClockNumbers();
void displayDigital(int,int,int);
void displayDate();
void starttick(int,int,int);
void alarm(int,int,int);
void calendar();
void calendar_intro();
void main_exit();
void submenu_exit();
void main()
{
	int gd=DETECT,gm;
	int hr,min,sec;

	struct time t;
	clrscr();
	initgraph(&gd,&gm,"c:\\tc\\bgi");
	main_menu();
	closegraph();
	getch();
}

initmouse()
{
  i.x.ax=0;
  int86(0x33,&i,&o);
  return(o.x.ax);
}
showmouse()
{
  i.x.ax=1;
  int86(0x33,&i,&o);
  return(o.x.ax);
}
hidemouse()
{
  i.x.ax=2;
  int86(0x33,&i,&o);
  return(o.x.ax);
}
void restrictmouse(int x1,int y1,int x2,int y2)
{
  i.x.ax=7;
  i.x.cx=x1;
  i.x.dx=x2;
  int86(0x33,&i,&o);
  i.x.ax=8;
  i.x.cx=y1;
  i.x.dx=y2;
  int86(0x33,&i,&o);
}
void getmousestatus(int *button,int *x,int *y)
{
  i.x.ax=3;
  int86(0x33,&i,&o);
  *button=o.x.bx;
  *x=o.x.cx;
  *y=o.x.dx;
}
void main_menu()
{
	int b,xx,yy;
	char opt_key='' '';
	cleardevice();

	initmouse();
	restrictmouse(0,0,getmaxx(),getmaxy());
	setbkcolor(0);
	settextstyle(10,0,2);
	setcolor(9);
	outtextxy(100,90,"           MENU           ");
	setcolor(5);
	outtextxy(100,130,"1 => MONTH''S CALENDAR");
	outtextxy(100,180,"2 => CLOCK");
	outtextxy(100,230,"3 => EXIT");
	setcolor(3);
	settextstyle(8,0,1);
	setlinestyle(3,1,3);
	setcolor(6);
	rectangle(45,80,590,300);
	setcolor(15);
	rectangle(55,90,580,290);

	outtextxy(60,320,"Project Made By Mohinee Patel AND Priyanka Patel");	showmouse();

//	If any key is not pressed.........................
	while(!kbhit())
	{
		getmousestatus(&b,&xx,&yy);
		if(xx>=100&&yy>=140&&xx<=500&&yy<180)
		{
			getmousestatus(&b,&xx,&yy);
			if(b&1==1)
			{
				hidemouse();
				cleardevice();
				calendar();
			}
		}

//***********************************************************
		if(xx>=100&&yy>190&&xx<=300&&yy<230)
		{
			getmousestatus(&b,&xx,&yy);
			if(b&1==1)
			{
				hidemouse();
				cleardevice();
				clock_intro();
				cleardevice();
				setbkcolor(0);
				fflush(stdin);
				printf("\n\n\n\n\t Do you want to set alarm ? Press Y or < ANYOTHER KEY >");
				scanf("%c",&ch);
				fflush(stdin);
				switch(ch)
				{
					case ''Y'':
					case ''y'':
						gettime(&t);
						hr=t.ti_hour;
						min=t.ti_min;
						sec=t.ti_sec;
						printf("\n\n\n\n\t\t\t Current TIme is %d %d %d ",hr,min,sec);
						printf("\n\n\t\t\t Enter the time for alarm:");
						scanf("%d %d %d",&alarm_hr,&alarm_min,&alarm_sec);
						break;
					case ''N'':
					case ''n'':break;
				}
				sprintf(alarm_time,"%02d:%02d",alarm_hr,alarm_min);
				cleardevice();
				starttick(hr,min,sec);

				//menu();
			}
		}
//************************************************************

		if(xx>=100&&yy>240&&xx<=300&&yy<275)
		{
			getmousestatus(&b,&xx,&yy);
			if(b&1==1)
			{
				hidemouse();
				cleardevice();
				main_exit();
			}
		}
	}
// If any key is pressed ......................................
	if(kbhit)
	{
		opt_key=getch();
		if(opt_key==''1'')
		{
			cleardevice();
			calendar();
		}
		else if(opt_key==''2'')
		{
			cleardevice();
			clock_intro();
			cleardevice();
			fflush(stdin);
				printf("\n\n\n\n\t Do you want to set alarm ? Press Y or < ANYOTHER KEY >");
				scanf("%c",&ch);
				fflush(stdin);
				switch(ch)
				{
					case ''Y'':
					case ''y'':
						gettime(&t);
						hr=t.ti_hour;
						min=t.ti_min;
						sec=t.ti_sec;
						printf("\n\n\n\n\t\t\t Current TIme is %d %d %d ",hr,min,sec);
						printf("\n\n\t\t\t Enter the time for alarm:");
						scanf("%d %d %d",&alarm_hr,&alarm_min,&alarm_sec);
						break;
					case ''N'':
					case ''n'':break;
				}
				sprintf(alarm_time,"%02d:%02d",alarm_hr,alarm_min);
				cleardevice();
				starttick(hr,min,sec);

		}
		else if(opt_key==''3'')
		{
			cleardevice();
			main_exit();
		}
		else
		{
			cleardevice();
			settextstyle(1,0,5);
			setcolor(RED);
			outtextxy(100,150,"Invalid Key is Pressed");
			delay(2000);
			main_menu();
		}
	}

}


void clock_intro()
{
	int i;
	char alm_ans;
	int a_hour,a_minu;
	struct time t1;
	for(i=0;i<=3;i++)
	{
		cleardevice();
		delay(200);
		setcolor(9);
		settextstyle(3,0,8);
		outtextxy(170,180,"CLOCK");
		setcolor(6);
		setlinestyle(3,1,3);
		rectangle(100,100,500,350);
		setcolor(15);
		rectangle(80,80,520,370);
		delay(200);
	}
	/*cleardevice();
	settextstyle(1,0,2);
	outtextxy(10,10,"Do You Wnt to set alarm??? ");
	alm_ans=getch();
	if(alm_ans==''y'')
	{
		gettime(&t1);
		printf("CurrentTIme ::::: %d  %d  %d ",t1.ti_hour,t1.ti_min,t1.ti_sec);
		outtextxy(10,50,"Enter Hour and sec");
		scanf("%d %d",&a_hour,&a_minu);
		printf("\n\n\n\n\nAla Time %d %d",a_hour,a_minu);
		alarm(a_hour,a_minu);
	}
	else
	{
		clock_draw();
	} */
}
void clock_draw()
{

	struct time t;
	int hr,min,sec;
	gettime(&t);
	hr=t.ti_hour;
	min=t.ti_min;
	sec=t.ti_sec;
	cleardevice();
	drawClockNumbers();
	//displayDigital();
	//displayDate();
	starttick(hr,min,sec);
	if(kbhit)
	{
		submenu_exit();
	}
}

void drawClockNumbers()
{
	int theta=0;
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"3"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"4"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"5"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"6"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"7"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"8"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"9"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"10"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"11"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"12"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"1"); theta+=30;
outtextxy(X+(Y-30)*cos(theta*(PI/180)),Y+(Y-30)*sin(theta*(PI/180)),"2"); theta+=30;
}
void displayDate()
{
	char *dateStr;
	struct date d;
	getdate(&d);
	settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
	sprintf(dateStr,"%d-%d-%d",d.da_day,d.da_mon,d.da_year);
	outtextxy(X-60,Y+150,dateStr);
}
void displayDigital(int hr,int min,int sec)
{
	char *digTime;
	settextstyle(SMALL_FONT,HORIZ_DIR,7);
	sprintf(digTime,"%02d:%02d:%02d",hr,min,sec);
	outtextxy(2*X-110,2*Y-30,digTime);
}
void starttick(int hr,int min,int sec)
{

int theta1=-90,theta2=-90,theta3=-90;
theta3+=hr*30;
theta2+=min*6;
theta1+=sec*6;
theta3+=(((theta2+90)/72)*6);
while(!(kbhit()))
{
	sound(500);
	drawClockNumbers();
	setlinestyle(0,1,3);
	setcolor(LIGHTBLUE);
	circle(X+7,Y+15,Y-15);
	setcolor(BROWN);
	circle(X+7,Y+15,Y-55);
	setcolor(WHITE);
	circle(X+7,Y+15,4);
	floodfill(X+7,Y+15,getmaxcolor());
	line(X+7,Y+15,X+7+(Y-30)*cos(theta1*(PI/180)),Y+15+(Y-30)*sin(theta1*(PI/180)));
	line(X+7,Y+15,X+7+(Y-60)*cos(theta2*(PI/180)),Y+15+(Y-60)*sin(theta2*(PI/180)));
	line(X+7,Y+15,X+7+(Y-120)*cos(theta3*(PI/180)),Y+15+(Y-120)*sin(theta3*(PI/180)));
	theta1+=6;sec++;
	if(theta1==270)
	{
		theta2+=6;
		theta1=-90;
		sec=0;
		min++;
	}
	if((theta2+90)%72==0 && theta1==-90)
	{
		theta3+=6;
	}
	if(theta2==270)
	{
		theta2=-90;
	}
	if(min==60)
	{
		hr++;
		min=0;
	}
	if(hr==13)
	{
		hr=1;
	}
	nosound();
	delay(1000);
	cleardevice();
	outtextxy(10,2*Y-80,"ALARM:");
	outtextxy(10,2*Y-50,alarm_time);
	displayDate();
	displayDigital(hr,min,sec);
	alarm(theta1,theta2,theta3);
}

}
void alarm(int theta1,int theta2,int theta3)
{
int alarm_theta1=-90,alarm_theta2=-90,alarm_theta3=-90;
int i=0;
alarm_theta3+=alarm_hr*30;
alarm_theta2+=alarm_min*6;
alarm_theta1+=alarm_sec*6;
alarm_theta3+=(((alarm_theta2+90)/72)*6);
alarm_theta1+=6;
if(alarm_theta1==270)
{
	alarm_theta2+=6;
	alarm_theta1=-90;
}
if((alarm_theta2+90)%72==0 && alarm_theta1==-90)
{
	alarm_theta3+=6;
}
if(alarm_theta2==270)
{
	alarm_theta2=-90;
}
if(theta2==alarm_theta2 && theta3==alarm_theta3)
{
	outtextxy(10,10,"ALARM TIME");
	for(i=1;i<10;i++)
	{
	 sound(1500);
	}
	delay(200);
	nosound();
	delay(100);
	for(i=1;i<10;i++)
	{
	 sound(1500);
	}
	delay(200);
	nosound();
}
if(kbhit())
{
	nosound();
}
}
void calendar()
{
	calendar_intro();
	restorecrtmode();
	clndr();
       // setgraphmode();
}



void calendar_intro()
{
	int i;
	for(i=0;i<=3;i++)
	{
		cleardevice();
		delay(200);
		setcolor(9);
		settextstyle(3,0,8);
		outtextxy(120,180,"CALENDAR");
		setcolor(6);
		setlinestyle(3,1,3);
		rectangle(100,100,500,350);
		setcolor(15);
		rectangle(80,80,520,370);
		delay(200);
	}
}
void main_exit()
{
	int i;
	for(i=0;i<=3;i++)
	{
	cleardevice();
	delay(200);
	setcolor(9);
	settextstyle(3,0,8);
	outtextxy(170,180,"EXITING");
	setcolor(6);
	setlinestyle(3,1,3);
	rectangle(100,100,500,350);
	setcolor(15);
	rectangle(80,80,520,370);
	delay(200);
	}
	exit(0);
}
void submenu_exit()
{
	int i;
	for(i=0;i<=3;i++)
	{
	cleardevice();
	delay(200);
	setcolor(9);
	settextstyle(3,0,8);
	outtextxy(170,180,"EXITING");
	setcolor(6);
	setlinestyle(3,1,3);
	rectangle(100,100,500,350);
	setcolor(15);
	rectangle(80,80,520,370);
	delay(200);
	}
	main_menu();
}
解决方案






这篇关于使用图形的C中的日历计划程序如何启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 10:25