1. OOP 스터디 ¶
- 객체지향적으로 프로그래밍을 하는 방법에 대해서 공부합니다.
- 목표 : 객체지향적으로 프로그래밍
- 시간 : 겨울방학 - 매주 화요일 오후 3시~5시
- 참고할만한 위키 페이지 : More EffectiveC++/Efficiency
- 참고할만한 위키 페이지 : More EffectiveC++/Efficiency
1.1.1. 고한종 ¶
#include <turboc.h> #include <math.h> #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; }
1.1.2. 김태진 ¶
// // main.cpp // Calender // // Created by 김 태진 on 12. 1. 10.. // Copyright (c) 2012년 __MyCompanyName__. All rights reserved. // #include <stdio.h> 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<myYear;i++){ if(isLeapYr(i-1)==1&&i!=1){ day+=2; }else{ day++; } //day 0 == 일 } day%=7; for(month=1;month<=12;month++){ date=1; if(isThirtyOne(month)==1){ monthEndDate=31; }else{ monthEndDate=30; if(month==2){ monthEndDate=28; if(isLeapYr(myYear)==1){ monthEndDate=29; } } } printf("\n%d월\n",month);//몇월 printf("일\t월\t화\t수\t목\t금\t토\n"); for(i=0;i<day;i++){ printf("\t"); } for(;date<=monthEndDate;date++){ printf("%d\t",date); if(i%7==6){ printf("\n"); } i++; } day=i%7; } return 0; } int isLeapYr(int yr){ int flag=0; if(yr%4==0){ flag=1;//1이면 윤년 if(yr%100==0){ flag=0; if(yr%400==0){ flag=1; } } } return flag; } int isThirtyOne(int mth){ if(mth==1||mth==3||mth==5||mth==7||mth==8||mth==10||mth==12){ return 1; }else{ return 0; } }
1.1.3. 이민규 ¶
#include <stdio.h> //#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; i<MonthStartDay; i++) printf("\t"); int date; for(date=1; ; date++){ if(month== sMonth&& date== sDate){ printf("O\t"); if(ScheduleTale->GetNextNode()!= 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; i<NumSchedule; i++){ ScheduleTale= ScheduleHead; while(ScheduleTale->GetNextNode()!= 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; } } }
1.1.4. 김수경 ¶
#include <iostream> 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<<endl; cout<<"\t\t\t"<<year<<"년 "<<month<<"월"<<endl<<endl; cout<<"월\t화\t수\t목\t금\t토\t일"<<endl; } void printMonth(int year, int month){ int startDay = accumulatedDays(year, month) % 7; for(int i = 1; i <= startDay; i++){ cout<<"\t"; } for(int i = 1; i <= numberOfDays(year, month); i++){ cout<<i<<"\t"; if((i + startDay) % 7 == 0){ cout<<endl; } } cout<<endl; } int accumulatedDays(int year, int month){ int sum = 0; if(year >= 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)); }