B. Member Functions get, put, fail, and eof
Create a file called input9B.txt and type (or copy) the following text exactly as it appears
below into that file. You may cut and paste the following 7 blue lines (including the blank
line between the two paragraphs) into that file:
C++ is a cross-platform language that can be used to create high-performance applications.
C++ was developed by Bjarne Stroustrup, as an extension to the C language. C++ gives
programmers a high level of control over system resources and memory.
C++ is one of the world's most popular
today's
object-oriented programming language which gives a clear structure to programs and
allows code to be reused, lowering development costs.
The following program reads the entire contents of the input9B.txt file and attempts to
display its entire contents exactly as it appears above:
3
Compile and run the program, using the input9B.txt file as the input file. Did this program
produce the same exact output as shown above? What do you think the problem is?
The problem is that the extraction operator does not read the white spaces, i.e., it skips
blank spaces, tabs (\t), and new lines (\n). Thus, the entire text will appear in one piece
without the separating spaces and new lines. In order to read and write the entire text with
correct spacing, we will use a member function with the input stream. The get(c) function,
where c is a character, allows us to read all characters from the file one character at a time.
So to fix the above program we could simply use this function instead of the extraction
operator.
The member function eof() can be used with a stream of input type to determine the endof-file. This function returns true when the end of the input file is reached. Thus, it can be
used in a while loop to control the looping process. In general, you need to read one
character before you check to see if the end of the file is reached.
4
Now, modify the above program by using the get() member function instead of the
extraction operator (i.e., >>) as well as the eof() member function to read until the end of
the file. But instead out displaying the contents to the terminal, modify the program so that
it writes to whatever output file is specified by the user using the put() function.
To do this, you will need to modify the program so that it prompts the user for the filenames
for two streams, one for the input and the other for the output. Note that you can remove
the two cout statements in main with the "***" as these lines do not need to be written to
the file. When testing, do not overwrite the input file input9B.txt, but instead use out9B.txt.
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
- 1. Create a file named dedup.js. Write a program that removes duplicates from an array. The program should be able to read an unspecified number of numbers input by the user. The user should enter a negative number when they are done entering scores. The program should remove all duplicates from the array and then iterate over the new array and display it. dedup.js const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const numbers = []; function readInput() { rl.question('Please enter a number or enter a negative to exit: ', (input) => { if (input < 0) { let deduped = [...new Set(numbers)]; console.log('Your array without duplicates is:', deduped); rl.close(); } else { numbers.push(Number(input)); readInput(); } }); } readInput(); 2. Create a file named dedeup_2.js. Modify your dedup program and prompt the…arrow_forwardComputer Science csv file "/dsa/data/all_datasets/texas.csv" Task 6: Write a function "county_locator" that allows a user to enter in a name of a spatial data frame and a county name and have a map generated that shows the location of that county with respect to other counties (by using different colors and/or symbols). Hint: function(); $county ==; plot(); add=TRUE.arrow_forwardDescriptionWrite a program to compute average grades for a course. The course records are in a single file and are organized according to the following format: each line contains a student's first name, then one space, then the student's last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program will read data from this file and write its output to a second file. The date in the output file will be nearly the same as the data in the input file except that you will print the names as last-name, first-name; each quiz score, and there will be one additional number at the end of each line:the average of the student's ten quiz scores.Both files are parameters. You can access the name of the input file with argv[1]. and the name of the output file with argv[2].The output file must be formatted as described below: 1. First and last names…arrow_forward
- CODE SHOULD BE PYTHON:arrow_forwardWrite a program that uses a structure to store the following information on a company division: Division name (such as East, West, North, or South) Quarter (1, 2, 3, or 4)Quarterly salesThe user should be asked for the four quarters’ sales figures for the East, West, North, and South divisions. The information for each quarter for each division should be written to a file.arrow_forwardwrite a function called fillArrayFromFilethat will read numbers from a file that contains one double per line into an array(up to the size of the array) and then returns the number of doubles successfully readfrom the file. You may assume that the file contains valid doublesarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education