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
1#include <iostream.h>2 intMain ()3 {4 intnum;5 intShang;6 intYushu;7 DoublePrice ;8cout<<"Please enter the number of books to buy:";9Cin>>num;Tenshang=num/5; Oneyushu=num%5; A Switch(Yushu) - { - Case 0: thePrice= -*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; A Case 2: atPrice= -*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; in Break; - Case 4: toPrice= -*shang+25.6; +cout<<"the total price of the book is:"<<price<<"Yuan"<<Endl; - Break; the } * return 0; $}
Four, the experiment
V. Summary of the Experiment
In fact, at the beginning of the teacher said this is a Microsoft's face test I really was frightened, the difficulty must be very large, it takes a long time to design code. But calm down, we two people on the overall layout and thinking of the negotiation and calculation, found not as we imagined, the idea is really more important than the code, but also confirmed that down-to-earth is always more important than ups and downs and the fear of the surface.
Team Development----Selling book problem