Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class drob{
- public:
- int first;
- int second;
- drob(){
- first=4;
- second=16;
- }
- drob(int x,int y){
- first=x;
- second=y;
- }
- void input(){
- cout << "Vvedite chislitel: "<<endl;
- cin >> first;
- do {
- cout << "Vvedite znamenatel: "<<endl;
- cin >> second;
- }
- while (second == 0);
- }
- void view(){
- cout<< "Chislitel:"<<first<<endl;
- cout<<"Znamenatel:"<<second<<endl;
- }
- int divisor(int x,int y)
- {
- if (!y) return x;
- else return divisor(y, x%y);
- }
- void reduct() {
- int gcd=divisor(first, second);//greatest common divisor
- first/=gcd;
- second/=gcd;
- }
- };
- int main() {
- drob val1,val2(5,15),val3;
- val3.input();
- cout<<"Drobi:"<<endl;
- val1.view();
- val2.view();
- val3.view();
- cout<<"Sokrashchaem:"<<endl;
- val1.reduct();
- val1.view();
- val2.reduct();
- val2.view();
- val3.reduct();
- val3.view();
- int n;
- cout<<"Razmer massiva:"<<endl;
- cin>>n;
- vector <drob> mas(n);
- for(int i=0;i<n;i++){
- mas[i].input();
- mas[i].reduct();
- mas[i].view();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement