1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Grade array assistance fast

Discussion in 'C++' started by sicwithstiX, Apr 11, 2010.

  1. sicwithstiX

    sicwithstiX New Member

    Joined:
    Apr 11, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello
    I am extremely new to C++ and currently taking it for my Computer Engineering degree. I have an assignment i've been working on and was wondering if anyone could help me out. I know I am having problems with making my functions and passing my functions. The program is pretty simple. Please, any help would be great-fast!
    Thanks
    Code:
    /************************************************************************
    * 
    *
    * Assignment: Week 6 Grade Arrays
    *
    * Write a program that asks the user how many students 
    * to process, then reads in the scores for two items, u
    * an exam score and lab average, for that many students, 
    * then calculates and displays a table of the students’ 
    * grade information. 
    *
    * Filename: gradeArray.cpp
    *
    * Input: Numeric menu items from the keyboard
    *
    * Output: Table of entered scores and calculated grades
    *
    **************************************************************************/
    #include<iostream>
    #include<iomanip>
    #define MAX_STUDENTS 20 //sets a default value that can be used for initializing the arrays
    using namespace std;
    int getStudentCount(); 
    int getExamScores(int, double[]); 
    int getLabScores(int,double[]); 
    int calculatePointGrades(double[], double[], int, double[]);
    int calculateLetterGrades(double[],char[], int); 
    int showGradeData(double[],double[],char[], double[],int); 
    double arrayExamAve(int, double[]); 
    double arrayLabAve(int, double[]); 
    void arrayPointGrades(char[], double[], int);
    char arrayLetterGrades(double[]);
    // Declare functions here, include the necessary parameters here and in the actual functions below.
    // (once the function prototypes are created, the main()
    // function can be moved back to the top of the code.)
    // Declare the arrays here
    void main() // controls program sequence (can be moved back to the top once the function parameters are defined.)
    {
    double numStudents = getStudentCount();
    cout << "You entered: " << numStudents <<" Students!" <<endl;
    //getStudentCount(numStudents);
    getExamScores(numStudents,arrayExamAve);
    //getLabScores(numStudents,arrayLabAve[lScores]);
    //calculatePointGrades(arrayLabAve[lScores],arrayExamAve[eScores],getStudentCount,arrayPointGrades[grades]);
    //calculateLetterGrades(arrayPointGrades[grades],arrayLetterGrades[grades],getStudentCount);
    //showGradeData(arrayExamAve[eScores],arrayLabAve[lScores],arrayLetterGrades[grades],arrayPointGrades[grades],getStudentCount);
    cout<<"processing has completed in main()"<<endl;// this statement is used for intial test and debugging
    cin.ignore(2);
    }
     
    int getStudentCount()// Ask for and store the number of students from user
    {
    int numStudents= 0;
    cout << "Please enter the number of students: ";
    cin >> numStudents;
    cout << endl;// this statement is used for intial test and debugging
    return numStudents; // returns the user entered number of students to main
    }
     
    int getExamScores(int numStudents, double arrayExamAve)// Gets exam scores from user, loads the array
    {
    cout << "Please enter the exam grades for each student:";
    for (int eScores = 0; eScores <= numStudents; eScores++) 
    {
    cin >> arrayExamAve[eScores];
    cout << endl;// this statement is used for intial test and debugging
    return 0; // returns no values to main
    }
    }
     
     
    int getLabScores(int numStudents,double arrayLabAve[])// Gets lab scores from user, loads the array
    {
    cout<<"Please enter the lab scores for each student:";
    for (int lScores = 0; lScores <= numStudents; lScores++)
    {
    cin >> arrayLabAve[lScores];
    cout << endl;// this statement is used for intial test and debugging
    return 0; // returns no values to main
    }
    }
     
    int calculatePointGrades(double arrayLabAve[], double arrayExamAve[], int getStudentCount,double arrayPointGrades[] )// Calculates the student's numeric grade, loads the point grade array
    { 
    // int grade=0;
    // int sum=0;
    // int pointGrade=0;
    // for (sum = 0; sum <= numStudents; sum++)
    // { sum = arrayLabAve[] + arrayExamAve[];
    // pointGrade = sum/2;
    // cin >> arrayPointGrades[grade];
    // cout << endl;
    // }
    // 
    //// this statement is used for intial test and debugging
    //return; // returns no values to main
    }
     
    int calculateLetterGrades(double arrayPointGrades[],char arrayLetterGrades[], int getStudentCount)// Determines the student's letter grade, loads the array
    { 
    char A,B,C,D,F;
    int grade;
    arrayPointGrades[grade];
    if (grade >= 90)
    cout << 'A';
    else if (grade >= 80)
    cout << 'B';
    else if (grade >= 70)
    cout << 'C';
    else if (grade >= 60)
    cout << 'D';
    else
    cout << 'F' << endl;
    cin >> arrayLetterGrades[grade];
    return 0;
    // this statement is used for intial test and debugging
    // returns no values to main
    } 
     
    //void showGradeData(double arrayExamAve[],double arrayLabAve[],char arrayLetterGrades[], double arrayPointGrades[],int getStudentCount )// Prints a table of the student's scores and grades from the arrays
    //{ 
    // cout << arrayExamAve[eScores] << arrayLabAve[lScores] << arrayLetterGrades[grades] << arrayPointGrades[grades];
    // cout <<endl;// this statement is used for intial test and debugging
    // // returns no values to main
    //}
     
    double arrayExamAve(int numStudents,double arrayExamAve[]) // Averages the student's numeric exam grades from the array
    { 
    int eScores=0;
    int sum=0;
    double ave=0;
    for (sum = 0; sum <= numStudents; sum++)
    { sum = sum + arrayExamAve[eScores];
    ave = sum/numStudents;
    }
    // this statement is used for intial test and debugging
    return ave; // returns average exam score to main
    }
     
    double arrayLabAve(int numStudents,double arrayLabAve[])// Averages the student's numeric lab grades from the array
    { 
    int lScores=0;
    int sum=0; 
    double aveg=0;
    for (sum = 0; sum <= numStudents; sum++)
    { sum = sum + arrayLabAve[lScores];
    aveg = sum/numStudents;
    }
    // this statement is used for intial test and debugging
    return aveg; // returns average lab score to main
    }
    void arrayLetterGrades(char [5], double arrayPointGrades[], int grades)
    {
    }
    //double arrayPointGrades[double grades]
    //{
    //
    // return arrayPointGrades[grades];
    //
    //}
    
     
    Last edited by a moderator: Apr 11, 2010
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Please use code blocks when posting code. The formatting is preserved, making it easier to read.

    What is going wrong? I can't see your screen from here or read your mind. Are you getting compiler errors?
    Or does it build and you get runtime errors?

    At getExamScores(numStudents,arrayExamAve);
    I get the error
    cannot convert parameter 2 from 'double (__cdecl *)(int,double [])' to 'double []'
    (compiling in Visual Studio 2008)

    Checking definitions:
    int getExamScores(int, double[]);

    but
    double arrayExamAve(int, double[]);

    so arrayExamAve is a function, not an array of doubles. It doesn't return an array of doubles either, so the solution
    isn't to pass in the return value, i.e.
    getExamScores(numStudents,arrayExamAve());

    So what exactly do you want to pass in to getExamScores? (Hint: it needs to be a variable. But you don't seem to have any defined.)


    Another problem:
    int getExamScores(int, double[]);
    int getExamScores(int numStudents, double arrayExamAve)// Gets exam scores from user, loads the array

    The prototype must match the definition. Is the second parameter a double or an array of doubles?
     
  3. sicwithstiX

    sicwithstiX New Member

    Joined:
    Apr 11, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello

    Yes it is giving me compiler errors, mainly:

    error C2664: 'getExamScores' : cannot convert parameter 1 from 'int (__cdecl *)(void)' to 'int'
    1> There is no context in which this conversion is possible

    I know my main issue is setting up the array functions and then passing information to them and displaying them. Basically I have the main function that calls each function to it for display. There are basically 4 arrays that will be stacked side by side to show the student number in one column, the exam grade, the lab grade, the letter, etc.

    Our teacher isn't really giving us much. Students with questions are just directed back to the book....

    Anyways, I can't see your
     
  4. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    1) first of all is int main()

    2)when you ask the number of students you must validate input.
    if input is less than 1 or above max students you have problem

    so i changed your function into this
    Code:
    int getStudentCount(){// Ask for and store the number of students from user
        int numStudents= 0;
        [COLOR=Red]while (numStudents[/COLOR][COLOR=Red]<1 || numStudents[/COLOR][COLOR=Red]>MAX_STUDENTS){[/COLOR]
            cout << "Please enter the number of students: ";
            cin >> numStudents;
        }
        cout << endl;// this statement is used for intial test and debugging
        return numStudents; // returns the user entered number of students to main
    }
    

    3) you have this line in your code
    double numStudents = getStudentCount();
    since the getStudentCount() returns an int value the correct is

    Code:
    ..........
    int main(){ // controls program sequence (can be moved back to the top once the function parameters are defined.)
        [COLOR=Red]int[/COLOR] numStudents = getStudentCount();
        cout << "You entered: " << numStudents <<" Students!" <<endl;
    ......
    
    4) int getExamScores(int, double[]);
    your function does not return a value so declare this as void
    Code:
    [COLOR="Red"]void [/COLOR]getExamScores(int, double[]);
    
    5)
    in the above function there are a lot of serious mistakes.
    -you use return 0; inside the for loop so the loop executes always only 1 time.
    -you do not show any messages for what the user must enter
    -you want the values entered to be returned to main() so you want a pointer to an array
    -you use as an array name a function's name
    -in the for loop you have <=numStudents which is wrong because you start
    counting from 0.

    the correct would be

    Code:
    [COLOR="Red"]void[/COLOR] getExamScores(int numStudents, [COLOR="Red"]double *arrayExam[/COLOR]){// Gets exam scores from user, loads the array
        cout << "Please enter the exam grades for each student:"<< endl;
        for (int eScores = 0; eScores [COLOR="Red"]<[/COLOR]numStudents; eScores++){
            [COLOR="Red"]cout<<"student "<<eScores+1<<" grade=";[/COLOR]
            cin >> arrayExam[eScores];
            cout << endl;// this statement is used for intial test and debugging
        }
    }
    
    and in main() you must declare an appropriate array to store data
    Code:
    ...........
    int main(){ // controls program sequence (can be moved back to the top once the function parameters are defined.)
        int numStudents = getStudentCount();
        cout << "You entered: " << numStudents <<" Students!" <<endl;
        [COLOR="Red"]double arrayExam[numStudents];
        getExamScores(numStudents,arrayExam);[/COLOR]
    //and if you want to check the values(grades) entered add this 3 lines to your code
        for (int i=0;i<numStudents;i++)
            cout<<arrayExam[i]<<" ";//in order to check values inserted
            cout<<endl;
    ...........
    
     
    Last edited by a moderator: Apr 16, 2010
  5. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    void getLabScores(int,double[]);

    is the same with
    void getExamScores(int,double[]);

    just change Exam to Lab in all occurences.

    Code:
    .............
    int main(){ // controls program sequence (can be moved back to the top once the function parameters are defined.)
        int numStudents = getStudentCount();
        cout << "You entered: " << numStudents <<" Students!" <<endl;
        double arrayExam[numStudents];
        getExamScores(numStudents,arrayExam);
        double arrayLab[numStudents];
        getLabScores(numStudents,arrayLab);
    ........
    

    now with this in mind do the rest by yourself.
    no more excuses!!ok?
     
    Last edited: Apr 11, 2010

Share This Page