Team Development----Selling book problem

Source: Internet
Author: User

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

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.