The function assigns a default value to the parameter

This preview shows page 7 - 9 out of 54 pages.

The function assigns a default value to the parameter which does not have a matching argument in the function call. They are useful in situations where some arguments always have the same value. e.g., float amt (float P, float n, float r = 0.15); 45. State the advantages of default arguments. The advantages of default arguments are, • We can use default arguments to add new parameters to the existing function. • Default arguments can be used to combine similar functions into one. 46. Define function overloading. (Nov/Dec 2011) A single function name can be used to perform different types of tasks. The same function name can be used to handle different number and different types of arguments. This is known as function overloading or function polymorphism. 47. List out the limitations of function overloading. We should not overload unrelated functions and should reserve function overloading for functions that perform closely related operations. 48. State the difference between structures and class. By default the members of a structure are public whereas the members of a class are private. 49.Define a class. A class is a way to bind the data and its function together. It allows the data to be hidden from external use. The general form of a class is, class class_name { private: variable declarations; function declaration; public: variable declarations; function declaration; }; 50. List the access modes used within a class. • Private – The class members are private by default. The members declared private are completely hidden from the outside world. They can be accessed from only within the class. • Public – The class members declared public can be accessed from any where.
Image of page 7

Subscribe to view the full document.

• Protected – The class members declared protected can be access from within the class and also by the friend classes. 51. How can we access the class members? The class members can be accessed only when an object is created to that class. They are accessed with the help of the object name and a dot operator. They can be accessed using the general format, Object_name.function_name (actual_arguments); 52.Where can we define member functions? Member functions can be defined in two places: • Outside the class definition – The member functions can be defined outside the class definition with the help of the scope resolution operator. The general format is given as, return_type class_name :: function_name (argument declaration) { function body } • Inside the class definition – The member function is written inside the class in place of the member declaration. They are treated as inline functions. 53.What are the characteristics of member functions? The various characteristics of member functions are, • Different classes can use the same function name and their scope can be resolved using the membership label.
Image of page 8
Image of page 9

{[ snackBarMessage ]}

Get FREE access by uploading your study materials

Upload your study materials now and get free access to over 25 million documents.

Upload now for FREE access Or pay now for instant access
Christopher Reinemann
"Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

Ask a question for free

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern