By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,415 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

Parallel Array and bubble sort

P: 3
I'm trying to write a program that takes numbers from a text file and then sorts them first by name and then by the average. When I go to compile I get 3 overload errors and I can't figure out where I am going wrong, I haven't written the sorting functions yet I am just trying to get my read and write functions to work properly. Any help would be appreciated. Here is the code
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. #include <fstream>
  4. #include <iomanip>
  5. using std::setiosflags;
  6. using std::resetiosflags;
  7. using std::setw;
  8. using std::setprecision;
  9.  
  10. int read (char filename[], char names[][30], int scores[][3], double averages[]);
  11. void write (char filename[], int mode, char description[], char names[][30], int scores[][3], double averages[], int numberOfStudents);
  12. //void bubbleSortByName (char names[][30], int scores[][3], double averages[], int numberOfStudents);
  13. //void bubbleSortByAverage (char names[][30], int scores[][3], double averages[], int numberOfStudnets);
  14.  
  15. char names [100][30];
  16. int scores [100][ 3];
  17. double averages [100];
  18.  
  19. int main ()
  20. {
  21.  
  22.  
  23.     cout << ':' << setiosflags(ios::left) << setw(30) << "hello, world!" << resetiosflags(ios::left) << ':';
  24.     cout << setiosflags(ios::fixed|ios::showpoint) << setw(7) << setprecision(2) << 3.1415927 << ':' << endl;
  25.  
  26.     int numberOfStudents = read ("dataHw.txt", names, scores, averages);
  27.     write ("sortHw.txt", ios::out, "Pre-Sorting", names, scores, averages, numberOfStudents);
  28.  
  29.     //bubbleSortByName (names, scores, averages, numberOfStudents);
  30.     //write ("sortHw.txt", ios::app, "Sorted by Name", names, scores, averages, numberOfStudents);
  31.  
  32.     //bubbleSoryByAverage (names, scores, averages, numberOfStudents);
  33.     //write ("sortHw.txt", ios::app, "Sorted by Average", names, scores, averages, numberOfStudents);
  34.  
  35.     return 0;
  36. }
  37.  
  38. int read (char filename[], char names[][30], int scores[][3], double averages)
  39. {
  40.  
  41.     ifstream infile (filename);
  42.     if(!infile)
  43.     {
  44.         cout << "File not found!";
  45.         exit(1);
  46.     }
  47.     int numberOfStudents = 0;
  48.     read (infile, names[numberOfStudents], scores[numberOfStudents], averages);
  49.     while (strcmp(names[numberOfStudents],"zzz")!=0)
  50.     {
  51.         numberOfStudents++;
  52.         read (infile, names[numberOfStudents], scores[numberOfStudents], averages);
  53.     }
  54.     infile.close ();
  55.  
  56.     return numberOfStudents;
  57. }
  58.  
  59. void write (char filename[], int mode, char description[], char names[][30], int scores[][3], double averages[], int numberOfStudents)
  60. {
  61.     ofstream outfile (filename, ios::out);
  62.     outfile << description << endl;
  63.     for (int i = 0; i < numberOfStudents; i++)
  64.     {
  65.  
  66.         write (outfile, names[i], scores[i], averages[i]);
  67.         outfile << endl;
  68.     }
  69.     outfile << endl;
  70.     outfile.close ();
  71.     return;
  72. }
  73.  
Nov 15 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.