Exp No: Constructor-1 Date: Aim: Program

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

EXP NO: CONSTRUCTOR-1

DATE:

AIM: To write a c++ program to calculate percentage of the given marks.

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()

cout<<"enter ur roll no:"<<endl;

cin>>roll;

cout<<"enter ur name : "<<endl;

gets(name);
cout<<"enter ur mark :"<<endl;

cout<<"english : "<<endl;

cin>>eng;

cout<<"math : "<<endl;

cin>>math;

cout<<"computer sci :"<<endl;

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:

AIM: To write a c++ program to calculate the volume of a cuboid.

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;

box(float l,float b,float h)

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;

cout<<"1.default 2.arg 3.copy";

cout<<"enter your choice"<<endl;

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:

You might also like