Write a C++ program to print student details using constructor and destructor.

Program Algorithm:
Step 1: Include the header files
Step 2: Invoke The Classes
Step 3: Call The Read() Function
Step 4: Get The Inputs Name ,Roll Number And Address
Step 5: Call The Display() Function
Step 6: Display The Name, Roll Number, And Address Of The Student

Program Code in C++:
class stu
stu :: stu( )
private: char name[20],add[20];
int roll,zip;
public: stu ( );//Constructor
~stu( );//Destructor
void read( );
void disp( );
cout<<”This is Student Details”<<endl;
void stu :: read( )
cout<<”Enter the student Name”;
cout<<”Enter the student roll no “;
cout<<”Enter the student address”;
cout<<”Enter the Zipcode”;
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( );

Program Output:
Enter the student Name
Enter the student roll no
Enter the student address
Enter the Zip code

Student Name: Mukesh
Roll no is : 101
Address is : Hamirpur
Zip code is : 176045
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment: