c++ programs examples

a.     Define two constructors to initialize the data members.

b.     Display the information of the class using object.

c++ programs examples
 /* 14. Create a class Student with roll no, name and age as private data
	members .
	a. Define two constructor to initialize the data members.
	b. Display the information of the class using object. */

 #include<iostream.h>
 #include<conio.h>
 #include<string.h>
 class Student
 {
  private:
   int roll_no,age;
   char name[20];
  public:
   Student()
   {
    roll_no=age=0;
    strcpy(name," ");
    }
   Student(int roll,int s_age,char s_name[])
   {
    roll_no=roll;
    age=s_age;
    strcpy(name,s_name);
    }
   void display()
   {
    cout<<endl<<"Student Name="<<name<<endl;
    cout<<"Roll No="<<roll_no<<endl;
    cout<<"Age="<<age<<endl;
    }
 };
 void main()
 {
  clrscr();
  Student s1,s2(1,22,"Ruhul Amin Khan");
  s1.display();
  s2.display();
  getch();
  }



Leave a Reply

Your email address will not be published. Required fields are marked *