1). Open the file "project.txt" and read the data into an integer array. Below is the sample code to open and read data from an existing file. Note. You can also refer to pp 621-622 of the textbook for a sample program.
#include <fstream>
... // other includes as needed
int main() {
ifstream inFile("project.txt", ios::in);
// declare an integer array of 100 elements here, I will name it the_array
// declare an integer to read data from file, I will name it the_input
int i{0};
if (!inFile) {
cerr << "File could not be opened" << endl;
exit(EXIT_FAILURE);
}
// to read data from the file to the array
while (inFile >> the_input) {
the_array[i] = the_input;
i++;
}
2). Once you have the data stored in the array, use the bubble sort algorithm to sort the data in ascending order. Here is the bubble sort algorithm.
int n, temp, i, j;
for (i = 0 ; i < n - 1; i++)
{
for (j = 0 ; j < n - i - 1; j++)
{
if (array[j] > array[j+1]) /* For decreasing order use < */
{
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
where n is the dimension of the array, which is 100 in this case.
3). Print the input array to the screen (using cout <<) in nice and neat order of 10 rows, 10 numbers per row.
4). Print the sorted array in 10 rows of 10 numbers as well.
4). Submit the .cpp program, and the screenshot(s) of the output of your program execution.
I’ve read your pm and I think you’re too pessimist. Do start writing your exercise and ask for help when (and only when) you’re stuck.
How can you know what you’re really able to do until you try it?
Brandonjanda, with all the respect..
Asking other programmers to do all the work for you will not make you a better programmer.
The thing you want to do is not difficult at all!
The only thing you need is just to watch some C++ tutorials and you will be able to make the program you need.
( if you don't understand something specific, ask :D )
cplusplus.com has an awesome Tutorials section, there you can find all the info you need!!