CONSTR

Home >> Sem 2 >> C++ programs >> CONSTR

/* Write a Program with class using constructor */
#include<iostream.h>
#include<conio.h>
class stud
 {
   int sub[3],tot;
   float per;
   public:
    stud()
    {
    }
    stud(int s1,int s2,int s3)
     {
       sub[0] = s1;
       sub[1] = s2;
       sub[2] = s3;
     }
     void disp();

  };

   void stud::disp()
     {
       tot = sub[0] + sub[1] + sub[2];
       per = tot / 3;
       cout<<"Total : "<<tot<<endl;
       cout<<"Per : "<<per<<endl;
      }

void main()
 {
    int s1,s2,s3;
    clrscr();
    cout<<"Enter Marks1 : ";
    cin>>s1;
    cout<<"Enter Marks2 : ";
    cin>>s2;
    cout<<"Enter Marks3 : ";
    cin>>s3;
    stud f1 = stud(s1,s2,s3);
    f1.disp();
    getch();
  }