i am creating a program where im trying to read in a data from a file into 4 different arrays by using a class but im having trouble with the syntax of it. does anyone know some good sites that can help?

The syntax for creating an array that's a member of a class is:

class MyClass
{
public:
   ...

private:
   int array[4];
};

Note that you don't necessarily have to declare it as a private member.

This is something similar.

ok so i got my class to work now im having confusing errors with this:

void sort(Student stu[], int parameter, int count)
{
   Student temp;
	
   bool finished = false;
   while (!finished)
   {
      finished = true;
      for (int i = 0; i< count-1; i++)
      {
[79]       if(Student[i].compareTo(Student[i+1], parameter) == true)
[80]       {
	temp = stu[i];
	stu[i] = stu[i+1];
	stu[i+1] = temp;
	finished = false;
             }
     }
  }
}

the errors are
1>h:\cs 215\program 2\program 2\program 2.cpp(79) : error C2059: syntax error : '['
1>h:\cs 215\program 2\program 2\program 2.cpp(80) : error C2143: syntax error : missing ';' before '{'

and my compareTo function is:

bool Student::compareTo (Student stu2, int parameter)
{
	if (parameter ==1)
	{
		if(FirstName < stu2.FirstName)
			return false;
		else 
			return true;
	}
	if (parameter ==2)
	{
		if(LastName < stu2.LastName)
			return false;
		else 
			return true;
	}
	if (parameter ==3)
	{
		if(GPA < stu2.GPA)
			return false;
		else
			return true;
	}
	if (parameter ==4)
	{
		if(age < stu2.age)
			return false;
		else
		    return true;
	}
}

Well, Student is a class, not an object. Thus, the compiler doesn't know what to do when it encounters Student.DoSomething(); . My guess is that you meant to use your array of Student objects, stu[] .

To get rid of the compiler errors, first remove the items in red

void sort(Student stu[], int parameter, int count)
{
<snip>
      for (int i = 0; i< count-1; i++)
      {
[79]       if(Student[i].compareTo(Student[i+1], parameter) == true)
[80]    {
<snip>
     }
  }
}

and then change the

if(Student[i].compareTo(Student[i+1], parameter) == true)
to
if([B]stu[/B][i].compareTo([B]stu[/B][i+1], parameter) == true)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.