Question: Need help and some tips on how to get this program to work. The program takes in integer numbers from a .dat file and puts

Need help and some tips on how to get this program to work. The program takes in integer numbers from a .dat file and puts them into an array. I have been able to read the number from the .dat file but i also need to be able to output 3 more values to the .dat file from user input. Once all the values are in the array, the program uses a reverse bubble sort method of sorting the values of the array. There is something going wrong with my b_sort function but im not quite sure what it is.

What I need:

Implementation of the load_from_file function

Implementation of the save_to_file function

Correction of the b_sort function

-----------------------------------------------------------------------------

Here is what I have in my main so far:

#include #include #include #include "numlist.h"

using namespace std;

int main(){ ifstream inputfile; string inputfilename; int array_size = 1000; char * array = new char[array_size]; cout << "Input file name: "; getline (cin, inputfilename); inputfile.open(inputfilename.c_str(),ios::in | ios::binary); string line; if (inputfile.is_open()){ int position = 0; int numToSave; cout << "file opened successfully "; while (!inputfile.eof() && position < array_size){ inputfile.get(array[position]); position++; }

for(int i = 0; array[i] != '\0'; i++) { cout << array[i]; } inputfile.close(); } else cout << "Unable to open file "; return 0; }

Here is the numlist.cc

---------------------------------------------------------------

#include "numlist.h" #include #include #include using namespace std;

// Constructor NumList::NumList(){ used = 0; }

void NumList::insert(int num){ if(used

void NumList::load_from_file(istream& ins){

} void NumList::save_to_file(ostream& outs){

} void NumList::see_all()const{ if(used == 0) cout<<"Empty list. "; else for(size_t i = 0; i= 0; --j){ if(data[j] < data[j-1]){ done = false; tmp = data[j]; data[j] = data[j-1]; data[j=1] = tmp; } } } }

Here is numlist.h

-----------------------------------------------------------

#ifndef NUMLIST_H #define NUMLIST_H #include #include #include

class NumList{ public: static const size_t CAPACITY = 100; // Default constructor NumList();

void insert(int num); size_t size()const {return used;}

void load_from_file(std::istream& ins);

void save_to_file(std::ostream& outs); void b_sort(); int get_item(size_t index)const; void see_all()const; private: int data[CAPACITY]; size_t used; };

#endif

And finally here is the smaller.dat file

-----------------------------------------------------------

14140 22089 26522 5203 9172 4435 28318 24583 6816 4587

Thank you very much for your time. Any help you can provide is very much appreciated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!