Write a program that reads a set of integers from a file use

Write a program that reads a set of integers from a file (use the attached data file and remember to import File and IOException classes). The program then finds the average (displays the avenge to 2 decimal places), and print the numbers above and below the average, 10 numbers in a row. Here is an example of the output: Drop the following 3 files (Don\'t Zip Them) in Blackboard before 10:30 am on the due day. Only when the Blackboard does not work, email it to me (sgarcia-otero@vsu.edu).

Solution

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

    std::fstream input(\"data.txt\");

   if (!input.is_open())

   {

        std::cout << \"There was an error opening data.txt\";

        return -1;

   }

   

   int number = 0;

    int zero = 0;

    int even = 0;

    int odd = 0;

    int sumEven = 0;

   int sumOdd = 0;

while (number != \'x\')

    for (int i = 0; i < 10; i++)

   {

        switch (number % 2)

        {

        case 0:

            even++;

            if (number == 0)

                zero++;

           sumEven = sumEven + 1;

            break;

        case 1:

        case -1:

            odd++;

            sumOdd = sumOdd + number;

        }

   }

   input.close();

   std::cout << \"The sum of the even numbers in file data.txt is: \" << sumEven << endl;

   system(\"pause\");

    system(\"pause\");

      return 0;

}

 Write a program that reads a set of integers from a file (use the attached data file and remember to import File and IOException classes). The program then fin
 Write a program that reads a set of integers from a file (use the attached data file and remember to import File and IOException classes). The program then fin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site