Group members: Chen Zhili Tan Wei
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%
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.
Second, the design idea
First of all, we have divided three ranges according to the book's number, 0-5,6-9,10 above. Then we decided to start from the actual data, written calculation the actual maximum discount below 10, summed up more than 10 is the front 6-9 of the cycle. The quotient of the 5 Division is the integer multiple of the maximum discount of 5, plus the remainder obtained by the 5 takes the corresponding discount, resulting in the lowest price.
Third, the code implementation
1#include <iostream.h>2 voidMain ()3 {4 intNumber//this number5 intShang//Business6 intremainder;//remainder7 DoublePrice ;8 intN;9 while(n)Ten { Onecout<<"Please enter the number of books you buy:"<<Endl; ACin>>Number ; -shang=number/5; -remainder=number%5; the Switch(remainder) - { - Case 0: -price=shang*8*0.75*5; +cout<<"buy"<<number<<"The lowest price of this book is:"<<price<<"Yuan"<<Endl; - Break; + Case 1: Aprice=shang*8*0.75*5+8; atcout<<"buy"<<number<<"The lowest price of this book is:"<<price<<"Yuan"<<Endl; - Break; - Case 2: -price=shang*8*0.75*5+8*2*0.95; -cout<<"buy"<<number<<"The lowest price of this book is:"<<price<<"Yuan"<<Endl; - Break; in Case 3: -Price= (shang-1)*8*0.75*5+8*4*0.8*2; tocout<<"buy"<<number<<"The lowest price of this book is:"<<price<<"Yuan"<<Endl; + Break; - Case 4: theprice=shang*8*0.75*5+8*4*0.8; *cout<<"buy"<<number<<"The lowest price of this book is:"<<price<<"Yuan"<<Endl; $ Break;Panax Notoginseng default: - Break; the } +cout<<"continue entering 1, exit input 0"<<Endl; ACin>>N; the } +}
Iv. Realization OF
V. Personal SUMMARY
In our calculation process, due to the calculation is not serious, not completely mistaken for 6-9 of the time are first to meet 5 discount, the remaining discount is the cheapest, but after the classmate's correction, we have carefully calculated a bit, when the 8, 4 and 4 This is the biggest discount, which is due to our not serious, It is too naïve to prevent such a situation from happening in the future.
Software Engineering class Assignment--the problem of buying books