Group members: Zhao Yonghen, Van Dey
First, the experimental topic
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.
Requires the design idea, code implementation, implementation, personal summary in the form of blog post.
Second, design ideas
When we first saw this problem, our idea was to discuss the situation, for example, when we say 12, the program automatically divides it into many kinds of situations, such as 4.4.4, 3.4.5 and so on. But in the design of the program we found that the implementation is very cumbersome or can not be achieved, because the larger the number of cases, the more we need to discuss the more, can not achieve a large number of sub-case discussion. Later through the calculation, we found that all the cases can be divided into 5 categories, that is, divisible by 5 after the remainder of the discussion, for the total price, we also categorized 5 formulas can be solved, so no matter how much can be brought in and very concise.
Third, the source code
#include <iostream.h>intMain () {intnum; intShang; intYushu; DoublePrice ; cout<<"Please enter the number of books to buy:"; CIN>>num; Shang=num/5; Yushu=num%5; Switch(Yushu) { Case 0: Price= -*Shang; cout<<"the total price of the book is:"<<price<<"Yuan"<<Endl; Break; Case 1: Price= -*shang+8; cout<<"the total price of the book is:"<<price<<"Yuan"<<Endl; Break; Case 2: Price= -*shang+15.2; cout<<"the total price of the book is:"<<price<<"Yuan"<<Endl; Break; Case 3: Price= -* (shang-1)+51.2; cout<<"the total price of the book is:"<<price<<"Yuan"<<Endl; Break; Case 4: Price= -*shang+25.6; cout<<"the total price of the book is:"<<price<<"Yuan"<<Endl; Break; } return 0;}
Four, the operation
V. Summary of the Experiment
Just see this topic feeling a bit difficult, but after and partner research, found that seemingly complex problems can be divided into a few small groups, and then each group analysis, so that the problem is resolved. Many problems in itself is not difficult, we are always by its appearance to frighten, calm analysis only found in their own ability within the scope.
Pair development----Buy book problem