Using Files—Numeric Processing
If you have downloaded this book’s source code from the Computer Science Portal, you will find a file named Random.txt in the Chapter 05 folder. (The Portal can be found at www.pearsonhighered.com/gaddis.) This file contains a long list of random numbers. Copy the file to your system, then write a
A) The number of numbers in the file
B) The sum of all the numbers in the file (a running total)
C) The average of all the numbers in the file
The program should display the number of numbers found in the file, the sum of the numbers, and the average of the numbers.
Trending nowThis is a popular solution!
Chapter 5 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Programming in C
Concepts Of Programming Languages
Computer Science: An Overview (12th Edition)
- 1. Use Notepad or Textpad to create a file called InputNumbers.txt. Your file should have the following positive integers. 35 45 50 13 24 29 91 47 69 45 78 56 35 68 79 90 80 30 37 58 99 You may create the file with 1 integer on each line or a few integers on each line as shown. 2. Write a Java program that will read the integers in the file until EOF is reached (hint: use a loop). The program should compute and print: the total sum of all the integers read the count of all the even integers read ⚫ the count of all the odd integers read ⚫ the average of all the numbers read 3. Send the output to a file called FileOut.txt 1. Make sure there is one line in the output file for each of output that is printed. In addition, format the average to have two digits of precision after the decimal point.Write a program that uses File I/O (input and output files). This is a Java program. Use a looparrow_forward**USE PYTHON** The U.S. Food & Drug Administration (FDA) offers downloadable/printable postersLinks to an external site. that “show nutrition information for the 20 most frequently consumed raw fruits … in the United States. Retail stores are welcome to download the posters, print, display and/or distribute them to consumers in close proximity to the relevant foods in the stores.” In a file called nutrition.py, implement a program that prompts consumers users to input a fruit (case-insensitively) and then outputs the number of calories in one portion of that fruit, per the FDA’s poster for fruitsLinks to an external site., which is also available as textLinks to an external site.. Capitalization aside, assume that users will input fruits exactly as written in the poster (e.g., strawberries, not strawberry). Ignore any input that isn’t a fruit. PLEASE SEE IMAGES FOR DETAILS (**use PYTHON**)arrow_forwardIn Python, Use num.txt file (below). create a program that opens num.txt, a file consisting of a series of integers. Display all of the numbers in the file. num.txt ————————————— 10 25 36 45 89 42 54 _____________________arrow_forward
- C++ do not use chegg Write a program that reads from a text file named “sales.txt”, which contains the sales figures (double) of a store. Your program should: Display the average, the highest, and the lowest sales figures Remember to: Test the file open error Close the file at the end. text file 284.12223.09579.12998.651237.84764.75395.65458.01670.353765.003842.10190.23335.35662.952719.253564.02193.23222.231457.2089.751323.65234.35789.89224.67663.95245.38arrow_forwardThe pressure of a gas changes as the volume and temperature of the gas vary. Write a program that uses theVan der Waals equation of state for gas, to create a file that displays in tabular form the relationship between the pressure and the volume of n molesof carbon dioxide at a constant absolute temperature (T). P is the pressure in atmospheres, and V is thevolume in liters. The Van der Waals constants for carbon dioxide are a = 3.592 L2 · atm/mol2 and b = 0.0427L/mol. Use 0.08206 L · atm/mol · K for the gas constant R. Inputs to the program include n, the Kelvintemperature, the initial and final volumes in milliliters, and the volume increment between lines of the table.Your program will output a table that varies the volume of the gas from the initial to the final volume insteps prescribed by the volume increment. Here is a sample run:arrow_forwardIn Python Prompt the user for a text file that contains a list of student names, one on each line. Also prompt the user for a CSV file that contains scores for the students in the following order: homework1, homework2, midterm exam, final exam. Each line in the CSV has four scores, delimited by a comma. Each name in the text file has the corresponding scores in the CSV file. You will need to calculate the weighted final grade for each student as follows: 5% homework1 5% homework2 40% midterm exam 50% final exam Homework is scored out of 10 points and exams are scored out of 100 points. You need to create a program that will read the scores from the CSV file, calculate the weighted final grade, and display the resulting final grade, along with the student's name. Sample input files are attached. You can assume that the same number of lines will be in the input files, and that the order of the names and corresponding grades is the same in the two files. Display the name and final grade…arrow_forward
- For this assignment, you will write a program that reads employee work data from a text file, and then calculates payroll information based on this file. The text file will contain one line of text for eachemployee. Each line consists of the following data (delimited by spaces or tabs):1) employee’s id2) employee’s hourly wage rate3) hours worked Monday4) hours worked Tuesday5) hours worked Wednesday6) hours worked Thursday7) hours worked Friday ex) txt file attached Your program should first prompt the user to get the location of the input file. Then it will read the data from the file, put it in appropriate arrays (as described below), and output to the screen the following information: (1) the employee ID, total number of hours worked, regular pay, overtime hours, overtime pay, and total paid to each employee (2) the total hours worked by all employees throughout the week; (3) the total amount paid out to all employees for the week; (4) the employee who received the highest pay for…arrow_forwardThe function print_last_line in python takes one parameter, fname, the name of a text file. The function should open the file for reading, read the lines of the file until it reaches the end, print out the last line in the file, report the number of lines contained in the file, and close the file. Hint: Use a for loop to iterate over the lines and accumulate the count. For example: Test Result print_last_line("wordlist1.txt") maudlin The file has 5 lines.arrow_forwardA mad man has locked you in a maze with only one exit. You need to escape the maze as quickly as possible. Thankfully you have the map of the maze, but you notice strange markings with each room; you discover that each room has special effects. Write a program to find the quickest path out of the maze. Input will be from a text file where the first line contains an integer, N, the number of cases. For Updated August 29, 2021 COSC 2436 F215 each case, the first line will consist of 2 integers, which indicate the number of rows and columns of the map, respectively. The map will consist of the characters: X, S, A, F, G, L, N, and O. The characters represent specific effects that each room has:•"S": The room marked S is the starting room. •"X": The room marked X is the ending room.•"A": In rooms marked A, you can enter through any direction and leave through any direction. It takes 10 seconds to pass through room A.•"F": It takes 20 seconds to pass through…arrow_forward
- What does the following python code do? f = open("sample.txt", "w") Choose all that apply. Select 2 correct answer(s) Question 11 options: If the file called sample.txt exists, it writes at the bottom of the file if the file sample.txt exists, deletes everything in it reads the file called sample.txt starting from the top if the file sample.txt does not exist, it creates the file and opens it for writing opens a file called sample.txt for appending writes "w" to the file called sample.txt opens a file called sample.txt for reading closes a file called sample.txtarrow_forwardA program stores the prime numbersin a file named PrimeNumbers.dat. Write a program that finds the numberof prime numbers that are less than or equal to 12, 120, 1,200, 12,000,100,000, 1,200,000, 12,000,000, 120,000,000, 1,200,000,000, and12,000,000,000. Your program should read the data from PrimeNumbers.dat.arrow_forwardJAVA PPROGRAM ASAP Hypergrade does not like this program because it says 2 out of 7 passed and take out the extra \n from the program. Please Modify and change this program ASAP BECAUSE IT IS HOMEWORK ASSIGNMENT so it passes all the test cases. The program must pass the test case when uploaded to Hypergrade. Also, for test cases 1-4 it wants only to input Please enter the file name or type QUIT to exit: then input the file and display the Total number of words. For test cases 5 and 7 it wants to only to input Please enter the file name or type QUIT to exit then input input5.txt and then display File: input5.txt does not exist.\n then display Please enter the file name again or type QUIT to exit:\n then type input1.txt to display the total number of words or type quit to exit the program. For test case 6 it wants only to Please enter the file name again or type QUIT to exit:\n then type quit to exit the porgram. import java.io.File;import java.io.FileNotFoundException;import…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning