Advertisement
Guest User

Untitled

a guest
Apr 13th, 2021
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // код на С++, с защитой от неверного ввода.
  2.  
  3. C++ (Qt)Выделить код
  4. #include <iostream>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. struct mypoint
  9. {
  10. double x;
  11. double y;
  12. };
  13.  
  14. template <class T>
  15. bool EnterValue(const char * msg, T &val)
  16. {
  17. bool bRet = true;
  18. cout<<msg;
  19. if(!(cin>>val))
  20. bRet = false;
  21. if(!bRet)
  22. {
  23. cin.clear();
  24. cin.sync();
  25. }
  26. return bRet;
  27. }
  28.  
  29. bool EnterPoint(const char * msg, mypoint &pt)
  30. {
  31. bool bRet = true;
  32. cout<<msg<<endl;
  33. if((bRet = EnterValue("x = ", pt.x)))
  34. bRet = EnterValue("y = ", pt.y);
  35. return bRet;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement