Page 173 - C++
P. 173

Parameterized Constructor (Overloaded Constructor):- Parameterized constructor accepts parameters and is
        used to assign these parameters to the data members of the class. There may be many definitions of the
        parameterized constructor depending upon the type and number of parameters passed to the constructor and
        so it is also called overloaded constructor.

        For example.

        #include<iostream.h>
        class student
        {
               int rollno;
               float percentage;
        public:
               student() // default constructor
               {
                       rollno=0;
                       percentage=0.0;
               }
               student(int rno,float p)     //parameterized constructor
               {
                       rollno=rno;
                       percentage=p;
               }
               void display()
               {
                       cout<<"RNo. "<<rollno;
                       cout<<"\n per "<<percentage;
               }
        };
        void main()
        {
        student s;     //call for the default constructor
        student s1(5,88.5);   //call for the parametrized constructor
        s.display();
        s1.display();
        }
         (c) Define a class RESORT in C++ with following description:                                        (4)

        Private Members:

        Rno // Data member to store Room No

        Name // Data member to store customer name

        Charges // Data member to store per day charges

        Days // Data member to store number of days of stay

        COMPUTE( ) // A function to calculate and return Amount as Days* Charges and if the value of Days *
   168   169   170   171   172   173   174   175   176   177   178