Advertisement
Guest User

C++

a guest
Dec 16th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. static const int max_word_count = 50;
  7. static const int word_length = 30;
  8.  
  9. int read_in(string e[][word_length], string f[][word_length]);
  10. void sort_words(string e[][word_length], string f[][word_length], const int used);
  11. void search_words(const string e[][word_length], const string f[][word_length], const int used);
  12. void write_out(const string e[][word_length], const string f[][word_length], const int used);
  13.  
  14. int main()
  15. {
  16.     string englishWords[max_word_count][word_length];
  17.     string frenchWords[max_word_count][word_length];
  18.     int num;
  19.     num = read_in(englishWords, frenchWords);
  20.     sort_words(englishWords, frenchWords, num);
  21.     search_words(englishWords, frenchWords, num);
  22.     write_out(englishWords, frenchWords, num);
  23.     return(0);
  24. }
  25.  
  26. int read_in(string e[][word_length], string f[][word_length])
  27.  
  28. {
  29.     ifstream infile;
  30.     infile.open("dict.txt");
  31.     if(!infile)
  32.     {
  33.         cout<<"Error opening output file"<<endl;
  34.         return -1;
  35.     }
  36.    
  37.     int count = 0;
  38.     while(count<max_word_count && infile >> e[count][word_length])
  39.     {
  40.         while(cin.peek()==' ')
  41.             cin.get();
  42.         getline(cin, f[count++][word_length]);
  43.     }
  44.    
  45.     infile.close();
  46.     //what do mean by return number used?
  47. } //have warning here says "Control reaches end of non-void function"
  48.  
  49. void sort_words(string e[][word_length], string f[][word_length], const int used)
  50. {
  51.     for(int i = 0; i < used; i++)
  52.     {
  53.         for(int j = (i + 1); j < used; j++)
  54.         {
  55.             if(e[j][word_length] < e[i][word_length])
  56.             {
  57.                 string temp = e[j][word_length];
  58.                 e[j][word_length] = e[i][word_length];
  59.                 e[i][word_length] = temp;
  60.                 temp = f[j][word_length];
  61.                 f[j][word_length] = f[i][word_length];
  62.                 f[i][word_length] = temp;
  63.             }
  64.         }
  65.     }
  66. }
  67.  
  68. void search_words(const string e[][word_length], const string f[][word_length], const int used)
  69. {
  70.     cout<<"Enter the English word you are searching for: ";
  71.     //getline(cin, input); // have an error here
  72.     cout<<"You entered: ";
  73.     //not sure how to do the input properly
  74.     //i would like to have this part clarified more
  75.    
  76. }
  77.    
  78.    
  79. void write_out(const string e[][word_length], const string f[][word_length], const int used)
  80. {
  81.     //and i don't get what exactly to do here
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement