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

Task 1: One-dimensional arrays with integer indexes Create a new C++ project in

ID: 657526 • Letter: T

Question

Task 1: One-dimensional arrays with integer indexes

Create a new C++ project in Visual Studio, add a new C++ file and copy the following code into it:

// Program Reverse reads numbers into an array

// and prints them out in reverse order.  

#include <iostream>

#include <fstream>

using namespace std;

const int MAX = 10;

int main ()

{

    int numbers[MAX];

    ifstream inData;

    int value;

    int index;

    inData.open("reverse.txt");

    for (index = 0; index < MAX; index++)

    {

        // FILL IN Code to read value from file inData

// and store it in array numbers at position indicated by variable index

    }

   

    for (index = MAX - 1; index >= 0; index--)

        // FILL IN Code to write numbers on the screen

    system(

Explanation / Answer

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

    const int MAX = 10;

    int num[MAX],

     sum = 0, i, j, n=0, g, s;

    float avg, total;

    ifstream fin;

    fin.open("input.txt", ios::in);

    while (!fin.eof()){

          fin >> num [n];

          sum += num [n];

          greatest = num[0];

          smallest = num[0];

          if (num[n] > num[0]){

                     greatest = num[n];}

          if (num[n] < num[0]){

                     smallest = num[n];}

           n++;

          }

    total = 10.0;

    cout << "Reverse order: ";

    for ( i = 9; i >= 0; i--){

         cout << num[i];}

    avg = sum / total;

    cout << " G: " << g << endl;

    cout << "S " << s << endl;

    cout << "Sum: " << sum << endl;

    cout << "Average: " << avg << endl;    

  system ("PAUSE");     

     return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote