U E D R , A S I H C RSS

OOP/2012년스터디 (rev. 1.13)

OOP/2012년스터디

OOP 스터디

  • 객체지향적으로 프로그래밍을 하는 방법에 대해서 공부합니다.
  • 목표 : 객체지향적으로 프로그래밍
  • 시간 : 겨울방학 - 매주 화요일 오후 3시~5시

1월 10일

고한종

#include "turboc.h"
 //from http://devcafe.kr
#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;

int isEvent(int month, int date);
void CalLeafYear(int year);
int CalDay(int year,int month, int date);
int PrintOutMonth(int year,int month,int line);

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("일정추가 (월/일) :");
		scanf("%d %d",&eMonth,&eDate);
		evt[count].M=eMonth;
		evt[count].D=eDate;
		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;
	line++;
	gotoxy(0*CELL,line);	printf("%d - %d",year,month);
	line++;
	gotoxy(0*CELL,line);		printf("일");	gotoxy(1*CELL,line);		printf("월");	gotoxy(2*CELL,line);		printf("화");
	gotoxy(3*CELL,line);		printf("수");	gotoxy(4*CELL,line);		printf("목");	gotoxy(5*CELL,line);		printf("금");
	gotoxy(6*CELL,line);		printf("토");
	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, date)==0){
			printf("%2d",day);
		}else{
			printf("ev");
		}
		if (week==6)	line++;
	}
	return line;
}

void CalLeafYear( int year )
{
	if (year%4==0)
	{
		isLeafYear=true;
		if(year%100==0)
		{
			isLeafYear=false;
			if(year%400==0)
				isLeafYear=true;
		}
	}
}
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 <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;
	}
}

이민규

#include <stdio.h>
//#include "CalLib.h"

int Calculate_Days(int year){
	year--;
	return (year*365)+(year/4)-(year/100)+(year/400);
}

void PrintCal(int 년도,int 시작요일, bool 윤년){
	int 월시작요일= 시작요일;
	for(int 달=1; 달<13; 달++){
		printf("%d년 %d월\n", 년도, 달);
		printf("월\t화\t수\t목\t금\t토\t일\n");
		for(int i=0; i<월시작요일; i++) printf("\t");
		for(int 날짜=1; ; 날짜++){
			printf("%d\t", 날짜);
			if((날짜+월시작요일)%7 ==0) printf("\n");		
			if((달== 1)||(달==3)||(달==5)||(달==7)||(달==8)||(달==10)||(달==12)){
				 if(날짜== 31){
					  printf("\n");
					  월시작요일= (월시작요일+날짜)%7;
					  break;
				 }
			}
			else if(달== 2){
				 if(윤년== true){
					  if(날짜== 29){
							printf("\n");
							월시작요일= (월시작요일+날짜)%7;
							break;
					  }
				 }
				 else
					  if(날짜== 28){
							printf("\n");
							월시작요일= (월시작요일+날짜)%7;
							break;
					  }
			}
			else
				 if(날짜== 30){
							printf("\n");
							월시작요일= (월시작요일+날짜)%7;
							break;
					  }
		}
	}
}


void main(){
	int 년도;
	bool 윤년= false;
	scanf("%d", &년도);
	int 지난날수= Calculate_Days(년도);

	int 시작요일=지난날수%7;
	if((년도%4== 0)&& (년도%100!= 0))
		윤년= true;

	PrintCal(년도, 시작요일, 윤년);
}

김수경

#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));
}

후기 & thread

  • gotoxy galagy 비슷하게 생겻다.
  • 코드를 살짝 급하게 짠건지 디버깅을 한참 했네요. 하지만 연산량은 적을 것이라 생각합니다. -ㅅ- -김태진

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:53
Processing time 0.0728 sec