You are on page 1of 4

GRADE CALCULATION USING CONSTRUCTOR AND DESTRUCTOR

#include<iostream.h> #include<conio.h> class grade { public: int m1; grade() { m1=0; } int get() { cin>>m1; return(m1); } ~grade() { cout<<"\nDestructor executed"; } void show(float); }; void grade :: show(float m1) { float m; m=m1; if(m>=90 && m<=100) { cout<<"\npassed with distinction"; } else if(m>=80 && m<=89) { cout<<"\nO grade"; } else if(m>=70 && m<=79) {

cout<<"\nA grade"; } else if(m>=60 && m<=69) { cout<<"\nB grade"; } else { cout<<"\nC grade"; } } void main() { grade g; int a,b,c,tot; float avg; char ch[20]; clrscr(); cout<<"\nNAME:G.VASANTH\tREGNO:1138M0276\tCLASS:II-MCA"; cout<<"\n GRADE CALCULATION USING CONSTRUCTOR AND DESTRUCTOR"; cout<<"\n\t************************************"; do { cout<<"\nEnter your name:"; cin>>ch; cout<<"\nEnter the mark1:"; a=g.get(); cout<<"\nEnter the mark2:"; b=g.get(); cout<<"\nEnter the mark3:"; c=g.get(); tot=a+b+c; avg=tot/3; cout<<"\nTotal ="<<tot; cout<<"\nAverage ="<<avg; g.show(avg); cout<<"\nDo you want to continue?(y/n)"; cin>>ch;

} while(ch=='y'|| ch=='Y'); cout<<"\nPROGRAM TERMINATED"; getch(); }

OUTPUT:
NAME:G.VASANTH REGNO:1138M0276 CLASS:II-MCA

GRADE CALCULATION USING CONSTRUCTOR AND DESTRUCTOR

Enter your name: MADHU Enter the mark1:86 Enter the mark2:79 Enter the mark3:90 Total =255 Average =85 O grade DO YOU WANT CONTINUE: n PROGRAM TERMINATED

You might also like