NEED HELP PLEASE!!

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.
15
98
39
37
56
82
97
80
97
19
69
84
77
75
5
87
9
93
11
14
78
100
40
67
37
88
80
81
76
31
44
62
72
53
85
56
43
88
66
71
46
93
11
2
58
2
54
59
43
86
6
88
47
6
51
11
44
14
94
38
12
87
73
84
35
66
40
54
67
93
21
66
84
100
29
60
31
27
64
17
27
37
60
60
80
32
41
15
47
80
43
59
43
21
90
96
18
65
49
59
The numbers in the project file
Last edited on
Brandonjanda, why did you write the above two posts?
need help under standing and griping the idea of this semester project
What’s the part you don’t understand?
i sent a pm
idk how to write the code or what goes in the parts that arent filled out, im sorry im very new at this.
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?
thank you, can you help me start then? what other includes would i do for this?
what other includes would i do for this?

You are opening a file, #include <fstream> would be needed.
thank you but what other ones i have that one already.
std::cerr requires <iostream>.
#include <fstream>
#include <iostream>
using namespace std;


int main() {

ifstream inFile("project.txt", ios::in);

int () ;array = new int[100];
for (int a = 0; a < array.length; a++) {
array[a] = a + 1;
}


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++;

}
int 100, temp, i, j;

for (i = 0 ; i < 100 - 1; i++)

{

for (j = 0 ; j < 100 - 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;

}

}

}

this is what i have so far idk if ive done stuff wrong or if i need more includes or not
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!!

I wish you good luck! :p
Topic archived. No new replies allowed.