Advertisement
frustration

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

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