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 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.
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.
Question: Conversion Program * This program will ask the user to input meters * After input,...
Question: Conversion Program * This program will ask the user to input meters * After input, a menu will be displayed: * 1. Convert to kilometers * 2. Convert to inches * 3. Convert to feet * 4. Quit * * The user will select the conversion and the converted answer will be displayed. * The program should redisplay the menu for another selection. * Quit program when user selects 4. Hi, my instructor requirement fix the bug in the...
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
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Write a Python program to implement Vignere Cipher. Take user input to get plain text and...
Write a Python program to implement Vignere Cipher. Take user input to get plain text and key. TRY TO MAKE IT AS EASY AS YOU CAN.
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT