Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 6.1, Problem 1STE
Program Plan Intro
File stream:
In C++, file is used for storing the data or information whereas stream is used for sequencing that data or information. Hence, file streams are used for performing the required operations on the stored data.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given 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…
Create a program that reads three lines from a text file. Each line should be read one at a time. For each word on a line, the user should be asked to specify how many syllables are in that word. The program should then inform the user if the file contains a valid Hiku using the function below:
def isHiku (firstLine, secondLine, thirdLine):if (firstLine == 5 and secondLine == 7 and thirdLine == 5):
return True return False
print("The file contains a Hiku:", isHiku(5,7,5))Note: You must replace the values in the function with the numbers counted by your program.
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.
Chapter 6 Solutions
Problem Solving with C++ (10th Edition)
Ch. 6.1 - Prob. 1STECh. 6.1 - Prob. 2STECh. 6.1 - Suppose that you are still writing the same...Ch. 6.1 - Prob. 4STECh. 6.1 - Prob. 5STECh. 6.1 - Prob. 6STECh. 6.1 - Suppose bla is an object, dobedo is a member...Ch. 6.1 - Prob. 8STECh. 6.1 - Prob. 9STECh. 6.1 - A program has read half of the lines in a file....
Ch. 6.1 - Prob. 11STECh. 6.2 - Prob. 12STECh. 6.2 - Prob. 13STECh. 6.2 - Prob. 14STECh. 6.2 - What output will be sent to the stuff.dat when the...Ch. 6.2 - Prob. 16STECh. 6.2 - In formatting output, the following flag constants...Ch. 6.2 - Here is a code segment that reads input from...Ch. 6.2 - Prob. 19STECh. 6.2 - Write the definition for a void function called...Ch. 6.2 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Prob. 24STECh. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Suppose that the program described in Self-Test...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Prob. 29STECh. 6.3 - Define a function called copyLine that takes one...Ch. 6.3 - Prob. 31STECh. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose ins is a file input stream that has been...Ch. 6.3 - Write the definition for a void function called...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Write some C++ code that will read a line of text...Ch. 6 - Write a program that will search a file of numbers...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - a. Compute the median of a data file. The median...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - Write a program that gives and takes advice on...Ch. 6 - Write a program that reads text from one file and...Ch. 6 - Prob. 7PCh. 6 - Write a program to generate personalized junk...Ch. 6 - Write a program to compute numeric grades for a...Ch. 6 - Enhance the program you wrote for Programming...Ch. 6 - Prob. 4PPCh. 6 - Write a program that will correct a C++ program...Ch. 6 - Write a program that allows the user to type in...Ch. 6 - This project is the same as Programming Project 6,...Ch. 6 - This program numbers the lines found in a text...Ch. 6 - Write a program that computes all of the following...Ch. 6 - The text file babynames2012.txt, which is included...Ch. 6 - To complete this problem you must have a computer...Ch. 6 - Write a program that prompts the user to input the...Ch. 6 - The following is an old word puzzle: Name a common...
Knowledge Booster
Similar questions
- Write a program that writes 100 integers created randomly into a file. Integers are separatedby a space in the file. Read the data back from the file and display the sorted data. Yourprogram should prompt the user to enter a file- name. If the file already exists, do not overrideit.arrow_forwardA photographer is organizing a photo collection about the national parks in the US and would like to annotate the information about each of the photos into a separate set of files. Write a program that reads the name of a text file containing a list of photo file names. The program then reads the photo file names from the text file, replaces the "_photo.jpg" portion of the file names with "_info.txt", and outputs the modified file names. Assume the unchanged portion of the photo file names contains only letters and numbers, and the text file stores one photo file name per line. If the text file is empty, the program produces no output. Ex: If the input of the program is: ParkPhotos.txt and the contents of ParkPhotos.txt are: Acadia2003_photo.jpg AmericanSamoa1989_photo.jpg BlackCanyonoftheGunnison1983_photo.jpg CarlsbadCaverns2010_photo.jpg CraterLake1996_photo.jpg GrandCanyon1996_photo.jpg IndianaDunes1987_photo.jpg LakeClark2009_photo.jpg Redwood1980_photo.jpg…arrow_forwardA photographer is organizing a photo collection about the national parks in the US and would like to annotate the information about each of the photos into a separate set of files. Write a program that reads the name of a text file containing a list of photo file names. The program then reads the photo file names from the text file, replaces the "_photo.jpg" portion of the file names with "_info.txt", and outputs the modified file names. Assume the unchanged portion of the photo file names contains only letters and numbers, and the text file stores one photo file name per line. If the text file is empty, the program produces no output. Ex: If the input of the program is: ParkPhotos.txtand the contents of ParkPhotos.txt are:…arrow_forward
- Mohammed is a freelance social media video marketing producer who makes social media commercials for different businesses. When he makes a commercial, he usually films several videos. He puts these videos together to make the final commercial. He has asked you to write the following two programs. 1) A program that allows him to enter the running time (in seconds) of each short video in a project. The running times (10 videos) are saved to a file. 2) A program that reads the contents of the file, displays the running times, and then displays the total running time of all the segments. Sample: Please enter the running time: 2 Please enter the running time: 3 Please enter the running time: 5 Please enter the running time: 8 Please enter the running time: 9 Please enter the running time: 1 Please enter the running time: 3 Please enter the running time: 2 Please enter the running time: 5 Please enter the running time: 2 The running time is: 2 The running time is: 3 The running time is: 5…arrow_forwardIN JAVA Arrange the data for your chart in a text file as follows: The first line of the file is the title for the chart The second line of the file is the units used in the chart The rest of the file contains data values for the chart alternating with the label to print with the value on the preceding line. The program must be able to produce a chart from any data file arranged as described above. The name of the data file and the output file are provided on the command line. The program must check that there are enough command line arguments and stop with a suitable message if not. The program saves the chart to the output file (2nd command line argument); it may also display the chart to the terminal, but it is not required to. In addition to the above, accept two additional command line arguments: The maximum width for the chart (just the bar itself, not including the labels) The symbol to use for the barsarrow_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 first reads the name of the text file from the user. The program then reads the text file, stores the information into four separate lists, and outputs the available food items 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'). Ex: If the input of the program is: food.txt and the contents of food.txt are: Classic ham sandwich Available sandwich Chicken salad sandwich Not available Classic cheeseburger Cheeseburger Not available Salads Water 16oz bottled water Available Caesar salad Chunks of romaine heart lettuce dressed with lemon juice Available Salads Asian salad Mixed greens with ginger dressing, sprinkled with sesame Not available Beverages Beverages Mexican food…arrow_forward
- Create a new file (in Dev C++) . In Lab 2, you created a menu for a simple calculator program. In Lab 6, you added some functionality based on the user selection. In Lab 7, you added some functionality for a main program loop and input validation. In this lab, you will create some general purpose functions to offload some of the tasks in main(). Write functions for: displaying "hello" message displaying menu displaying "goodbye" message displaying "invalid selection" message (for invalid menu selection) displaying "invalid input" message (for divide-by-zero input validation) Prototypes should be written for each function Function definitions can be in any order, after main() Call the functions as needed in main(), replacing the original code The program should: call function to display a "hello" message before presenting the menu call function to display the menu prompt user for selection accept either uppercase or lowercase for selection call function to display error message if…arrow_forwardWrite a program that asks the user for the name of a text file. The program should display the last 10 lines of the file on the screen (the “tail” of the file). If the file has less than 10 lines, the entire file is displayed, with a message that the entire file has been displayed. The program should do this by seeking to the end of the file and then backing up to the tenth line from the end.arrow_forwardA program reads the data from a file called inputFile.dat and, after doing some calculations, writes the results to a file called outFile.dat. Answer the following questions:a. After the program executes, what are the contents of the file inputFile.dat?b. After the program executes, what are the contents of the file outFile.dat if this file was empty before the program executed?c. After the program executes, what are the contents of the file outFile. dat if this file contained 100 numbers before the program executed?d. What would happen if the file outFile.dat did not exist before the program executed?arrow_forward
- Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the files and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number.arrow_forwardWrite a program in cpp that gives and takes advice on program writing. The program starts by writinga 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 adviceis kept in a file, and the contents of the file change after each run of the program. You can use your editor to enterthe initial piece of advice in the file so that the first person who runs the program receives some advice. Allow theuser 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 heradvice by pressing the Return key two times. Your program can then test to see that it has reached the end of theinput by checking to see when it reads two consecutive occurrences of the character ‘\n’.arrow_forwardC++ I have three .txt files. I want to create a program that reads those files. I want to create a program that lets me simply type in back and reads the previous file. For example: Filename: text1.txt This is text 1. Filename: text2.txt This is text 2. Filename: back This is text 1. So basically, I want a program that has a back command.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 - CONSIGNMENT
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