Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
пример2_ ПЗ_курсовой ЧМИ.doc
Скачиваний:
2
Добавлен:
28.08.2019
Размер:
804 Кб
Скачать
☆
  1. Порядок контроля и приёма

Пояснительная записка должна быть сдана за 3 дня до защиты курсовой работы.

Защита осуществляется перед комиссией из двух преподавателей.

Оценка определяется степенью выполнения требований в техническом задании и качеством пояснительной записки.

Приложение Б

Руководство пользователя

Приложение В

Текст программы

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include <string.h>

#include <dos.h>

#include <time.h>

#include <io.h>

class CGraphInterface

{

protected:

int wTop;

int wLeft;

int pos_x,pos_y;

virtual void draw()=0;

public:

void initgraph_();

int closegraph();

};

class CFactory

{

public:

CGraphInterface* createobj(char*);

};

class CCalendar:public CGraphInterface

{

char notes[256][50];

int inote;

int note_;

int imonth;

int year;

int day;

int day_per_mon;

int cur_day;

char *str_year;

char month[12][10];

struct date d; // system date,month,year

struct tm time_check; // a weekday from current date,month,year

public:

void change_month(char);

int day_in_month();

void day_to_coord(int);

int day_vs_note(int);

void draw();

void note();

void keystrike(int);

CCalendar();

void init();

void operator>>(char*);

void operator<<(char*);

};

class CTimer:public CGraphInterface

{

int min;

float sec;

clock_t time_;

public:

CTimer();

CTimer(int);

void draw();

int start();

~CTimer();

int zero_timer();

void operator<<(char*);

};

class CMenu

{

public:

void show();

};

#include "planner.h"

////////////////////CFactorty///////////////////////////

CGraphInterface* CFactory::createobj(char* objname)

{

CGraphInterface *obj;

if (strcmp(objname,"timer")==NULL)

obj=new CTimer;

if (strcmp(objname,"calendar")==NULL)

obj=new CCalendar;

return obj;

}

////////////////////////////////////////////////////////

////////////////CGraphInterface/////////////////////////

void CGraphInterface:: initgraph_()

{

int gdriver = DETECT, gmode, errorcode;

initgraph(&gdriver, &gmode, "");

errorcode = graphresult();

if (errorcode != grOk)

{

printf("ЋиЁЎЄ  Ё­ЁжЁ «Ё§ жЁЁ Ја дЁЄЁ: %s\n", grapherrormsg(errorcode));

getch();

exit(1);

}

}

int CGraphInterface::closegraph()

{

closegraph();

return 1;

}

///////////////////////////////////////////////////////////

/////////////////////CCalendar/////////////////////////////

CCalendar::CCalendar()

{

sprintf(month[0],"џ­ў ам");

sprintf(month[1],"”Ґўа «м");

sprintf(month[2],"Њ ав");

sprintf(month[3],"ЂЇаҐ«м");

sprintf(month[4],"Њ ©");

sprintf(month[5],"€о­м");

sprintf(month[6],"€о«м");

sprintf(month[7],"ЂўЈгбв");

sprintf(month[8],"‘Ґ­впЎам");

sprintf(month[9],"ЋЄвпЎам");

sprintf(month[10],"H®пЎам");

sprintf(month[11],"„ҐЄ Ўам");

inote=0;

getdate(&d);

// read current date,month, year

year= d.da_year;

day= d.da_day;

imonth= d.da_mon-1;

cur_day=day;

wLeft = 150;

wTop = 100;

for (int i=0;i<256;i++)

{

sprintf(notes[i],"");

}

}

void CCalendar::init()

{

inote=0;

getdate(&d);

// read current date,month, year

year= d.da_year;

day= d.da_day;

imonth= d.da_mon-1;

cur_day=day;

wLeft = 150;

wTop = 100;

for (int i=0;i<256;i++)

{

sprintf(notes[i],"");

}

}

void CCalendar::keystrike(int key)

{

switch(key)

{

case 72: if(cur_day-7>=1)cur_day-=7;break; //up

case 80: if (cur_day+7<=day_per_mon)cur_day+=7;break; //down

case 75: if(cur_day>1)cur_day--;break; //left

case 77: if (cur_day<day_per_mon)cur_day++;break; //right

case 73: change_month(key);break;//PgUp

case 81: change_month(key);break; // PgDown

case 71: if (year>1970)year--;break; //Home

case 79: if (year<2037)year++;break; //End

case 13: note();

}

}

void CCalendar::operator>>(char* fname)

{

FILE* file2save;

file2save=fopen(fname,"wt");

for (int i=0;i<256;i++)

if ((strcmp(notes[i],""))!=NULL)

fprintf(file2save,"%s\n",notes[i]);

fclose(file2save);

}

