Advertisement
Spocoman

04. Car To Go

Sep 6th, 2023
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     double budget;
  8.     cin >> budget;
  9.  
  10.     string season;
  11.     cin >> season;
  12.  
  13.     string modelCar = "";
  14.     string classCar = "";
  15.  
  16.     if (budget <= 100) {
  17.         if (season == "Summer") {
  18.             modelCar = "Cabrio";
  19.             budget *= 0.35;
  20.         }
  21.         else {
  22.             modelCar = "Jeep";
  23.             budget *= 0.65;
  24.         }
  25.         classCar = "Economy class";
  26.     }
  27.     else if (budget <= 500) {
  28.         if (season == "Summer") {
  29.             modelCar = "Cabrio";
  30.             budget *= 0.45;
  31.         }
  32.         else {
  33.             modelCar = "Jeep";
  34.             budget *= 0.80;
  35.         }
  36.         classCar = "Compact class";
  37.     }
  38.     else {
  39.         modelCar = "Jeep";
  40.         classCar = "Luxury class";
  41.         budget *= 0.90;
  42.     }
  43.  
  44.     cout << (classCar) << endl;
  45.     cout << modelCar << " - " << fixed << setprecision(2) << budget << endl;
  46.  
  47.     return 0;
  48. }
  49.  
  50. Или леко тарикатската:
  51.  
  52. #include <iostream>
  53. #include <iomanip>
  54.  
  55. using namespace std;
  56.  
  57. int main() {
  58.     double budget;
  59.     cin >> budget;
  60.  
  61.     string season;
  62.     cin >> season;
  63.  
  64.     string modelCar = "Jeep";
  65.     string classCar = "Luxury";
  66.  
  67.     if (budget <= 100) {
  68.         if (season == "Summer") {
  69.             modelCar = "Cabrio";
  70.             budget *= 0.35;
  71.         }
  72.         else {
  73.             budget *= 0.65;
  74.         }
  75.         classCar = "Economy class";
  76.     }
  77.     else if (budget <= 500) {
  78.         if (season == "Summer") {
  79.             modelCar = "Cabrio";
  80.             budget *= 0.45;
  81.         }
  82.         else {
  83.             budget *= 0.80;
  84.         }
  85.         classCar = "Compact class";
  86.     }
  87.     else {
  88.         classCar = "Luxury class";
  89.         budget *= 0.90;
  90.     }
  91.  
  92.     cout << (classCar) << endl;
  93.     cout << modelCar << " - " << fixed << setprecision(2) << budget << endl;
  94.  
  95.     return 0;
  96. }
  97.  
  98. Решение с тернарен оператор:
  99.  
  100. #include <iostream>
  101. #include <iomanip>
  102.  
  103. using namespace std;
  104.  
  105. int main() {
  106.     double budget;
  107.     cin >> budget;
  108.  
  109.     string season;
  110.     cin >> season;
  111.  
  112.     string modelCar = budget <= 500 ? (season == "Summer" ? "Cabrio" : "Jeep") : "Jeep";
  113.  
  114.     string classCar = budget <= 100 ? "Economy class" : budget <= 500 ? "Compact class" : "Luxury class";
  115.  
  116.     budget *=
  117.         budget <= 100 ? (season == "Summer" ? 0.35 : 0.65) :
  118.         budget <= 500 ? (season == "Summer" ? 0.45 : 0.80) : 0.90;
  119.  
  120.     cout << (classCar) << endl;
  121.     cout << modelCar << " - " << fixed << setprecision(2) << budget << endl;
  122.  
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement