The following script was posted as a solution to a problem I did in school, however, when I run this exact script I get 3 warnings and the script will not complete. I have also attached the warnings. They are below the script. Any help is greatly appreciated.

#include <iostream>
#include <cstdlib>

using namespace std;

struct FullName
{
    char first[30];
    char last[30];
};

struct StudentData
{
    FullName name;
    char nid[30];
    int score;
};

bool GetString(char []);
bool GetNID(char []);
bool GetScore(int *);
void DisplayStudent(StudentData);

void main()
{
    StudentData student[100];
    int n,i;
    float aveSco = 0.0;
    char space = ' ';
    bool valid;
    int score;

    do
    {
        cout << "Enter the number of students (0-100): ";
        valid = GetScore(&n);
        if (!valid)
        {
            cout << "Invalid Entry... Try again\n";
        }
    } while (!valid);
    
    for (i=0;i<n;i++)
    {
        cout << "\nStudent #" << i+1 << endl;

        do
        {
            cout << "Enter the first name of student #" << i+1 << ": ";
            valid = GetString(student[i].name.first);
            if (!valid)
            {
                cout << "Invalid Entry... Try again\n";
            }
        } while (!valid);

        do
        {
            cout << "Enter the last name of student #" << i+1 << ": ";
            valid = GetString(student[i].name.last);
            if (!valid)
            {
                cout << "Invalid Entry... Try again\n";
            }
        } while (!valid);

        do
        {
            cout << "Enter the NID of student #" << i+1 << ": ";
            valid = GetNID(student[i].nid);
            if (!valid)
            {
                cout << "Invalid Entry... Try again\n";
            }
        } while (!valid);

        do
        {
            cout << "Enter the score of student #" << i+1 << " (0-100): ";
            valid = GetScore(&student[i].score);
            if (!valid)
            {
                cout << "Invalid Entry... Try again\n";
            }
        } while (!valid);
    }

    cout << endl << endl;
    do
    {
        cout << "Enter the curve score (0-100): ";
        valid = GetScore(&score);
        if (!valid)
        {
            cout << "Invalid Entry... Try again\n";
        }
    } while (!valid);

    for (i=0;i<n;i++)
    {
        if (student[i].score < score)
        {
            DisplayStudent(student[i]);
        }
    }

}

bool GetString(char string[])
{
    int i;
    bool validString = true;

    cin.getline(string,30);
    i=0;
    do
    {
        if (((string[i] < 'A') || (string[i] > 'Z')) &&
            ((string[i] < 'a') || (string[i] > 'z')))
        {
            validString = false;
        }
        i++;
    } while ((validString) && (i < strlen(string)));

    return validString;
}

bool GetNID(char string[])
{
    int i;
    bool validString = true;

    cin.getline(string,30);
    i=0;
    do
    {
        if (((string[i] < '0') || (string[i] > '9')) &&
            ((string[i] < 'a') || (string[i] > 'z')))
        {
            validString = false;
        }
        i++;
    } while ((validString) && (i < strlen(string)));

    return validString;
}

bool GetScore(int *score)
{
    int i;
    char string[30];
    bool validString = true;

    cin.getline(string,30);
    i=0;
    do
    {
        if ((string[i] < '0') || (string[i] > '9'))
        {
            validString = false;
        }
        i++;
    } while ((validString) && (i < strlen(string)));

    if (validString)
    {
        *score = atoi(string);
        if ((*score) > 100)
        {
            validString = false;
        } 
    }
    
    return validString;
}

void DisplayStudent(StudentData entry)
{
    cout << entry.name.first << " ";
    cout << entry.name.last  << " NID: ";
    cout << entry.nid << " Score is: ";
    cout << entry.score  << endl;
}

1>------ Build started: Project: assignment10, Configuration: Debug Win32 ------
1>Compiling...
1>file1.cpp
1>c:\users\cvarner\desktop\assignment10\assignment10\file1.cpp(124) : warning
C4018: '<' : signed/unsigned mismatch
1>c:\users\cvarner\desktop\assignment10\assignment10\file1.cpp(144) : warning
C4018: '<' : signed/unsigned mismatch
1>c:\users\cvarner\desktop\assignment10\assignment10\file1.cpp(164) : warning
C4018: '<' : signed/unsigned mismatch
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://c:\Users\cvarner\Desktop\assignment10\assignment10
\Debug\BuildLog.htm"
1>assignment10 - 0 error(s), 3 warning(s)