void CCalendar::operator<<(char* fname)

{

int len;

FILE* file2load;

if ((file2load=fopen(fname,"rt"))==NULL)

{

file2load=fopen("notes.txt","wt");

fclose(file2load);

}

while (!feof(file2load))

{

fgets(notes[inote],256,file2load);

len=strlen(notes[inote]);

notes[inote][len-1]='\0';

inote++;

}

fclose(file2load);

}

void CCalendar::change_month(char key)

{

switch (key)

{

case 73: if (imonth>0)

imonth--;

break;

case 81: if (imonth<11)

imonth++;

break;

}

}

int CCalendar::day_in_month()

{

int days;

switch(imonth+1)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12: days=31;break;

case 4:

case 6:

case 9:

case 11: days=30;break;

case 2:

if (year%4==0) days= 29;

else return days=28;

break;

}

return days;

}

void CCalendar::day_to_coord(int day)

{

pos_x = time_check.tm_wday-1;

pos_y = 0;

while (day>0)

{

day--;

pos_x++;

if (pos_x>6) {pos_x=0;pos_y++;}

}

}

int CCalendar::day_vs_note(int day)

{

char str1[20];

int i;

char q[3];

char str2[20];

int rez;

sprintf(str1,"");

sprintf(str1,"%d",year);

sprintf(q,"%d",imonth+1);

if (imonth+1<10)

strcat(str1,"0");

strcat(str1,q);

sprintf(q,"%d",day);

if (day<10)

strcat(str1,"0");

strcat(str1,q);

rez=-1;

//cycle for all notes

for (i=0;i<256;i++)

{

strncpy(str2,notes[i],8);

str2[8]='\0';

if (strcmp(str1,str2)==NULL)

{rez=i;break;}

}

return rez;

}

void CCalendar::draw()

{

int i,j,k;

char *c1,*c;

char ss[60];

int len;

setfillstyle(SOLID_FILL, 1);

bar(wLeft-4,wTop-25,wLeft+318,wTop-12);

setcolor(WHITE);

strcpy(c1,"Ї­");

outtextxy(wLeft,wTop-20,c1);

strcpy(c1,"ўв");

outtextxy(wLeft+1*50,wTop-20,c1);

strcpy(c1,"ба");

outtextxy(wLeft+2*50,wTop-20,c1);

strcpy(c1,"зв");

outtextxy(wLeft+3*50,wTop-20,c1);

strcpy(c1,"Їв");

outtextxy(wLeft+4*50,wTop-20,c1);

strcpy(c1,"бЎ");

outtextxy(wLeft+5*50,wTop-20,c1);

strcpy(c1,"ўб");

outtextxy(wLeft+6*50,wTop-20,c1);

// draw a days

/* load the time_check structure with the data */

time_check.tm_year = year - 1900;

time_check.tm_mon = imonth;

time_check.tm_mday = 0; // detect weekday for the 1st day of month

time_check.tm_hour = 0;

time_check.tm_min = 0;

time_check.tm_sec = 1;

time_check.tm_isdst = -1;

/* call mktime to fill in the weekday field of the structure */

if (mktime(&time_check) == -1)

time_check.tm_wday = 7;

day_per_mon=day_in_month();

i=0;k=1;

j=time_check.tm_wday;

setfillstyle(SOLID_FILL, BROWN);

while (k<=day_per_mon)

{

c=itoa(k,c,10);

//highlights days with notes

if (day_vs_note(k)!=-1)

bar(wLeft+j*50-5,wTop+i*50-7,wLeft+j*50+19,wTop+i*50+12);

outtextxy(wLeft+j*50,wTop+i*50,c);

k++;

j++;

if (j==7) { i++; j=0;}

}

setfillstyle(SOLID_FILL, BLUE);

// draw a cursor

day_to_coord(cur_day);

setcolor(GREEN);

rectangle(wLeft+(pos_x)*50-5,wTop+pos_y*50-8,

wLeft+(pos_x)*50+20,wTop+pos_y*50+12);

setcolor(WHITE);

// draw a month

setcolor(LIGHTGRAY);

rectangle(145,25,218,43);

floodfill(146,26,LIGHTGRAY);

setcolor(WHITE);

outtextxy(150,30,month[imonth]);

// draw a year

sprintf(str_year,"%d",year);

setcolor(LIGHTGRAY);

rectangle(245,25,285,43);

floodfill(246,26,LIGHTGRAY);

setcolor(WHITE);

outtextxy(250,30,str_year);

setfillstyle(SOLID_FILL, DARKGRAY);

// draw a note

setcolor(LIGHTGRAY);

rectangle(135,350,502,365);

floodfill(136,351,LIGHTGRAY);

setcolor(WHITE);

if ((note_=day_vs_note(cur_day))!=-1)

{

len=strlen(notes[note_]);

for (j=8;j<len;j++)

ss[j-8]=notes[note_][j];

ss[len-8]='\0';

outtextxy(140,354,ss);

}

}

