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

AIM:

A program to print student details using a constructor and destructor.

ALGORITHM:

  1. Start the process
  2. Invoke the classes
  3. Call the read() function
    • Get the inputs name, roll number and address
  4. Call the display() function
    • Display the name, roll number, and address of the student
  5. 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.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

34 thoughts on “C++ program to print student details using constructor and destructor

  1. hai sir, these program are used my course,i have some one program in constructor and destructor in with parameter&without parameter,copy constructor

  2. thanks for the program sir. its very much effective to a person like me(beginer to c++
    )

  3. 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

  4. the program is really helps me to understand how to make these types of prgrms

Leave a Reply

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

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in