Advertisement
Garey

Задача за освобождаване

Oct 13th, 2017
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.01 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //        NAME: main.cpp
  3. // DESCRIPTION: A program that helps a printer in making quotes for
  4. //              their products.
  5. //      AUTHOR: Stf Kolew
  6. // AUTHOR/DATE: JP 2017-10-11
  7. // MODIFY/DATE: JP 2017-10-12
  8. ////////////////////////////////////////////////////////////////////////////////
  9. #include <iostream>
  10. #include <iomanip>
  11.  
  12. using namespace std;
  13.  
  14. ////////////////////////////////////////////////////////////////////////////////
  15. //        NAME: round
  16. // DESCRIPTION: Rounds down or up, respectively to the number,
  17. //              to the nearest multiple of the number.
  18. //   ARGUMENTS: numer, multiple
  19. // USES GLOBAL: none
  20. // MODIFIES GL: none
  21. //     RETURNS: int
  22. //      AUTHOR: Stf Kolew
  23. // AUTHOR/DATE: JP 2017-10-11
  24. // MODIFY/DATE: JP 2017-10-12
  25. ////////////////////////////////////////////////////////////////////////////////
  26. #define roundNumber(number, multiple) ( number % multiple < 8 ? (number >= 0 ? (number / multiple) * multiple : ((number - multiple + 1) / multiple) * multiple) : (number >= 0 ? ((number + multiple - 1) / multiple) * multiple : (number / multiple) * multiple))
  27.  
  28. ////////////////////////////////////////////////////////////////////////////////
  29. //        NAME: calculate_the_job
  30. // DESCRIPTION: Calculates the price of a job given the number of pages,
  31. //              price per sheet, price per plate, and number of copies.
  32. //   ARGUMENTS: number_of_pages, number_of_copies, price_per_sheet,
  33. //              price_per_plate
  34. // USES GLOBAL: none
  35. // MODIFIES GL: none
  36. //     RETURNS: double number
  37. //      AUTHOR: Stf Kolew
  38. // AUTHOR/DATE: JP 2017-10-12
  39. ////////////////////////////////////////////////////////////////////////////////
  40. double calculate_the_job(int number_of_pages, int number_of_copies, int print_car_pages, double price_per_sheet, double price_per_plate) {
  41.   number_of_pages = roundNumber(number_of_pages, print_car_pages);
  42.   return (((number_of_pages * price_per_plate) + (((number_of_pages / 2) * number_of_copies) * price_per_sheet) + (number_of_copies * 2.00)) + (((number_of_pages * price_per_plate) + (((number_of_pages / 2) * number_of_copies) * price_per_sheet) + (number_of_copies * 2.00)) * (17.5 / 100)));
  43. }
  44.  
  45. ////////////////////////////////////////////////////////////////////////////////
  46. //        NAME: calculate_bw_printing
  47. // DESCRIPTION: Calculates the price of a job given the number of pages and
  48. //              the number of copies for black and white printing.
  49. //   ARGUMENTS: number_of_pages, number_of_copies
  50. // USES GLOBAL: none
  51. // MODIFIES GL: none
  52. //     RETURNS: double number
  53. //      AUTHOR: Stf Kolew
  54. // AUTHOR/DATE: JP 2017-10-12
  55. ////////////////////////////////////////////////////////////////////////////////
  56. double calculate_bw_printing(int number_of_pages, int number_of_copies, int print_car_pages) {
  57.   return calculate_the_job(number_of_pages, number_of_copies, print_car_pages, 0.01, 7);
  58. }
  59.  
  60. ////////////////////////////////////////////////////////////////////////////////
  61. //        NAME: calculate_color_printing
  62. // DESCRIPTION: Calculates the price of a job given the number of pages and
  63. //              the number of copies for color printing.
  64. //   ARGUMENTS: number_of_pages, number_of_copies
  65. // USES GLOBAL: none
  66. // MODIFIES GL: none
  67. //     RETURNS: double number
  68. //      AUTHOR: Stf Kolew
  69. // AUTHOR/DATE: JP 2017-10-12
  70. ////////////////////////////////////////////////////////////////////////////////
  71. double calculate_color_printing(int number_of_pages, int number_of_copies,int print_car_pages) {
  72.   return calculate_the_job(number_of_pages, number_of_copies, print_car_pages, 0.04, 28);
  73. }
  74.  
  75. ////////////////////////////////////////////////////////////////////////////////
  76. //        NAME: main
  77. // DESCRIPTION: The main fragment of the program. Outputs information
  78. //              about the functions that are described above.It has
  79. //              been used manipulators to output two numbers after
  80. //              the decimal part of the number.
  81. //              Manipulators Used: setprecision and fixed
  82. //   ARGUMENTS: none
  83. // USES GLOBAL: none
  84. // MODIFIES GL: none
  85. //     RETURNS: int(0)
  86. //      AUTHOR: Stf Kolew
  87. // AUTHOR/DATE: JP 2017-10-12
  88. ////////////////////////////////////////////////////////////////////////////////
  89. int main() {
  90.  
  91.   // 1 Print Car
  92.   cout << fixed << setprecision(2) << calculate_the_job(16, 1, 1, 0.01, 7) << endl;
  93.  
  94.   // 50 copies of books with 30 pages each, rounded down to 16 pages
  95.   // due to 1 print car = 16 pages.
  96.   cout << calculate_color_printing(30, 50, 16) << endl;
  97.  
  98.   // 35 copies of books with 34 pages each. Uses 2 print cars
  99.   // Due to 34's lowest multiple of 16 is 32.
  100.   cout << calculate_bw_printing(34, 35, 16) << endl;
  101.  
  102.   // 35 copies of books with 34 pages each where print car
  103.   // pages equals 8.
  104.   cout << calculate_bw_printing(34, 35, 8) << endl;
  105.   // 100 copies of books with 34 pages each where print car
  106.   // pages equals 6.
  107.   cout << calculate_bw_printing(34, 100, 6) << endl;
  108.  
  109.   return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement