i m studying the multiple level of inheritance.This is my code.but i have error in this line:
subject(string facultlyname,string studentsname,string code)
: facultly(facultlyname,studentsname),code(code){}
the compiler said that need declaration b4 {,can anyone tell me the error?thanks~
there is also an error saying that there is an ambiguity for the base facultly.Why?
It compiles without error here (though I do get an ambiguity warning). Can you post the actual error instead of just paraphrasing it? And can you tell us what line it's on? (EDIT: you did tell us what line -- I just wasn't reading. Sorry)
Your larger problem here is that of design. The way your classes are inherited don't make any sense.
Inheritance forms an "is a" relationship. For example, if "Poodle" is derived from "Dog", that implies that a Poodle "is a" dog.
Here, you're deriving subject from faculty, implying that a subject "is a" faculty, which makes no sense.
Furthermore, you're deriving students from faculty and subject -- when subject is already derived from faculty. This results in you have two separate faculties as parents. This is what is causing your ambiguity errors.
Rethink your design. None of these classes make sense.
i got facultly, student, subject, then how should i link together?
If you only have those 3 classes and no others, then inheritance doesn't apply. None of them are related.
The only way I can think to apply inheritance would be to make a class person and have faculty and student derive from it (since students and faculties are both people, that would make sense). However that doesn't necessarily mean it's practical to do that.
As for tying it with a subject... maybe make something like a classroom class?
Problem Statement
You are required to develop a system that models a subject registration system in a university. A student may register for many subjects and a subject may have many students. The attributes of subject and student are listed below:
· Subject: Code, faculty (faculty offering the subject), students (students taking the subject)
· Student: Name, faculty, subjects (subjects taken by the student).
Nothing in the assignment description you posted suggests you need to use inheritance.
"Attributes" generally mean "member variables". So if code, faculty, and students are attributes of Subject, then Subject has 3 member vars with those names (similar to my "classroom" example above). That doesn't mean you inherit.
this is the criteria given to complete the assignment.
1.1. Style (indentation, self-documentation, identifier) & Modularity (small size functions/methods)
1.2. Composition
1.3. Inheritance
1.4. Dynamic Polymorphism
2.2. Correct program features and results (all attributes must be shown during listing)
2.2.1. Correctly list all students after creating student(s)
2.2.2. Correctly list all subjects after creating subject(s)
2.2.3. Correctly list students from a specified subject
2.2.4. Correctly list subjects of a specified student
2.2.5. Correctly list students of a subject after a student registers for the subject
2.2.6. Correctly list students of a subject after a student drops the subject
2.2.7. Correctly list subjects of a student after the student registers for a new subject
2.2.8. Correctly list subjects of a student after the student drops a subject