一个简单的算法!大家共同分享!

xiemengjun 2004-03-13 08:58:07
一个简单的算法!大家共同分享!谁会啊!
Project 1: Simulating a Print Queue
objective
The objectives of this project are 1) to practice coding in C++, 2) to practice using the documentation and naming standards for the course, 3) to review pointer manipulations and linked lists, and 4) to write a program using an object-orientated approach.

Background
In this project you will simulate adding jobs to a print queue and dispatching the jobs to one of three printers based on printer workload. Some simple rules and assumptions will govern the operation of the queue:
 The size of each print job will be specified in number of pages.
 Every page takes the same amount of time to print regardless of content.
 All of the printers take the same amount of time to print one page.
 The time that it takes to remove a job from the queue and send it to any of the printers is equal to the time that it takes to print one page.
The following programming specifications apply to the print queue:
 Use a Queue (FIFO) data structure.
 Implement the Queue as a linked list.
 There is no restriction on the number of jobs that may be added to the queue.
We will use C++ classes to simulate the print jobs, the print queue, and the printers. The class declarations are given below:
class PrintJob {
private:
long _id;
int _num_pages;
PrintJob* _next_job;

public:
// Constructor
// Param id_num: Id Number for job
// Param page_count: # pages in job
PrintJob (long id_num, int page_count);

// Gets the print job's id number
// Returns: id number
long GetId();

// Gets number of pages in print job
// Returns: number of pages
int GetNumPages();

// Gets the job that follows this job
// in the print queue
// Returns: Pointer to next job or NULL
// if last job in queue
PrintJob* GetNextJob();

// Sets the next job pointer for this job
// Param next: Pointer to next job in queue
void SetNextJob (PrintJob* next);
};

class PrintQueue {
private:
char _name[21];
PrintJob* _head;
PrintJob* _tail;
public:
// Default constructor. Name is "Unnamed";
PrintQueue();

// Construct PrintQueue with specified name
// Param queueName: Name of the queue
// (20 characters max.)
PrintQueue (char* queueName);

// Add a job to the queue
// Param jobPtr: Pointer to the PrintJob
// to be added
void Enqueue (PrintJob* job);

// Remove a job from the queue
// Returns: Pointer to first job in queue
// Pre-condition: The queue must not be empty
PrintJob* Dequeue ();

// Check to see if queue is empty
// Returns: True if empty, false if not
int IsEmpty();
};

class Printer {
private:
char _name[21];
long _current_job_id;
int _total_pages;
int _pages_remaining;
public:
// Default constructor
// Sets printer name to "Unnamed"
Printer();

// Constructs printer with specified name
// Param printer_name: Name of printer (20 chars. max)
Printer (char* printer_name);

// Accept job from the print queue
// Parm job_ptr: Pointer to the job to be accepted
void AcceptJob (PrintJob* job_ptr);

// Print one page and decrement count of
// pages remaining to be printed
void PrintPage();

// Determine if printer is idle
// Returns: true if pages remaining is zero,
// otherwise false
int IsIdle();
};

Assignment
For this project, you will implement all the member functions of the PrintJob, PrintQueue, and Printer classes. Or, you may use the implementations existing in the textbook by modifying some identifier names. Your main() should begin with the statements shown below. You will need to write the necessary additional statements that will produce the required output (also shown below). There are to be no print statements in main(). All of the output should be produced by print statements in appropriate member functions.
PrintJob myJobs[10] = { PrintJob (100, 43),
PrintJob (101, 17),
PrintJob (102, 22),
PrintJob (103, 54),
PrintJob (104, 11),
PrintJob (105, 10),
PrintJob (106, 3),
PrintJob (107, 18),
PrintJob (108, 12),
PrintJob (109, 27) };

PrintQueue myQueue ("CMSC 202 Print Queue");

for (int i = 0; i < 10; ++i) {
myQueue.Enqueue (&myJobs[i]);
}

Printer myPrinters[3] = { Printer ("Printer #1"),
Printer ("Printer #2"),
Printer ("Printer #3") };
Expected Output:
Print Job #100 added to CMSC 202 Print Queue
Print Job #101 added to CMSC 202 Print Queue
Print Job #102 added to CMSC 202 Print Queue
Print Job #103 added to CMSC 202 Print Queue
Print Job #104 added to CMSC 202 Print Queue
Print Job #105 added to CMSC 202 Print Queue
Print Job #106 added to CMSC 202 Print Queue
Print Job #107 added to CMSC 202 Print Queue
Print Job #108 added to CMSC 202 Print Queue
Print Job #109 added to CMSC 202 Print Queue
Print Job #100 accepted by Printer #1
Print Job #101 accepted by Printer #2
Print Job #102 accepted by Printer #3
Print Job #101 finished (17 pages)
Print Job #103 accepted by Printer #2
Print Job #102 finished (22 pages)
Print Job #104 accepted by Printer #3
Print Job #104 finished (11 pages)
Print Job #105 accepted by Printer #3
Print Job #100 finished (43 pages)
Print Job #106 accepted by Printer #1
Print Job #105 finished (10 pages)
Print Job #107 accepted by Printer #3
Print Job #106 finished (3 pages)
Print Job #108 accepted by Printer #1
Print Job #108 finished (12 pages)
Print Job #109 accepted by Printer #1
Print Job #107 finished (18 pages)
Print Job #103 finished (54 pages)
Print Job #109 finished (27 pages)
...全文
89 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hedongliyy 2004-04-01
  • 打赏
  • 举报
回复
好漂亮
joec 2004-03-24
  • 打赏
  • 举报
回复
还没有来及看明白....
就晕了...
怎办..
我还要去考高程!
dufeiyan9170 2004-03-20
  • 打赏
  • 举报
回复
就这些?
Didizyp 2004-03-16
  • 打赏
  • 举报
回复
请用中文!
Ramer 2004-03-16
  • 打赏
  • 举报
回复
说的是什么东西啊?
rightyeah 2004-03-16
  • 打赏
  • 举报
回复
就是有3台打印机,要我们做个打印机管理队列,给打印机提供数据。就这么简单。
然后限制一下:要用oop,要用c语言的单链表构造队列,假设每打印一页需要相同的时间,假设开始一个文件和结束一个文件需要的时间等于等于一页的时间。要求我们实现他给的三个类,要产生他指定的输出结果(不能在main函数里面写输出命令,必须在类的方法里面写)
jim6724 2004-03-15
  • 打赏
  • 举报
回复
花了半天时间翻译好了
做程序的耐心都被磨光了
xiemengjun 2004-03-15
  • 打赏
  • 举报
回复
呵呵!我直接从外国的网站拿来了!
54muster 2004-03-14
  • 打赏
  • 举报
回复
为什么用英文呢!

257

社区成员

发帖
与我相关
我的任务
社区描述
其他产品/厂家
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