#define _CRT_SECURE_NO_WARNINGS
/*
8.3 编写一个密码类,其中包含一个 str 密码字符串私有成员数据,一个“==”运算
符重载成员函数,用于比较用户输入的密码是否正确。并用数据测试该类
*/
#include<iostream>
#include <math.h>
using namespace std;
class secret
{
char* str ;
public:
bool operator ==(secret& s)
{
//if (this->str == s.str)//指针指向同一个地方,所以比较成功
if (strcmp(this->str,s.str)==0)
{
cout << "\n\n" << "密码正确" << endl;
return true;
}
cout << "\n\n" << "密码错误" << endl;
return false;
}
void setstr(char *s)
{
this->str = s;
}
char *getstr()
{
return str;
}
};
void main()
{
secret secrets;
char *s = "secrcet";
secrets.setstr(s);
secret customer;
char *b = "secret";
customer.setstr(b);
secrets == customer;
system("pause");
}
/*
8.3 编写一个密码类,其中包含一个 str 密码字符串私有成员数据,一个“==”运算
符重载成员函数,用于比较用户输入的密码是否正确。并用数据测试该类
*/
#include<iostream>
#include <math.h>
using namespace std;
class secret
{
char* str ;
public:
bool operator ==(secret& s)
{
//if (this->str == s.str)//指针指向同一个地方,所以比较成功
if (strcmp(this->str,s.str)==0)
{
cout << "\n\n" << "密码正确" << endl;
return true;
}
cout << "\n\n" << "密码错误" << endl;
return false;
}
void setstr(char *s)
{
this->str = s;
}
char *getstr()
{
return str;
}
};
void main()
{
secret secrets;
char *s = "secrcet";
secrets.setstr(s);
secret customer;
char *b = "secret";
customer.setstr(b);
secrets == customer;
system("pause");
}