Define a function called copyLine that takes one argument that is an input stream. When called, copyLine reads one line of input from the input stream given as its argument and writes that line to the screen. You should be able to call your function using either cin or an input-file stream as the argument to your function copyLine. (If the argument is an input-file stream, then the stream is connected to a file before the function is called, so copyLine will not open or close any files.) For example, the first of the following two calls to copyLine will copy a line from the file stuff.dat to the screen, and the second will copy a line from the keyboard to the screen:
ifstream fin;
fin.open(“stuff.dat”);
copyLine(fin) ;
copyLine(cin) ;
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Database Concepts (7th Edition)
Database Concepts (8th Edition)
Experiencing MIS
Starting Out with C++: Early Objects
Concepts Of Programming Languages
Starting Out With Visual Basic (7th Edition)
- in C program pleasearrow_forwardWrite a function count_character(filename, character) that takes in a filename and a character, both as strings, and returns the total number of times the given character occurs in the file. Examples: Contents of hello.txt:HelloHELLOHelloHELLO count_character('hello.txt', 'L') returns 4count_character('hello.txt', 'H') returns 4count_character('hello.txt', 'e') returns 2 Requirements: Please use Python Programming only Show screenshot of your work.arrow_forwardThis Python Lab 9 Lab: Write a file copying program. The program asks for the name of the file to copy from (source file) and the name of the file to copy to (destination file). The program opens the source file for reading and the destination file for writing. As the program reads each line from the source file and it writes the line to the destination file. When every line from the source file has been written to the destination file, it close both files and print “Copy is successful.” In the sample run, “add.py” is the source file and “add-copy.py” is the destination file. Note that both “add-copy.py” is identical to “add.py” because “add-copy.py” is a copy of “add.py”. Sample run: Enter file to copy from: add.py Enter file to copy to : add-copy.py Copy is successful. Source file: add.py print("This program adds two numbers") a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print(f"{a} + {b} = {a+b}") Destination file:…arrow_forward
- P7arrow_forwardGiven a text file containing the availability of food items, write a program that reads the information from the text file and outputs the available food items. The program should first read the name of the text file from the user. The program then should read the text file, line by line. If a food is available, the program should output the available food item in the following format: name (category) -- description Assume the text file contains the category, name, description, and availability of at least one food item, separated by a tab character ('\t'). Hints: Use the find() function to find the index of a tab character in each row of the text file. Use the substr() function to extract the text separated by the tab characters. Ex: If the input of the program is: food.txt and the contents of food.txt are: Sandwiches Ham sandwich Classic ham sandwich Available Sandwiches Chicken salad sandwich Chicken salad sandwich Not available Sandwiches Cheeseburger Classic cheeseburger Not…arrow_forwardPython - Text Processing Write a function copy(x, y) that can copy a file x into another file y. Use demo.txt as the input to verify your function. _Hint_: use functions open( ), read( ), write( ), and close( ).arrow_forward
- Let A and B two text files, containing some binary lines between of length 1...N. Where N is the line with the maximum number of characters, 1 the minimum number of characters in each line. Design a Python3 function to compare each line of the files, character by character, and if there is a match of the characters, create a variable representing the similarity between the lines of each file, and return that similarity variable measures the similarity between two files.arrow_forwardWrite a function named repeat_words that takes two string parameters: 1. in_file: the name of an input file that exists before repeat_words is called 2. out_file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than once on that line. Each word should be lower cased and stripped of leading and trailing punctuation. Each repeated word on a line should be written to the corresponding line of the output file only once, regardless of the number of times the word is repeated. For example, if the following is the content of the file catInTheHat.txt: Too wet to go out and too cold to play ball. So we sat in the house. We did nothing at all. So all we could do was to Sit! Sit! Sit! Sit! The following function call: inF = 'catInTheHat.txt' outF =…arrow_forwardPaytonarrow_forward
- Start by writing a function, plot_grades (filename, first_name, last_name), which plots the grades for the specified student. This will be very similar in nature to what you did in Assignment 5.2 but will use the csv library instead of split (). a. The function should find the specified student in the file associated with filename. b. It should use plotter to plot all of the graded items for that student. c. Manually test your function using the full grades_ XXX.csv files.arrow_forwardWriteaC++programthatpromptstheusertoenterafilenamethatcontains the total mark of students. Each line in the input file contains a student name followed by the student’s total mark. The program should ask the user for the passing threshold (i.e. student whose total mark is greater than or equal the threshold will pass the course) and copy the students who pass the course to a new file (the name of the output file is specified by the user). Moreover, the output file should be format so that all the marks are displayed with two digits after the decimal point. The width for the names and marks fields should be eight and seven, respectively. A sample input and output files are shown below (the passing mark in this sample is assumed to be 60). Total.txt Ahlam 80.123 Bader 83.1 Nabil 91.25 Khoula 70 Saif 55.333 Salem 50 Sultan 92.5 Qais 77.2arrow_forwardWrite a function called max_age(inFile, outFile, breed) for a (python program), 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…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr