#include <iostream>
using namespace std;
class a {
private:
int x=0;
public:
int t = 0;
int sum() {
cout << "選擇完輸入-1" << endl<<"1.小白菜 :20元" << endl;
cout << "2.高麗菜:30元" << endl;cout << "3.番茄:40元"<<endl;while (1) {
cin >> x;
if (x == -1) {
break;
}if (x == 1) {
t+=20;
}if (x == 2) {
t+=30;
}if (x == 3) {
t+=40;
}
}
cout << "總金額:" << t << endl;
return 0;
}
};
class b :public a{
private:
public:
int rebate() {
cout << "金額超過50元打5折" << endl;
if (t == 50) {
t*0.5;
}
return 0;
}
};
int main() {
a asum;
asum.sum();
b bsum;
bsum.rebate();
return 0;
}
歡迎光臨 伊莉討論區 (http://a04.eyny.com/) | Powered by Discuz! |