void CCalendar::note()

{

char s[60];

char *s1;

char s2[60];

char s3[2]="00";

char s4[2]="00";

char key=0;

int count=0;

sprintf(s,"");

sprintf(notes[note_],"");

cleardevice();

draw();

while (key!=13)

{

key=getch();

switch(key)

{

case 8:

if (count>0)

{

s[strlen(s)-1]='\0';

cleardevice();

draw();

count--;

}

break;

case 13:

break;

default:

if (count<45)

{

sprintf(s1,"%c",key);

strcat(s,s1);

count++;

}

}

setcolor(WHITE);

outtextxy(140,354,s);

}

if (strlen(s)>0)

{

sprintf(s2,"%d",year);

sprintf(s3,"%d",imonth+1);

if (imonth+1<10)

strcat(s2,"0");

strcat(s2,s3);

sprintf(s4,"%d",cur_day);

if (cur_day<10)

strcat(s2,"0");

strcat(s2,s4);

strcat(s2,s);

strcpy(notes[inote],s2);

inote++;

}

}

//////////////////////////////////////////////////////////

/////////////////// CTimer class////////////////////////

CTimer::CTimer(int init_time)

{

time_=init_time*CLK_TCK;

}

CTimer::CTimer()

{

wLeft=280;

wTop=220;

sec=0;

min=0;

}

int CTimer::zero_timer()

{

if ((min==0)&&(sec==0))

return 0;

else

return 1;

}

void CTimer::operator<<(char* fname)

{

FILE* timer_ini;

char *time_init;

char s[2];

int i,j;

timer_ini=fopen(fname,"rt");

fscanf(timer_ini,"%s",time_init);

fclose(timer_ini);

min=atoi(time_init);

i=0;j=0;

while(time_init[i]!=':') i++;

i++;

while (i<strlen(time_init)) s[j++]=time_init[i++];

s[j]='\0';

sec=atoi(s);

}

void CTimer::draw()

{

char* time_rest;

if ((min<10)&&(sec<10))

sprintf(time_rest,"0%d:0%.2f",min,sec);

else if(min<10)

sprintf(time_rest,"0%d:%.2f",min,sec);

else if (sec<10)

sprintf(time_rest,"%d:0%.2f",min,sec);

else

sprintf(time_rest,"%d:%.2f",min,sec);

// draw a timer

setfillstyle(SOLID_FILL, BLACK);

bar(wLeft,wTop,wLeft+80,wTop+16);

setfillstyle(SOLID_FILL, BLUE);

setcolor(LIGHTGRAY);

rectangle(wLeft,wTop,wLeft+80,wTop+16);

floodfill(wLeft+1,wTop+1,LIGHTGRAY);

setcolor(WHITE);

outtextxy(wLeft+8,wTop+5,time_rest);

delay(50);

}

int CTimer::start()

{

clock_t start,end,difftime;

difftime=0;

int time=min*60+sec;

start=clock();

while (!kbhit() && (difftime<time*CLK_TCK))

{

end=clock();

difftime=end-start;

min= (time-difftime/CLK_TCK)/60;

sec= (time-difftime/CLK_TCK)-min*60;

if (sec<0)sec=0;

draw();

}

return time;

}

CTimer::~CTimer()

{

}

//////////////////////////////////////////////////////////

//////////////////////////////CMenu///////////////////////

void CMenu::show()

{

cleardevice();

outtextxy(250,200,"1. Calendar");

outtextxy(250,210,"2. Timer");

}

#include "planner.h"

int main()

{

CCalendar* calendar;

CTimer timer;

CMenu Menu;

CFactory factory;

int k=0,key=0;

calendar=(CCalendar*)factory.createobj("calendar");

calendar->initgraph_();

while (k!=27)

{

Menu.show();

k=getch();

switch(k)

{

case 49:

key=1;

calendar->init();

*calendar<<"notes.txt";

while (key!=27)

{

calendar->keystrike(key);

cleardevice();

calendar->draw();

key=getch();

}

*calendar>>"notes.txt";

break;

case 50:

if (timer.zero_timer()==0)

timer<<"timer.ini";

cleardevice();

timer.draw();

timer.start();

getch();

break;

}

}

closegraph();

return 0;

}