Get help now
  • Pages 3
  • Words 642
  • Views 185
  • Download

    Cite

    Katrina
    Verified writer
    Rating
    • rating star
    • rating star
    • rating star
    • rating star
    • rating star
    • 5/5
    Delivery result 2 hours
    Customers reviews 876
    Hire Writer
    +123 relevant experts are online

    Polymorphism in C Essay (642 words)

    Academic anxiety?

    Get original paper in 3 hours and nail the task

    Get help now

    124 experts online

    The problem is that we need to compress our programs while still having them function correctly and process items differently depending on type or class. The solution is polymorphism.

    Polymorphism in object oriented programming is the programming language’s ability to process items differently depending on their data type or class. In other words, it is the ability to redefine methods for derived classes. The true rule for C++ polymorphism is that when one class, named A is derived from or “inherits” another class, named B, A can do anything that B can do, thus it can store pointers to A in variables declared as B. Here are examples for and the definitions of the three types of polymorphism.

    If you were to have a base class named shape, polymorphism lets the programmer define different and separate circumference methods for any number of derived classes, such as circles, rectangles, and triangles. No matter what the shape of the object is, the circumference method will always return correct. This is an example of one of three types of polymorphism. This specific type is known as parameterized polymorphism, or parametric polymorphism. Another type of polymorphism is called overloading. Overloading is a form of polymorphism that allows an object to have different meanings depending on context.

    It is most often used to reference operators that can behave differently because of the data type class or operands. This is best illustrated using X+Y. X+Y can mean different things depending on wheather x and y are simple intergers or complex data structures. Here is a clearer example:3.

    14 + 2. 0 *– floating point additions1 + “bar” *– string concatenation!The final form of polymorphism is called pure polymorphism. This form of polymorphism is a selection of a function at run time based on the class type and its position in an inheritance hierarchy. Now here is an example of polymorphism using people that a company might be interested in. They are defined in the following classes: char *name, *ident, *address, *phone;person(char *n, char *i, char *a, char *p);Through the mechanism of inheritance, all the four classes inherit the members: members name, ident, address, and phone; and the methods: get_name, get_ident, get_address, get_phone, set_address, set_phone, and print from person.

    Thus, no matter what extra functionality these classes have, they are always guaranteed to have all the functionality of a person. Anything you can possibly do to or with a person, you must also be able to do to or with a customer. A customer is a kind of person. Without polymorphism, we would need a different list for each class and would also need to define separate but almost identical functions for searching each of the four arrays, and just about every other operation: custs33=new customer(“. . .

    “,”. . . “,. . .

    );emps175=new employee(“. . . “,”. .

    . “,. . . );With polymorphism, we only need one array and just one search function: everyone33=new customer(“. .

    . “,”. . . “,.

    . . );everyone175=new employee(“. . .

    “,”. . . “,. .

    . );for (i=0; i*NUMPEOPLE; strcmp(everyonei- && (everyonei!=”NULL” if i+=”1)”name,nm)==0)In conclusion, polymorphism will save the hard working programmer lots of time. Sure it takes more understanding, but it is worth it when writing large programs. In the long run polymorphism will help the serious programmer become more efficient in his programming. In my conclusions this is a better topic for someone in a more advanced class but it is a good way to save time when writing involved programs.

    I hope to learn more about this subject as I progress in my programming, and use this newfound knowledge to my advantage.Bibliography:Deitel & DeitelHow to program C++2nd editionCopyright 1988 United States of AmericaInternet.comhttp://www.wdvl.com/Authoring/Languages/Perl/5/polymorph.htmlCopyright 1999-2000 internet.com CorpWebopediahttp://webopedia.internet.com/TERM/p/polymorphism.htmlCopyright 1999-2000 internet.com Corp.UNKNOWNhttp://www.cs.orst.edu/cs582/slides/chap14/slide2.htm

    This essay was written by a fellow student. You may use it as a guide or sample for writing your own paper, but remember to cite it correctly. Don’t submit it as your own as it will be considered plagiarism.

    Need custom essay sample written special for your assignment?

    Choose skilled expert on your subject and get original paper with free plagiarism report

    Order custom paper Without paying upfront

    Polymorphism in C Essay (642 words). (2019, Jan 29). Retrieved from https://artscolumbia.org/polymorphism-in-c-essay-76341/

    We use cookies to give you the best experience possible. By continuing we’ll assume you’re on board with our cookie policy

    Hi, my name is Amy 👋

    In case you can't find a relevant example, our professional writers are ready to help you write a unique paper. Just talk to our smart assistant Amy and she'll connect you with the best match.

    Get help with your paper