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;
}
```
You might also like to view...
A function that is a member of a class is called __________ .
a. a module b. a method c. a component d. an element
What output is sent to the file out.dat by the following code, assuming these lines of code are embedded in a correct program?
``` ofstream fout; fout.open("out.dat"); fout << "*" << setw(5) << 123 << "*" << 123 << "*" << endl; fout.setf(ios::showpos); fout << "*" << setw(5) << 123 << "*" << 123 << "*" << endl; fout.unsetf(ios::showpos): fout.setf(ios::left); fout << "*" << setw(5) << 123 << "*" << setw(5) << 123 << "*" << endl; ```
You download Windows apps from the Windows Store
Indicate whether the statement is true or false
The Charms give you ________ different options from which you can choose
A) 3 B) 5 C) 6 D) 10