0% found this document useful (0 votes)
30 views

#Include #Include Using Namespace Class Public Char

This C++ program defines a mystring class to represent strings. The mystring class includes operators to assign strings from char, char arrays, and other mystring objects. It also includes operators to compare mystring objects and a display method. The main function demonstrates assigning and comparing mystring objects and using the if/else conditional.

Uploaded by

Hamza Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

#Include #Include Using Namespace Class Public Char

This C++ program defines a mystring class to represent strings. The mystring class includes operators to assign strings from char, char arrays, and other mystring objects. It also includes operators to compare mystring objects and a display method. The main function demonstrates assigning and comparing mystring objects and using the if/else conditional.

Uploaded by

Hamza Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

#include<string.h>
using namespace std;

class mystring
{
public :
char *arr;

mystring()
{
arr=NULL;
cout<<"I am Constructor"<<endl;
}
void operator=(char ch)
{
if(arr!=NULL)
{
free(arr);
}
arr=(char*)malloc(2);

arr[0]=ch;
arr[1]='\0';
}
void operator=(char *t)
{
if(arr!=NULL)
{
free(arr);
}
int l1=strlen(t);
arr=(char*)malloc(l1+1);
strcpy(arr,t);
}
void operator=(mystring scopy)
{
if(arr!=NULL)
{
free(arr);
}
int l1=strlen(scopy.arr);
arr=(char*)malloc(l1+1);
strcpy(arr,scopy.arr);
}

int operator>(mystring s)
{
int d;
d=strcmp(arr,s.arr);
if(d>0)
{
return 1;
}
else
{
return 0;
}
}

int operator<(mystring s)
{
int d;
d=strcmp(arr,s.arr);
if(d<0)
{
return 1;
}
else
{
return 0;
}
}
void display()
{
puts(arr);
}

};

void main()
{
mystring s1,s2;
s1="Sahibzada Muhammad Shahid Khan Afridi "; //char *t
s1.display();
s1='a'; //char ch
s1.display();
s2="Ali"; //mystring temp
s2.display();
if(s1>s2)
{
s1="If Condition";
}
else
{
s1="else Condition";
}
s1.display();

You might also like