Code CAdd Constructor
#include<conio.h>
#include<iostream>
using namespace std;
class CAdd{
public:
int one;
CAdd(int two){
cout<<"Contructor with paramater "<<endl;
one = two;
}
CAdd(){
cout<<" Default Contructor"<<endl;
}
~CAdd(){
cout<<" Descontructor of programs" <<endl;
}
int add(){
return(one + one);
}
};
int main(){
CAdd myObj1(4);
CAdd myObj2;
cout<<"The value of Obj 1 : "<<myObj1.add()<<endl;
cout<<"Please enter value : ";
cin>>myObj2.one;
cout<<"The value of Obj 2 : "<<myObj2.add()<<endl;
getch();
return 0;
}
0 comments: