AIM:
A program to print student details using a constructor and destructor.
ALGORITHM:
- Start the process
- Invoke the classes
- Call the read() function
- Get the inputs name, roll number and address
- Call the display() function
- Display the name, roll number, and address of the student
- Stop the process
PROGRAM
#include <iostream>
using namespace std;
class student
{
private: char name[20],add[20];
int roll,zip;
public: student ( ); //Constructor
~student( ); //Destructor
void read( );
void disp( );
};
student :: student( )
{
cout<<"Student class constructor called."<<endl;
}
void student :: read( )
{
cout<<"Enter the student Name: ";
cin>>name;
cout<<"Enter the student roll no: “;
cin>>roll;
cout<<"Enter the student address: ";
cin>>add;
cout<<"Enter the Zipcode: ";
cin>>zip;
}
void student :: disp( )
{
cout<<"Studet details"<<endl;
cout<<"Student Name :"<<name<<endl;
cout<<"Roll no is :"<<roll<<endl;
cout<<"Address is :"<<add<<endl;
cout<<"Zipcode is :"<<zip<<endl;
}
student :: ~student( )
{
cout<<"Student class destructor called.";
}
int main( )
{
student s;
s.read();
s.disp();
}
Output:
Student class constructor called.
Enter the student Name: Rajesh
Enter the student roll no: 1234
Enter the student address: Bangalore
Enter the Zipcode: 560001
Studet details
Student Name :Rajesh
Roll no is :1234
Address is :Bangalore
Zipcode is :560001
Student class destructor called.
good
thank u sir very useful for me
Thnx a lot!!!! With this program my assignment gets completed….!
i want abstract
thank you sir . these is very usefull my assignment
Hai sir, What is the purpose of constructor here……………can you explain please . This is my mail id antony.goldgueen@gmail.com
hai sir, these program are used my course,i have some one program in constructor and destructor in with parameter&without parameter,copy constructor
thank u…….now i understand it clearly
thanks for the program sir. its very much effective to a person like me(beginer to c++
)
Sir,likely I have understand from the above program but can you explain why we use constructurs and destructurs (main purpose) my mail id:yogesh.avhale2010@gmail.com
program is simple n very clear…it really helped me a lot…!!! thank u…
program is simple n very clear…it really helped me a lot…!!! thank u…
Thank you Very Much. i think this works for me
thanx sir…works smoothly
thank you very much very good programming…..!!!!!!!!!!!!!
the program is really helps me to understand how to make these types of prgrms
good programming,but copy paste karne se sab idhar udar ho jata hai!!!!
its very useful for us……………..v present this pgm in exhibiton
very good!!!!!!!!!!! program is simple and very easy to understand………….
Thanks and very helpful.
Its good ………………….
thanks a lot! to you…………………….!
Very nice programm……!!
I like it !!!
Better programming……..!!!
Bhosdi ka koi kharab nhi bta sakta ise…..!!!
Thank you for the good work you done for us.
Not functnng in Dev-c++
This program is good but deatructor message does not show
more advanced programs required,,,am able to join
its very useful to me thanks to your program
wOw I got it .
thank u vry much
wOw I got it .
thank u vry much
am very happpy….!!!!!!!!
its very helpful for us
it is very nice ,good useful for us
It’s very useful for us so we are expecting more ex