Advertisement
Guest User

Untitled

a guest
May 21st, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include<string>
  3. #include<cmath>
  4. using namespace std;
  5. double Dzielenie(double, double);
  6. int Modulo(int, int);
  7.  
  8. int main()
  9. {
  10. int x,y;
  11. cout << "Dzielenie" <<endl;
  12. cout << "Podaj x:" << endl;
  13. cin >>x;
  14. cout << "Podaj y:" << endl;
  15. cin >> y;
  16.  
  17. try
  18. {
  19. Dzielenie(x,y);
  20. cout << "Wynik dzielenia: " << Dzielenie(x,y)<<endl;
  21. }
  22. catch(string wyjatek_dzielenia)
  23. {
  24. cout << "Wyjatek: " <<wyjatek_dzielenia<<endl;
  25. }
  26. cin.get();
  27.  
  28.  
  29. cout << "Modulo" <<endl;
  30. cout << "Podaj x:" << endl;
  31. cin >>x;
  32. cout << "Podaj y:" << endl;
  33. cin >> y;
  34.  
  35. try
  36. {
  37. Modulo(x,y);
  38. cout << "Wynik modulo: " << Modulo(x,y) << endl;
  39. }
  40. catch(string wyjatek_modulo)
  41. {
  42. cout << "Wyjatek: " <<wyjatek_modulo <<endl;
  43. }
  44. cin.get();
  45. return 0;
  46. }
  47.  
  48. double Dzielenie(double a, double b)
  49. {
  50. if(b==0)
  51. {
  52. string wyjatek = "dzielenie przez zero !";
  53. throw wyjatek;
  54. }
  55. return a/b;
  56. }
  57.  
  58. int Modulo(int c, int d)
  59. {
  60. if(c==d || d==0 || c%d==0 || d%c==0)
  61. {
  62. string wyjatek = "Wprowadzone dane sa rowne, badz sa swoja wielokrotnoscia albo druga liczba jest rowna zero";
  63. throw wyjatek;
  64. }
  65. return c%d;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement