Petro_zzz

lesson4

Jun 23rd, 2022
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. void checkVar() {
  8.     int var;
  9.     cout << "Input ";
  10.     cin >> var;
  11.     if (var > 0)
  12.         cout << "positive" << endl;
  13.     else {
  14.         if (var < 0)
  15.             cout << "negative" << endl;
  16.         else
  17.             cout << "zero" << endl;
  18.     }
  19. }
  20.  
  21. void calcVolume() {
  22.     int isSphere = 0;
  23.     cout << "Что вы хотите вычислить?" << endl;
  24.     cout << "1 - Объём шара" << endl;
  25.     cout << "2 - Объём куба" << endl;
  26.     cin >> isSphere;
  27.     //const double pi = M_PI;
  28.     double volume = 0;
  29.     double size = 0;
  30.     if (isSphere == 1) {
  31.         cout << "Введите радиус" << endl;
  32.         cin >> size;
  33.         volume = 3.0 / 4.0 * M_PI * size * size * size;
  34.     }
  35.     else if (isSphere == 2) {
  36.         cout << "Введите сторону" << endl;
  37.         cin >> size;
  38.         volume = size * size * size;
  39.     } else {
  40.         cout << "Ошибка" << endl;
  41.     }
  42.     cout << "Объём " << volume << endl;
  43. }
  44.  
  45. void calcPrice() {
  46. /*Покупатель покупает N дисков по M рублей.
  47. Если сумма покупки больше 10000 рублей, то
  48. скидка составит 10 %, если число дисков больше 4,
  49. то 5 диск достаётся в подарок.*/
  50.     int num, price;
  51.     const double sale = 0.1;
  52.     const int minPriceForSale = 10000;
  53.     const int numForGift = 4;
  54.    
  55.     cout << "Введите число дисков ";
  56.     cin >> num;
  57.     cout << "Введите цену каждого диска ";
  58.     cin >> price;
  59.    
  60.     if (num > numForGift) {
  61.         num = num - 1;
  62.         cout << "Один диск в подарок." << endl;
  63.     }
  64.     if (num * price > minPriceForSale) {
  65.         cout << "Ваша скидка 10%" << endl;
  66.         cout << "К оплате " << num * price * (1 - sale) << " рублей.";
  67.     }
  68.     else {
  69.         cout << "К оплате " << num * price << " рублей.";
  70.     }
  71. }
  72.  
  73. void isInSquare() {
  74.     int x, y; // point
  75.     int x0, y0, a; // square
  76.     cout << "Input point ";
  77.     cin >> x >> y;
  78.     cout << "Input x0, y0, a for square ";
  79.     cin >> x0 >> y0 >> a;
  80.     int xmin = x0;
  81.     int xmax = x0 + a;
  82.     int ymin = y0;
  83.     int ymax = y0 + a;
  84.     bool ex = (x >= xmin) && (x <= xmax) &&
  85.               (y >= ymin) && (y <= ymax);
  86.     if (ex)
  87.         cout << "The point in square";
  88.     else
  89.         cout << "The point no in square";
  90. }
  91.  
  92. void ring() {
  93.     int x, y; // point
  94.     int x0, y0, R1, R2; // ring
  95.     cout << "Input point ";
  96.     cin >> x >> y;
  97.     cout << "Input x0, y0, r1, r2 for ring ";
  98.     cin >> x0 >> y0 >> R1 >> R2;
  99.     int RR = pow((x - x0), 2) + pow((y - y0), 2);
  100.     if (R1 * R1 < RR < R2 * R2)
  101.         cout << "The point in ring";
  102.     else
  103.         cout << "The point no in ring";
  104. }
  105.  
  106. int main(){
  107.     setlocale(LC_ALL, "Russian");
  108.     // просто раскомментируй то, что нужно
  109.     //checkVar();
  110.     //calcVolume();
  111.     //calcPrice();
  112.     //isInSquare();
  113.     //ring();
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment