C++ program to print student details using constructor and destructor

Friday, March 12th, 2010

CONSTRUCTOR AND DESTRUCTOR
AIM:
A program to print student details using constructor and destructor

ALGORITHAM:

1. Start the process
2. Invoke the classes
3. Call the read() function
a. Get the inputs name ,roll number and address
4. Call the display() function
a. Display the name,roll number,and address of the student
5. Stop the process

PROGRAM

#include<iostream.h>
#include<conio.h>
class stu
{
		private: char name[20],add[20];
		  	int roll,zip;
		public: stu ( );//Constructor
			~stu( );//Destructor
			void read( );
			void disp( );			
};
stu :: stu( )
{
	cout<<”This is Student Details”<<endl;
}
void stu :: 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 stu :: disp( )
{
	cout<<”Student Name :<<name<<endl;
	cout<<”Roll no   is       :<<roll<<endl;
	cout<<”Address is       :<<add<<endl;
	cout<<”Zipcode is       :<<zip;
}
stu : : ~stu( )
{
	cout<<”Student Detail is Closed”;
}
 
void main( )
{
	stu s;
	clrscr( );
s.read ( );
s.disp ( );
getch( );
}

Output:

Enter the student Name
James
Enter the student roll no
01
Enter the student address
Newyork
Enter the Zipcode
919108

Student Name : James
Roll no is : 01
Address is : Newyork
Zipcode is :919108

Avatar of Ranjith

Author Name :
Ranjith

Total : 12 Comments


12 Responses to “C++ program to print student details using constructor and destructor”

  1. Romelia Medora says:

    This nigga have fun, like a serial killer

  2. Rashed says:

    Very good programming.

  3. rihana says:

    thanks a lot! to you!!!!!

  4. Awesum says:

    Thanx program works beatifully :)

  5. Subash says:

    This Site very useful for my carrier.Thanks a lot sir.

  6. subash says:

    Hello sir,what is the purpose of destructor here????can you explain please…..this is my mail id:[email protected]……

  7. saranya says:

    program is very clear and simple…..purpose of destructor pls? thank yu

  8. dhaya says:

    destructor will be called after the program completes.. after getting output press ALT + F5… u can see destructor function invoked

  9. suganya says:

    good

  10. gayathri says:

    thank u sir very useful for me

  11. Molly says:

    Thnx a lot!!!! With this program my assignment gets completed….!

  12. majahar says:

    i want abstract

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: