what is polymorphism and how can I use it

This is a discussion on what is polymorphism and how can I use it within the C++ Programming forums, part of the General Programming Boards category; in this situation? ------------------------------------------------------------------------- Book is the root class Nativebool and ForeignBook derivated from it. you want to enter a ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    34

    what is polymorphism and how can I use it

    in this situation?
    -------------------------------------------------------------------------
    Book is the root class Nativebool and ForeignBook derivated from it.

    you want to enter a number from user.
    if number is 1, you will create NativeBook object
    else if number is 2, you will create ForeignBook Object; (Polymorphism)

    int main()
    {
    Book *fptr; // you will point a object prefered by user
    ……………………………………………….
    NativeBook tf(“xxx”,”xxx”,”1997”,60);
    (1) tf.display();
    ForeignBook ff(“Brave”,”Michael Michiel”,”2002”,95,”English”);
    (2) ff.display();
    Cout<<”please give a number
    (1) Native Book
    (2) Foreign Book”;
    // You will code this area..
    ………………………………..
    fptr=&ff; // if you enter 1 polymorphism
    (3) fptr->display(); //
    ---------------------------------------------------------------------------

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    34
    foreignbook ff, behave like nativebook bf. How can I do this in this situation.

  3. #3

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    34
    thanks

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21