PROGRAM TO IMPLEMENT CONSTRUCTOR WITH DEFAULT ARGUMENTS

/*PROGRAM TO IMPLEMENT CONSTRUCTOR WITH DEFAULT ARGUMENTS*/

#include<conio.h>

#include<iostream.h>

class student

{

int roll_no;

float marks;

public:

student(int x=10,float y=40)

{

roll_no=x;

marks=y;

}

void display()

{

cout<<“Roll no: “<<roll_no<<endl;

cout<<“Marks: “<<marks<<endl;

}

};

void main()

{

student s1;

student s2(1,60);

clrscr();

cout<<“Output using default constructor arguments:\n”;

s1.display();

cout<<“Output without default constructor arguments:\n”;

s2.display();

getch();

};

Leave a Reply

Your email address will not be published. Required fields are marked *