def safeOpen(filename):
try:
file = open(filename)
except:
file = None
return file
def safeFloat(x):
try:
float(x)
return True
except ValueError:
return False
def averageSpeed():
filename = input("Enter file name: ")
file = safeOpen(filename)
if file == None:
print("File not found. Please try
again")
filename = input("Enter file
name: ")
file = safeOpen(filename)
if file == None:
print("File not
found. Yet another human error. Goodbye")
return None
content = file.readlines()
avg_speed = []
for i in content:
a = i.split()
for j in a:
if safeFloat(j)
and float(j) > 2.0:
avg_speed.append(float(j))
print("Average speed is " + str(round(sum(avg_speed)/len(avg_speed),2)) + " miles per hour")
averageSpeed()
Problem 1 Recall that when the built-in function open() is called to open a file for...
A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...
Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...
I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...