First in my Person class the comments = errors visual basics is giving me and I am not sure why. Also when i try and set up my array of pointers to Student class I get the error that is in the comment. This is really bothering me as I spent the last hour and a half with a classmate working on this and we can not figure out whats up.
Expand|Select|Wrap|Line Numbers
- class Person
- {
- public:
- Person(int sinNumber, char studentName[]);
- int compareByBirthday(Student & s); //syntax error identifier Student
- int compareByEmailAddress(Student & s); //syntax error identifier Student
- int compareByMajor(Student & s); //syntax error identifier Student
- int compareByName(Student & s); //syntax error identifier Student
- int compareBySin(Student & s); //syntax error identifier Student
- private:
- int sin;
- char name[30];
- };
- Person::Person(int sinNumber, char studentName[])
- {
- sin = sinNumber;
- strcpy (name, studentName);
- }
- int Person::compareByBirthday()
- {
- return 0;
- }
- int Person::compareByEmailAddress()
- {
- return 0;
- }
- int Person::compareByMajor()
- {
- return 0;
- }
- int Person::compareByName()
- {
- return 0;
- }
- int Person::compareBySin()
- {
- return 0;
- }
- class Student : Person
- {
- public:
- Student(int sinNumber, char studentName[], int bDay, char email[], char mjr[]);
- private:
- int birthday;
- char emailAddress[30];
- char major[10];
- };
- Student::Student(int sinNumber, char studentName[], int bDay, char email[], char mjr[]) : Person(sinNumber, studentName)
- {
- birthday = bDay;
- strcpy (emailAddress, email);
- strcpy (major, mjr);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- Student *stu = new Student[6]; //No appropriate default constuctor available
- char recordIn[255];
- ifstream infile;
- infile.open("studentFile.txt");
- if(!infile)
- {
- cout<<"Cannot open file."<<endl;
- }
- else
- while(infile)
- {
- infile.getline(recordIn, 255);
- cout<<" "<<recordIn<<endl;
- }
- return 0;
- }
Using 2 classes (with inheritance) compare students (these functions in my program were given by prof). My main program is supposed to read in a .txt file and dynamically create my student objects (txt file contains sin#, birthday, etc..) and the user should be able to sort by each of the attributes found in the txt file. I can only assure you that I have spent the better part of my day trying to write this dam thing and have failed miserably. If someone could please explain to me why I am getting these errors and a possible point in the right direction I would appreciate it.
Also I am unclear about the whole dynamic creation of the Student objects. I tried reading the file into an array and creating it but that doesn't seem to be possible.