bài giảng ký thuật lập trình các cấu trúc dữ liệu cơ bản đại học bách khoa hà nội - Pdf 23

1
Case Study: Mô phỏng sân bay
Nhậndạng các lớp
•Lớp Plane, các phương thức?
–Khởitạo
–Hạ cánh
–Cất cánh
•LớpRunway:
–Chứa thành phầnthể hiện hàng đợi củacác
máy bay đang đợicất cánh hoặchạ cánh.
•Lớp Random:
–trạng thái ngẫu nhiên củaviệccất cánh và hạ
cánh củamáybay
Cài đặt
const int END_TIME = 30; // time to run simulation
const int QUEUE_LIMIT = 60; // size of Runway
queues
const double ARRIVAL_RATE = 0.5, DEPARTURE_RATE =
0.5;
int main( ) // Airport simulation program
/* Pre: The user must supply the number of time intervals the
simulation is to run, the expected number of planes arriving,
the expected number of planes departing per time interval,
and the maximum allowed size for runway queues.
Post: The program performs a random simulation of the airport,
showing the status of the runway at each time interval, and
prints out a summary of airport operation at the conclusion.
Uses: Classes Runway, Plane, Random and functions run_idle,
initialize
.
*

23. current_plane.refuse( );
24. }
25. Plane moving_plane;
26. switch (small_airport.activity(current_time, moving_plane)) {
27. // Let at most one Plane onto the Runway at current_time.
28. case land:
29. moving_plane.land(current_time);
30. break;
31. case takeoff:
32. moving_plane.fly(current_time);
33. break;
34. case idle:
35. run_idle(current_time);
36
}
// end of switch
Class Runway
•Cầnquản lý hai hàng đợi
–Cất cánh và hạ cánh
• Ưu tiên máy bay đợihạ cánh
•Yêucầuthống kê:
–Số máy bay đượcxử lý
–Thờigianđợi trung bình
–Số máy bay bị từ chối
2
1. enum Runway_activity {idle, land, takeoff};
2. class Runway {
3. public:
4. Runway(int limit);
5. Error_code can_land(const Plane &current);

6. void refuse( ) const;
7. void land(int time) const;
8. void fly(int time) const;
9. int started( ) const;
10.private:
11. int flt_num;
12. int clock_start;
13. Plane_status state;
14.};


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status