Friday 1 February 2013

constructor in c++ by zafar iqbal levi

// record of a three students
#include<iostream.h>
#include<conio.h>

class student
{
private:
int marks,per;
char grade;
public:

student()  //constuctor
{
marks=80;
grade='A';
}

void show() //function
{
cout<<"marks    "<<marks<<endl;
cout<<"grade    "<<grade<<endl;
}

void hide() //function
{
cout<<"marks    "<<marks<<endl;
cout<<"grade    "<<grade<<endl;
cout<<"perc    "<<per<<endl;
}

student(int m,char c)       //constuctor
{
marks=m;
grade='c';
}

student(int m,char c,float p)     //constuctor
{
marks=m;
grade=c;
per=p;
}


};

void main()
{
student s1;
cout<<"\nrecord of s1\n\n";
s1.show();
student s2(60,'c');
cout<<"\nrecord of s2\n\n";
s2.show();
student s3(49,'f',44);
cout<<"\nrecord of s3\n\n";
s3.hide();
getch();
}

0 comments:

Post a Comment