运用类和对象的知识,使用public,完成以下要求的代码:一、定义管理员类(Administrator)要求: 1.类的属性:姓名(name)和密码(password) 2.类的方法show():输出管理员姓名和密码二、定义客户类(Customer)要求: 1.类的属性:积分(score)、卡类型(type) 2.类的方法show():输出客户的积分和卡类型三、更改管理员密码要求: 1.输入旧的用户名和密码,如果正确,方有权限更新 2.从键盘获取新的密码,进行更新 四、客户积分回馈要求: 1.创建客户对象输出他得到的回馈积分(金卡客户积分大于1000分或普卡客户积分大于5000,获得回馈积分500分)
时间: 2023-04-10 07:03:49 浏览: 120
以下是代码实现:
```
#include <iostream>
using namespace std;
class Administrator {
public:
string name;
string password;
void show() {
cout << "管理员姓名:" << name << endl;
cout << "管理员密码:" << password << endl;
}
};
class Customer {
public:
int score;
string type;
void show() {
cout << "客户积分:" << score << endl;
cout << "客户卡类型:" << type << endl;
}
int feedback() {
if (type == "金卡" && score > 1000) {
return 500;
}
else if (type == "普卡" && score > 5000) {
return 500;
}
else {
return 0;
}
}
};
int main() {
Administrator admin;
admin.name = "admin";
admin.password = "123456";
Customer customer;
customer.score = 1500;
customer.type = "金卡";
admin.show();
customer.show();
string old_password;
cout << "请输入旧密码:";
cin >> old_password;
if (old_password == admin.password) {
string new_password;
cout << "请输入新密码:";
cin >> new_password;
admin.password = new_password;
cout << "密码修改成功!" << endl;
}
else {
cout << "密码错误,无法修改!" << endl;
}
int feedback_score = customer.feedback();
cout << "客户获得的回馈积分:" << feedback_score << endl;
return 0;
}
```
输出结果:
```
管理员姓名:admin
管理员密码:123456
客户积分:1500
客户卡类型:金卡
请输入旧密码:123456
请输入新密码:654321
密码修改成功!
客户获得的回馈积分:500
```
注意:这里只是一个简单的示例,实际应用中可能需要更多的属性和方法,以及更复杂的逻辑。