Calculate individual taxes (define a salary class)

Source: Internet
Author: User

(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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.