C++ 2011.09.17 (미검사)
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
/*
class string
{
char *data;
int len;
public :
void set (char *p)
{
len = strlen(p);
data = new char [len+1];
strcpy(data, p);
}
void print( ) { cout << data << "(" << len << ")" << endl; }
void del( ) { delete data; }
};
void func (string temp)
{
temp.print( ); // korea(5)
temp.del( );
}
void main ( )
{
string ob;
ob.set("korea");
ob.print( ); // korea(5)
func(ob);
ob.print(); // korea(5)
}
*/
/*
class user
{
int num;
char name[12];
public :
void input(int x, char *y)
{
num = x;
strcpy(name, y);
}
void print( )
{
cout << "번호 = " << num << ", 이름 = " << name << endl;
}
};
void main ( )
{
user ob;
ob.input(1, "홍길동");
ob.print( );
cout << "sizeof(ob) = " << sizeof(ob) << endl;
user pb[3]; // 객체 배열
pb[0].input(2, "김두한");
pb[1].input(3, "김연아");
pb[2].input(4, "유재석");
pb[0].print(); pb[1].print(); pb[2].print();
user *cp;
cp = &ob;
(*cp).print(); // 1, 홍길동
cp->print(); // 1, 홍길동
cp = pb;
cp[0].print( ); // 2, 김두한
cp[1].print( ); // 3, 김연아
cp[2].print( ); // 4, 유재석
cp[2] = func( ob, cp );
cp[2].print( ); // 1, 홍길동
}
user func(user temp, user *t)
{
temp.print( ); // 1, 홍길동
t->print( ); // 2, 김두한
return temp;
}
*/
/*
class game
{
private :
int x, y; // x는 사용자가 낸 값 y는 컴퓨터가 낸 값
public :
void user(); // 함수의 원형
void com () { y = rand()%3; }
int bi ();
void start( );
};
void game::user( ) // 멤버함수를 클래스 외부에 정의하는 방법
{
cout << "내세요 (0=가위, 1=바위, 2=보) : ";
cin >> x;
}
int game::bi ()
{
if(x==y)
cout << "비겼습니다." << endl;
else if((x==0&&y==1) || (x==1&&y==2) || (x==2&&y==0))
{
cout << "졌습니다." << endl;
return 0;
}
else
cout << "이겼습니다." << endl;
return 0;
}
void game::start( )
{
srand(time(NULL));
do {
user( );
com( );
}
while( bi( ));
}
void main ( )
{
game ob;
ob.start();
}
*/
/*
class game
{
private :
int x, y; // x는 사용자가 낸 값 y는 컴퓨터가 낸 값
public :
void user()
{
cout << "내세요 (0=가위, 1=바위, 2=보) : ";
cin >> x;
}
void com ()
{
y = rand()%3;
}
int bi ()
{
if(x==y)
cout << "비겼습니다." << endl;
else if((x==0&&y==1) || (x==1&&y==2) || (x==2&&y==0))
{
cout << "졌습니다." << endl;
return 0;
}
else
cout << "이겼습니다." << endl;
return 0;
}
void start ( )
{
srand(time(NULL));
do {
user();
com();
}
while( bi());
}
};
void main ( )
{
game ob;
ob.start();
}
*/
/*
class circle {
private : // 이하 다음 키워드가 나올때 까지 전용멤버가 된다.
int x; // 중심점의 x좌표를 보관할 변수
int y; // 중심점의 y좌표를 보관할 변수
double r; // 원의 반지름 정보를 보관할 변수
public : // 이하 다음 키워드가 나올때 까지 공용멤버가 된다.
double area( ) // 원의 넓이를 구해 리턴하는 함수
{
double nul;
nul = r*r*3.14;
return nul;
}
void setr( ) { r = 1.0; }
};
void main ( )
{
circle ob; // class circle형 객체 ob
// cout << "ob.x = " << ob.x << endl;
// 전용 멤버는 외부에서 접근할 수 없다.
cout << "ob.area( ) = " << ob.area( ) << endl;
ob.setr( );
cout << "ob.area( ) = " << ob.area( ) << endl;
}
*/