Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 10, Problem 9E
Repeat the previous exercise, but write the new lines to a new binary file instead of a text file.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program to copy an existing text file from your hard disk to another file that you will call: Your Last Name.txt, e.g. if your last name was Smith, the output file name would be Smith.txt. You can create a text file and add two or three lines of text to it. You may use the attached program as your program or write your own. Please note the inclusion of at the top of the program. Also pay attention to the open and close statements in the program.
// File: CopyFile.cpp
// Copies file InData.txt to file OutData.txt
#include // for the definition of EXIT_FAILURE
#include // required for external file streams
#include
using namespace std;
// Associate stream objects with external file names
#define inFile "InData.txt"
#define outFile "OutData.txt"
// Functions used ...
// Copies one line of text
int copyLine(ifstream&, ofstream&);
int main()
{
// Local data ...
int lineCount; // output: number of lines processed
ifstream ins; // ins is…
Suppose that you have two text files that contain sequences of integers separated by white space (blank space, tabs, and line breaks). The integers in both files appear in sorted order, with smaller values near the beginning of the file and large values closer to the end. Write a pseudocode algorithm that merges the two sequences into a single sorted sequence that is written to a third file.
You have a huge text file with words in it. Find the smallest distance (in terms of number of words) between any two words in the file. Can you optimise your solution if the procedure will be performed several times for the same file (but different pairs of words)?
Chapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 10.1 - Why would anybody write a program that sends its...Ch. 10.1 - When we discuss input, are we referring to data...Ch. 10.1 - What is the difference between a text file and a...Ch. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Prob. 5STQCh. 10.2 - Prob. 6STQCh. 10.2 - Prob. 7STQCh. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Suppose you run a program that writes to the text...Ch. 10.2 - Prob. 10STQ
Ch. 10.3 - Prob. 11STQCh. 10.4 - Write some Java code to create an output stream of...Ch. 10.4 - Give three statements that will write the values...Ch. 10.4 - Give a statement that will close the stream toFile...Ch. 10.4 - What import statement(s) do you use when creating...Ch. 10.4 - Prob. 16STQCh. 10.4 - Give three statements that will read three numbers...Ch. 10.4 - Give a statement that will close the stream...Ch. 10.4 - Can you use writeInt to write a number to a file...Ch. 10.4 - Can you use readUTF to read a string from a text...Ch. 10.4 - Prob. 21STQCh. 10.4 - Prob. 22STQCh. 10.4 - Does the class FileInputStream have a method named...Ch. 10.4 - Does the class FileOutputStream have a constructor...Ch. 10.4 - Does the class ObjectOutputStream have a...Ch. 10.4 - Prob. 26STQCh. 10.4 - Suppose that a binary file contains exactly three...Ch. 10.4 - The following code appears in the program in...Ch. 10.4 - Prob. 29STQCh. 10.5 - Prob. 30STQCh. 10.5 - Prob. 31STQCh. 10.5 - Prob. 32STQCh. 10.5 - Prob. 33STQCh. 10.6 - Prob. 34STQCh. 10.6 - Prob. 35STQCh. 10 - Write a program that will write the Gettysburg...Ch. 10 - Modify the program in the previous exercise so...Ch. 10 - Write some code that asks the user to enter either...Ch. 10 - Write a program that will record the purchases...Ch. 10 - Modify the class LapTimer, as described in...Ch. 10 - Write a class TelephoneNumber that will hold a...Ch. 10 - Write a class contactInfo to store contact...Ch. 10 - Write a program that reads every line in a text...Ch. 10 - Repeat the previous exercise, but write the new...Ch. 10 - Write a program that will make a copy of a text...Ch. 10 - Suppose you are given a text file that contains...Ch. 10 - Suppose that you have a binary file that contains...Ch. 10 - Suppose that we want to store digitized audio...Ch. 10 - Write a program RecoverSignal that will read the...Ch. 10 - Even though a binary file is not a text file, it...Ch. 10 - Write a program that searches a file of numbers...Ch. 10 - Write a program that reads a file of numbers of...Ch. 10 - The following is an old word puzzle: Name a common...Ch. 10 - The Social Security Administration maintains an...Ch. 10 - The following is a list of scores for a game....Ch. 10 - Write a program that checks a text file for...Ch. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Revise the class Pet, as shown in Listing 6.1 of...Ch. 10 - Write a program that reads records of type Pet...Ch. 10 - Prob. 12PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
You do not need to have an import statement in a program to use the functions in the random module
Starting Out with Python (4th Edition)
What are the two basic types of stationary spot-welding machines?
Degarmo's Materials And Processes In Manufacturing
Porter’s competitive forces model: The model is used to provide a general view about the firms, the competitors...
Management Information Systems: Managing The Digital Firm (16th 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 (8th Edition)
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction To Programming Using Visual Basic (11th Edition)
Sum of Numbers Assume that a file containing a series of integers is named numbers.dat and exists on the comput...
Starting Out with Programming Logic and Design (5th 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
- Write a program to copy an existing text file from your hard disk to another file that you will call: Your Last Name.txt, e.g. if your last name was Smith, the output file name would be Smith.txt. You can create a text file and add two or three lines of text to it. You may use the attached program as your program or write your own. Please note the inclusion of <fstream> at the top of the program. Also pay attention to the open and close statements in the program. // LAB6.cpp// Kunika Saxena// File: CopyFile.cpp// Copies file InData.txt to file OutData.txt #include <cstdlib> // for the definition of EXIT_FAILURE#include <fstream> // required for external file streams#include <iostream>using namespace std; // Associate stream objects with external file names#define inFile "InData.txt"#define outFile "Saxena.txt" // Functions used ...// Copies one line of textint copyLine(ifstream&, ofstream&); int main(){ // Local data ... int…arrow_forwardRefer to the previous question. How many passes will it take to sort the file completely?arrow_forwardWrite a program that expands on the program below (i.e. reading data of each record in the file and storing it into data structure). The expansion involves writing all records to a file (use fprintf, call the name of the file csv). The displayed data must be accessed (and thus written) from data structure (i.e. array of structs). The format written to the file should be one line per record, with each field separated by a comma (‘,’) program should then output the number of lines in the file.test the program by creating a text file with at least 10 lines of text (of any composition). Use notepad++ to create the data file. #include<stdio.h>#include<stdlib.h> //Structurestruct Person{ char name[10];int age;float wage; }; //Main int main (int argc, char **argv) { FILE* f; if (argc != 2) { printf("No filename in the argument"); return 1; } f = fopen(argv[1], "r"); if (f == NULL) { printf("The file cannot be opened successfully:…arrow_forward
- Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name (the key field), merge the information as shown below. File 1 and file 2 are supplied. Here is an algorithm to merge the data from two files: Read a line from each data file While the end of both files has not been reached While the end of both files has not been reached Write the line from file 1 to the output file and read a new line from file 1. Else Write the line from file 2 to the output file and read a new line from file 2. Write the remaining lines (if any) from file 1 to the output file. Write the remaining lines (if any) from file 2 to the output file. See the Merging Filesslides attachedto the project in Canvasfor a visual look at this algorithm.arrow_forward1.Write a program that reads words from a text file (.txt format) and displays all the nonduplicate words in ascending order. Prepare a words.txt file with your words and pass the file name in the command line. (2 points) 2 .Write a program that reads an unspecified number of integers (unsorted) and finds the one that has the most occurrences. The input ends with the input is 0. (Enter 0 will end the input of the integers value). If several number has the same occurrences, all of them should be reported (output all with equal counts).arrow_forwardProgram in Scala that do the following:arrow_forward
- Using disk files help please, thank you.arrow_forwardCreate a cpp file containing tests for a program that takes in two numbers and outputs the addition for them. Add three tests but only write code for passing one of them.arrow_forwardHow do I seperate the parts of the code into different files properly?arrow_forward
- First, take your program and add one more feature: at the end, just before you close the file, write the word “END” all by itself on a line. Run that program once to create a file of items with “END”. Instead of reading from cin and writing to a file, you read from your file and write to cout. The only tricky part is deciding when to stop reading. In your previous code, you stopped reading when the user said they didn’t want to continue. For the new code, keep reading until you read “END” for the name of the produce. You can use “==” on strings, so if (product name == ”END”) will tell you that you can stop reading. My code: #include<iostream>#include<string.h>#include<fstream>using namespace std; int main(){ string filename; cout<<"Enter the name of the file to store the information"<<endl; getline(cin,filename); ofstream fileptr(filename.c_str()); if(!fileptr.is_open()) { cout<<"Couldn't open a file"<<endl; }…arrow_forwardWrite a program that reads the contents of a text file and prints the letter that starts the mostunique words in that file.arrow_forwardanswer this question in Python (using numpy )arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Files & File Systems: Crash Course Computer Science #20; Author: CrashCourse;https://www.youtube.com/watch?v=KN8YgJnShPM;License: Standard YouTube License, CC-BY
UNIX Programming (Part - 10) The File System (Directories and Files Names); Author: ITUTEES;https://www.youtube.com/watch?v=K35faWBhzrw;License: Standard Youtube License