느낀 및 명 ¶
뭔가 미 보 만들기 다.
C++라 그런.. 내가그런는 몰라 게 래로만 면 C로 는 것 보다 더 리는듯..
만 미다!!^^*
미 뚝 리다 보.. 미 람 길... 러렸..
그렇만 까 고고, 고, 낭럽만 메모리 관리 및 가 망다.ㅎ
.. 그래 미 뭐..ㅎㅎ
( 명 뮬 량 무대고 객 내리 더라 객 고, 는데 린다는 것만로 가 몰려다는 것로 명되 나.. 미~ 는 고로 량 .. 그리고면 내리는게 .ㅎ)
노라던가.. 길과 길 린다나.. 를 복다나.. 는것 보고 만, 보류!
력부 대부 로 만들 데.. 단 로 그대로 기로 다. 나 가기 록 겠다.
들떠 다 고나 명 되는것 깨닫고 급 .. 그런데 느 그 를 변경 물 머고 다다.ㅠ.ㅜ
C++라 그런.. 내가그런는 몰라 게 래로만 면 C로 는 것 보다 더 리는듯..
만 미다!!^^*
미 뚝 리다 보.. 미 람 길... 러렸..
그렇만 까 고고, 고, 낭럽만 메모리 관리 및 가 망다.ㅎ
.. 그래 미 뭐..ㅎㅎ
( 명 뮬 량 무대고 객 내리 더라 객 고, 는데 린다는 것만로 가 몰려다는 것로 명되 나.. 미~ 는 고로 량 .. 그리고면 내리는게 .ㅎ)
노라던가.. 길과 길 린다나.. 를 복다나.. 는것 보고 만, 보류!
력부 대부 로 만들 데.. 단 로 그대로 기로 다. 나 가기 록 겠다.
들떠 다 고나 명 되는것 깨닫고 급 .. 그런데 느 그 를 변경 물 머고 다다.ㅠ.ㅜ
는 동 격로 되게 되며, 객 랜덤로 된다.( 객 되는 만들때 다. )
관로 객 목는 객 된 곳(랜덤)로 다.
또 런 문로 막 객 만들(!) 다.
가 (만들때 며 는 80로 다.)로 는데 모된다. ( 량 나, 들가게되 동리를 다 가 못더라 동게 모된다.)
객 1 고, 객1 내리는데 1 모된다. (둘 가 과만 루 더라 동게 1 모된다.)
러 규 기본로 뮬 고 다.
관로 객 목는 객 된 곳(랜덤)로 다.
또 런 문로 막 객 만들(!) 다.
가 (만들때 며 는 80로 다.)로 는데 모된다. ( 량 나, 들가게되 동리를 다 가 못더라 동게 모된다.)
객 1 고, 객1 내리는데 1 모된다. (둘 가 과만 루 더라 동게 1 모된다.)
러 규 기본로 뮬 고 다.
(당 날렸던 격 라 많 명 만 리라 믿는다.^^)
- 물런 미가 긴 겠만 명 가 로 고 량 무며, 객 내리 더라 객 고 객 는데 만 린다면 몰림 발다. (고로 명기 를 많 가 다. 미가 겠만..ㅎ)
- 물런 미가 긴 겠만 명 가 로 고 량 무며, 객 내리 더라 객 고 객 는데 만 린다면 몰림 발다. (고로 명기 를 많 가 다. 미가 겠만..ㅎ)
메모리 낭를 로롬 답다.^^*
많 대 늘난 듯 만.. 본 메모리 낭 ..;;; 다 보..ㅎ
메모리 관리는 무 들..ㅠ.ㅜ 발견되 던 문 그것 다.
못된 메모리 근류..ㅠ.ㅜ 기 들다는.ㅎ
많 대 늘난 듯 만.. 본 메모리 낭 ..;;; 다 보..ㅎ
메모리 관리는 무 들..ㅠ.ㅜ 발견되 던 문 그것 다.
못된 메모리 근류..ㅠ.ㅜ 기 들다는.ㅎ
main.cpp ¶
~cpp
#include "bus_and_man.h"
#include <iostream>
using namespace std;
void Set_memory();
void Call_act();
road *cau_road;
void main()
{
cout << " 기 다.\n";
Set_memory();
Call_act();
}
void Set_memory()
{
cau_road=new road(3000);
cau_road->Build("문",5,0,5);
cau_road->Build("issac",10,700,5);
cau_road->Build("",3,1000,5);
cau_road->Build("문",10,1320,5);
cau_road->Build("곰두리",10,1700,5);
cau_road->Build("공대물",2,2100,5);
cau_road->Build("",30,2750,5);
cau_road->Build("문",10,2999,5);
}
void Call_act()
{
for (register int i=1; i<20; ++i)
{
for (register int j=0; j<5; ++j)
{
cau_road->Act();
cout << "\n";
system("PAUSE");
cout << "\n";
}
cau_road->Start_car(i,20,0,80);
}
delete cau_road;
}
bus_and_man.cpp ¶
~cpp
// .
//객
//는
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include "bus_and_man.h"
using namespace std;
const int MOVE=1;
const int STOP=0;
man::man(int input_from, int input_to)
{
from=input_from;
to=input_to;
}
man::~man()
{
}
int man::where_go()
{
return to;
}
station::station(int input_station_number, char *input_name, int input_percent, int input_size )
{
strcpy(name,input_name);
percent=input_percent;
station_size=input_size;
number_man=0;
station_number=input_station_number;
humans=new man*[station_size];
for (register int i=0; i<station_size; ++i)
humans[i]=0;
cout << name << " 되다.\n";
}
station::~station()
{
for (register int i=0; i<station_size; ++i)
{
if (0!=humans[i])
delete humans[i];
}
delete humans;
cout << name << " 괴되다.\n";
}
void station::make_people(int numbers_station)
{
if (station_size!=number_man && numbers_station!=station_number+1)
{
if (0==rand()%percent)
{
humans[number_man]=new man(station_number,station_number+rand()%(numbers_station-station_number-1)+1);
++number_man;
cout << name << " 람 명 되다.\n";
}
}
}
man* station::out_people()
{
if (0==number_man)
return 0;
man *temp_man=humans[0];
humans[0]=0;
for (register int i=1; i<number_man; ++i)
{
humans[i-1]=humans[i];
humans[i]=0;
}
--number_man;
return temp_man;
}
int station::where_here()
{
return station_number;
}
void station::act(int numbers_station)
{
make_people(numbers_station);
}
void bus::move(road *in_road)
{
int in_station=0;
int temp_where=where;
temp_where=in_road->car_move(&in_station, speed, where);
if (1==in_station)
state=STOP;
if (-1==temp_where)
in_road->car_stop(where);
else
{
where=temp_where;
cout << number << " 가 " << where << "로 동다.\n";
}
}
void bus::stop(station *in_station, road* in_road)
{
man*in_people=in_station->out_people();
if (0!=in_people)
{
humans[number_man]=in_people;
++number_man;
cout << number << " 가 객 다.\n";
}
int suched=0;
for (register int i=0; i<number_man; ++i)
{
if (in_station->where_here()==humans[i]->where_go())
{
delete humans[i];
humans[i]=0;
for (register int j=i+1; j<number_man; ++j)
{
humans[j-1]=humans[j];
humans[j]=0;
}
--number_man;
suched=1;
cout << number << " 가 객 다.\n";
}
}
if (0==suched && 0==in_people)
{
state=MOVE;
move(in_road);
}
}
bus::bus(int input_number, int input_size, int input_where, int input_speed)
{
number=input_number;
bus_size=input_size;
humans=new man*[bus_size];
state=STOP;
where=input_where;
number_man=0;
speed=input_speed;
for (register int i=0; i<bus_size; ++i)
humans[i]=0;
cout << number << "가 되다.\n";
}
bus::~bus()
{
for (register int i=0; i<bus_size; ++i)
{
if (0!=humans[i])
delete humans[i];
}
delete humans;
cout << number << "가 괴되다.\n";
}
void bus::act(station* in_station, road* in_road)
{
if (STOP==state)
stop(in_station, in_road);
else
move(in_road);
}
road::road (int input_long)
{
srand(time(NULL));
road_long=input_long;
number_station=0;
cars=new bus*[road_long];
buildings=new station*[road_long];
for (register int i=0; i<road_long; ++i)
{
cars[i]=0;
buildings[i]=0;
}
cout << "로1개가 되다.\n";
}
road::~road()
{
for (register int i=0; i<road_long; ++i)
{
if (0!=buildings[i])
delete buildings[i];
if (0!=cars[i])
delete cars[i];
}
delete cars;
delete buildings;
cout << "로1개가 괴되다.\n";
}
int road::Build(char *input_name, int input_percent, int where, int input_size)
{
if (0!=buildings[where])
{
cout << " 는데 다.\n";
return -1;
}
buildings[where]=new station(number_station,input_name,input_percent,input_size);
++number_station;
return 0;
}
int road::Start_car(int input_number, int input_size, int input_where, int input_speed)
{
if (0!=cars[input_where])
{
cout << "를 는데 다.\n";
return -1;
}
cars[input_where]=new bus(input_number,input_size,input_where, input_speed);
return 0;
}
void road::Act()
{
for (register int i=road_long-1; i>=0; --i)
{
if (0!=buildings[i])
buildings[i]->act(number_station);
if (0!=cars[i])
cars[i]->act(buildings[i],this);
}
}
int road::car_move(int *state, int speed, int where)
{
register int i;
for (i=where+1; i<=where+speed; ++i)
{
if (i>=road_long)
return -1;
if (0!=cars[i])
break;
if (0!=buildings[i])
{
*state=1;
++i;
break;
}
}
if (i-1!=where)
{
cars[i-1]=cars[where];
cars[where]=0;
}
return i-1;
}
void road::car_stop(int where)
{
delete cars[where];
cars[where]=0;
}
bus_and_man.h ¶
~cpp
class man;
class station;
class bus;
class road;
class man{
private:
int from;
int to;
public:
man(int input_from, int input_to);
~man();
int where_go();
};
class station{
private:
char name[256];
int station_number;
int percent;
int station_size;
int number_man;
man **humans;
void make_people(int);
public:
station(int, char*, int, int);
~station();
man* out_people();
int where_here();
void act(int);
};
class bus{
private:
int number;
int bus_size;
int state;
int where;
man **humans;
int number_man;
int speed;
void move(road*);
void stop(station*, road*);
public:
bus(int , int , int , int );
~bus();
void act(station* , road* );
};
class road{
private:
int road_long;
int number_station;
bus **cars;
station **buildings;
public:
road (int );
~road();
int Build(char*, int , int, int );
int Start_car(int , int , int , int );
void Act();
int car_move(int*, int , int );
void car_stop(int);
};
1 ¶
main.cpp ¶
~cpp
#include "bus_and_man.h"
#include <iostream>
using namespace std;
void Set_memory();
void Call_act();
road *cau_road;
void main()
{
cout << " 기 다.\n";
Set_memory();
Call_act();
}
void Set_memory()
{
cau_road=new road(3000);
cau_road->Build("문",5,0,5);
cau_road->Build("issac",10,700,5);
cau_road->Build("",3,1000,5);
cau_road->Build("문",10,1320,5);
cau_road->Build("곰두리",10,1700,5);
cau_road->Build("공대물",2,2100,5);
cau_road->Build("",30,2750,5);
cau_road->Build("문",10,2999,5);
}
void Call_act()
{
for (register int i=1; i<20; ++i)
{
for (register int j=0; j<5; ++j)
{
cau_road->Act();
cout << "\n";
system("PAUSE");
cout << "\n";
}
cau_road->Start_car(i,20,0,80);
}
delete cau_road;
}
bus_and_man.cpp ¶
~cpp
// .
//객
//는
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include "bus_and_man.h"
using namespace std;
const int MOVE=1;
const int STOP=0;
man::man(int input_from, int input_to)
{
from=input_from;
to=input_to;
}
man::~man()
{
}
int man::where_go()
{
return to;
}
station::station(int input_station_number, char *input_name, int input_percent, int input_size, int input_where)
{
strcpy(name,input_name);
percent=input_percent;
station_size=input_size;
number_man=0;
station_number=input_station_number;
where=input_where;
humans=new man*[station_size];
for (register int i=0; i<station_size; ++i)
humans[i]=0;
cout << name << " 되다.\n";
}
station::~station()
{
for (register int i=0; i<station_size; ++i)
{
if (0!=humans[i])
delete humans[i];
}
delete humans;
cout << name << " 괴되다.\n";
}
void station::make_people(int numbers_station)
{
if (station_size!=number_man && numbers_station!=station_number+1)
{
if (0==rand()%percent)
{
humans[number_man]=new man(station_number,station_number+rand()%(numbers_station-station_number-1)+1);
++number_man;
cout << name << " 람 명 되다.\n";
}
}
}
man* station::out_people()
{
if (0==number_man)
return 0;
man *temp_man=humans[0];
humans[0]=0;
for (register int i=1; i<number_man; ++i)
{
humans[i-1]=humans[i];
humans[i]=0;
}
--number_man;
return temp_man;
}
int station::where_here()
{
return station_number;
}
void station::act(int numbers_station)
{
make_people(numbers_station);
}
int station::where_am_i()
{
return where;
}
void bus::move(road *in_road)
{
int in_station=0;
int temp_where=where;
temp_where=in_road->car_move(&in_station, speed, where);
if (1==in_station)
state=STOP;
if (-1==temp_where)
in_road->car_stop(number);
else
{
where=temp_where;
cout << number << " 가 " << where << "로 동다.\n";
}
}
void bus::stop(station *in_station, road* in_road)
{
man*in_people=0;
if (number_man<bus_size)
{
in_people=in_station->out_people();
if (0!=in_people)
{
humans[number_man]=in_people;
++number_man;
cout << number << " 가 객 다.\n";
}
}
int suched=0;
for (register int i=0; i<number_man; ++i)
{
if (in_station->where_here()==humans[i]->where_go())
{
delete humans[i];
humans[i]=0;
for (register int j=i+1; j<number_man; ++j)
{
humans[j-1]=humans[j];
humans[j]=0;
}
--number_man;
suched=1;
cout << number << " 가 객 다. (객 : " << number_man << " ) \n";
break;
}
}
if (0==suched && 0==in_people)
{
state=MOVE;
move(in_road);
}
}
bus::bus(int input_number, int input_size, int input_where, int input_speed)
{
number=input_number;
bus_size=input_size;
humans=new man*[bus_size];
state=STOP;
where=input_where;
number_man=0;
speed=input_speed;
for (register int i=0; i<bus_size; ++i)
humans[i]=0;
cout << number << "가 되다.\n";
}
bus::~bus()
{
for (register int i=0; i<bus_size; ++i)
{
if (0!=humans[i])
delete humans[i];
}
delete humans;
cout << number << "가 괴되다.\n";
}
void bus::act(station* in_station, road* in_road)
{
if (STOP==state)
stop(in_station, in_road);
else
move(in_road);
}
int bus::where_am_i()
{
return where;
}
int bus::what_number()
{
return number;
}
road::road (int input_long)
{
srand(time(NULL));
road_long=input_long;
number_station=0;
number_bus=0;
cars=NULL;
buildings=NULL;
cout << "로1개가 되다.\n";
}
road::~road()
{
for (register int i=0; i<number_bus; ++i)
delete cars[i];
for (register int i=0; i<number_station; ++i)
delete buildings[i];
if (cars!=NULL)
delete cars;
if (buildings!=NULL)
delete buildings;
cout << "로1개가 괴되다.\n";
}
int road::Build(char *input_name, int input_percent, int where, int input_size)
{
if (0!=number_station)
{
for (register int i=0; i<number_station; ++i)
{
if (buildings[i]->where_am_i()==where)
{
cout << " 는데 다.\n";
return -1;
}
}
station** temp=new station*[number_station+1];
for (register int i=0; i<number_station; ++i)
{
temp[i]=buildings[i];
}
delete buildings;
buildings=temp;
buildings[i]=new station(number_station,input_name,input_percent,input_size,where);
}
else
{
buildings=new station*;
buildings[0]=new station(number_station,input_name,input_percent,input_size,where);
}
++number_station;
return 0;
}
int road::Start_car( int input_number, int input_size, int input_where, int input_speed)
{
if (0!=number_bus)
{
for (register int i=0; i<number_bus; ++i)
{
if (cars[i]->where_am_i()==input_where)
{
cout << "를 는데 다.\n";
return -1;
}
}
bus** temp=new bus*[number_bus+1];
for (register int i=0; i<number_bus; ++i)
{
temp[i]=cars[i];
}
delete cars;
cars=temp;
cars[number_bus]=new bus(input_number,input_size,input_where, input_speed);
}
else
{
cars=new bus*;
cars[0]=new bus(input_number,input_size,input_where, input_speed);
}
++number_bus;
return 0;
}
void road::Act()
{
for (register int i=0; i<number_station; ++i)
buildings[i]->act(number_station);
for (register int i=0; i<number_bus; ++i)
{
for (register int j=0; j<number_station; ++j)
{
if (buildings[j]->where_am_i()==cars[i]->where_am_i())
{
cars[i]->act(buildings[j],this);
break;
}
}
if (j==number_station)
cars[i]->act(0,this);
}
}
int road::car_move(int *state, int speed, int where)
{
int temp_where=where+speed;
for (register int i=0; i<number_station; ++i)
{
if (where<buildings[i]->where_am_i() && temp_where>=buildings[i]->where_am_i())
{
temp_where=buildings[i]->where_am_i();
*state=1;
}
}
for (register int i=0; i<number_bus; ++i)
{
if (where<cars[i]->where_am_i() && temp_where>=cars[i]->where_am_i())
{
temp_where=cars[i]->where_am_i();
*state=0;
}
}
if (temp_where>=road_long)
return -1;
if (*state==0)
return temp_where-1;
else
return temp_where;
}
void road::car_stop(int number)
{
bus** temp=new bus*[number_bus-1];
int swit=0;
for (register int i=0; i<number_bus; ++i)
{
if (0==swit)
{
if (cars[i]->what_number()==number)
{
delete cars[i];
swit=1;
}
else
temp[i]=cars[i];
}
else
temp[i-1]=cars[i];
}
delete cars;
cars=temp;
--number_bus;
}
bus_and_man.h ¶
~cpp
class man;
class station;
class bus;
class road;
class man{
private:
int from;
int to;
public:
man(int input_from, int input_to);
~man();
int where_go();
};
class station{
private:
char name[256];
int station_number;
int percent;
int station_size;
int number_man;
int where;
man **humans;
void make_people(int);
public:
station(int, char*, int, int, int);
~station();
man* out_people();
int where_here();
void act(int);
int where_am_i();
};
class bus{
private:
int number;
int bus_size;
int state;
int where;
man **humans;
int number_man;
int speed;
void move(road*);
void stop(station*, road*);
public:
bus(int , int , int , int );
~bus();
void act(station* , road* );
int where_am_i();
int what_number();
};
class road{
private:
int road_long;
int number_station;
int number_bus;
bus **cars;
station **buildings;
public:
road (int );
~road();
int Build(char*, int , int, int );
int Start_car( int, int , int , int );
void Act();
int car_move(int*, int , int );
void car_stop(int);
};










