Chapter – 4. CLASSES AND OBJECTS

The working of inline functions: After writing any program, it is first compiled to get an executable code, which consists of a set of machine language instructions. When this executable code is executed, the operating system loads these instructions into the computer’s memory, so that each instruction is stored in a specific memory location. Thus, each instruction has a particular memory address.
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 inline function 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:

  1. For functions that return values and are having a loop or a switch or a goto.
  2. For functions not returning values, if a return statement exists.
  3. f functions contain static variables.
  4. If the function is recursive(a function that calls itself).

Inlining and the member functions: The member function of a class, if defined within the class definition, are inlined by default. Therefore, only very small member functions should be defined within the class definition. The member functions defined outside the class definition can be made explicitly inline by placing the keyword inline before their definition.
Inline functions are best for small functions that are called often.
The compiler may even ignore your attempt to linline a function if it consists more than 50 lines of code.

2. c. Define a class named HOUSING in C++ with the following descriptions: 4

Private Members:

REG_NO integer(Ranges 10-1000)
NAME Array of characters(String)
TYPE Character
COST Float

Public Members: Function Read_Data( ) to rread an object of HOUSING type. Function Display( ) to display the details of an object. Function Draw_Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING. Use random function to generate the registration nos. to match with REG_NO from the array.


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter4_c.php on line 116

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter4_c.php on line 116

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter4_c.php on line 118

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/chapter4_c.php on line 118