Constructor-2

Create a class named ‘String’ with one data member of typechar *, which stores a string. Include default, parameterized and copy constructor to initialize the data member. Write a program to test this class.


class string
{
 char *s;
 int t,len;
public:
 string()
 {
  s=new char[1];
  s[0]='\0';
  len=0;
 }
 string(char s1[])
 {
  len=strlen(s1);
  s=new char[len+1];
  strcpy(s,s1);
 }
  void disp()
 {
  cout<<"string:"<<s;
 }
};
void main()
{
clrscr();
string s1("abc");
s1.disp();
getch();

}