Starting Out with C++ from Control Structures to Objects, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (8th Edition)
8th Edition
ISBN: 9780133862232
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 12.5, Problem 12.7CP
Assume the file input.txt contains the following characters:
What will the following program display on the screen?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream inFile (“input.txt”, ios: :in);
string item;
inFile >> item;
while (inFile)
{
cout << item << endl;
inFile >> item;
)
inFile.close();
return 0;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(C#)Assume inputFile references a StreamReader object that is associated with a file that is already open. Which statement can read all the items in the file without knowing how many items the file contains?
Question 9 options:
while (!inputFile.EndOfStream) { }
while (inputFile.EndOfStream) { }
while (inputFile != EndOFStream) { }
while (inputFile == EndOfStream) { }
Two of the menu options (#2 and #3) are unfinished, and you need to complete the code necessary to write to and read from a binary file. You will need to read through the code to find the functions that are called by these options, and then supply the missing code. Please help me get menu 2 and 3 to display properly.the .cpp and .h have the information:.cpp file:
// Corporate Sales Data Outputusing namespace std;
#include <iostream>#include <fstream>#include <stdlib.h>#include "HeaderClassActivity1.h"
int main() { Sales qtrSales[NUM_QTRS]; while (true) { cout << "Select an option: " << endl; cout << "1. Input data" << endl; cout << "2. Write data to file" << endl; cout << "3. Read data from file" << endl; cout << "4. Display sales" << endl; cout << "99. End program" << endl; int menuItem; cin >> menuItem;
if (menuItem ==…
Two of the menu options (#2 and #3) are unfinished, and you need to complete the code necessary to write to and read from a binary file. You will need to read through the code to find the functions that are called by these options, and then supply the missing code. How do I get menu 2 and 3 to display properly?the .cpp and .h have the information:.cpp file:
// Corporate Sales Data Outputusing namespace std;
#include <iostream>#include <fstream>#include <stdlib.h>#include "HeaderClassActivity1.h"
int main() { Sales qtrSales[NUM_QTRS]; while (true) { cout << "Select an option: " << endl; cout << "1. Input data" << endl; cout << "2. Write data to file" << endl; cout << "3. Read data from file" << endl; cout << "4. Display sales" << endl; cout << "99. End program" << endl; int menuItem; cin >> menuItem;
if (menuItem == 1)…
Chapter 12 Solutions
Starting Out with C++ from Control Structures to Objects, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (8th Edition)
Ch. 12.1 - Which file access flag would you use if you want...Ch. 12.1 - Prob. 12.2CPCh. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Assuming diskInfo is an fstream object, write a...Ch. 12.1 - Write a statement that defines an fstream object...Ch. 12.5 - Assume the file input.txt contains the following...Ch. 12.5 - Describe the difference between reading a file...Ch. 12.5 - What will be stored in the file out.txt after the...Ch. 12.10 - Describe the difference between the seekg and the...
Ch. 12.10 - Describe the difference between the tellg and the...Ch. 12.10 - Describe the meaning of the following file access...Ch. 12.10 - What is the number of the first byte in a file?Ch. 12.10 - Briefly describe what each of the following...Ch. 12.10 - Describe the mode that each of the following...Ch. 12 - What capability does the fstream data type provide...Ch. 12 - Which file access flag do you use to open a file...Ch. 12 - Assume the file data.txt already exists, and the...Ch. 12 - How do you combine multiple file access flags when...Ch. 12 - Should file stream objects be passed to functions...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - Under what circumstances is a file stream objects...Ch. 12 - How do you read the contents of a text file that...Ch. 12 - What arguments do you pass to a file stream...Ch. 12 - What arguments do you pass to a file stream...Ch. 12 - Prob. 12RQECh. 12 - Prob. 13RQECh. 12 - How do you get the byte number of a files current...Ch. 12 - If a program has read to the end of a file, what...Ch. 12 - How do you determine the number of bytes that a...Ch. 12 - How do you rewind a sequential-access file?Ch. 12 - The _____ file stream data type is for output...Ch. 12 - If a file fails to open, the file stream object...Ch. 12 - The same formatting techniques used with...Ch. 12 - The _____ function reads a line of text from a...Ch. 12 - The ____________ member function reads a single...Ch. 12 - The ________member function writes a single...Ch. 12 - Prob. 24RQECh. 12 - __________ files contain data formatted as...Ch. 12 - Prob. 26RQECh. 12 - Prob. 27RQECh. 12 - The ___________ member function writes raw binary...Ch. 12 - The __________ member function reads raw binary...Ch. 12 - Prob. 30RQECh. 12 - In ___________ file access, the contents of the...Ch. 12 - In __________ file access, the contents of a file...Ch. 12 - The _____________ member function moves a files...Ch. 12 - The ___________ member function moves a files...Ch. 12 - The __________ member function returns a files...Ch. 12 - The ___________ member function returns a files...Ch. 12 - The __________ mode flag causes an offset to be...Ch. 12 - The __________ mode flag causes an offset to be...Ch. 12 - The ________ mode flag causes an offset to be...Ch. 12 - A negative offset causes the files read or write...Ch. 12 - Write a statement that defines a file stream...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write two statements that use a file stream object...Ch. 12 - Write a program segment that defines a file stream...Ch. 12 - Write code that opens the file data.txt for both...Ch. 12 - Write code that determines the number of bytes...Ch. 12 - The infoFile file stream object is used to...Ch. 12 - T F Different operating systems have different...Ch. 12 - T F fstream objects are only capable of performing...Ch. 12 - T F ofstream objects, by default, delete the...Ch. 12 - T F ifstream objects, by default, create a file if...Ch. 12 - T F Several file access flags may be joined by...Ch. 12 - T F A file may be opened in the definition of the...Ch. 12 - T F If a file is opened in the definition of the...Ch. 12 - T F A file stream objects fail member function may...Ch. 12 - T F The same output formatting techniques used...Ch. 12 - T F The operator expects data to be delimited by...Ch. 12 - T F The getline member function can be used to...Ch. 12 - T F It is not possible to have more than one file...Ch. 12 - T F Binary files contain unformatted data, not...Ch. 12 - T F Binary is the default mode in which files are...Ch. 12 - T F The tellp member function tells a file stream...Ch. 12 - T F It is possible to open a file for both input...Ch. 12 - fstream file(ios::in | ios::out);...Ch. 12 - ofstream file; file.open (info.dat, ios::tin); if...Ch. 12 - fstream file("info.dat"); if (!file) { cout ...Ch. 12 - fstream dataFile("info.dat", ios:in | ios:binary);...Ch. 12 - Prob. 69RQECh. 12 - fstream dataFi1e("info.dat", ios:in); char...Ch. 12 - Prob. 71RQECh. 12 - fstream inFile("info.dat", ios:in); int x;...Ch. 12 - File Head Program Write a program that asks the...Ch. 12 - File Display Program Write a program that asks the...Ch. 12 - Punch Line Write a program that reads and prints a...Ch. 12 - Tail Program Write a program that asks the user...Ch. 12 - Line Numbers (This assignment could be done as a...Ch. 12 - String Search Write a program that asks the user...Ch. 12 - Sentence Filter Write a program that asks the user...Ch. 12 - Array/File Functions Write a function named...Ch. 12 - File Encryption Filter File encryption is the...Ch. 12 - File Decryption Filter Write a program that...Ch. 12 - Prob. 11PCCh. 12 - Prob. 12PCCh. 12 - Inventory Program Write a program that uses a...Ch. 12 - Inventory Screen Report Write a program that reads...Ch. 12 - Average Number of Words If you have downloaded...Ch. 12 - Customer Accounts This program should be designed...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
If c is a lowercase character, the expression C produces the uppercase equivalent of c, assuming an ASCII chara...
Programming in C
State which of the following are true and which are false. If a statement is false, explain why. Experience has...
C How to Program (8th Edition)
The job of the _____ is to fetch instructions, carry out the operations commanded by the instructions, and prod...
Starting Out with C++: Early Objects (9th Edition)
What output is produced by the following code? int count = 0; while (count 5) { System.out.println(count); cou...
Java: An Introduction to Problem Solving and Programming (7th Edition)
What statement do you have to have in a value-returning function?
Starting Out with Python (3rd Edition)
Explain why using model checking is sometimes a more cost-effective approach to verification than verifying a p...
Software Engineering (10th Edition)
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
- Assuming that a text file named FIRST.TXT contains some text written into it, write a function namedcopyupper(), that reads the file FIRST.TXT and creates a new file named SECOND.TXT contains allwords from the file FIRST.TXT in uppercase. (write c++ code)arrow_forwardWrite a statement that defines an fstream object named dataFile and opens afile named salesfigures.txt for input. ( Note: The file should be opened withthe definition statement, not an open function call.)arrow_forwardQuestion 1 of 1: Word Swap: Write a C++ program that will swap the words Caesar and Brutusin the file “source_file.txt”. You will need to load the file “source_file.txt” and finally write theupdated contents with the replaced words to the file “target_file.txt”.Successful operation should swap all occurrences of Caesar with Brutus and Brutus with Caesar.You can use functions from the cstring library. You are not allowed to use the string datatype.Please properly comment your code before submission.arrow_forward
- Write a function, WriteFile(), that saves information to a text file. The function receives a string value (obtained from Question 3.2) that is written to the text file. The function does not return any value to the calling statement.Store the output text file as Output.txt.The output must be added on a new line to the text file each time without erasing any existing The above functions (ReadFile(), Decode(), and WriteFile()) must now be implemented in the main program in the following order:1. Create a list of type character, i.e. the data type that is stored in the list is text.2. Read the contents of the file to the lists with ReadFile(). Display the number of lines that are read from the text file.3. Decode each card number with the Decode() function by passing the list to the function.4. As each card number is decoded, write the information to an output file with WriteFile(). The WriteFile() function should be called from within the Decode() function.arrow_forwardQuestion 1 of 1: Word Swap: Write a C++ program that will swap the words Caesar and Brutusin the file “source_file.txt”. You will need to load the file “source_file.txt” and finally write theupdated contents with the replaced words to the file “target_file.txt”.Successful operation should swap all occurrences of Caesar with Brutus and Brutus with Caesar.You can use functions from the cstring library. You are not allowed to use the string datatype. Once again, do not use string datatype.Please properly comment your code before submission.arrow_forwardin c++ input file is .txt Write a program that asks for the name of an input file. Then, read all the numbers in the file, and display the following information to the screen: count of numbers in the file sum of all numbers in the file average of all numbers in the file (to 2 decimal places) count of numbers in each range (100-199, 200-299, 300-399, etc.) The program should: display a hello message ask the user for an input file display the name of the input file validate the file opens correctly display statistical information as shown above display a goodbye messagearrow_forward
- assume the file data.dat contains a sequence of binary data. write a program that does the following: displays the first 5 bytes stored in the file. each byte should be displayed on a separate line. starting with byte 0, displays every even-numbered byte in the file. (in other words, display byte 0, byte 2, byte 4, and so on.) each byte should be displayed on a separate line. starting with byte 1, displays every odd-numbered byte in the file. (in other words, display byte 1, byte 3, byte 5, and so on.) each byte should be displayed on a separate line. displays the last 5 bytes stored in the file, in reverse order. (display the last byte, then the next-to-last byte, and so on.) each byte should be displayed on a separate line. handle exceptions in the following manner: if a filenotfoundexception is thrown, the program should display the string "file error". if an eofexception is thrown, the program should display the string "eof error". if any other exception is thrown, the program…arrow_forwardMAKE SURE THE WHOLE PROGRAM IS DONE ON WINDOWS DEV C++ with no ERRORS. This program should not include "outFile.close". Please make sure you can compile this code!!! Design a C++ program to store AND retrieve grocery information using the following guidelines: (1) Write a function named CreateGrocery List that repeatedly asks the user for grocery item and its cost and stores the information into a text file named grocery.txt (2) Your function must store at least 5 grocery items in grocery.txt (3) Write another function named ReadGrocery List that reads the information from grocery. txt and displays the information on the screen like Item Cost Apple $4.5 Banana $1.20 (4) Your program must include your information and algorithm as specified in classarrow_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. (Practice) Enter the data for the info.txt file in Figure 9.1 or download it from this book’s Web site. Then enter and execute Program 9.5 and verify that the backup file was written. 2. (Modify) Modify Program 9.5 to use a getline() function in place of the get()method currently in the program. =============1 - 9.1========== #include <iostream>#include <fstream>#include <cstdlib> // needed for exit()#include <string>using namespace std; int main(){string fileOne = "info.txt"; // put the filename up frontstring fileTwo = "info.bak";char ch;ifstream inFile;ofstream outfile;try //this block tries to open the input file{// open a basic input streaminFile.open(fileOne.c_str());if (inFile.fail()) throw fileOne;} // end of outer try blockcatch (string in) // catch for outer try block{cout << "The input file " << in<< " was not successfully opened." << endl<< " No backup was made." << endl;exit(1);}try // this block tries to…arrow_forwardWrite a function named file_stats that takes one string parameter (in_file) that is the name of an existing text file. The function file_stats should calculate three statistics about in_file: the number of lines it contains, the number of words and the number of characters, and print the three statistics on separate lines. For example, the following would be the correct input and output:>>> file_stats('created_equal.txt')lines 2words 13characters 72Note: The number of characters may vary slightly between operating systems. Similarly, the number of lines may vary by 1 line, depending on the method used to calculate it.arrow_forwardwhat is input file stream ?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 PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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