madzik4113

sztangret fun_lin

Jan 31st, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Utwórz strukturę o nazwie fun_lin z dwoma polami a oraz b(parametry funkcji liniowej y=ax+b). Napisz trzy
  2. funkcje: wpr– funkcja służąca do wprowadzenia a i b zwracająca strukturę; zero– funkcja jako argument
  3. przyjmuje strukturę i zwraca miejsce zerowe funkcji (zakładamy że a!=0); wart– funkcja zwracająca wartość
  4. funkcji w punkcie przesłanym do funkcji jako drugi argument. W funkcji mainutwórz stworzoną strukturę i
  5. napisz wywołania funkcji.
  6.  
  7.  
  8. #include "stdafx.h"
  9. #include <cmath>
  10. #include <cstdlib>
  11. #include <cstdio>
  12. #include <iostream>
  13. using namespace std;
  14.  
  15. struct fun_lin
  16. {
  17. double a,b;
  18. };
  19.  
  20. fun_lin wpr()
  21. {
  22. fun_lin jeden;
  23. cout<<"podaj a : ";
  24. cin>>jeden.a;
  25. cout<<"podaj b : ";
  26. cin>>jeden.b;
  27. return jeden;
  28. }
  29. double zero(fun_lin jeden)
  30. {
  31. return -(jeden.b/jeden.a);
  32. }
  33. double wart(fun_lin jeden, double x)
  34. {
  35. return jeden.a*x+jeden.b;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. int _tmain(int argc, _TCHAR* argv[])
  42. {
  43. fun_lin jeden;
  44. double x;
  45. jeden=wpr();
  46. cout<<"miejsce zerowe : "<<zero(jeden)<<endl;
  47. cout<<"podaj x : ";
  48. cin>>x;
  49. cout<<"wartosc funkcji w punkcie "<<x<<" wynosi : "<<wart(jeden,x)<<endl;
  50.  
  51. system("PAUSE");
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment