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

(knowledge of foreign language not required.) An example of the exercise_diction

ID: 3554333 • Letter: #

Question

(knowledge of foreign language not required.)

An example of the exercise_dictionary before sorting can be found in:

http://textuploader.com/ttda

Sort the dictionary in exercise_dictionary.txt according to the Malay words (in alphabetic order), and write the sorted dictionary into the file C:mycomputerexercise_dictionary.txt In the file C:mycomputerexercise_dictionary.txt one line gives a Malay word, and the following line gives its English translation. The first several Malay words and their English translation in the exercise_dictionary.txt are given below: (Expected outcome after sorting)

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

int main () {
fstream myfile;
int i,n,j;
string data[10000][2],temp="";
myfile.open ("exercise_dictionery.txt");
for(i=0;!myfile.eof();i++)
{
getline(myfile,data[i][0],' ');
getline(myfile,data[i][1],' ');
}
n=i;

for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(data[j][0].compare(data[j+1][0])>0)
{
temp=data[j][0];
data[j][0]=data[j+1][0];
data[j+1][0]=temp;

temp=data[j][1];
data[j][1]=data[j+1][1];
data[j+1][1]=temp;
}
}
}
/*for(i=0;i<n;i++)
{
cout<<data[i][0]<<endl;
cout<<data[i][1]<<endl;
}*/
myfile.close();

ofstream file;
file.open ("exercise.txt");
for(i=0;i<n;i++)
{
file<<data[i][0]<<endl;
file<<data[i][1]<<endl;
}
file.close();
return 0;
}