Page 218 - C++
P. 218
*(a+j) = *(a+j+1) ;
*(a+j+1) = temp ;
}
for(i=n-1 ; i>=n/2 ; i--)
{ sm = *(a+i) ;
pos = i ;
for(j=i-1 ; j>=n/2 ; j--)
if(*(a+j)< sm)
{ pos = j ;
sm = *(a+j) ;
}
temp = *(a + i);
*(a+i) = *(a + pos) ;
*(a + pos) = temp ;
}
}
void main( )
{ int w[ ]={-4 , 6 , 1 , -8 , 19 , 5},i ;
FUNC(w , 6) ;
for(i=0 ; i<6 ; i++)
cout<<w[i];
} [3]
f) Observe the following program & find out the correct possible outputs from the options.
(Assuming that all required header files are included in the program)
void main( )
{ char serial[ ] = {‘E’ , ‘X’ , ‘A’ , ‘M’} ;
int number[ ] = {69 , 66 , 67 , 68} ;
randomize( );
cout<<number[random(3)] ;
for(int i=0 ; i<4 ; i++)
cout<<serial[sizeof(int) + random(2)-1] ;
}
(i) 67XXAX (ii) 69AXXA (iii) 66AAXA (iv) 67AAAM [2]
Q.2 a) Why is a destructor function required in classes ? Illustrate with the help of a example? [2]
b) Answer the questions (i) and (ii) after going through the following class:
class Computer
{ char c_name[20];
char Config[100] ;
public :
Computer(Computer &obj); //function 1
Computer( ) ; //function 2
Computer(char *n , char *C) ; //function 3
};
(i) Name the specific feature of the OOPs shown in the above example.
(ii) Write complete definition for function 1. [2]
c) Define a class named “Housing” in with the following specifications:
Private members:
2