GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Jun-2008, 14:10
harry1617 harry1617 is offline
New Member
 
Join Date: Apr 2008
Posts: 3
harry1617 is on a distinguished road

Polymorphic programing


Hi everybody,

I don't have any problems with a program or anything like that, so i am not sure if this forum is the correct place to ask this question, but ill try and see what happens.
I am currently learning about polymorphic programming and inheritance, but the book i am reading only gives one exercise in this area; "Create a shape hierarchy, where TwoDShape and ThreeDShape inherit form class Shape....ect." I'm sure a lot of you have seen the exercise before.
So anyway, i was wondering if anyone out there had any good ideas for exercises to do with polymorphism, because all i can find is the one i just mentioned or a simple variation of it.

Any ideas are welcome.

Harry.
  #2  
Old 21-Jun-2008, 14:48
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: polymorphic programing


One example, using animals (although it's a short example) can be found here.

Others that I've seen before:
1. Vehicle base class, inherited by Truck, Car, etc. classes. (including bicycles, segway's as these can also be 'vehicles')
2. Employee base class, inherited by CommissionEmployee, HourlyEmployee, and SalaryEmployee classes. (plus Faculty, Staff could be other example possibilities)
3. Account base class, inherited by CheckingAccount, SavingsAccount, CreditLineAccount classes.
4. Student base class, inherited by GraduateStudent, UndergraduateStudent classes.
5. Loan base class, inherited by CarLoan, MortgageLoan, HomeImprovementLoan classes.

I'm sure there's more, but I'll start with those. Maybe others can offer more examples.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
Last edited by TurboPT : 21-Jun-2008 at 15:58.
  #3  
Old 21-Jun-2008, 16:53
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 586
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: polymorphic programing


Quote:
Originally Posted by harry1617
So anyway, i was wondering if anyone out there had any good ideas for exercises to do with polymorphism, because all i can find is the one i just mentioned or a simple variation of it.
Anything which exhibits commonality can be implemented using polymorphism. Simply push all attributes which are shared down into base classes.

Most GUI libraries are implemented in this manner for exactly this reason.
  #4  
Old 24-Jun-2008, 22:01
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Polymorphic programing


Polymorphism is divided into two section static and dynamic.

Static polymorphism consist of function overloading and operator overloading.

Dynamic overloading is the evaluation based on object content rather than type.

References is here:
gd.tuwien.ac.at
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I load DLL files for windows programing in the Microsoft visual c++? mhasan_mitul C++ Forum 1 01-Nov-2006 14:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:09.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.