Question

Implement the File Input/Output example presented in page 7. You need to create your own test.txt...

Implement the File Input/Output example presented in page 7. You need to create your own test.txt file using any text editor. The input file should have some integer values (e.g., 10 values) separated by whitespaces. Normally this input file should be placed in the same directory as the program code resides. But depending on the IDE you use, it may be a different directory in the project. Figure out which directory your IDE reads an input file from and writes an output file to.

UPLOAD THE 'new_test.txt' FILE FOR THIS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note:

#####

Please comment in case of any issue

Input file name === test.txt

output filename === new_test.txt

INPUT
#########

//######################### PGM START ###############################

#include<iostream>
#include<fstream>
using namespace std;

//main method
int main(){
  
   int number;
  
   //reading data from file test.txt
   fstream infile;
   infile.open("test.txt");
  
   //opening a file named new_test.txt to prin the data
   ofstream outfile;
   outfile.open("new_test.txt");
  
   //if the test.txt file is not present then print error and quit
   if(!infile.is_open()){
       cout<<"Test.txt file does not exist"<<"\n";
       exit(1);
   }
  
   cout<<"Reading data from input file.......\n";
   //read untill numbers are present in the test.txt file
   while(infile>>number){
       //writing numbers to output file
       outfile<<number<<" ";  
   }
   cout<<"Completed File IO operations........\n";
   return 0;
}

//######################### PGM END #################################

OUTPUT
########

Add a comment
Know the answer?
Add Answer to:
Implement the File Input/Output example presented in page 7. You need to create your own test.txt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Exceptions Suppose a library is processing an input file containing the titles of books in...

    Java Exceptions Suppose a library is processing an input file containing the titles of books in order to remove duplicates. Write a program that reads all of the titles from an input file called bookTitles.inp and writes them to an output file called uniqueTitles.out. When complete, the output file should contain all unique titles found in the input file. Create the input file using Notepad or another text editor, with one title per line. Make sure you have a number...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should...

    Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should meet the following requirements: 1. The program shall graphically prompt the user for a file. 2. The program shall read the selected file which will contain 1 integer per line. 3. The program shall sort the values it reads from the file from largest to smallest. 4. The program shall write the values to an output file from largest to smallest in the same...

  • Overview These exercises will allow you to have some practice with basic Java file Input/Output. In...

    Overview These exercises will allow you to have some practice with basic Java file Input/Output. In addition, you will also have an opportunity to have more practice with methods and arrays.   Objectives Practice with programming fundamentals Variables - Declaration and Assignment Primitive types Arithmetic Expressions Simple keyboard input and text display output Branching - if-elseif-else syntax Loops - simple while loops, nested while loops Methods - functions and procedures ArrayLists - collections of variables File I/O Works towards the following...

  • *Java* You will write a program to do the following: 1. Read an input file with...

    *Java* You will write a program to do the following: 1. Read an input file with a single line of text. Create a method named load_data. 2. Determine the frequency distribution of every symbol in the line of text. Create a method named 3. Construct the Huffman tree. 4. Create a mapping between every symbol and its corresponding Huffman code. 5. Encode the line of text using the corresponding code for every symbol. 6. Display the results on the screen....

  • python Create a program to open a text file for reading, find the maximum number in...

    python Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...

  • Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find...

    Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find the greatest common divisor of any two positive integers. It should implement the pseudocode provided in the text. It should allow the user to enter two integers.   Your program should output the intermediate values of q, r1, r2 for each step and should return the greatest common divisor. Challenge component: Allow the user's input to be zero as well as the positive integers. Provide...

  • In this module you learned how to create polymorphic code using virtual functions. A file filter...

    In this module you learned how to create polymorphic code using virtual functions. A file filter reads an input file, transforms it in some way, and writes the results to an output file. Write an abstract file filter class that defines a pure virtual function for transforming a character. Create one subclass of your file filter class that performs encryption, another that transforms a file to all uppercase, and another that creates an unchanged copy of the original file. The...

  • Description Write C++ code that correctly input and output information. (Moving data to and from the...

    Description Write C++ code that correctly input and output information. (Moving data to and from the screen and to and from text files. Also inputting predefined functions, etc., from included libraries.) Problem Description Consider a data file that has geometrical angle values in degrees. Angle values may be on one line, several lines, or any other white space separated format. Fig. 1 below shows one possible format, but other formats are possible. 12.9 100.8 270.5 300.6 120.8 There are no...

  • You need to implement a web application that is split in three parts, namely, Webpage, PHP and My...

    You need to implement a web application that is split in three parts, namely, Webpage, PHP and MySQL. Each of them will be used accordingly to solve a simple problem described below. Remember to implement the logic in the most secure way of your knowledge. PHP Implement a PHP function that reads in input a string from the user and store it in a table (e.g., in a field called "Content Name"). The function should be able to read the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT