Sunday, 8 September 2013

What are manipulators

What are manipulators? 

Ans: Manipulators are the instructions to the output stream to modify the output in various ways. The manipulators provide a clean and easy way for formatted output in comparison to the formatting flags of the ios class. When manipulators are used, the formatting instructions are inserted directly into the stream. Manipulators are of two types, those that take an   argument and those that don't.

Unitbuf flag

When should I use unitbuf flag?
Ans: The unit buffering (unitbuf) flag should be turned on when we want to ensure that each character is output as soon as it is inserted into an output stream. The same can be done using unbuffered output but unit buffering provides a better performance than the unbuffered output.

Implement assignment operator and copy constructor in this class

Write a program that implements a date class containing day, month and year as data members. Implement assignment operator and copy constructor in this class.
Ans: This is shown in following program: 

#include 

class date
{ 
private : 
int day ;
int month ;
int year ; 
public : 
date ( int d = 0, int m = 0, int y = 0 ) 
{ 
day = d ;
month = m ;
year = y ; 
}

// copy constructor
date ( date &d ) 
{ 
day = d.day ;
month = d.month ;
year = d.year ;  
}

// an overloaded assignment operator
date operator = ( date d ) 
{ 
day = d.day ;
month = d.month ;
year = d.year ; 
return d ;  
} 
void display( )
{ 
cout << day << "/" << month << "/" << year ; 
} 
} ;

void main( )
{ 
date d1 ( 25, 9, 1979 ) ;
date d2 = d1 ; 
date d3 ;
d3 = d2 ; 
d3.display( ) ; 
}
What is the purpose of ios::basefield in the following statement?
cout.setf ( ios::hex, ios::basefield ) ;  


Ans: This is an example of formatting flags that work in a group. There is a flag for each numbering system (base) like decimal, octal and hexadecimal. Collectively, these flags are   referred to as basefield and are specified by ios::basefield flag. We can have only one of these   flags on at a time. If we set the hex flag as setf ( ios::hex ) then we will set the hex bit but we           won't clear the dec bit resulting in undefined behavior. The solution is to call setf( ) as setf ( ios::hex, ios::basefield ). This call first clears all the bits and then sets the hex bit.

How do I carry out conversion of one object of user-defined type to another?

How do I carry out conversion of one object of user-defined type to another?
Ans: To perform conversion from one user-defined type to another we need to provide conversion function. Following program demonstrates how to provide such conversion function.
                           

  class circle
                        

     {
                             private :
                             int radius ;
                             public:
                             circle ( int r = 0 )
                             {  

                             radius = r ;  
                             }
                             } ;
                            class rectangle
                             {
                             private :
                             int length, breadth ;                                public :                                rectangle( int l, int b )                              {  
                             length = l ;                              breadth = b ;  
                             }
                             operator circle( )                              {  
                             return circle ( length ) ;  
                             }                                } ;                              void main( )                             {  
                             rectangle r ( 20, 10 ) ;                              circle c;                              c = r ;  
                                                    }
                             } 

Here, when the statement c = r ; is executed the compiler searches for an overloaded assignment  operator in the class circle which accepts the object of type rectangle. Since there is no such overloaded assignment operator, the conversion operator function that converts the rectangle object to the circle object is searched in the rectangle class. We have provided such a  conversion function in the rectangle class. This conversion operator function returns a circle object. By default conversion operators have the name and return type same as the object type to which it converts to. Here the type of the object is circle and hence the name of the operator function as well as the return type is circle.

overloading a binary operator

While overloading a binary operator can we provide default values?
Ans: No!. This is because even if we provide the default arguments to the parameters of the overloaded operator function we would end up using the binary operator incorrectly. This is explained  in the following example: 


                     sample operator + ( sample a, sample b = sample (2, 3.5f ) )
                             {
                             }

                             void main( )
                             {
                                    sample s1, s2, s3 ;
                                    s3 = s1 + ; // error
                             }

How do I refer to a name of class or function that is defined within a namespace?

How do I refer to a name of class or function that is defined within a namespace?

Ans:
There are two ways in which we can refer to a name of class or function that is 


defined within a namespace: Using scope resolution operator through the using keyword. 

This is shown in following example: 


                             namespace name1
                             {
                             class sample1
                             {
                             // code
                             } ;
                             }
                            namespace name2
                             {
                             class sample2
                             {
                             // code
                             } ;
                             }
                             using namespace name2 ;
                             void main( )
                             {
                             name1::sample1 s1 ;
                             sample2 s2 ;
                             } 


zero-argument manipulator that should work same as hex

How do I write my own zero-argument manipulator that should work same as hex?

Ans:
This is shown in following program.

Forward referencing

What is forward referencing and when should it be used?

Ans: Consider the following program:  


                       class test                        {
                       public :
                       friend void fun ( sample, test ) ;                          } ;
                       class sample                        {
                       public :
                       friend void fun ( sample, test ) ;
                       } ;
                       void fun ( sample s, test t )                        {
                       // code                          }
                       void main( )                        {
                       sample s ;                        test t ;                        fun ( s, t ) ;
                       } 


User-defined object be declared as static data member of another class

Can user-defined object be declared as static data member of another class?

Ans:
Yes. The following code shows how to initialize a user-defined object.

     #include

     class test
     {
     int i ;
     public :
     test ( int ii = 0 )
     {
     i = ii ;
     }
     } ;

     class sample
     {
     static test s ;
     } ;
     test sample::s ( 26 ) ;

     Here we have initialized the object s by calling the one-argument constructor. We can use the same convention to initialize the object by calling multiple-argument constructor.

Formatting flags in ios class

What are formatting flags in ios class?

Ans: The ios class contains formatting flags that help users to format the stream data. Formatting
flags are a set of enum definitions. There are two types of formatting flags: 

  1. On/Off flags 
  2. Flags that work in-group  


The On/Off flags are turned on using the setf( ) function and are turned off using the unsetf( ) function. To set the On/Off flags, the one argument setf( ) function is used. The flags working in groups are set through the two-argument setf( ) function. For example, to left justify a  string we can set the flag as,

  1. cout.setf ( ios::left ) ;
  2. cout << "KICIT Nagpur" ; 

Tuesday, 3 September 2013

What is ASP?

What is ASP?

Active Server Pages (ASP), also known as Classic ASP, is a Microsoft's server-side technology, which helps in creating dynamic and user-friendly Web pages. It uses different scripting languages to create dynamic Web pages, which can be run on any type of browser. 

The Web pages are built by using either VBScript or JavaScript and these Web pages have access to the same services as Windows application, including ADO (ActiveX Data Objects) for database access, SMTP (Simple Mail Transfer Protocol) for e-mail, and the entire COM (Component Object Model) structure used in the Windows environment. ASP is implemented through a dynamic-link library (asp.dll) that is called by the IIS server when a Web page is requested from the server.