Write a program to create a file named temp.txt if it does not exist. Write one hundred integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read the data back from the file and display the sorted data.

What will be an ideal response?

```
#include
#include
#include
#include
using namespace std;

void selectionSort(int list[], int arraySize)
{
for (int i = arraySize - 1; i >= 1; i--)
{
// Find the maximum in the list[0..i]
int currentMax = list[0];
int currentMaxIndex = 0;

for (int j = 1; j <= i; j++)
{
if (currentMax < list[j])
{
currentMax = list[j];
currentMaxIndex = j;
}
}

// Swap list[i] with list[currentMaxIndex] if necessary;
if (currentMaxIndex != i)
{
list[currentMaxIndex] = list[i];
list[i] = currentMax;
}
}
}

int main()
{
ofstream output;

// Create a file
output.open("temp.txt", ios::out | ios::app);

srand(time(0));

for (int i = 0; i < 100; i++)
{
output << rand() << " ";
}

output.close();


ifstream input;

// Open a file
input.open("temp.txt");

int numbers[100];
int i = 0;
while (!input.eof()) // Continue if not end of file
{
input >> numbers[i];
i++;
}
input.close();

selectionSort(numbers, 100);

for (int i = 0; i < 100; i++)
cout << numbers[i] << endl;

cout << "Done" << endl;

return 0;
}
```

Computer Science & Information Technology

You might also like to view...

A user is experiencing slowness while opening documents from the hard drive. Which of the following tools should a technician use as a FIRST step in solving this problem?

A. Defrag B. Event Viewer C. Performance Monitor D. Regedit

Computer Science & Information Technology

A DSS manipulates the data needed to make a decision as well as making a decision.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology