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");
}
/*
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");
}
相关文章推荐
- 编写一个密码类,其中包含一个 str 密码字符串私有成员数据,一个“==”运算 符重载成员函数,用于比较用户输入的密码是否正确。并用数据测试该类。
- 8.6 编写一个类,其中有一个 double 型私有数据成员 yuan(存放人民币数量,单位 为元),另外包含一个转换运算符重载成员函数以将 yuan 转换成美元(假设 1 美元对换 8.268 人民
- 编写Java程序,模拟简单的计算器。 定义名为Number的类,其中有两个整型数据成员n1和n2,应声明为私有。 编写构造方法,用于初始化n1和n2,再为该类定义 加(addition)、 减(su
- 编写一个程序设计一个汽车类vehicle,包含的私有数据成员有车轮个数wheels和车重weight
- ACM457现在给出了一个只包含大小写字母的字符串,不含空格和换行,要求把其中的大写换成小写,小写换成大写,然后输出互换后的字符串。输入 第一行只有一个整数m(m<=10),表示测试数据组数。
- 编写一个程序,用于接收用户输入的数,然后显示从0到该数为止表示的所有字符,询问用户是否愿意再次继续同样的过程
- 编写设计一个People(人)类。该类的数据成员有年龄(age)、身高(height)、体重(weight)和人数(num),其中人数为静态数据成员,成员函数有构造函数(People)、进食(Eatt
- 编写设计一个People(人)类。该类的数据成员有年龄(age)、身高(height)、体重(weight)和人数(num),其中人数为静态数据成员,成员函数有构造函数(People)、进食(Eatt
- 编写设计一个People(人)类。该类的数据成员有年龄(age)、身高(height)、体重(weight)和人数(num),其中人数为静态数据成员
- 在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)
- JAVA--第十周作业编写之一个Teacher类负责给出算术题目,随机给出两个整数并进行运算,并判断回答者的答案是否正确;编写一个GUI类ComputerFrame,回答者可以通过GUI看到题目并给出
- c++编程:编写程序,任意输入一个字符串,将其中的最大字符放在字符串的第二个
- 设计一个时间类Time, 包括时,分,秒等私有数据成员。要求实现时间的基本运算,一个时间加上另一个时间。。
- 编写一个函数 char *strfind(char *s, char *t),用于查找字符串t在字符串s中最右边出现的位置,如果没有找到则返回NULL.
- 华为:通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串
- 华为机试——通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串
- 2. 编写一个Java应用程序,用户从键盘输入一个1~9999之间的数,程序将判断这个数是几位数,并判断这个数是否是回文数。回文数是指将该数含有的数字逆序排列后得到的数和原数相同,例如12121、32
- 定义一个圆类(Circle),私有数据成员为半径(radius)、圆周长和面积,共有成员函数为输入半径;计算周长、面积;输出半径、周长和面积。要求定义构造函数(以半径为参数,缺省值为0,周长和面积在
- 描述:用户在sudo一个命令的时候必须输入root密码。用起来比较麻烦。
- 编写一个程序,接受用户输入的一段英文文字后,输出其中的字符数、单词数和句子数(设句子以"?"、"!"、"."结束)。