AIM:
To implement a C++ program to print student details using constructor and destructor
To implement a C++ program to print student details using constructor and destructor
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
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:
#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( );
}
SAMPLE OUTPUT:
Enter the student Name
James
Enter the student roll no
01
Enter the student address
Newyork
Enter the Zip code
919108
James
Enter the student roll no
01
Enter the student address
Newyork
Enter the Zip code
919108
Student Name: James
Roll no is : 01
Address is : Newyork
Zip code is :919108
Roll no is : 01
Address is : Newyork
Zip code is :919108
No comments:
Post a Comment