U E D R , A S I H C RSS

OOP/2012년스터디

Difference between r1.8 and the current

@@ -1,44 +1,59 @@
[[TableOfContents]]
= OOP 스터디 =
* 객체지향적으로 프로그래밍을 하는 방법에 대해서 공부합니다.
* 목표 : 객체지향적으로 프로그래밍
* 시간 : 겨울방학 - 매주 화요일 오후 3시~5시
* 참고할만한 위키 페이지 : [More EffectiveC++/Efficiency]
== 1월 10일 ==
=== 고한종 ===
* 일단 오늘 짜본건 똥 코드가 나왔습니다.
simple is the best 라고 했는데 너무 어렵게 돌아갔어요.
* 테트리스 만들때 문자를 찍기 위해 gotoxy를 쓰던걸 활용 하고 싶어서 해보다가 망함..
* 좌표를 정해놓고 한글자씩 찍는것으로 바꾸면 좀더 나을지도
* 윤년이 문제야ㅡㅡ..
* 난 삽질을 살려 냈도다.
{{{
#include <turboc.h>
#include <math.h>

#define CELL 3

/*#define gotoxy_c(x,y) gotoxy(wherex()+x,wherey()+y)*/
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;

struct PT
{
int x;
int y;
};
void CalLeafYear(int year);
int CalDay(int year,int month, int date);
void PrintOutMonth(int year,int month);
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);

PrintOutMonth(year,1);
}
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;
@@ -47,60 +62,75 @@
yCode=(year%100);
yCode+=yCode/4;
yCode-=(yCode/7)*7;
if (year%4==0)
{
isLeafYear=true;
if(year%100==0)
{
isLeafYear=false;
if(year%400==0)
isLeafYear=true;
}
}
if((month==1 || month==2) && isLeafYear==true) month+=12;
result=yCode+mCode[month]+date;
result-=(result/7)*7;
return result%7;
}

void PrintOutMonth( int year, int month )
int PrintOutMonth( int year, int month, int line)
{
int line=2;
int day;
int eDay;
int week;
gotoxy(0*CELL,0); printf("%d - %d",year,month);
gotoxy(0*CELL,1); printf("일"); gotoxy(1*CELL,1); printf("월"); gotoxy(2*CELL,1); printf("화");
gotoxy(3*CELL,1); printf(""); gotoxy(4*CELL,1); printf("목"); gotoxy(5*CELL,1); printf("금");
gotoxy(6*CELL,1); printf("토");
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);
printf("%2d",day);
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 )
{
if (year%4==0)
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++)
{
isLeafYear=true;
if(year%100==0)
if(evt[i].M==month && evt[i].D==date)
{
isLeafYear=false;
if(year%400==0)
isLeafYear=true;
result=true;
break;
}
}
return result;
}
}}}
* 년도를 입력하면 그 해의 1월 달력이 나옵니다. 입력부분만 바꾸면 전부 출력 할 수 잇으요
=== 김태진 ===
{{{
//
@@ -123,13 +153,7 @@
int Max;

scanf("%d",&myYear);
if(isLeapYr(myYear)==1){
Max=366;
}else{
Max=365;
}
for(i=1;i<myYear;i++){
if(isLeapYr(i-1)==1&&i!=1){
day+=2;
@@ -202,64 +226,156 @@
#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 PrintCal(int 년도,int 시작요일, bool 윤년){
int 월시작요일= 시작요일;
for(int =1; <13; ++){
printf("%d년 %d월\n", 년도, );
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<월시작요일; 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;
}
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 if(달== 2){
if(윤년== true){
if(날짜== 29){
printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}
}
else 
if(날짜== 28){
printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}
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(날짜== 30){
printf("\n");
월시작요일= (월시작요일+날짜)%7;
break; 
}
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 main(){
int 년도;
bool 윤년= false;
scanf("%d", &년도);
int 지난날수= Calculate_Days(년도);
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 시작요일=지난날수%7;
if((년도%4== 0)&& (년도%100!= 0))
윤년= true;
int main(){
ScheduleNode* ScheduleHead= NULL;
int select;
while(1){
puts("-----------------Menu-----------------");
puts("1. Set Schedule");
puts("2. Print Calander");
puts("else. Exit");

PrintCal(년도, 시작요일, 윤년);
scanf("%d", &select);
switch(select){
case 1:
SetSchedule(&ScheduleHead); 
break;
case 2:
SortSchedule(ScheduleHead);
PrintCal(ScheduleHead);
break;
default:
return 0;
}
}
}
}}}
=== 김수경 ===
@@ -348,5 +464,8 @@
=== 후기 & thread ===
* gotoxy galagy 비슷하게 생겻다.
* 코드를 살짝 급하게 짠건지 디버깅을 한참 했네요. 하지만 연산량은 적을 것이라 생각합니다. -ㅅ- -[김태진]
== 1월 31일 ==
특강
=== 후기 & thread ===
----
[OOP], [2012년활동지도]



1. OOP 스터디

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

1.1. 1월 10일

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

1.1.5. 후기 & thread

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

1.2. 1월 31일

특강

1.2.1. 후기 & thread

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