those warning could be safely ignored -- but to remove the warnings check the return value of strlen() -- it returns and size_t (an unsigned int), and you are attempting to compare it with an int. In the case of line 124 just change the data type of variable i to size_t

Awesome That worked.

Now another question. I ran the script and as soon as I enter a curve score and press enter, the script finishes and dissappears. I never even see the reults that are supposed to take place. This is supposed to be a solution to a problem in my class, but it is not working for me.

Can you help with this issue?

you have to put something before main() returns to stop it until you hit a key. There are several ways to do that but cin.get() is the most common in c++ programs.

I am working on a extra points assignment that I need desperately. Do I atleast have the below filled out properly?

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

class person
{
protected:
	char m_FirstName[30];
	char m_LastName[30];
public:
	void SetFirstName(char []);
	char * GetFirstName(void);
	void SetLastName(char []);
	char * GetLastName(void);
	float AverageGrade(Student [], int);
	int MaximumGradeStudent(Student [], int);
};

Here are the instructions for my extra points assignment.

- Write an object-oriented program that reads student information (first name, last name, NID, and test score) and displays the average grade and the information of the student with the highest grade.
- The student information must be stored in a Student class with the following data and methods:

protected:
char m_NID[30];
float m_Grade;
		public:
void SetNID(char []);
char * GetNID(void);
void SetGrade(float);
float GetGrade(void);

- The student class publicly inherits from the Person class which has the following data and methods:

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

- The program must request the number of students from the user and dynamically allocate an array of objects studentInfo with this size.
- The program must request all the student information on a student-by-student basis.
- The program must then compute the average grade using a global functions with the following prototype:

float AverageGrade(Student [], int);

- The program must then find the number of the student with the highest grade using a global functions with the following prototype:

int MaximumGradeStudent(Student [], int);

- Validation is NOT required on any of the data entries.

What should I do next. I am truthfully lost on this stuff.

declare class Person first because it needs to be used in class Student class Student : public Person Next you need to code the implementation of the methods of both classes.

OK I have been workin on this some more but I am still getting errors. Can you tell me why I would get these errors on the following script?

1>c:\users\cvarner\desktop\assignment10\assignment10\file1.cpp(62) : error C2664: 'Student::SetNID' : cannot convert parameter 1 from 'float *' to 'char []'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\cvarner\desktop\assignment10\assignment10\file1.cpp(69) : error C2447: '{' : missing function header (old-style formal list?)

#include <iostream>
#include <cstdlib>

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);
};

float AverageGrade(Student [], int);
int MaximumGradeStudent(Student [], int);

void main()
{
    Student *studentInfo;
    char studentFName, studentLName;
    float studentGrade, studentNID;
    int i,n;

    cout << "Enter the number of students: ";
    cin  >> n;

	studentInfo = new Student[n];

    for (i = 0;i < n; i++)
    {
        cout << "\nStudent #" << i+1 << endl;
        cout << "Enter the student's first name: ";
        cin  >> studentFName;

		cout << "Enter the student's last name: ";
        cin  >> studentLName;

		cout << "Enter the student's NID: ";
        cin  >> studentNID;

        cout << "Enter the student's grade:     ";
        cin  >> studentGrade;

		studentInfo[i].SetFirstName(&studentFName);
		studentInfo[i].SetLastName(&studentLName);
		studentInfo[i].SetNID(&studentNID);
		studentInfo[i].SetGrade(studentGrade);
	}

}

float AverageGrade(Student studentGrade[], int average);
{
    int i;
    float AveSco = 0.0;
    bool validString = true;

	for (i=0;i<Student;i++)
    {
        AveSco = AveSco + Student[i];
    }
    AveSco = AveSco / Student;
	cout << "The average student grade is: " << AveSco << endl;   
}

I have attached my overall goal as well. It has an image of what my requirements are and what the script should look like. I appreciate everyones help.

