Thread: I'm confused, can someone help me?

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    5

    I'm confused, can someone help me?

    Assignment:
    You’ll need to make sure you have the following functions included. A description of
    each is below:

    void read(string s[], int r[][8]); - Opens and reads from a file called bcs.txt. See above for
    data format on each line of the file. The school name is stored in the s array. The
    rankings are stored in the r array. This includes the Coaches points, Harris points, and six
    computer rankings.

    void cleanse(string s[]); - Goes through each cell of the string array, and looks at each
    school’s name. It looks to see if there is an underscore anywhere in the name. If so, the
    underscore is replaced with a space.

    void score(int r[][8], double s[]); - For each row of 8 cells, determine the BCS score.

    void sort (string s[], int r[][8], double sc[]); - Looking at the BCS scores, sort the list of
    teams, rankings, and scores from highest score to lowest score. To aid in readability, you
    might consider writing some helper functions and using them here.

    void print(string s[], int r[][8], double sc[]); - Print out the school’s name, BCS score, and
    rankings (see screen shot), one per line.



    my code:
    Code:
    #include<iostream>
    #include<fstream>
    #include<bcs.txt>
    using namespace std;
    
    
    
    
    /*(void read(string s[], int r[][8]); - Opens and reads from a file called bcs.txt. See above for
    data format on each line of the file. The school name is stored in the s array. The
    rankings are stored in the r array. This includes the Coaches points, Harris points, and six
    computer rankings.
    */
    
    
    (void read(string s[], int r[][8]);
    ifstream inFile;
    inFile.open("bcs.txt");
    cout<<s[]<<r[][8]<<endl;
    inFile.close();
    return 0;
    
    
    
    
    /*void cleanse(string s[]); - Goes through each cell of the string array, and looks at each
    school’s name. It looks to see if there is an underscore anywhere in the name. If so, the
    underscore is replaced with a space.
    */
    void cleanse(string s[]);
    for(string s=0,s<s1,length();s++){
    if(s1[s]==' ')
    }
    
    
    
    
    
    
    
    
    //void score(int r[][8], double s[]); - For each row of 8 cells, determine the BCS score.
    void score(int r[][8], double s[])
    
    
    (coaches + harris + computer)/3
    
    
    
    
    
    
    
    
    
    
    
    
    /*void sort (string s[], int r[][8], double sc[]); - Looking at the BCS scores, sort the list of
    teams, rankings, and scores from highest score to lowest score. To aid in readability, you
    might consider writing some helper functions and using them here.
    */
    
    
    
    
    
    
    
    
    
    
    /*void print(string s[], int r[][8], double sc[]); - Print out the school’s name, BCS score, and
    rankings (see screen shot), one per line.
    */
    I'm lost...
    Attached Files Attached Files
    Last edited by bcd6f; 11-07-2012 at 06:10 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    A development process
    Start with the read() function by itself.

    Start simple
    Code:
    ifstream inFile;
    inFile.open("bcs.txt");
    string line;
    int lineNum;
    while ( getline(inFile,line) ) {
        cout << lineNum << " " << line << endl;
        lineNum++;
    }
    inFile.close();
    This just prints the file.

    Now replace the cout with something to just extract the school name (into say a variable called schoolName) and print it
    So instead of
    0 Wisconsin 136 104 0 0 22 22 25 25
    1 Notre_Dame 2374 1221 4 3 2 2 5 5
    2 Florida 2622 1329 2 5 1 1 1 2
    you see
    0 Wisconsin
    1 Notre_Dame
    2 Florida


    When you're happy with that, then you can assign your input array
    s[lineNum] = schoolName;

    Keep chipping away at the problem a bit at a time.
    Add lots of debug print to make sure each new step is working as expected.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    the code you posted (in the forum - not the attached files) has a couple of problems.

    1. you can't pass arrays that way. you have to either use templates to automatically determine the size, or you need to use a second parameter that contains the size.
    with templates:
    Code:
    template<int size>
    void SomeFunction(int (&array)[size])
    {
      for (int i = 0; i < size; ++i)
      {
        // do something with array[i]
      }
    }
    With a size parameter:
    Code:
    void SomeFunction(int* array, int size)
    {
      for (int i = 0; i < size; ++i)
      {
        // do something with array[i]
      }
    }
    2. your function definition syntax is inconsistent and wrong in every case. the syntax for a function is as follows:
    Code:
    ReturnType FunctionName(ParameterType1 param1, PrameterType2 param2)
    {
      ReturnType returnValue;
      // code goes here
      return returnValue; // not required if ReturnType is void
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very Confused about this....
    By Matty_Alan in forum Game Programming
    Replies: 2
    Last Post: 04-01-2010, 08:28 PM
  2. Really confused. ):
    By Rawr in forum C Programming
    Replies: 11
    Last Post: 03-26-2010, 06:44 PM
  3. I'm confused!
    By Newbeee in forum C++ Programming
    Replies: 5
    Last Post: 06-12-2006, 01:59 AM
  4. confused with cin.get()
    By Shal in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2006, 07:27 AM
  5. Very confused
    By Aerie in forum C Programming
    Replies: 3
    Last Post: 01-23-2005, 01:08 PM