Advertisement
frustration

DONE. Вычислить значение функции F. функция. 1вариант

Apr 5th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. /* Вычислить и вывести на экран в виде таблицы значение функции F на интервале Xнач. до Хкон. с шагом Xd.
  2.       |a*i*i*i + b*i*i + c;   при х<0.6 и b+c !=0
  3.  F = < (i - a) / (i - c);     при х>0.6 и b+c =0
  4.       |i / c + i / a;         в остальных случаях
  5.  если ((int(a) || int(b) && int(c)) != 0) вывести не int, иначе int */
  6.  
  7.  
  8.  
  9. #include <iostream>
  10. #include <conio.h>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <stdio.h>
  14.  
  15.  
  16. using namespace std;
  17.  
  18. float func1(float a, float b, float c, float i){
  19.     return a*i*i*i + b*i*i + c;
  20. }
  21.  
  22. float func2(float a, float c, float i){
  23.     return (i - a) / (i - c);
  24. }
  25.  
  26. float func3(float a, float c, float i){
  27.     return i / c + i / a;
  28. }
  29.  
  30. void system(float a, float b, float c, float Xnach, float Xkon, float Xd){
  31.  
  32.  
  33.     cout.setf(ios::fixed);
  34.     cout << setprecision(1);
  35.  
  36.     cout << "___________________" << endl;
  37.     cout << "|  x     |   F    |" << endl;
  38.     cout << "|________|________|" << endl;
  39.  
  40.  
  41.     float r;
  42.     for (float i = Xnach; i < Xkon; i += Xd){
  43.  
  44.         if (i < 0.6 && b + c != 0)
  45.             r=func1(a, b, c, i);
  46.  
  47.         else if (i > 0.6 && b + c == 0){
  48.             if (i - c >= 0)
  49.                 r=func2(a, c, i);
  50.         }
  51.  
  52.         else  if (c != 0 && a != 0)
  53.             r=func3(a, c, i);
  54.         else continue;
  55.         cout.width(4);
  56.  
  57.         if ((int(a) || int(b) && int(c)) != 0){
  58.  
  59.             printf_s("| %5.1f  | %5.1f  |\n", i, r);
  60.         }
  61.         else printf_s("| %5.1f  | %5.1f  |\n"), i, int(r);
  62.         cout << endl;
  63.     }
  64.     cout << "-------------------" << endl;
  65.  
  66. }
  67.  
  68. int main(){
  69.  
  70.     float a, b, c, Xnach, Xkon, Xd;
  71.  
  72.  
  73.     cout << "vvod a = ";
  74.     cin >> a;
  75.     cout << "vvod b = ";
  76.     cin >> b;
  77.     cout << "vvod c = ";
  78.     cin >> c;
  79.     cout << "vvod Xnach = ";
  80.     cin >> Xnach;
  81.     cout << "vvod Xkon = ";
  82.     cin >> Xkon;
  83.     cout << "vvod Xd = ";
  84.     cin >> Xd;
  85.  
  86.     system(a, b, c, Xnach, Xkon, Xd);
  87.  
  88.  
  89.     _getch();
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement