473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Parallel Array and bubble sort

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
0 2613

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

Similar topics

9
by: lawrence | last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by the second field in each row? Also, when I use sort() on a two dimensional array, it seems to work a lot like...
6
by: Xiaozhu | last post by:
say, if you had parallel arrays containing the sales person id, the month, and the sales figures (for that person in that month), sorting on sales figure and preserve the order of figures within...
3
by: Bob Dankert | last post by:
Is there any way to maintain the sort order of a sort on a 2D array? For example: I have the array: 1,a 2,a 3,f 4,a 5,s 6,a 7,z 8,b and sort it by the second column, and I...
6
by: Tamir Khason | last post by:
Let's say I have Point and I want to sort it circle way (e.g. 2;2.4;1,8;2,8,5;4;8,2;7,1;4 The algo for this is: if ((p.X<p.X & p.Y<Avg(p).Y & p.Y<Avg(p).Y) | (p.X>p.X & p.Y>Avg(p).Y &...
6
by: CodeRazor | last post by:
My array is int list = new int{20,99,6}; Using a for-loop, how can I order the output of this array. I don't want to use a sorted list. I know this is straightforward but can't figure it...
25
by: Allie | last post by:
How would I go about sorting this structure by title? typedef struct { char author; char title; char code; int hold; int loan; } LIBRARY;
5
kuchma2000
by: kuchma2000 | last post by:
Hi. I have a C program (see code below) which I need to urgrade. All I need to do is: a. Extract the temps for the City #1 and store in a one dimensional array, display the array. b. Sort the one...
20
by: Acolyte | last post by:
Hey, I'm working on a project that involves sorting a two-dimensional array of integers using bubble sort. I've got it semi-working, my only issue is that it seems to be 'losing' values, I'm assuming...
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
12
by: midknight5 | last post by:
Hello everyone, I am familiar with a normal bubble sort when dealing with an array of number but I am unsure as how to implement a sort when I have an array that is filled with classes which hold...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.