OK I redid some stuff and everything seems to be working except for the
average and the highest grade portion. Here is what I have now.
Can you see what I need to do to get this working?

#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

class Person
{
protected:
char m_FirstName[30];
char m_LastName[30];
                public:
void SetFirstName(char []);
char * GetFirstName(void);
void SetLastName(char []);
char * GetLastName(void);
};

class Student : public Person
{
protected:
        char m_NID[30];
        float m_Grade;
public:
        void SetNID(char []);
        char * GetNID(void);
        void SetGrade(float);
        float GetGrade(void);
};

void main()
{
    Student studentInfo[100];
    float studentGrade;
    int i,numStudents;
    char firstName[30], lastName[30], nid[30];

        cout << "Enter the number of Students: ";
    cin  >> numStudents;
  
        for (i=0;i<numStudents;i++)
    {
                cout << "\nStudent #" << i+1 << endl;
        cout << "  First name: ";
        cin  >> firstName;
                cout << "  Last name: ";
        cin  >> lastName;
                cout << "  NID: ";
        cin  >> nid;
        cout << "  Grade:      ";
        cin  >> studentGrade;

        studentInfo[i].SetFirstName(firstName);
                studentInfo[i].SetLastName(lastName);
                studentInfo[i].SetNID(nid);
        studentInfo[i].SetGrade(studentGrade);
    }

    for (i=0;i<numStudents;i++)
    {
        cout << "Student " << studentInfo[i].GetFirstName();
        cout << "'s grade is " << studentInfo[i].GetGrade() << endl;
    }

        system("PAUSE");
}

float AverageGrade(Student [], int value)
{
        float sum = 0.0;
        int NumofVals = 0;
    
        sum += value;
    NumofVals++;
    
        return sum / NumofVals;
};

void Person::SetFirstName(char firstName[])
{
    strcpy_s(m_FirstName,firstName);
}

char * Person::GetFirstName(void)
{
    return m_FirstName;
}

void Person::SetLastName(char lastName[])
{
    strcpy_s(m_LastName,lastName);
}

char * Person::GetLastName(void)
{
    return m_LastName;
}

void Student::SetNID(char nid[])
{
    strcpy_s(m_NID,nid);
}

char * Student::GetNID(void)
{
    return m_NID;
}

void Student::SetGrade(float studentGrade)
{
    m_Grade = studentGrade;
}

float Student::GetGrade(void)
{
    return m_Grade;
}


Chris Varner, MCSA, MCDST
Network Technician
Clairson Plastics

2811 NE 14th St, Ocala, FL. 34470
Phone: (352) 732-3244 x120
Fax: (352) 368-1796
Cell: (352) 427-3555
[EMAIL PROTECTED]
http://www.clairson.com


-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Jim Dougherty
Sent: Wednesday, April 23, 2008 2:10 PM
To: [email protected]
Subject: Re: [c-prog] Please Help


[email protected] wrote:
> I need to figure out what is wrong with this. I need the average of 
> the scores to be calculated in the AverageGrade function, but I am 
> having problems. Can someone help me?
> 
> float AverageGrade(Student studentGrade, int average)
> {
> int i;
> float n;
> float AveSco = 0.0;
> bool validString = true;
> 
> for(i=0;i<n;i++)
> {
> AveSco = AveSco + n;
> };
> AveSco = AveSco / n;
> cout << "The average student grade is: " << AveSco << endl; 
> return AverageGrade;
> };
>

You have a variable 'n' in main() that you set to the number of students

via operator input (cin).

You have another variable 'n' in your AverageGrade function that has the

same name but it is not the same variable and you do not initialize it
in 
any way.  It's value is undefined.  Perhaps what you want to do is make
'n' 
or 'number_of_students' and argument that is passed in to the
AverageGrade 
function.  Also it's type should be int not float.

You have a 'for' loop in AverageGrade that is intended to calculate the
sum
of the scores for all students and you are keeping this sum in AveSco.
Just
to make thinks clearer, create a new float parameter called
sum_of_all_scores
and use it in your 'for' loop after initializing it to zero.  During
each pass 
thru your 'for' loop you need to increment sum_of_all_scores by the
current 
students score.

After you are done with the loop calculate the average score using the
sum and
the number of students.



------------------------------------

To unsubscribe, send a blank message to
<mailto:[EMAIL PROTECTED]>.Yahoo! Groups Links



Reply via email to