C++ PRACTICAL PROGRAMS

Class 12 Computer Science | ASSEB

Program to demonstrate constructor overloading

#include<iostream>

using namespace std;

class Student {

       private:

              int rollno;

              float marks;

       public:

              Student( )

              {            rollno=1;                                                      

                      marks=80.5;

              }

              Student(int r, float m)

              {      rollno=r;   

                      marks=m;

              }

Student(Student &s)

              {      rollno=s.rollno;                                                          

                   marks=s.marks;

              }

void display( )

{     

cout<<“Rollno is ” <<rollno<<endl;

cout<<“Marks is ”<<marks<<endl;

}

};

int main( ) {

Student s1;

Student s2(2,75.5);

Student s3(s2);

s1.display( );

s2.display( );

s3.display( );

return 0;

}

Output

Rollno is 1

Marks is 80.5

Rollno is 2

Marks is 75.5

Rollno is 2

Marks is 75.5

QUICK LINKS

Class 11

Class 12

Previous Year Paper

Practical Programs

Scroll to Top