Monday, 30 September 2024

Journal PRogram 6

 #include<iostream.h>

#include<conio.h>

#include<string.h>

#include<process.h>

class String

{

char str1[100],str2[100];

public:

void getData()

{

cout<<"Enter first string : ";

cin>>str1;

cout<<"Enter second string : ";

cin>>str2;


}

void strlen1()

{

int len1,len2;

len1=strlen(str1);

len2=strlen(str2);

cout<<"\nLength of "<<str1<< " is "<<len1;

cout<<"\nLength of "<<str2<< " is "<<len2;


}

void strcpy1()

{

cout<<"\nAfter Copy String2 in to String1 :";

strcpy(str1,str2);

cout<<"\nString 1 ="<<str1;

}

void strcat1()

{

strcat(str1,str2);

cout<<"\nConcated String is ="<<str1;

}

void strcmp1()

{

if(strcmp(str1,str2)==0)

cout<<"\nTwo Strings are equal";

else

cout<<"\nTwo Strings are not equal";

}


};

int main()

{

clrscr();

int choice;

char ch;

String s;

s.getData();

do

{

cout<<endl<<"1:String Length";

cout<<endl<<"2:Copy in another string";

cout<<endl<<"3:To combine two string";

cout<<endl<<"4:To compare two strings";

cout<<endl<<"5:Exit";


cout<<endl<<"\nEnter your choice=";

cin>>choice;

switch(choice)

{

case 1:

s.strlen1();

break;

case 2:

s.strcpy1();

break;

case 3:

s.strcat1();

break;

case 4:

s.strcmp1();

break;

case 5: exit(0);

break;

default:

cout<<endl<<"Invalid choice";

}

cout<<"\nDo you want to cont...";

cin>>ch;

}while(ch=='y'||ch=='Y');

return 0;

}

No comments:

Post a Comment