Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class drob{
  6. public:
  7. int first;
  8. int second;
  9. drob(){
  10. first=4;
  11. second=16;
  12. }
  13. drob(int x,int y){
  14. first=x;
  15. second=y;
  16. }
  17. void input(){
  18. cout << "Vvedite chislitel: "<<endl;
  19. cin >> first;
  20. do {
  21. cout << "Vvedite znamenatel: "<<endl;
  22. cin >> second;
  23. }
  24. while (second == 0);
  25. }
  26. void view(){
  27. cout<< "Chislitel:"<<first<<endl;
  28. cout<<"Znamenatel:"<<second<<endl;
  29. }
  30. int divisor(int x,int y)
  31. {
  32. if (!y) return x;
  33. else return divisor(y, x%y);
  34. }
  35. void reduct() {
  36. int gcd=divisor(first, second);//greatest common divisor
  37. first/=gcd;
  38. second/=gcd;
  39. }
  40. };
  41.  
  42. int main() {
  43. drob val1,val2(5,15),val3;
  44. val3.input();
  45.  
  46. cout<<"Drobi:"<<endl;
  47.  
  48. val1.view();
  49. val2.view();
  50. val3.view();
  51.  
  52. cout<<"Sokrashchaem:"<<endl;
  53. val1.reduct();
  54. val1.view();
  55. val2.reduct();
  56. val2.view();
  57. val3.reduct();
  58. val3.view();
  59. int n;
  60.  
  61. cout<<"Razmer massiva:"<<endl;
  62. cin>>n;
  63. vector <drob> mas(n);
  64. for(int i=0;i<n;i++){
  65. mas[i].input();
  66. mas[i].reduct();
  67. mas[i].view();
  68. }
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement