Question
Please WRITE PROGRAM IN C or C++ There are 1 to N non-intersecting circles (where N be any number between 2 and 10). Start at
Please WRITE PROGRAM IN C or C++
There are 1 to N non-intersecting circles (where N be any number between 2 and 10). Start at circle 1 and randomly choose among the out arrows (all out arrows should be equally likely to be picked). The next circle is the new current circle. Each visited circle gets a "check mark" to indicate it has been visited. Once all circles have at least one check mark, stop the game.
Write a program that will read from a textfile and write to another textfile. The input file will have N and K positive integers, where:
N is the FIRST LINE and
K is the SECOND LINE indicating number or arrows between the circles.
The next K lines indicate the arrows. 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.
Note: 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
At the end of the game, print out to the screen AND to the output textfile, the following numbers:
1. The number of circles used for this game
2. The number of arrows used for this game
3. The total number of checks on all the circles
4. The average number of checks in a circle marked .
5. The maximum number of checks in any one circle
Sample 1 input.txt file:
**note there is an arrow missing from circle 4 to 1 in the above diagram so that it is 'strongly connected' **
4 // line 1 indicates N circles
4 // line 2 indicates K arrows total
1 2 // The following K lines contain 2 integers separated by one space. First integer indicates circle N and second integer is the next circle travelled to represented by an 'arrow'
2 3 // line 4
3 4 // line 5
4 1 // Now each circle has been visited once (has one check) and program is complete
Sample 1 output.txt
4 // Num circles used
4 // Num arrows used
4 // Total num checks in all circles combined
1 // Avg num checks in a circle
1 // Max num of checks in circle
Sample 2 input.txt
**note the above diagram is missing an additional arrow from 4 to 1 so it is strongly connected**
4 // Num circles used
6 // Num arrows used
1 2 // circle 1 visited once
2 1 // circle 2 visited once
1 3 // circle 1 visited twice and circle 3 visited once
3 1 // circle 3 visited once
1 4 // circle 1 visited 3 times and circle 4 visited once
4 1 // circle 1 visited 4 times and program is complete
Sample 2 Output.txt
4 // 4 circles total
8 // 8 arrows used
7 // circle 1 visited 4 times and circle 2, 3, 4 each visited once
1.75 // 7 visits divided by 4 circles
4 // circle 1 has 4 checks
1 2 4 1 2 4 1 2 4 1 2 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started