卡访问方法C++
我正在尝试重新创建一个收银机程序。 我有一个员工对象,它有一个名称和一个折扣%卡访问方法C++,c++,class,oop,object,C++,Class,Oop,Object,我正在尝试重新创建一个收银机程序。 我有一个员工对象,它有一个名称和一个折扣% staffMember me ("tom", 20); 我想对收银机的总数打折扣。如果我像这样使用me.getDiscountPercent将折扣作为整数参数传递,则我的方法有效 cashy.applyStaffDiscount(me.getDiscountPercent()); void cashRegister::applyStaffDiscount(int discount){ total = (t
staffMember me ("tom", 20);
我想对收银机的总数打折扣。如果我像这样使用me.getDiscountPercent将折扣作为整数参数传递,则我的方法有效
cashy.applyStaffDiscount(me.getDiscountPercent());
void cashRegister::applyStaffDiscount(int discount){
total = (total/100)*(100-discount);
}
但是,我想输入员工姓名,这样我就可以拥有不同折扣的员工。我做的这件事不管用
string employee;
cout << "Enter name: ";
cin >> employee;
cashy.applyStaffDiscount(employee);
谢谢Tom,employee的数据类型是string。std命名空间中的字符串类没有任何名为getDiscountPercent的方法。也许,你想做的是:
string name;
int discount;
cout << "Enter name: ";
cin >> name;
cout << "Enter discount: ";
cin >> discount;
staffMember employee (name, discount); // <-- this is what you really want!
cashy.applyStaffDiscount(employee);
employee的数据类型为string。std命名空间中的字符串类没有任何名为getDiscountPercent的方法。也许,你想做的是:
string name;
int discount;
cout << "Enter name: ";
cin >> name;
cout << "Enter discount: ";
cin >> discount;
staffMember employee (name, discount); // <-- this is what you really want!
cashy.applyStaffDiscount(employee);
参数employee是std::string,而不是staffMember。在applyStaffDiscount函数中,必须传递员工,而不是字符串:
string employee_name;
int employee_discount;
cout << "Enter employee data: ";
cin >> employee_name;
cin >> employee_discount;
staffMember employee( employee_name , employee_discount); //Staff variable
cashy.applyStaffDiscount(employee);
/* ... */
void cashRegister::applyStaffDiscount(const staffMember& employee)
{
total = (total/100)*(100-employee.getDiscountPercent());
}
参数employee是std::string,而不是staffMember。在applyStaffDiscount函数中,必须传递员工,而不是字符串:
string employee_name;
int employee_discount;
cout << "Enter employee data: ";
cin >> employee_name;
cin >> employee_discount;
staffMember employee( employee_name , employee_discount); //Staff variable
cashy.applyStaffDiscount(employee);
/* ... */
void cashRegister::applyStaffDiscount(const staffMember& employee)
{
total = (total/100)*(100-employee.getDiscountPercent());
}
employee是一个没有getDiscountPercent方法的字符串。如果您有一个包含名称和折扣的基数,那么请编写一个将名称作为参数并返回折扣的方法。employee的数据类型为string。std命名空间中的string类没有任何名为getDiscountPercent的方法。您可以将员工存储在其名称字符串为键的映射中。employee是一个没有getDiscountPercent方法的字符串。如果您有一个包含名称和折扣的基数,那么请编写一个将名称作为参数并返回折扣的方法。employee的数据类型为string。std命名空间中的string类没有任何名为getDiscountPercent的方法。您可以将员工存储在其名称字符串为键的映射中。