编写一个密码类,其中包含一个 str 密码字符串私有成员数据,一个“==”运算 符重载成员函数,用于比较用户输入的密码是否正确。并用数据测试该类。
2016-07-03 16:37
771 查看
#define _CRT_SECURE_NO_WARNINGS
/*
编写一个密码类,其中包含一个 str 密码字符串私有成员数据,一个“==”运算
符重载成员函数,用于比较用户输入的密码是否正确。并用数据测试该类。
*/
#include <iostream>
class secret
{
private:
//char str[] = "secret";
char * str = "secret";
public:
bool operator ==(char * pass)
{
for (int i = 0; i<6; i++)
{
if (str[i] != pass[i])
{
return false;
}
}
return true;
}
};
void main()
{
secret a;
char b[10];
//std::cin >> "%s";
scanf("%s", b);
if (a == b)
{
std::cout << "登录成功" << std::endl;
}
else
{
std::cout << "密码错误" << std::endl;
}
system("pause");
}
/*
编写一个密码类,其中包含一个 str 密码字符串私有成员数据,一个“==”运算
符重载成员函数,用于比较用户输入的密码是否正确。并用数据测试该类。
*/
#include <iostream>
class secret
{
private:
//char str[] = "secret";
char * str = "secret";
public:
bool operator ==(char * pass)
{
for (int i = 0; i<6; i++)
{
if (str[i] != pass[i])
{
return false;
}
}
return true;
}
};
void main()
{
secret a;
char b[10];
//std::cin >> "%s";
scanf("%s", b);
if (a == b)
{
std::cout << "登录成功" << std::endl;
}
else
{
std::cout << "密码错误" << std::endl;
}
system("pause");
}
相关文章推荐
- 二叉搜索树的序列化和反序列化
- [置顶] django实现qq一键登录(qq互联)
- Android: Drawable Resources
- iOS 即时通讯XMPP
- 在win和Linux系统中python命令行运行的不同
- ImageNet Classification with deep convolutional neural networks
- 函数模板
- 矩阵的最小路径之和
- WIN10下 JAVA环境搭配
- CNN学习(一)
- CNN学习(一)
- 求无序数组中最小的k个数
- centos6.4安装mongodb
- 人生三大遗憾
- [译]Android内存泄漏的八种可能
- android学习日记之activity
- redhat 6 配置 yum 源的两种方法
- UIAppearance使用方法
- Vector的实现
- poj3050