[[TableOfContents]] = OOP 스터디 = * 객체지향적으로 프로그래밍을 하는 방법에 대해서 공부합니다. * 목표 : 객체지향적으로 프로그래밍 * 시간 : 겨울방학 - 매주 화요일 오후 3시~5시 * 참고할만한 위키 페이지 : [More EffectiveC++/Efficiency] == 1월 10일 == === 고한종 === {{{ #include #include #define CELL 3 struct MD { int M; int D; }; int mCode[15]={0,6,2,2,5,0,3,5,1,4,6,2,4,5,1}; int mEnd[13]={29,31,28,31,30,31,30,31,30,30,31,30,31}; MD evt[366]; bool isLeafYear; void CalLeafYear(int year); int CalDay(int year,int month, int date); int PrintOutMonth(int year,int month,int line); int isEvent(int month, int date); int main() { int year; int i; int nLine=0; int eMonth,eDate; int count=0; printf("Year : "); scanf("%d",&year); CalLeafYear(year); while(1) { for(i=1;i<=12;i++) { nLine=PrintOutMonth(year,i,nLine); nLine++; } printf("\n일정추가 (월/일) :"); scanf("%d %d",&eMonth,&eDate); evt[count].M=eMonth; evt[count].D=eDate; count++; system("cls"); nLine=0; }} int CalDay(int year,int month,int date=1) { int yCode; int result; yCode=(year%100); yCode+=yCode/4; yCode-=(yCode/7)*7; if((month==1 || month==2) && isLeafYear==true) month+=12; result=yCode+mCode[month]+date; result-=(result/7)*7; return result%7; } int PrintOutMonth( int year, int month, int line) { int day; int eDay; int week; static char *han[7]={ "일","월","화","수","목","금","토" }; line++; gotoxy(0*CELL,line); printf("%d - %d",year,month); line++; for (int i = 0; i < 7 ; i++) { gotoxy(i*CELL,line); printf("%s",han[i]); } line++; if(isLeafYear==true&&month==2) eDay=mEnd[0]; else eDay=mEnd[month]; for (day=1;day<=eDay;day++) { week=CalDay(year,month,day); gotoxy(week*CELL,line); if(isEvent(month, day)==0) { if(week==0){ SetColor(RED,BLACK); } if (week==6) { SetColor(BLUE,BLACK); } printf("%2d",day); SetColor(WHITE,BLACK); }else{ SetColor(GREEN,BLACK); printf("ev"); SetColor(WHITE,BLACK); } if (week==6) line++; } return line; } void CalLeafYear( int year ) { isLeafYear =(year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0)); } int isEvent(int month, int date) { int i; int result=0; for(i=0;i<366;i++) { if(evt[i].M==month && evt[i].D==date) { result=true; break; } } return result; } }}} === 김태진 === {{{ // // main.cpp // Calender // // Created by 김 태진 on 12. 1. 10.. // Copyright (c) 2012년 __MyCompanyName__. All rights reserved. // #include int isLeapYr(int yr); int isThirtyOne(int mth); int main() { int month,day=1,myYear,date=1,monthEndDate; int i; int Max; scanf("%d",&myYear); for(i=1;i //#include "CalLib.h" class ScheduleNode{ int Month; int Date; ScheduleNode* NextNode; public: ScheduleNode(int Month, int Date){ this->Month= Month; this->Date= Date; NextNode= NULL; } void SetNextNode(ScheduleNode* NextNode){ this->NextNode= NextNode; } ScheduleNode* GetNextNode(){ return NextNode; } void GetSchedule(int* Month, int* Date){ (*Month)= this->Month; (*Date)= this->Date; } void SetSchedule(int Month, int Date){ this->Month= Month; this->Date= Date; } }; int Calculate_Days(int year){ year--; return (year*365)+(year/4)-(year/100)+(year/400); } void PrintMonth(int Month, bool LeapYear, int* MonthStartDay){ } void PrintCal(ScheduleNode* ScheduleHead){ int year; printf("Set Year:"); scanf("%d", &year); bool LeapYear= false; int LastDays= Calculate_Days(year); int StartDay=LastDays%7; if((year%4== 0)&& (year%100!= 0)) LeapYear= true; int MonthStartDay= StartDay; ScheduleNode* ScheduleTale= ScheduleHead; int sMonth, sDate; ScheduleTale->GetSchedule(&sMonth, &sDate); for(int month=1; month<13; month++){ printf("%d년 %d월\n", year, month); printf("월\t화\t수\t목\t금\t토\t일\n"); for(int i=0; iGetNextNode()!= NULL){ ScheduleTale= ScheduleTale->GetNextNode(); ScheduleTale->GetSchedule(&sMonth, &sDate); } } else printf("%d\t", date); if((date+MonthStartDay)%7 ==0) printf("\n"); if((month== 1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12)){ if(date== 31) break; } else if(month== 2){ if(LeapYear== true){ if(date== 29) break; } else if(date== 28) break; } else if(date== 30) break; } MonthStartDay= (MonthStartDay+date)%7; printf("\n"); } } void SetSchedule(ScheduleNode** ScheduleHead){ int sMonth, sDate; ScheduleNode* ScheduleTale= *ScheduleHead; printf("Set Schedule:"); scanf("%d%d", &sMonth, &sDate); if(*ScheduleHead== NULL){ *ScheduleHead= new ScheduleNode(sMonth, sDate); } else{ while(ScheduleTale->GetNextNode()!= NULL){ ScheduleTale= ScheduleTale->GetNextNode(); } ScheduleTale->SetNextNode(new ScheduleNode(sMonth, sDate)); } } void SortSchedule(ScheduleNode* ScheduleHead){ if(ScheduleHead== NULL) return; int NumSchedule=1; int aMonth=0, aDate=0, bMonth=0, bDate=0; ScheduleNode* ScheduleTale= ScheduleHead; while(ScheduleTale->GetNextNode()!= NULL){ NumSchedule++; ScheduleTale= ScheduleTale->GetNextNode(); } for(int i=0; iGetNextNode()!= NULL){ ScheduleTale->GetSchedule(&bMonth, &bDate); ScheduleTale->GetNextNode()->GetSchedule(&aMonth, &aDate); if((bMonth> aMonth)||((bMonth== aMonth)&&(bDate> aDate))){ ScheduleTale->SetSchedule(aMonth, aDate); ScheduleTale->GetNextNode()->SetSchedule(bMonth, bDate); } ScheduleTale= ScheduleTale->GetNextNode(); } } } int main(){ ScheduleNode* ScheduleHead= NULL; int select; while(1){ puts("-----------------Menu-----------------"); puts("1. Set Schedule"); puts("2. Print Calander"); puts("else. Exit"); scanf("%d", &select); switch(select){ case 1: SetSchedule(&ScheduleHead); break; case 2: SortSchedule(ScheduleHead); PrintCal(ScheduleHead); break; default: return 0; } } } }}} === 김수경 === {{{ #include using namespace std; void printYear(int year); void printHeader(int year, int month); void printMonth(int year, int month); int accumulatedDays(int year, int month); int numberOfDays(int year, int month); int isLeapYear(int year); int main(){ int year; cin>>year; printYear(year); return 0; } void printYear(int year){ for(int i = 1; i <= 12; i++){ printHeader(year, i); printMonth(year, i); } } void printHeader(int year, int month){ cout<= 1){ sum = (year-1) * 365; for(int i = 1; i < year; i++){ sum += isLeapYear(i); } for(int i = 1; i < month; i++){ sum += numberOfDays(year, i); } } return sum; } int numberOfDays(int year, int month){ switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return 28 + isLeapYear(year); } } int isLeapYear(int year){ return (year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0)); } }}} === 후기 & thread === * gotoxy galagy 비슷하게 생겻다. * 코드를 살짝 급하게 짠건지 디버깅을 한참 했네요. 하지만 연산량은 적을 것이라 생각합니다. -ㅅ- -[김태진] == 1월 31일 == 특강 === 후기 & thread === ---- [OOP], [2012년활동지도]