473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dynamic Creation of objects... and some errors i cant figure out

94
Any help here is appreciated folks.

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
  1. class Person
  2. {
  3. public:
  4.     Person(int sinNumber, char studentName[]);
  5.     int compareByBirthday(Student & s);            //syntax error identifier Student
  6.     int compareByEmailAddress(Student & s);        //syntax error identifier Student
  7.     int compareByMajor(Student & s);            //syntax error identifier Student
  8.     int compareByName(Student & s);                //syntax error identifier Student
  9.     int compareBySin(Student & s);                //syntax error identifier Student
  10. private:
  11.     int sin;
  12.     char name[30];
  13. };
  14. Person::Person(int sinNumber, char studentName[])
  15. {
  16.     sin = sinNumber;
  17.     strcpy (name, studentName);
  18. }
  19. int Person::compareByBirthday()
  20. {
  21.     return 0;
  22. }
  23. int Person::compareByEmailAddress()
  24. {
  25.     return 0;
  26. }
  27. int Person::compareByMajor()
  28. {
  29.     return 0;
  30. }
  31. int Person::compareByName()
  32. {
  33.     return 0;
  34. }
  35. int Person::compareBySin()
  36. {
  37.     return 0;
  38. }
  39.  
  40. class Student : Person
  41. {
  42. public:
  43.     Student(int sinNumber, char studentName[], int bDay, char email[], char mjr[]);
  44. private:
  45.     int birthday;
  46.     char emailAddress[30];
  47.     char major[10];
  48. };
  49. Student::Student(int sinNumber, char studentName[], int bDay, char email[], char mjr[]) : Person(sinNumber, studentName)
  50. {
  51.     birthday = bDay;
  52.     strcpy (emailAddress, email);
  53.     strcpy (major, mjr);
  54. }
  55.  
  56.  
  57. int _tmain(int argc, _TCHAR* argv[])
  58. {
  59.     Student *stu = new Student[6];    //No appropriate default constuctor available
  60.     char recordIn[255];
  61.     ifstream infile;
  62.     infile.open("studentFile.txt");
  63.     if(!infile)
  64.     {
  65.         cout<<"Cannot open file."<<endl;
  66.     }
  67.     else 
  68.         while(infile)
  69.         {
  70.             infile.getline(recordIn, 255);
  71.             cout<<" "<<recordIn<<endl;
  72.         }
  73.     return 0;
  74. }
  75.  
Here is an overview of my project.
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.
Jan 27 '07 #1
1 1560
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. // Declaration
  2.     int compareByBirthday(Student & s);    
  3.  
  4. // Definition
  5. int Person::compareByBirthday()
  6. {
  7.     return 0;
  8. }
  9.  
Student sub-class person, it then seems odd, wrong even, that person should have functions that take student as a parameter. If the method is declared in Person then it should take a reference to a Person not a student. If you need the data declared in Student then the method should be a member of Student not Person.

Also note from quote code that your declaration and definition of compareByBirthday do not match (and similarly for all the other compare functions).

And finally, birthday and email address appear to be members of student, however I think that all people not just students have birthdays and email addresses, the only additional piece of data that a Student has is their major.

major and compareByMajor should be in Student, the rest should be in Person.

Reading the file shouldn't be too hard, however it will be easier if you create a sensible constructor on Student and Person that allows you to pass initialisation values into it.

Don't use a fixed size array, use a STL list or one of the other STL containers.
Jan 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Leslaw Bieniasz | last post by:
Cracow, 20.10.2004 Hello, As far as I understand, the generic programming basically consists in using templates for achieving a static polymorphism of the various code fragments, and their...
0
by: Mike Meyer | last post by:
The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to...
0
by: chris | last post by:
Hello Group, I have been trying to read books about ASP.NET/VB.NET. Cant really figure out a good way to design neat web pages using VS.NET. I would appreciate if anyone can give me some pointers...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
13
by: xian_hong2046 | last post by:
Hello, I think dynamic memory allocation is supposed to be used when one doesn't know in advance how much memory to allocate until run time. An example from Thinking in C++ is to dynamically...
1
by: None | last post by:
Dynamic array creation Hi all... here's a good one for you... I have a situation where I have some bean, and I need to populate an array field in it... here's the problem... I do not know the...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
1
by: philin007 | last post by:
Hi , I am having a page where leave is applied. - In this page 1 new rows is created dynamically everytime the 'Add row' button is pressed - Each row has a begin date text field and beside it a...
0
by: daylond | last post by:
I'm developing a robot control architecture, and am trying to maximize platform independence (robot hardware, not OS) by generating my individual behaviors as dynamic libraries. The individual...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.