Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13, Problem 13RQE
Write two statements that use the pets file stream object to open a file named pets.dat. (Show how to open the file with a member function and at definition.) The file should be opened for input.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write two statements that use the people file stream object to open a file named people.dat. (Show how to open the file with a member function and at definition.) The file should be opened for output.
PROGRAM NEEDS TO MATCH EXAMPLE PHOTO
Write a program ( lab6.cpp ) that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the program. You can use your editor to enter the initial piece of advice in the file so that the first person who runs the program receives some advice. Allow the user to type in advice of any length so that it can be any number of lines long. The user is told to end his or her advice by pressing the Return key two times. Your program can then test to see that it has reached the end of the input by checking to see when it reads two consecutive occurrences of the character ‘\n’.
Hints:- You need to look at each character as it is read to see if it is…
In Python do the following:
Writing to Files: write code to write to a file called ‘writefile.txt’To write in a file we first have to open the file. That is what the first line should do so that Pythoncreates a file object to represent the file, and give the object the name f (variable). We use this variableto refer to the file. To write to the file, use the print statement with the optional file argument thatspecifies the file to write to. When done writing, close the file to make sure all the changes are saved.Remember, if writefile.txt already exists, its contents will be overwritten.
Chapter 13 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 13.1 - Name three different C++ classes that can be used...Ch. 13.1 - Name three different C++ classes that can be used...Ch. 13.1 - What is the purpose of the second parameter to the...Ch. 13.1 - Why is it important for a program to close an open...Ch. 13.1 - Which file open flag causes all output to take...Ch. 13.1 - Which file open flag causes the contents of an...Ch. 13.1 - What happens if ios: :out is used by itself to...Ch. 13.1 - What happens if ios::out is used by itself to open...Ch. 13.1 - Write a sequence of C++ statements that reads in...Ch. 13.1 - Write a sequence of C++ statements that reads in...
Ch. 13.1 - Show how to use the constructor of the fstream...Ch. 13.1 - Consider two parallel arrays of the same size, one...Ch. 13.3 - Make the required changes to the following program...Ch. 13.3 - Describe the purpose of the eof member function.Ch. 13.3 - Assume the file input.txt contains the following...Ch. 13.3 - Describe the difference between reading a file...Ch. 13.3 - Describe the difference between the getline...Ch. 13.3 - Describe the purpose of the put member function.Ch. 13.3 - What will be stored in the file out.dat after the...Ch. 13.3 - The following program skeleton, when complete,...Ch. 13.5 - Write a short program that opens two files...Ch. 13.5 - How would the number 479 be stored in a text file?...Ch. 13.5 - Describe the differences between the write member...Ch. 13.5 - What arc the purposes of the two arguments needed...Ch. 13.5 - What are the purposes of the two arguments needed...Ch. 13.5 - Describe the relationship between fields and...Ch. 13.5 - Prob. 13.27CPCh. 13.7 - Describe the difference between the seekg and the...Ch. 13.7 - Describe the difference between the tellg and the...Ch. 13.7 - Describe the meaning of the following file access...Ch. 13.7 - What is the number of the first byte in a file?Ch. 13.7 - Briefly describe what each of the following...Ch. 13.7 - Describe the mode that each of the following...Ch. 13 - Prob. 1RQECh. 13 - Before a file can be used, it must first beCh. 13 - When a program is finished using a file, it shouldCh. 13 - The__________ header file is required for file I/O...Ch. 13 - Prob. 5RQECh. 13 - The_____________ file stream data type is for...Ch. 13 - The____________ file stream data type is for input...Ch. 13 - The ______ file stream data type is for output...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write a statement that defines a file stream...Ch. 13 - Write two statements that use the people file...Ch. 13 - Write two statements that use the pets file stream...Ch. 13 - Write two statements that use the places file...Ch. 13 - If a file fails to open, the file stream object...Ch. 13 - Write a program segment that defines a file stream...Ch. 13 - The same formatting techniques used with ______...Ch. 13 - The ______ member function reports when the end of...Ch. 13 - The ______ function reads a line of text from a...Ch. 13 - The _______ member function reads a single...Ch. 13 - The _____ member function writes a single...Ch. 13 - Prob. 22RQECh. 13 - Prob. 23RQECh. 13 - Prob. 24RQECh. 13 - In C++, _______ provide a convenient way to...Ch. 13 - The _______ member function writes raw binary data...Ch. 13 - The _______ member function reads raw binary data...Ch. 13 - The ______ operator is necessary if you pass...Ch. 13 - In _______ file access, the contents of the file...Ch. 13 - In _____ file access, the contents of a file may...Ch. 13 - The _______ member function moves a files read...Ch. 13 - The ______ member function moves a files write...Ch. 13 - The _______ member function returns a files...Ch. 13 - The _______ member function returns a files...Ch. 13 - The ______ mode flag causes an offset to be...Ch. 13 - The ______ mode flag causes an offset to be...Ch. 13 - The ______ mode flag causes an offset to he...Ch. 13 - A negative offset causes the files read or write...Ch. 13 - Give a pseudocode algorithm for determining the...Ch. 13 - Give a pseudocode algorithm for comparing two...Ch. 13 - Prob. 41RQECh. 13 - Suppose that you have two text files that contain...Ch. 13 - Each of the following programs or program segments...Ch. 13 - File Previewer Write a program that asks the user...Ch. 13 - File Display Program Write a program that asks the...Ch. 13 - Punch Line Write a program that reads and prints a...Ch. 13 - Tail of a File Write a program that asks the user...Ch. 13 - String Search Write a program that asks the user...Ch. 13 - Sentence Filter A program that processes an input...Ch. 13 - File Encryption Filter File encryption is the...Ch. 13 - File Decryption Filter Write a program that...Ch. 13 - Letter Frequencies The letter e is the most...Ch. 13 - Put It Back C++ input stream classes have two...Ch. 13 - Prob. 11PCCh. 13 - Insertion Sort on a File II Modify the program...Ch. 13 - Prob. 13PCCh. 13 - Prob. 14PCCh. 13 - Inventory Program Write a program that uses a...Ch. 13 - Inventory Program Write a program that uses a...Ch. 13 - Group Project 17. Customer Accounts This program...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What is the difference between a class and an instance of a class?
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
What is the main advantage of parallel transfer over serial transfer of binary data?
Digital Fundamentals (11th Edition)
What is pseudocode?
Starting Out With Visual Basic (7th Edition)
It has been suggested that the control software for a radiation therapy machine, used to treat patients with ca...
Software Engineering (10th Edition)
Explain the problems that denormalized tables may have for insert, update, and delete actions.
Database Concepts (8th Edition)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- TRUE FALSE The dereference operator * is used to obtain the address of a variable. The void functions return noting when called. the flag eof() is FALSE at the beginning of a text file. There is no way to show text on graphic screen The reserved word struct is used when declaring a void function.arrow_forwardPlease write comments in detail to show how the code functions.arrow_forwardFile redirection allows you to redirect standard input (keyboard) and instead read from a file specified at the command prompt. It requires the use of the < operator (e.g. java MyProgram < input_file.txt) True or Falsearrow_forward
- please code in pythonredact_file: This function takes a string filename. It writes a new file that has the same contentsas the argument, except that all of the phone numbers are redacted. Assume that the filename has onlyone period in it. The new filename is the same as the original with '_redacted' added before theperiod. For instance, if the input filename were 'myfile.txt', the output filename would be'myfile_redacted.txt'. Make sure you close your output file.The first hard task in this function is to make the output filename from the input filename that waspassed in. You can break it into two pieces by splitting on the dot or by using the index method andslicing. Then put it back together again using string concatenation.We are also working with files in this one. To open a file with a filename stored in the variable fname,in read mode use the open function as such: fp = open(fname). You will need to open the outputfile in write mode: open(fname, 'w'). Then you can traverse the…arrow_forwardCan this be done in Java and not C++arrow_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_forward
- 1. Write a program that opens an output file with the filename my_name.txt, writes your name to the file, then closes the file. 2. Write a program that opens the my_name.txt file that was created by the program in problem 1, reads your name from the file, displays the name on the screen, then closes the file. Write code that does the following: opens an output file with the filename number_list.arrow_forwardPython - Next Birthdate In this task, we will write a program that reads birthdate data from a given CSV file, and given the current date, determines which person's birthday will be celebrated next. Create a function with the following signature: nextBirthdate(filename, date) filename: parameter, which represents the CSV filename. date: parameter, which represents the current date. The function should open the CSV file, read the birthdate data, and determine which person's birthday will be celebrated next, given the current date. The name of the person should be returned. In other words, given a date, find the person whose birthday is next. Sample Run birthdates.csv Draven Brock, 01/21/1952 Easton Mclean, 09/02/1954 Destiny Pacheco, 10/10/1958 Ariella Wood, 12/20/1961 Keely Sanders, 08/03/1985 Bryan Sloan,04/06/1986 Shannon Brewer, 05/11/1986 Julianne Farrell,01/29/2000 Makhi Weeks, 03/20/2000 Lucian Fields, 08/02/2018 Function Call nextBirthdate("birthdates.csv", "01/01/2022") Output…arrow_forwardThe function file_first_chars in python takes one parameter, fname, the name of a text file, and returns a string made up of the first character from each line in the file. You may assume there are no blank lines in the file. Hint: Use a for loop to iterate over the lines of the file and accumulate the string of first characters. NOTE: Return the function, don't print For example: Test Result print(file_first_chars("wordlist1.txt")) hsaemarrow_forward
- The Info.txt file contains the statement This is a file which stores some information. What is the output of the following code snippet? int main() { } ifstream read_file; read_file.open("Info.txt"); string linel; string line2; read_file >> linel; get line (read_file, line2); cout << linel << endl; cout << line2 << endl; return 0; This is a file which stores some information This is a file which stores some information This is a file which stores some information This is a file which stores some information There is no output because the code snippet does not compile.arrow_forwardread the pictures first then this is the remaining of the question. Option 2: Display the Record of a particular PatientWhen a user selects option 2, The main function prompts for and reads a PatientID. Then it calls the thefunction getPatient(patientID), which then searches for this PatientID in the text-file. If the Patient is notfound, an appropriate error message is displayed, otherwise; the Patient’s information is displayed. Inboth cases, the option waits for the Enter key to be pressed before returning control to the main menu.Please select your choice: 2Enter Patient ID: 1002Patient ID Patient Name Weight Ave. Weight Visits1002 Majed Sameer 18 .6 18 .2 2Press Enter key to continue . . .Please select your choice: 2Enter Patient ID: 1552Error: Invalid PatientPress Enter key to continue . . . Option 3: Display all Patient WeightIt prompts for- and reads a maximum weight from the user. Then it displays all patients with weight lessthan or equal to the give weight. Also, it…arrow_forwardInside Files (Use Python) Write a program that accepts an integer input, opens a file, and analyzes what and how many types of words are there in a line within the opened file. PROGRAM DESIGNThe program should be able to accept an integer input. This program should be able to open and read a file called tweets2.txt. The integer input represents the order of the line (from 1st to 5th line), within the tweets2.txt file. The program should be able to count how many stopwords, common words, unique words, and overall words are there in the line number input. In Natural Language Processing (NLP), stopwords are defined to be words with no meaning when left alone and with no context. For this activity, stopwords are words that are at most, 3 characters in length, with common words having more than 3 characters. Unique words are words, within the line, that don’t have any duplicates. Whereas overall words are the over all count of all words within the line. The program should also be able to…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License