(Threshold 800 ):
# Include <iostream> using namespace STD; # define tax_threshold 800 struct tax {double standard; double tax_rate ;}; class salary {double income; public: static tax tax_array []; salary (INT m = 0) {income = m;} void operator-(INT payout) {income-= payout; cout <"salary balance: "<income <Endl;} void calculatesalary (void) ;}; tax salary: tax_array [] ={{ 0, 0.05 },{ 500, 0.10 }, {2000, 0.15}, {5000, 0.20}, {20000, 0.25}, {40000, 0.30}, {60000, 0.35}, {80000, 0.40}, {100000, 0.45 }}; void salary: calculatesalary (void) {double tax = 0; Double X = income-tax_threshold; If (x> 0) {for (INT I = sizeof (tax_array)/sizeof (* tax_array)-1; I> = 0; I --) {If (x> tax_array [I]. standard) {tax + = (X-tax_array [I]. standard) * tax_array [I]. tax_rate; X = tax_array [I]. standard ;}}cout <"pre-tax salary:" <income <Endl; cout <"Personal Income Tax:" <tax <Endl; income-= tax; cout <"real-time salary:" <income <Endl;} int main (void) {double myincome; double mypayout; while (cout <"your monthly salary is:", CIN> myincome) {salary mysalary (myincome); mysalary. calculatesalary (); cout <"withdrawal amount:"; CIN> mypayout; mysalary-mypayout; // cout <Endl ;}return 0 ;}
Running result:
It's easy to modify! (I also paid attention to the magic number problem)