C++ program – Classes with pointers as data members

0
550

C++ program – Classes with pointers as data members

CONSTRUCTION:

  1. Start the program.
  2. Include the header files.
  3. Declare two string variables in public.
  4. Create class strptr with member function char *s1,char *s2.
  5. Access the member function using objects.
  6. Print two strings.
  7. Stop the program.

PROGRAM:

#include<iostream.h>
#include<conio.h>
#include<string.h>
class strptr
{
char *str1;
char *str2;
public:
void input(char *s1,char *s2)
{
str1=s1;
str2=s2;
cout<<"\nThe strings are";
cout<<"\nS1="<<str1;
cout<<"\nS2="<<str2;
strcat(str1,str2);
cout<<"\nSTRING is "<<str1<<"\n";
}
};
void main()
{
clrscr();
char s1[100];
char s2[100];
strptr p1;
cout<<"\nEnter two strings";
cin>>s1>>s2;
p1.input(s1,s2);
getch();
}

Leave a Reply