Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i've got a prgram for a college system which allows a user to determine the overall grades for a student. What I want to do is add polymorphism to this program, but im sure how I could? the program uses a base class and a derived class.


Heres the code for main:

#include "HNDStudent.h"
#include "NatdipStudent.h"

int main(int argc, char *argv[])
{
    string sname, sQT,g;
    double sID;
    char si;
    int sQL,sY;
        
    HNDstudent s2009("x", 'x', 000, 0, "x", 0, "incomplete");
    
    s2009.Set_surname(sname);
    s2009.Set_initial(si);
    s2009.Set_ID(sID);
    s2009.Set_level(sQL);
    s2009.Set_qual_title(sQT);
    s2009.Set_year(sY);
    s2009.Set_grade(g);
    
   
   cout<<s2009.Get_surname()<<endl; //inherited functions 
   cout<<s2009.Get_initial()<<endl;;
   cout<<s2009.Get_ID()<<endl;;
   cout<<s2009.Get_level()<<endl;;
   cout<<s2009.Get_qual_title()<<endl;;
   cout<<s2009.Get_year()<<endl;
   cout<<s2009.Get_grade()<<endl;
       
   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Posted

This is a homework assignment, so I'm not going to just give you the answer. I will however give you some guidance.

You have to know what polymorphism is before you can expect to be able to implement it. Since you said you're not sure how you could implement it in the specified code, I assume you don't know what it is.

After having told you that, I assume that your instructor gave you his definition of "polymorphism" (there are several different categories of polymorphism), but my guess is that he's talking about subtype (or inclusion) polymorphism.

Google is your friend.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Apr-11 13:02pm    
Good points, a 5.
--SA
Your program is already using polymorphism - just work your way through the workings of ios :)
cout<<s2009.Get_surname()<<endl;


Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Apr-11 0:54am    
He he he... and hard to argue against that! My 5.
--SA
Espen Harlinn 8-Apr-11 3:42am    
Thanks, SAKryukov :)
Polymorphism is a tool, not a purpose. You cannot "add" it as a condiment. Is it only because somebody assigned you to do so?

You probably don't have even a remote idea of what you are talking about, otherwise you wound know that there is no polymorphism without classes (you use one and don't show any code of any and don't explain the purpose of any class); you would also understand that "inherited" and "polymorphism" make no sense if you use only one class.

So, it does not matter what kind of answer you will get here: it won't help you, because you hardly will be able to understand them. You need education, not answers. And it's well beyond of the CodeProject format to educate you. Read books, search Web and do elementary exercise. It will take considerable time. After you know the very basics, you will be able to get some help through Questions-and-Answers.

Sorry,
—SA
 
Share this answer
 
Comments
Espen Harlinn 6-Apr-11 17:02pm    
Nice reply :)
Sergey Alexandrovich Kryukov 6-Apr-11 18:59pm    
Thank you very much.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900