Question

Write a C++ program that open the text file “numbers.txt”. (the numbers.txt looks like: ' 1....

Write a C++ program that open the text file “numbers.txt”.

(the numbers.txt looks like: ' 1. 6 8 ')

Have a “output.txt”

If summation of the numbers is bigger than 10, your code must write the first number inside “numbers.txt” in another file called “output.txt”.

(use conditional statement for comparison)

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

/*
 *  C++ Program for illustrating the concepts of file hndling
 */

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

int main()
{
  fstream ifile, ofile;
  ifile.open("numbers.txt", ios :: in);
  ofile.open("output.txt", ios :: out);

  int num1, num2, num3;

  ifile >> num1;
  ifile >> num2;
  ifile >> num3;

  if ((num1 + num2 + num3) > 10)
    ofile << num1;
  
  ifile.close();
  ofile.close();
  
  return 0;
}

/*  Program ends here */

Note: Please provide a complete file or more sets of input and output examples, I will test the code for them to ensure you or drop a comment for your queries.

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that open the text file “numbers.txt”. (the numbers.txt looks like: ' 1....
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
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