Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**Program must be written in Pascal ** Imagine there is white board. You draw non-intersecting circles on the board, numbered 1 to N, where N

**Program must be written in Pascal**

Imagine there is white board. You draw non-intersecting circles on the board, numbered 1 to N, where N is an integer from 2 to 10. You next draw arrows from one circle to another, making sure that each circle has at least one out arrow and one in arrow. Now you play the following game:

1. Place a magnetic marker in circle #1, and put a check mark in circle #1. The circle where the marker resides is called the current circle.

2. Randomly choose among the out arrows in the current circle. (If there is only one out arrow, that choice is trivial.) In this selection, all the out arrows should be equally likely to be picked.

3. Move the marker to the circle pointed to by the out arrow. This becomes the new current circle.

4. Put a check mark in the current circle.

5. If all the circles have at least one check mark, stop the game. If not, go to step 2 and repeat.

The program will read from a textfile in the same directory as the executable program, and will write to another textfile in that same directory.

Let N and K be positive integers. For this assignment, N is between 2 and 10 inclusive. The input text file should be named Proj1.txt. It should be in this form:

The first line has only the number N, the number of circles that will be used in your game.

The second line has the number K, the number of arrows you will drawing between the circles.

The next K lines designate the arrows, one arrow per line. Each arrow line consists of two numbers, each number being one of circles in the game. These two numbers are separated by a single blank. The first number designates the circle that is the source (back end) of the arrow; the second number designates the circle that is the destination (pointed end) of the arrow. The circles and arrows of this game describe a directed graph, sometimes known as a diagraph. In order to set up the game correctly, you should describe a strongly connected diagraph. A diagraph is strongly connected when there is a path between any two nodes. In our game, our paths are the arrows, and our nodes are circles.

Make sure that you test it with circles and arrows that describe a strongly connected digraph. Not all circles need to be connected directly to each of the other circles; but as a system, they should be connected in the sense described above. I suggest that each time you make a new Proj1.txt you draw the desired game board and then translate into the required input file.

Shown below are three systems of circles and arrows. With respect to the definition of connected above, NOT ONE of them is strongly connected. In Figure 1 and Figure 3, you could make the digraph strongly connected by adding an arrow from circle 4 to circle 1. The reason we need strong connection is so that you dont get stuck in your random walk around the digraph.

Figure 1. This system is not strongly connected; there is no path to circle 1. If you add an arrow from circle 4 to circle 1, it would be strongly connected.

Figure 2. This system is not strongly connected. Once you follow an arrow, you are stuck.

Figure 3. This system is not quite strongly connected; an added arrow from circle 4 to circle 1 would make it strongly connected.

Your program can assume this connectedness for a given input file. That is, your program need not verify that the circles and arrows described in the input file form a strongly connected digraph. A subsequent assignment will require your program to verify the connectedness.

If the text in the input file does not follow the format described above, your program should end with an error message to the screen and to an output file. The output file should be a textfile. Name your output textfile Ass1.txt where lastname is replaced by your last name.

If the text in the input file DOES follow the description above, then you should play the game until each circle has at least one check. When that happens, the game stops. At the end of the game, you should print out to the screen, and to the output textfile, the following numbers:

1. The number of circles that were used for this game

2. The number of arrows that were used for this game

3. The total number of checks on all the circles combined.

4. The average number of checks in a circle marked during the game.

5. The maximum number of checks in any one circle.

All of these numbers should be labeled clearly in both outputs, with explanations sufficient for someone who knows only vaguely whats going on with this strange game.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

Students also viewed these Databases questions