Professional Documents
Culture Documents
Exp No: Constructor-1 Date: Aim: Program
Exp No: Constructor-1 Date: Aim: Program
Exp No: Constructor-1 Date: Aim: Program
DATE:
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class stu
public:
float roll;
float eng,math,cs,chem,phy;
int mark,per;
char name[100];
stu()
roll=1;
strcpy(name,"swas");
eng=69;
math=89;
cs=45;
chem=36;
phy=85;
}
stu(stu &s)
roll=s.roll;
strcpy(name,s.name);
phy=s.phy;
chem=s.chem;
cs=s.cs;
eng=s.eng;
math=s.math;
~stu()
{cout<<"\nend";
void calc()
mark=(chem+math+eng+phy+cs)/5;
cout<<"percentage= "<<mark<<"%"<<endl;
void cino()
cin>>roll;
gets(name);
cout<<"enter ur mark :"<<endl;
cout<<"english : "<<endl;
cin>>eng;
cout<<"math : "<<endl;
cin>>math;
cin>>cs;
cout<<"physics : "<<endl;
cin>>phy;
cout<<"chemistry : "<<endl;
cin>>chem;
}a;
void main()
clrscr();
stu st1;
//stu st1,st3;
stu st3=st1;
st3.cino();
st3.calc();
getch();
}
OUTPUT:
EXP NO: CONSTRUCTOR-2
DATE:
PROGRAM:
#include<iostream.h>
#include<conio.h>
class box
{ public:
float length,breath,height,len,bre,hei;
box()
{ length=2.1;
breath=3.2;
height=3.3;
length=l;
breath=b;
height=h;
box(box &ob1)
len=ob1.length;
bre=ob1.breath;
hei=ob1.height;
}
void volume()
cout<<"volume"<<length*breath*height<<endl;
~box()
cout<<"dest invoked";
}bo;
void main()
{ clrscr();
float l1,b1,h1;
char rep;
int ch;
cin>>ch;
switch(ch)
case 1:
box ob1;
ob1.volume();
break;
case 2:
cout<<"enter l,b,h";
cin>>l1>>b1>>h1;
box ob2(l1,b1,h1);
ob2.volume();
break;
case 3:
box ob3;
ob3.volume();
break;
getch();
OUTPUT: