First, the topic requirements
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%
Requirements:
- 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.
- Requires the design idea, code implementation, implementation, personal summary in the form of blog post. (Due date 2015-4-15 18:00)
Second, design ideas
Book prices when the best, more than 10 of them are universal, so only need to consider 10 of the price of books within the best can, where buy a book is not preferential, so each buy book can be divided into batches, so that each time the best
10 within the representative, here no longer the implementation of the algorithm, directly through the corresponding quantity corresponding to different prices for the calculation.
Third, the source code
1 //book.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include"iostream"6 using namespacestd;7 8 intMain ()9 {Ten intNum//number of books purchased One Doublesum1,sum2;//Original price sum1, Total discount price sum2 A DoublePrice//Preferential Price - intNo1,no2;//determine the portion of the lot (five per batch) No1 and less than 10 copies of the books to be sold NO2 - intb; thecout<<"Please enter the number you want to buy:"; -Cin>>num; -sum1=8*num; -no1=num/5; +no2=num%5; - if(no1%2!=0) + { ANo1=no1-1; atno2=no2+5; - } - Switch(NO2) - { - Case 0: -Price=0; inA=0; b=0; - Break; to Case 1: +Price=0; -A=1; b=0; the Break; * Case 2: $Price=0.8;Panax NotoginsengA=2; b=0; - Break; the Case 3: +Price=2.4; AA=2; b=0; the Break; + Case 4: -Price=6.4; $A=4; b=0; $ Break; - Case 5: -Price=Ten; theA=5; b=0; - Break;Wuyi Case 6: thePrice=Ten; -A=1; b=5; Wu Break; - Case 7: AboutPrice=10.8; $A=2; b=5; - Break; - Case 8: -Price=12.8; Aa=b=4; + Break; the Case 9: -Price=16.4; $A=4; b=5; the Break; the } theSum2=Ten*no1+Price ; thecout<<"The best rates are:"<<sum1-sum2<<Endl; -cout<<"Purchase Plan: first time purchase"<<no1<<"batches (set of each batch);"<<"second time purchase"<<a<<"this;"<<"third time purchase"<<b<<"this;"<<Endl; in return 0; the}
Iv. Results of the experiment
Five, experimental analysis
The topic is not so difficult, I think this is the most important to reflect their own way of thinking, how to find a better solution, the same problem may have a lot of different ideas, but we have to determine which way to choose, which method of solving the problem, which is important. The implementation process of the problem can be through learning to customer service, but the method of the problem is indeed their own ideas, to find the best solution is a cumulative process, is to continue to explore, not only for a problem, only groping more, to be able to correctly plan and classify the problem, This is also helpful for dividing the problem in a team project
Best Buy Book