CBSE Computer Science - Revision Tour(Solved) CBSE Guess > eBooks > Class XII > CBSE Computer Science Class And Object Solved Revision Tour By Mr. Ravi Kiran COMPUTER SCIENCE CLASS AND OBJECTS 2006 Delhi: 2.c) Define a class named ADMISSION in C++ with the following descriptions: Private Members:
Public Members: Function Read_Data( ) to read an object of ADMISSION type. Function Display( ) to display the details of an object. Function Draw-Nos.( ) to choose 2 students randomly. And display the details. Use random function to generate admission nos. to match with AD_NO. Ans:
2006 Outside Delhi: 1.b) Illustrate the use of Inline function in C++ with the help of an example. 2 Ans: INLINE FUNCTIONS: The inline functions are a C++ enhancement designed to speed up programs. The coding of normal functions and inline functions is similar except that inline functions definitions start with the keyword inline. The working of inline functions: After loading the executable program in the computer memory, these instructions are executed step by step. When a function call instruction is encountered, the program stores the memory address of the instruction
immediately following the function call statement, loads the function being called into the memory, copies argument values, jumps to the memory location of the called function, executes the function code, stores the return value of the function, and then jumps back to the address of the instruction that was saved just before executing the called function. With inline code, the compiler replaces the function call statement with the function code itself (this process is called expansion) and then compiles the entire code. Thus, with inline functions, the compiler does not have to jump to another location to execute the function, and then jump back as the code of the called function is already available to the calling program. Inline functions run a little faster than the normal functions as function calling overheads are saved, however there is a memory penalty. If 10 times an inlinefunction is called, there will be 10 copies of the function inserted into the code. A function can be declared inline by placing the keyword inline before it. An inline function definition should be placed above all the functions that call it. The functions should be inlined only when they are small. Since for large functions, they will become memory penalty. The inlining does not work for following situations:
Inlining and the member functions: The member functions defined outside the class definition can be made explicitly inline by placing the keyword inline before their definition.
CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] ) |
|