PRACTICAL – 3.1
Constructor to allocate memory dynamically and read value.
#include <iostream>using namespace std;class Rahi{int num1;public:Print(int x){num1 = x;}void getdata(){cout << num1 << endl;}};int main(){int i;cout << "Enter the value of a : ";cin >> i;Rahi r(i);r.getdata();return 0;}
Practical 3.2
Display () function to display the string
#include <iostream>#include <string>using namespace std;class String{string s = " Kitzu ";public:void Display(){cout << s;}};int main(){String r;r.Display();return 0;}
Practical 3.3
Destructor function to free allocated memory.
#include <iostream>using namespace std;class Box{public:Box(){cout<<"Contructor Data"<<endl;}~Box(){cout<<"Destuct data"<<endl;}};int main(){{Box b;}cout<<"Program is End !!";return 0;}
0 Comments