Untitled
Anonymous
plain_text
02/03/2026 1:24 PM
2.1 KB
13
Indexable
#include <iostream>
using namespace std;
// 1. ฟังก์ชัน f(x): ลดราคา 10% (x * 0.90)
double f_discount(double x) {
return x * 0.90;
}
// 2. ฟังก์ชัน g(x): คิดภาษี 7% (x * 1.07)
double g_tax(double x) {
return x * 1.07;
}
// 3. ฟังก์ชันประกอบ (Composite): คิดราคาสุทธิ g(f(x))
// เอาเข้า f ก่อน (ลดราคา) แล้วเอาผลลัพธ์ไปเข้า g (คิดภาษี)
double calculate_final(double x) {
return g_tax(f_discount(x));
}
// 4. ฟังก์ชันผกผัน (Inverse): คิดย้อนกลับหา "ราคาป้าย"
// จากเดิม คูณ ก็เปลี่ยนเป็น หาร (ย้อนลำดับจากหลังมาหน้า)
double find_original(double y) {
return y / 1.07 / 0.90;
}
int main() {
double price;
cout << "Input Price: ";
cin >> price;
// ใช้งานฟังก์ชันประกอบ (หาที่ต้องจ่ายจริง)
double net_price = calculate_final(price);
cout << "Final Price (Discount -> Tax): " << net_price << endl;
// ใช้งานฟังก์ชันผกผัน (พิสูจน์คำตอบโดยการย้อนกลับ)
double original = find_original(net_price);
cout << "Reverse back to Tag Price: " << original << endl;
return 0;
}Editor is loading...
Leave a Comment