您的位置:首页 > 其它

8.3 编写一个密码类,其中包含一个 str 密码字符串私有成员数据,一个“==”运算 符重载成员函数,用于比较用户输入的密码是否正确。并用数据测试该类

2016-07-31 14:49 1156 查看
#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");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