Question

In: Computer Science

Write a program that will ask for the user to input a filename of a text...


Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value, and standard deviation. These results will be reported to both the screen and placed into the output file that the user choose.
Output to screen and file could look like this:

Read from file: 12 values
Maximum value = 20
Minimum value = 3
Average value = 13.34
Standard Deviation = 2.15

You can create a simple NotePad file to store a bunch of integers, just make sure that there is at least a space or a line between each number

Solutions

Expert Solution

The whole is implemented in python
f1=input("Enter the filename to read:- ")
d1=input("Enter the filename to display:- ")
l=[]
p=[]
with open(f1) as f:
   r=f.readlines()
   #preprocessing the file and storing in a list.
   for i in r:
       l.extend(i.split(" "))
   for s in l:
       p.append(s.strip("\n"))
   l=[]
   for i in p:
       if(i!=''):
           l.append(int(i))
   #total vals
   tval=len(l)
   #min
   mn=min(l)
   #max
   mx=max(l)
   #Average
   avg=sum(l)/tval
   #Standard deviatin
   std=0.0
   for i in l:
       std=std+((i-avg)**2)
   std=std/tval
   std=std**0.5
   #Displaying results
   print("Read from file: %d"%(tval))
   print("Maximum Value: %d"%(mx))
   print("Minimum Value: %d"%(mn))
   print("Average Value: %.2f"%(avg))
   print("Standard Deviation: %.2f"%(std))
   #Writing to file
   d = open(d1, "w")
   d.write("Read from file:%d\n"%(tval))
   d.write("Maximum Value: %d\n"%(mx))
   d.write("Minimum Value: %d\n"%(mn))
   d.write("Average Value: %.2f\n"%(avg))
   d.write("Standard Deviation: %.2f\n"%(std))
   d.close()
  

Output

Output in file...


Related Solutions

Ask the user for a filename, then ask the user for a line of text. Write...
Ask the user for a filename, then ask the user for a line of text. Write the line of text the filename specified by the user. The filename may be absolute or relative to the project directory.
Write a Python program that will ask the user to input a word, will return the...
Write a Python program that will ask the user to input a word, will return the first letter of the input word, and ask the user to put another word, and so on, in the form of a loop. If the user chooses to stop, he or she should input the integer "0" for the loop to stop.
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
2. Write a program to do the following: • ask the user to input the size...
2. Write a program to do the following: • ask the user to input the size of an array of integers and allocate space for the array • ask the user to input the integer values for the array and store these values into the array • calculate and display the sum and the average of elements of the array
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
Write a program that reads a line of text input by the user and places each...
Write a program that reads a line of text input by the user and places each word in a TreeSet. Print the elements of the TreeSet to the screen. This will cause the elements to be printed in ascending order. Using Eclipse for this. TreeSetUse.java.
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT