COMPARE STRINGS TAKING FUNCTION AS PRIVATE FUNCTION

/*PROGRAM TO COMPARE TWO STRINGS BY TAKING STRING COMPARISON FUNCTION AS PRIVATE FUNCTION*/

#include<conio.h>

#include<iostream.h>

#include<stdio.h>

class str_comparison

{

int i,count1,count2;

char a[10],b[10];

void output();

public:

void input();

};

void str_comparison::input()

{

cout<<“Enter first string: “;

gets(a);

cout<<“Enter second string: “;

gets(b);

output();

}

void str_comparison::output()

{

i=0;

count1=0;

while(a[i]!=’\0′)

{

i++;

count1++;

}

i=0;

count2=0;

while(a[i]!=’\0′)

{

i++;

count2++;

}

i=0;

if(count1==count2)

{

while(a[i]==b[i] && a[i]!=’\0′)

{

i++;

}

if(count1==i)

cout<<“Strings are equal”;

else

cout<<“Strings are not equal”;

}

else

cout<<“Strings are not equal”;

}

void main()

{

str_comparison s1;

clrscr();

s1.input();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *