Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

( I hope I will get answer ... I need asnswer JUST in C++ programming language ,

ID: 3824646 • Letter: #

Question

( I hope I will get answer ... I need asnswer JUST in C++ programming language , and NOT in any other )

Write a program that read 250 numbers from an input file. If the numbers are even put them into an array. Otherwise, put them into a Linked Lists. Sort and print the numbers in the array in descending order. Print the numbers in the Lined List in descending order.

The output file should contain the following:

1. Numbers read from a file

2. The number of even numbers

3. The number of odd numbers

4. The array printed in descending order

5. The Linked list in descending order

Please give the white box, and pseudocode

Explanation / Answer

//have used STL

// input file name input.txt

// output file name output.txt

#include<iostream>
#include<fstream>
#include<list>
#include<algorithm>
#include<iterator>
using namespace std;
struct greater
{
   template<class T>
   bool operator()(T const &a, T const &b) const { return a > b; }
};

int main()
{
   int numb;
   int arr[250];
   list<int> linked_list;
   int i = 0;
   ifstream infile("input.txt");
   ofstream outfile("output.txt");
   while (infile >> numb)
   {
       if (numb % 2 == 0)
       {
           arr[i] = numb;
           i++;

       }
       else
           linked_list.push_back(numb);
       outfile << numb <<" ";
   }
   outfile << endl;
   outfile << "The number of even numbers:" << i << endl;
   outfile << "The number of odd numbers:" << linked_list.size()<< endl;
   outfile << "The array printed in descending order" << endl;
   sort(arr, arr + 250, greater());
   int k = 0;
   while (k < i)
   {
       outfile << arr[k] << " ";
       k++;
   }
      
   outfile << endl;
   outfile << "The Linked list in descending order"<< endl;
   linked_list.sort(greater());
   list<int>::iterator itr = linked_list.begin();
   for (itr = linked_list.begin(); itr != linked_list.end(); itr++)
       outfile << *itr << " ";
   cout << " File created ";

}