Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Classes sort the .txt file This is the .txt file Lbfkoeddhoffbmg Lkcmggjcd

ID: 3548547 • Letter: U

Question

Using Classes sort the .txt file


This is the .txt file

Lbfkoeddhoffbmg

Lkcmggjcdhhglif

Cgldjhcekjigcdd

Cgldjhcekjigcdn

Bffmdbkcenlafjk

Fggdijijegfblln

Jjlncnimjldfedj

Amliglfohajcdmm

Balgfcaelhfkgeb

Kmlhmhcdcfoeilc


Sort a single column array and/or sort a 2 dimensional array

of characters given any column.  Here is what I used as my

template specification.


//This class sorts arrays either ascending or descending

template<class T>

class Prob2Sort

{

private:

int *index;                                 //Index that is utilized in the sort

public:

Prob2Sort(){index=NULL;};                   //Constructor

~Prob2Sort(){delete []index;};              //Destructor

T * sortArray(const T*,int,bool);           //Sorts a single column array

T * sortArray(const T*,int,int,int,bool);   //Sorts a 2 dimensional array

};


Driver program for the above class

cout<<"The start of Problem 2, the sorting problem"<<endl;

Prob2Sort<char> rc;

bool ascending=true;

ifstream infile;

infile.open("Problem2.txt",ios::in);

char *ch2=new char[10*16];

char *ch2p=ch2;

while(infile.get(*ch2)){cout<<*ch2;ch2++;}

infile.close();

cout<<endl;

cout<<"Sorting on which column"<<endl;

int column;

cin>>column;

char *zc=rc.sortArray(ch2p,10,16,column,ascending);

for(int i=0;i<10;i++)

{

for(int j=0;j<16;j++)

{

cout<<zc[i*16+j];

}

}

delete []zc;

cout<<endl;


The output from this problem.


The start of Problem 2, the sorting problem

Lbekoeddhoffbmg

Lkcmggjcdhhglif

Cgldjhcekjigcdd

Cgldjhcekjigcdn

Bffmdbkcenlafjk

Fggdijijegfblln

Jjlncnimjldfedj

Amliglfohajcdmm

Balgfcaelhfkgeb

Kmlhmhcddfoeilc


Sorting on column 15

Cgldjhcekjigcdn

Fggdijijegfblln

Amliglfohajcdmm

Bffmdbkcenlafjk

Jjlncnimjldfedj

Lbekoeddhoffbmg

Lkcmggjcdhhglif

Cgldjhcekjigcdd

Kmlhmhcddfoeilc

Balgfcaelhfkgeb


Explanation / Answer

So for example you wrote the text file data :

If I sort with as column 5 the output should be as below: (I have separated the sorted column by space)

Lbfk c eddhoffbmg

Lkcm d gjcdhhglif

Cgld f hcekjigcdd

Cgld g hcekjigcdn

Bffm g bkcenlafjk

Fggd i jijegfblln

Jjln j nimjldfedj

Amli j lfohajcdmm

Balg m caelhfkgeb

Kmlh o hcdcfoeilc

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote