⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opload.cpp

📁 All are the assignments of mine that I have developped in Data Structure Laboratory Hours
💻 CPP
字号:
// Program To Implement Op Overloading.
# include<iostream.h>
# include<conio.h>
# include<stdio.h>
# include<string.h>
#include<stdlib.h>
class op
{
	public:
		char s[10];
	public:
		void operator=(op B)
		{
			int c;
			c=strcmp(this->s,B.s);

			if(c==0)
			{
				cout<<"\n\tBoth Strings Are Equal.";
			}

			else
			if(c<0)
			{
				cout<<"\n\tString "<<this->s<<" is Smaller Than "<<B.s;
			}

			else
			if(c>0)
			{
				cout<<"\n\tString "<<B.s<<" is Smaller Than "<<this->s;
			}
		}

		void operator==(op B)
		{
			cout<<"\n\tString 1: "<<s;
			cout<<"\n\tString 2: "<<B.s;
			cout<<"\n\tCopied String: "<<strcpy(s,B.s);
		}

		void operator+(op B)
		{
			cout<<"\n\tString 1: "<<s;
			cout<<"\n\tString 2: "<<B.s;
			cout<<"\n\tConcatinated String: "<<strcat(s,B.s);
		}

		void operator<<(op B)
		{
			cout<<"\n\tString 1: "<<s;
			cout<<"\n\tString 2: "<<B.s;
		}

		void operator>>(op B)
		{
			cout<<"\n\tReverse Of "<<s<<" Is: "<<strrev(s);
			cout<<"\n\tReverse Of "<<B.s<<" Is: "<<strrev(B.s);
		}

		void operator-(op B)
		{
			char *temp;
			temp=strrev(s);
			if(strcmp(temp,s)==0)
			{
				cout<<"\n\tThe String "<<s<<" Is Pallendrome";
			}

			flushall;
			temp=strrev(B.s);
			if(strcmp(temp,B.s)==0)
			{
				cout<<"\n\tThe String "<<B.s<<" Is Pallendrome";
			}
		}

		void operator*(op B)
		{
			if(strstr(s,B.s))
				cout<<"\n\tThe String "<<B.s<<" Is Present In "<<s;
			else
				cout<<"\n\tThe String "<<B.s<<" Is Not Present In "<<s;
		}

		void accept()
		{
			cout<<"\n\tEnter A String: ";
			gets(s);
		}
};

void main()
{
	op A,B;
	int ch;
	clrscr();
	do{
	cout<<"\n\tMenu: ";
	cout<<"\n\t1.String Equality.";
	cout<<"\n\t2.String Copy.";
	cout<<"\n\t3.String Concatination.";
	cout<<"\n\t4.String Display.";
	cout<<"\n\t5.String Reverse.";
	cout<<"\n\t6.String Pallendrome";
	cout<<"\n\t7.Sub String.";
	cout<<"\n\t8.Exit.";
	cout<<"\n\n\tEnter Ur Choice: ";
	cin>>ch;


	switch(ch)
	{
		case 1:
			B.accept();
			A.accept();

			A=B;
			flushall;
			break;
		case 2:
			A.accept();
			B.accept();
			flushall;
			A==B;
			break;
		case 3:
			A.accept();
			B.accept();
			flushall;
			A+B;
			break;
		case 4:
			A.accept();
			B.accept();
			flushall;
			A<<B;
			break;
		case 5:
			A.accept();
			B.accept();
			flushall;
			A>>B;
			break;
		case 6:
			A.accept();
			B.accept();
			flushall;
			A-B;
			break;
		case 7:
			A.accept();
			B.accept();
			flushall;
			A*B;
			break;
		case 8:
			break;
		default:
			cout<<"\nWrong Choice";
	}
	}while(ch!=8);
	//getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -