Solved Tutorial Automata Theory

Embed Size (px)

Citation preview

  • 8/11/2019 Solved Tutorial Automata Theory

    1/2

    1. What is the difference between private or public class members??

    Private class members can be accessed with in the class only while public class members can be

    accessed outside the class as well.

    2. Why we use #include string directive?

    We use #include string directive before using string data type.

    3. How automatic initialization is carried out in class??

    Automatic initialization is carried out in class by using a member function called Constructor.

    4. What is the difference between getline and cin?

    cin will ignore the whitespace, except to use them as terminators for input to the variable, while getline

    doesn't ignore whitespace, unless whitespace is used as the terminating char.

    5. What are instance variables?

    An object is an instance of a class. Objects are sometimes called instance variables.

    6. How can compilers get info about constructor?? How its name helps finding it?

    Compiler gets info about constructor if the name of constructor is same as of class. Constructor does

    not return the value as constructor is called automatically, this is also a way compiler knows that it is a

    constructor.

    7. What is the destructor??

    Destructor is a function called automatically when an object is destroyed. The most common use of

    destructors is to de-allocate memory that was allocated for the object by the constructor.

    8. Write out the function of strcpy?

    strcpy copies the string pointed to by s2 into the object pointed to by s1. It returns a pointer to the

    destination.

    9.

    Give an example why data members are kept private in class and functions public?

    Data members are kept private in class so they may be accessed from inside the class. This way, if

    something goes wrong, we only need to look at one source file. Functions are kept public so that other

    parts of program call to get and set private member variables.

    10.What are objects and classes??

    Objects have certain state and behavior, which a live entity. While class, is a non-live entity, a blue print

    of the object. For example, Fruit is a class and Banana is an object.

  • 8/11/2019 Solved Tutorial Automata Theory

    2/2

    11.What is a constructor?? What is default constructor and when it is called??

    A constructor is a member function that is executed automatically whenever an object is created. Each

    class may also define what happens if a variable of the type is defined but an initializer is not provided. A

    class does so by defining a special constructor, known as the default constructor. This constructor is

    called the default constructor because it is run "by default;" if there is no initializer, then this constructoris used.