首页 > > 详细

program程序辅导、辅导Python/Java编程

Lab 4 - Conways Problem
Conway’s Problem
In this lab you will write a program to solve Conway’s problem.
Description
You will again use the IPC implementation under UNIX and the ezipc.h library to solve the problem. If
ezipc is not used, points will be taken off. You may use SHOW() and SET() only for debugging purposes.
Purpose
Conway's Problem: Write a program to read 80-column cards and write them as 125-character lines with
the following changes. After every card image the string is inserted. Every adjacent pair of
asterisks ** is replaced by a #.
Of course Conway's problem can be solved by a single sequential program. However, it is difficult to be
sure that you have taken care of all special cases such as pairs of asterisks at the end of a card and so
on.
The problem has an elegant solution with three concurrent processes. One process producer reads
cards and inserts the string when necessary and passes characters through a one-character
buffer to a process squash. squash, which knows nothing about 80-column cards, simply looks for
double asterisks and passes a stream of modified characters to a process print. print takes the
characters and prints them as 125-character lines.
Program Guidlines
Write a program to solve Conway's problem with three separate processes for the producer, squasher
and printer as described above using three concurrent processes with the following modifications:
- Your program should read in the card text from a file called “conway.txt”
- Each card is 20 characters long (not 80 column cards).
- To simulate card input read from a file where each line has 20 characters.
- Printer process: prints 25-character lines to the screen (not 125 character lines).
*Note that each shared memory is a 1 character buffer.
.
producer squash print
shared
memory
shared
memory
input
file output
Here is an example, given the text file provided, program would be expected the shown to output
Input file
1234*6**9*ABCDEFGHI*
*bcdefghij**bcdefghi
*****XXXXXabcdefghij
********************
********************
ABCDEFGHIJKLMNOPQRST
** Z
Output
1234*6#9*ABCDEFGHI**
bcdefghij#bcdefghi##
*XXXXXabcdefghij####
################

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!