想写一个模拟atm机的c++代码,在写密码校验的函数时提示报错
//class.h#pragmaonceclassconsumer{public:chargetname();chargetnum();chargetpwd();doub...
//class.h#pragma onceclass consumer {public: char getname(); char getnum(); char getpwd(); double getmoney(); void setpwd(char[10]); void setmoney(double); consumer(char[20], char[20], char[10], double);private: char m_name[20], m_num[20]; char m_pwd[10]; double m_money;};class atm{public: void welcome(); void functionshow(); bool check_pwd( char pwd[]); char chang_pwd(); void find_info(); void feth_money(); void timeout(); void exit_atm(); atm(consumer &cn) :cnsm(cn) { } private: consumer cnsm;};//cpp文件#include "pch.h"#include <string>#include <iostream>#include"class.h"using namespace std;consumer::consumer(char name[20],char num[20],char pwd[10],double money){ memset(m_name, 0, 20); memset(m_num, 0, 20); memset(m_pwd, 0, 10); m_money = 0; strcpy_s(m_name, name); strcpy_s(m_num, num); strcpy_s(m_pwd, pwd); m_money = money;}char consumer::getname(){ return m_name[20];}double consumer::getmoney(){ return m_money;}char consumer::getnum(){ return m_num[20];}char consumer::getpwd(){ return m_pwd[10];}void consumer::setpwd(char pwd[10]){ strcpy_s(m_pwd, pwd);}void consumer::setmoney(double money){ m_money=m_money - money;}void atm::timeout(){ cout << "输入错误次数太多,已强制退出系统!" << endl; exit(0);}void atm::exit_atm(){ cout << "已退出系统,谢谢使用!" << endl; exit(0);} bool atm::check_pwd(char pwd[10]){ int i=0; i=strcmp(cnsm.getpwd(), pwd);/*报错"char" 类型的实参与 "const char *" 类型的形参不兼容,“int strcmp(const char *,const char *)”: 无法将参数 1 从“char”转换为“const char * */ if (i=0) { cout << "输入密码正确!" << endl; return true; } else if (i!=0) { cout << "密码错误!请重新输入" << endl; return false; }}
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询