Question

write a short c++ program that reads integers from a file named zzin1.dat (5,7,21,2,-9,10,3,1,11) until the...

write a short c++ program that reads integers from a file named zzin1.dat (5,7,21,2,-9,10,3,1,11) until the eof condition is reached add 1 to each value and save it to an output file named acdc1.dat

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

Program:

#include<iostream>
#include<fstream>
using namespace std;
int add( ifstream & in, ofstream & out)
{
   int count;
   while (true)
   {
       in >> count;   // copying from input file
       if(in.eof()) break;   // exiting at the end of file
       count++;       // Incrementing values of every number
       out<<count<<" ";   // copying into output file
   }
}
int main()
{  
   char inputfile[500]="zzin1.dat";
   char outputfile[500]="acdc1.dat";
   ifstream fileinp;       // stream class to read from files
   fileinp.open(inputfile);
   ofstream fileop;       // stream class to write on files
   fileop.open(outputfile);
   add(fileinp,fileop);      
   return(0);
}

Output:

zzin1.dat should have number 5 7 21 2 -9 10 3 1 11

zzin1.dat x 5 7 21 2-9 1O 3 1 11

Add a comment
Know the answer?
Add Answer to:
write a short c++ program that reads integers from a file named zzin1.dat (5,7,21,2,-9,10,3,1,11) until the...
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
  • Write a C program that reads a list of positive integers from a file named "input.txt."...

    Write a C program that reads a list of positive integers from a file named "input.txt." and count number of odd integers and even integers and prints the results to another file called "results.txt". Please submit both the input and results files along with the c program.

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • Write a C program, named sortit, that reads three integers from the command line argument and...

    Write a C program, named sortit, that reads three integers from the command line argument and returns the sorted list of the integers on the standard output screen, For instance, >sortit 3 5 7 >The sorted list is 3, 5, 7. >sortit 4 0 9 >The sorted list is 0, 4, 9 >sortit 1 p 9 >sortit: invalid input p. >sortit >usage: sortit num1 num2 num3! 1. The source code of a c file 2. Screenshots that show successful execution...

  • write a c++ code to read multiple integers from input.dat until the end of file. Edit...

    write a c++ code to read multiple integers from input.dat until the end of file. Edit input.dat and put several integers in it. Compile and execute the code then check output.dat to verify all the integers are in there. Update the code to check to see if input.dat exists before reading from it. If it doesn’t exist print an error message (and don’t read!). Compile and execute your code. Delete input.dat and output.dat and execute – did you see your...

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • C++ Programming question Problem: 5. Write a program that reads in a list of integers into...

    C++ Programming question Problem: 5. Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be...

  • I need to write a C++ program that reads two integers from a data filed called...

    I need to write a C++ program that reads two integers from a data filed called "integers.dat" The first integer should be low and the other one high. The program should loop through all integers between the low and high values and include the low and high integers and then display Display the integers in the file Displays the number of integers divisible by 5 OR 6, but not both. Displays the sum of the integers from condition 2 as...

  • C Program Question: Write a program that reads all integers that are in the range of...

    C Program Question: Write a program that reads all integers that are in the range of 0 to 100, inclusive from an input file named: a.txt and counts how many occurrences of each are in the file. After all input has been processed, display all the values with the number of occurrences that were in are in the input file. Note: The program ignores any number less than 0 or greater than 100. Note: Do not display zero if a...

  • write a C++ program that reads in a text file and reads each character or lexemes...

    write a C++ program that reads in a text file and reads each character or lexemes and states what token it is and writes to another file for example: while (fahr < upper) a = 23.00 whileend Output: token lexeme -------------------------------- keyword while separator ( identifier fahr operator < identifier upper separator ) identifier a operator = real 23.00 keyword whileend the program aslo reads in comments but does not add to the list. characters that are commented out or...

  • Write a C++ program that reads the values from a data file til the end of...

    Write a C++ program that reads the values from a data file til the end of the data file is reached. It displays the values read, and computes and displays the largest, smallest, and the average of these values

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