Hello everyone, I am starting to run completely out of time on an assignment that is due tomorrow. No I'm not asking for free code here, because I already have it 99% complete.
My assignment is to read a text file into an array and bubble sort them from highest to lowest. The specific file that we have to use has 19 as the first value. The 19 serves as a unit of information pertaining to how many data values are in the file. Now my current issues are that I need the 19 to not show up in the display and the other issue is that the last value in the text file is not being read. the last value in the file is 77.7 . Can some one please help me out on this? I am at yet another brick wall. Thanks in advance.
P.S. here is the data file values:
E:\numbers.txt
19
12.6
7.2
8.0
3.9
100.8
98.6
21.50
1.6
5.6
32.6
16.6
1.9
12.2
0.7
80.0
15.9
55.01
47.0
77.7
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
const int N=19;
double y[N];
void read_file()
{
int i=0;
char name[20];
double temp;
ifstream emma;
cout<<"Enter a file name."<<endl;
cout<<"This Program limits file names to a maximum of 19 characters."<<endl;
cin>>name;
emma.open(name, ios::in);
if (emma.fail())
{
cerr<<"File could not be opened"<<endl;
cin.get();
exit(1);
}
emma>>temp;
while (i < N && !emma.eof())
{
y[i] = temp;
i++;
emma>>temp;
}
}
void orig_data()
{
int i=0;
ofstream emma_1;
for(i=0; i<N + 1; ++i)
{
emma_1<<y[i];
cout<<setw(15)<<left<<y[i]<<endl;
}
emma_1.close();
}
void bb_sort()
{
double temp_1;
for(int i=1; i<N; i++)
for(int j=0; j<N-1;j++)
{
if (y[j]<y[j+1])
{
temp_1 = y[j];
y[j]= y[j+1];
y[j+1]= temp_1;
}
}
}
void main()
{
read_file();
cout<<"The original order of the data values is:"<<endl;
orig_data();
cout<<" "<<endl;
bb_sort();
cout<<" "<<endl;
cout<<"The data values from highest to lowest is:"<<endl;
orig_data();
}