Preferential purchase Book

Source: Internet
Author: User

1. Title:

Bookstore for the "Harry Potter" series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of 8 yuan, the specific discount is as follows:

Discount on this number

2 5%

3 10%

4 20%

5 25%

Depending on the number of volumes purchased and this number, different discount rules will be applicable. The singular book only corresponds to one discount rule, for example, two volume 1, one volume 2, you can enjoy 5% discount, another volume does not enjoy the discount. The design algorithm calculates the lowest price for the reader to buy a batch of books. 2. Design ideas just start to see this topic, feel very difficult, feeling there are many kinds of situations, and then carefully read the topic after the discussion with the students after the analysis, found that this topic is actually the number decomposition, know so back, began to analyze each number, the analysis process found that less than 5 of the number is not analyzed, You only need to analyze 6-9 of the numbers, then the number will loop. For the analysis of the numbers between 6-9, the various cases are calculated, and finally the conclusion is reached: 6=5+17=5+28=4+49=5+4 this will be extended to the general situation. 3. Source code
#include <iostream>using namespacestd;DoubleMSum (intN) {    intm =0; DoubleMoney ; M= n%5; M= m +5; Switch(m) { Case 5: Money= n *8*0.75;  Break;  Case 6: Money= (N-1) *8*0.75+8;  Break;  Case 7: Money= (N-2) *8*0.75+8*2*0.95;  Break;  Case 8: Money= (N-8) *8*0.75+4*8*0.8*2;  Break;  Case 9: Money= (N-4) *8*0.75+8*4*0.8;  Break; }    returnMoney ;}intMain () {intN; cout<<"Please enter purchase quantity:"<<Endl; CIN>>N; cout<<Endl; cout<<"most favorable total book price:"<< mSum (n) <<"Yuan"<<Endl;}
4. Procedures




5. Summary
To learn to abstract the actual problem, the actual problem into a more easily understood model. For the feeling of more complex procedures, to pay attention to the particularity of the analysis, the first analysis of a relatively small number, from the special to the general, so as to find the law, so that the program will be much simpler.

Preferential purchase Book

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.