>>1>c:\users\cvarner\desktop\assignment10\assignment10\file1.cpp(62) : error C2664: 'Student::SetNID' : cannot convert parameter 1 from 'float *' to 'char []'

That means you are attempting to pass a float to a function that is expecting a character array. Look at the class for method SetNID and then look at the parameter it expects. Either change the parameter type or change the data type that you are trying to send it.

OK I got that issue fixed and now I just have one error. I am trying to get the average of the grades but I am getting this error, otherwise I could run it to see what is actually happening.

Here is the error:
\file1.cpp(78) : error C2109: subscript requires array or pointer type

My script looks like this:

#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);
};

float AverageGrade(Student [], int);
//int MaximumGradeStudent(Student [], int);

void main()
{
    Student *studentInfo;
    char studentFName, studentLName, studentNID;
    float studentGrade;
    int i,n;

    cout << "Enter the number of students: ";
    cin  >> n;

	studentInfo = new Student[n];

    for (i = 0;i < n; i++)
    {
        cout << "\nStudent #" << i+1 << endl;
        cout << "Enter the student's first name: ";
        cin  >> studentFName;

		cout << "Enter the student's last name: ";
        cin  >> studentLName;

		cout << "Enter the student's NID: ";
        cin  >> studentNID;

        cout << "Enter the student's grade:     ";
        cin  >> studentGrade;

		studentInfo[i].SetFirstName(&studentFName);
		studentInfo[i].SetLastName(&studentLName);
		studentInfo[i].SetNID(&studentNID);
		studentInfo[i].SetGrade(studentGrade);
	}

}

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[i];
    };
    AveSco = AveSco / n;
	cout << "The average student grade is: " << AveSco << endl;   
};

I cant figure out wht I need to put in the "float AverageGrade(Student [], int);" function to get it to return the average. Can someone help me?

#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);
};

float AverageGrade(Student [], int);
//int MaximumGradeStudent(Student [], int);

void main()
{
    Student *studentInfo;
    char studentFName, studentLName, studentNID;
    float studentGrade;
    int i,n;

    cout << "Enter the number of students: ";
    cin  >> n;

	studentInfo = new Student[n];

    for (i = 0;i < n; i++)
    {
        cout << "\nStudent #" << i+1 << endl;
        cout << "Enter the student's first name: ";
        cin  >> studentFName;

		cout << "Enter the student's last name: ";
        cin  >> studentLName;

		cout << "Enter the student's NID: ";
        cin  >> studentNID;

        cout << "Enter the student's grade:     ";
        cin  >> studentGrade;

		studentInfo[i].SetFirstName(&studentFName);
		studentInfo[i].SetLastName(&studentLName);
		studentInfo[i].SetNID(&studentNID);
		studentInfo[i].SetGrade(studentGrade);
	}

	
}

float AverageGrade(Student [], int n)
{
    int i;
	int ave;

	ave = /n;
	
	return ave;
};

int MaximumGradeStudent(Student [], int)
{
	int i;
	float max;

	return max;
};

Can someone tell me why the average score from the AverageGrade function is not being returned to the main function? Thanks for your help.

#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);
};

float AverageGrade(Student[], int);

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 << "The average grade is " << AverageGrade << endl;
    }

	system("PAUSE");
}

float AverageGrade(Student[], int nStudents)
{
	int i=0;
	float sumofgrades=0;
	
	float ave;
	ave = sumofgrades/nStudents;
	
	return ave;
	i++;
};

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;
}
float AverageGrade(Student[], int nStudents)
{
    // This function receives the array Student[], why are you not
    // using it here at all?
    int i=0;
    float sumofgrades=0;
    float ave;
    // sumofgrades is zero at this point, since you initialized it to zero
    // couple lines ago ...
    // so you end up dividing zero by the number of students, always 
    ave = sumofgrades/nStudents;
    return ave;
    // Here you have one line of code that never gets executed ...
    i++;
}/* ; <- you had a semicolon here, that's not allowed */

line 68: >> float AverageGrade(Student[], int nStudents)
You have to give Student array a name before you can use it, for example: float AverageGrade(Student students[], int nStudents) you had that function almost right in your post #7. Why did you decide to delete all that code? All you had to do was add a return statement at the end of the function.

This article has been dead for over six months. Start a new discussion instead.