Create a class named ‘String’ with one data member of type char *, which stores a string. Include default, parameterized and copy constructor to initialize the data member. Write a program to test this class.
CODING:
#include<iostream.h>
#include<conio.h>
class string
{
char *name;
public:
string()
{
name="I Like ";
}
string(char *a)
{
name=a;
}
void disp()
{
cout<<name;
}
};
void main()
{
string ob1,ob2("C++ "),ob3=ob2;
clrscr();
ob1.disp();
ob2.disp();
ob3.disp();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
class string
{
char *name;
public:
string()
{
name="I Like ";
}
string(char *a)
{
name=a;
}
void disp()
{
cout<<name;
}
};
void main()
{
string ob1,ob2("C++ "),ob3=ob2;
clrscr();
ob1.disp();
ob2.disp();
ob3.disp();
getch();
}
Comments
Post a Comment