Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write pseudocode to read in a set of numbers from a file representing rolls of a

ID: 664087 • Letter: W

Question

Write pseudocode to read in a set of numbers from a file representing rolls of a single, 6-sided die.

The size of the file is unknown, so you'll have to use the "while not eof" to control reading. Track the

number of ones, twos, threes, fours, fives, and sixes rolled. When the entire contents of the file are

processed, display the total number of die rolls, the number of ones, twos, threes, etc. rolled, and the

probability of each possible roll (the number for that result divided by the total number of die rolls).

Explanation / Answer

===============================================
PSEUDOCODE
===============================================

BEGIN
   DECLARE fileName,filePointer,onesCount=0,twosCount=0,threesCount=0,
       foursCount=0,fivesCount=0,sixesCount=0,total=0,digit
  
   DISPLAY "Enter Input file Name"
   READ fileName
  
   //Open file in read mode
   filePointer = open(fileName,"r")


   WHILE fp NOT EOF
   DO

       digit = fp.next()
      
       IF digit EQUAL TO 1
           +1
       ELSE IF digit EQUAL TO 2  
           twosCount = twosCount +1
       ELSE IF digit EQUAL TO 3  
           threesCount = threesCount +1
       ELSE IF digit EQUAL TO 4  
           foursCount = foursCount +1
       ELSE IF digit EQUAL TO 5  
           fivesCount = fivesCount +1
       ELSE IF digit EQUAL TO 6  
           sixesCount = sixesCount +1
       END IF

       total = total +1
   END WHILE

  
   //Display number occurences

   DISPLAY "Total Number of Dice rolled :"
   DISPLAY total

   DISPLAY "Number of once:"
   DISPLAY onesCount

   DISPLAY "Number of twos:"
   DISPLAY twosCount

   DISPLAY "Number of threes:"
   DISPLAY threesCount

   DISPLAY "Number of fours:"
   DISPLAY foursCount
  
   DISPLAY "Number of fives:"
   DISPLAY fivesCount

   DISPLAY "Number of sixes:"
   DISPLAY sixesCount

   //Probabilty
   DISPLAY "Probability of once:"

   DISPLAY onesCount/total

   DISPLAY "Probability of twos:"
   DISPLAY twosCount/total

   DISPLAY "Probability of threes:"
   DISPLAY threesCount/total

   DISPLAY "Probability of fours:"
   DISPLAY foursCount/total
  
   DISPLAY "Probability of fives:"
   DISPLAY fivesCount/total

   DISPLAY "Probability of sixes:"
   DISPLAY sixesCount/total
  

END  

===============================================
input.txt file content
===============================================

1
2
2
3
3
4
4
4
5
6
===============================================
SAMPLE INPUT AND OUTPUT
===============================================

Enter Input file Name
input.txt

Total Number of Dice rolled :
10

Number of once:
1

Number of twos:
2

Number of thress:
2

Number of fours:
3

Number of fives:
1

Number of sixes:
1

Probability of once:
0.1

Probability of twos:"
0.2

Probability of threes:"
0.2  

Probability of fours:"
0.3

Probability of fives:"
0.1

Probability of sixes:"
0.1
===============================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote