Write a function called process_data that meets the specification written below. Your method should be programmed defensively and should handle any of the possible errors that may arise from reading from a file printing an appropriate error message to the screen. Function: process_data This function reads data from a file and calculates the sum of all of the values found in the file. It does this by reading the file one line at a time and if the line contains a single number, it adds that value to the sum; otherwise the line is ignored. Params: filename -- a string that contains the name of a file Returns: The sum of all of the numbers in the file, or 0 if there are no numbers
Q: C++ Inside the following function declaration, make a method that creates a child process. The…
A: SUMMARY: - hence, we got the desired output.
Q: Write a function called max_age(inFile, outFile, breed), that takes three strings as input…
A: 1. create function max_age with paramter infile outfile and breed 2. try to open the input file and…
Q: In this laboratory work, you are expected to write a c# console application to make some operations…
A: Programming is a way to instruct the computer devices to operate. Every computer needs a set of…
Q: In the context of binary file, write C statement to perform the following tasks: (i) Declare a file…
A: The question is to write C program for the given problem.
Q: Start by writing a function, plot_grades (filename, first_name, last_name), which plots the grades…
A: What is a CSV? CSV(Comma Separated Values) is a simple file format used to store tabular data, such…
Q: UNIX Systems Programming A UNIX user is trying to write a short function to automate figuring out…
A: Line no 8 may contain following code num_lines=$( lines_in_file $1 )
Q: Time remaining: 01:47:21 Computer Science The file numbers.txt contains integer numbers, one number…
A: NOTE - I have used python programing language. I have opened the file and stored the object into a…
Q: Write the following two functions in c programming language maintaining a database of entries of…
A: As the requirement to question the Source code is given below:
Q: Write a function called max_age(inFile, outFile, breed), that takes three strings as input…
A: Since no programming language is mentioned, I am using python. Algorithm: Start Read input file…
Q: Modify sh.c so that all commands entered by the user are appended to a file called commands.txt.…
A: The code is given below.
Q: Write a program in C/C++ which is passed as command line argument a file name. Your program will…
A: Program in C: #include <stdio.h>#include <stdlib.h>#include <unistd.h>#define…
Q: Consider the following function declaration/definition (the body of the function is not shown;…
A: Answer : No ,
Q: Project 1-UNIX Shell Design a C program that copy the file "input.txt" to "out.txt" using Ubuntu…
A: Given: C program to copy contents of one file to another file.
Q: Our requirement is to keep information of students who are taking “Introduction to Python” in…
A: Due to the Honor code, I can solve only 1st part. Resubmit the 2nd part of the question. Code:…
Q: Write a program in C/C++ which is passed as command line argument a file name. Your program will…
A: Given:
Q: Fruit Juice Machine In this programming example, there are one function available which is main()…
A: Actually, given information: The program should do the following; Show the customer the different…
Q: Write a void function that will merge the contents of two text files containing the chemical…
A: This question is solved by C languages Programming. Program Plan :- merge2binary.c Define a…
Q: Write a function that reads data from a file. The file has already been opened and verified. The…
A: Programming instructions: Include necessary header files. Create a structure 'ship'. Declare…
Q: Write a program that computes and prints the average of the numbers in a text file. You should make…
A: Note: As programming language is not mentioned, we are providing solution in python programming.…
Q: 3. Filename: assign4-11.py Modify the assign1-4 script by adding a function calcinterest (). The…
A: Input : Input Principle, rate, number of payments, and number of years. Output : Return of…
Q: Write a program whose main function is merely a collection of variable declarations and function…
A: #include <iostream> #include <fstream> using namespace std; // Create a struct…
Q: Write a function that generates a file with following parameters: def fillFile(fileSize, fileName):…
A: I will be using python to solve this question. Please thumbs up if i am able to help you :-)
Q: Write a function stat(fName) that takes a filename that contains a matrix of numbers. Your function…
A: Algorithm: Start Open the file in read mode and read the content and store it in a variable By…
Q: Write a function definition called, sigma, that takes an input file reference and two integer…
A: answer: writing this code in java : main function:public static void main(String[] args) {…
Q: program in C/C++ which is passed as command line
A: #include<stdio.h> #include<stdlib.h> #include<unistd.h>…
Q: Write a program in C/C++ which is passed as command line argument a file name. Your program will…
A: #include <stdio.h>#include <unistd.h>#define MSGSIZE 16char* msg1 = "Take care #1";char*…
Q: Assume that there is a valid file cards.txt in the current directory which contains 5 valid int…
A: #include <iostream>#include <fstream> using namespace std; void printSevens(); int…
Q: A user wants to write a C program for manipulating student records. The program contains a function…
A: The concept here is to identify the option that is line of code is used to open the student file for…
Q: Write a function named repeat_words that takes two string parameters: 1. in_file: the name of an…
A: It is defined as a class represents character strings. All string literals in Java programs, such as…
Q: Complete the below function that takes the name of two files, inFilename and outFilename as…
A: Below is the required python program: - Approach: - Define the function readText that read the…
Q: Write a C program using system call(s) to create A directory called “os”. Inside “os” create…
A: In questions with multiple questions, we must answer the first three sub parts
Q: Assume that the following information is stored in a text file called "data.txt". Fill in the blanks…
A: Use ifstream to read a file and then load one by one input and check for id only
Q: QUESTION 2 Pointers are never used for pointing to an object O pointing to a variable O pointing to…
A: According to the guidelines we are supposed to answer only one question. SO I am answering the…
Q: Perform the following exercises in MATLAB. Follow the required filenames for each activity.
A: code: %BMI = mass / height^2 = (kg/m^2) in SI units disp('Hello, this is the BMI calculator.')…
Q: In this laboratory work, you are expected to write a c# console application to make some operations…
A: To read the stored data from server to browser-var myObj = {name: "Kaan", age: 31, city:…
Q: Write a program that will create file with at least 10 lines. Each line of your file should have…
A: Write a program that will create file with at least 10 lines. Each line of your file should have…
Q: Do not copy paste from any source else downvote Write a void function that will merge the contents…
A: Given: Write a void function that will merge the contents of two text files containing chemical…
Q: PROGRAM DESCRIPTION: In this assignment, you will write a Python program to process an input file.…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.…
Q: All I need is the main.cpp file Programming Specifications: Task: Two files have been provided…
A: Algorithm: Start the program. Read the data from the file wordcounter. Call the function and add…
Q: Create a file named "pointer.c" and include the header file "pointer.h" Implement all functions…
A: We need to write a C program for the given scenario.
Q: For this challenge, you will extend the existing program so that players scores are saved to and…
A: Answer: I have done code and also I have attached code as well as code screenshot.
Q: Write a C/C++ program that calculates the least squares line for two sets of values. The program…
A: Actually, c++ is a powerful general purpose language.
Q: ask 2. File handling Develop a program with two methods where the first method will accept a…
A: Java program to implement two methods which accepts user input and file handling
Q: Write a C/C++ program that calculates the least squares line for two sets of values.
A: Solution (C++ program) is in Step 2.
Q: In Python Write a program that consists of (at least) two function: A function that creates and…
A: Note: Follow Proper indentation as specified in snapshots. To implement the program, 4 methods are…
Q: Using the python code below. Identify the Variabale, Conditional Statement,Operators,Loops and…
A: We need to identify the Variabale, Conditional Statement,Operators,Loops and Functions used in the…
Q: Our requirement is to keep information of students who are taking “Introduction to Python” in…
A: Required: Write a python code that: Creates a file named ‘Students.txt’ if it does not exist (use…
Q: in this function is f a variable? in what other way can we write this function? why does mode not…
A: The correct way is
Q: Information for 20 customers of a bank is stored in a random Access file named musteri.dat using the…
A: // File Name:CustomerAccount.c #include <stdio.h>#include <stdlib.h>#include…
Q: 3. Which of the following is correct for header files? A. Header files are also called as library…
A: Correct options: 3. D 4. D
Use python please
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- Write a function called countWord(). It takes 2 parameters: The name of a text file(e.g. gettysburg.txt) and a word to be searched within that file. Your code should returnthe number of times the given word appears in the file.>>> countWord('gettysburg.txt', 'people')3in this function is f a variable? in what other way can we write this function? why does mode not work in this function? def process_lines(filename, mode): # Actually this is function is used to read the file line by line with open(filename, 'r') as f: # file opened msg = f.read() # read the message return msg # return message def write_lines(lines): # function to write some into message with open('results.txt', 'w') as f: # open the text file f.writelines(lines) # write some line print("Output written to results.txt") # print the output what does os.path do?def check_file_exists(filename): # check weather this file is exist or not to avoid exception from os.path import exists # import library of exist file_exists = exists(filename) # if file exist return file_existsWrite a function definition called, sigma, that takes an input file reference and two integer references as its parameters. The function should read the numbers from a file, calculate their total value (cumulative sum), find the largest, and smallest numbers in the file. The function should return the cumulative sum, the largest, and the smallest values to the calling function. Note: the function reads the entire file.
- Question 55 Write a function that takes two parameters, a file name to create and an integer. The function should write all the even numbers between 0 and the integer to the file name passed in. The numbers should be all on one line of the file For example: write_evens("even_file.txt",20) This should create a file called even_file.txt that contains 0 2 4 6 8 10 12 14 16 18 20 Full explain this question and text typing work only thanksWrite a function void saveByDept(char *fileName, char *deptName , student allStudents[], int size) that will save the information of all students who belong to the department with name pointed to by deptNameinto a text file. The name of the file is given as an input parameter, fileNameWrite a program whose main function is merely a collection of variable declarations and function calls. This program reads a text and outputs the letters, together with their counts, as explained below in the function printResult. (There can be no global variables! All information must be passed in and out of the functions. Use a structure to store the information.) Your program must consist of at least the following functions: Function openFile: Opens the input and output files. You must pass the file streams as parameters (by reference, of course). If the file does not exist, the program should print an appropriate message ("The input file does not exist.") and exit. The program must ask the user for the names of the input and output files. Function count: Counts every occurrence of capital letters A-Z and small letters a-z in the text file opened in the function openFile. This information must go into an array of structures. The array must be passed as a parameter, and the file…
- Write a function called max_age(inFile, outFile, breed), that takes three strings as input parameters. The function reads all the data from the inFile (1st input parameter) and writes data to the outFile (2nd input parameter) as described below. Each line in the input file represents a pet record and has the following format. name, breed, age where name and breed are strings, and age is an integer value. Your function must find the oldest pet of a given breed (3rd input parameter) from the inFile and write the following information to the outFile. breed, total records of this breed name of the oldest pet, age of the oldest pet Note that outFile must only have these two lines of information. Suppose, inFile contains the following data: shadow, longhair, 3 poshi, bangal, 5 mikus, longhair, 4 tigger, calico, 9 If you call this function with breed = "longhair", then the following must be written in the outFile: longhair, 2 mikus, 4 Your function must return…Write a function called max_age(inFile, outFile, breed), that takes three strings as input parameters. The function reads all the data from the inFile (1st input parameter) and writes data to the outFile (2nd input parameter) as described below. Each line in the input file represents a pet record and has the following format. name, breed, age where name and breed are strings, and age is an integer value. Your function must find the oldest pet of a given breed (3rd input parameter) from the inFile and write the following information to the outFile. breed, total records of this breed name of the oldest pet, age of the oldest pet Note that outFile must only have these two lines of information. Suppose, inFile contains the following data: shadow, longhair, 3 poshi, bangal, 5 mikus, longhair, 4 tigger, calico, 9 If you call this function with breed = "longhair", then the following must be written in the outFile: longhair, 2 mikus, 4 Your function must return…My Question starts here In the code linked Implement a function readEmpFromFile that takes a FILE * as the only argument and returns a pointer to a struct employee. This function should read the information from the file (reversing what writeEmpToFile does), create a new employee and fill in the data. If the FILE has no more info (is at end of file), this function should return NULL. This function must also ensure any employee actually created (not the NULL) is added to the array (as is done in createEmployee). Change main to load employees from a file if a command line argument is given to the program (using your readEmpFromFile function you just wrote). Question ends here To make it easier so that you do not have to go through the entire code I'm going to put writeEmpToFile function right here after the question but if you still need to look at the full code to get an understanding of what you are working with its linked at the bottom void writeEmpToFile(Employee *emp, FILE…
- Write a void function that will merge the contents of two text files containing the chemical elements into a single binary file. The function's parameters will be three file pointers; each text file will contain an integer atomic number followed by the element name, chemical symbol and atomic weight. Here are two sample lines: 11 Sodium Na 22.9920 Calcium Ca 40.08 The function can assume that one file does not two copies of the same elements and that the binary output file should have the same property. IN C PLEASEModify sh.c so that all commands entered by the user are appended to a file called commands.txt. The commands should be logged into the file before they are If txt does not exist, your program is responsible for creating it. Create a program called frequency.c. This program will read from commands.txt and display the number of times each command occurred. You are not allowed to request more memory than necessary during the calculation of the frequency. You need to implement and apply the following two utility functions: int num_elements(char* str); This function counts the number of characters in string str. void append(char** str, char c); This function appends char c to string str. It might need to resize str. The output should be in the form <command>:<occurrence> for each unique command in commands.txt. You also need to provide a readme file (in PDF format) to (i) answer the questions in Part A; (ii) explain the major points of your program. Sample run: $…In this laboratory work, you are expected to write a c# console application to make someoperations about the customers. Operations and required featurest that you need to cover inyour program are following:• Add: This function adds a new person to json file. You need to get inputs from userand adds the new one into json file.• Display: This function displays all people in your json file.• Search: This function let you search with the user id.• Create Password: This function will create a random password for the user and usermay choose the length of the password. Password may include numbers andcharacters.• Exceptions: You need to handle exceptions as well. You should at least handle 3 ofexceptional cases. For the case that file can not be found, It is mandatory to catch theexception.