Shreyash Kalaskar - 19 - Oops - Practical No.5
Shreyash Kalaskar - 19 - Oops - Practical No.5
5
Aim:. Stud class to display student information using constructor and destructor .
Theory:-
Constructor: A constructor is a special type of member function of a calass which initialize
member function of a class which initialize object of a class.
Destructor: a member function in a class that dele an object they are called when the
object get out of scope such as when the function ends the program ends a=delete variable
is called destructor.
Program
include<iostream>
using namespace std;
class student{ private:
string name; string
course; string add; int
year,age; public:
student()
{
cout<<"\nConstructor Is called";
}
void info()
{
cout<<"\n\n"; cout<<"\nEnter
Name Of Student:"; cin>>name;
cout<<"\nEnter Course :";
cin>>course; cout<<"\nEnter Year
:"; cin>>year;
cout<<"\nEnter Your address :"; cin>>add;
}
void display()
{
cout<<"\n\n\n******The Info Of Student is *******:";
cout<<"\nName :"<<name; cout<<"\nCourse
:"<<course; cout<<"\nYear :"<<year;
cout<<"\nAddress :"<<add;
}
~student()
{
cout<<"\n\n\nDestructor is called";
}
};
int main()
{
Student Riya; Riya.info();
Riya.display();
}
#
Output:
Taste Case
Sr. Input Output
No.
1 #include<iostream> using Constructor is called
namespace std;
class student{ private:
string name; Enter Name of Student : Neha
string course; Enter Course : Msc
string add; int Enter Year: 2
year,age; public: Enter Your Adress: Nashik The
student()
Info Of Student is:
{
cout<<"\nConstructor Is called"; Name: Neha
} Course: Msc
void info() Year:2
{ Destructor is Called
cout<<"\n\n";
cout<<"\nEnter Name Of Student:";
cin>>name;
cout<<"\nEnter Course :";
cin>>course; cout<<"\nEnter
Year :"; cin>>year;
cout<<"\nEnter Your address :";
cin>>add;
}
void display()
{
cout<<"\n\n\n******The Info Of
Student is *******:";
cout<<"\nName :"<<name;
cout<<"\nCourse :"<<course;
cout<<"\nYear :"<<year;
cout<<"\nAddress :"<<add;
}
~student()
{
cout<<"\n\n\nDestructor is called";
}
};
int main()
{
student;neha neha.info();
neha.display();
}