0% found this document useful (0 votes)
45 views2 pages

#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)
45 views2 pages

#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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy