Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #include <fstream>
- using namespace std;
- class NWD
- {
- public:
- int liczba1 = { 0 };
- int liczba2 = { 0 };
- int operacja(int a, int b);
- NWD(int a, int b);
- };
- /**************************************/
- int NWD::operacja(int a, int b)
- {
- while (a != b)
- {
- if (b > a)
- b -= a;
- else
- a -= b;
- }
- return a;
- }
- /**************************************/
- NWD::NWD(int a, int b)
- {
- liczba1 = a;
- liczba2 = b;
- }
- /**************************************/
- void zapisz(int a, int b, int wynik_NWD);
- /**************************************/
- class wczytaj
- {
- public:
- int a;
- wczytaj(int liczba)
- {
- a = liczba;
- }
- void odczyt();
- };
- int main()
- {
- int a, b;
- int wynik_NWD = { 0 };
- int ktory;
- do
- {
- cout << "******************************" << endl;
- cout << "Witamy w programie" << endl;
- cout << "1 - Konwertuj z Dziesietnego na Binarne i zapisz do pliku " << endl;
- cout << "2 - Odczytaj zawartosc pliku " << endl;
- cout << "0 - Koniec Programu " << endl;
- cout << "Wybierz opcje Programu ";
- cin >> ktory;
- switch (ktory)
- {
- case 1:
- {
- cout << "Podaj liczbe a: ";
- cin >> a;
- cout << "Podaj liczbe b: ";
- cin >> b;
- NWD zestaw1(a, b);
- wynik_NWD = zestaw1.operacja(a, b);
- zapisz(a, b, wynik_NWD);
- break;
- }
- case 2:
- {
- wczytaj losowe(1);
- losowe.odczyt();
- break;
- }
- default:
- {
- cout << "Podano bledny nr. produktu";
- break;
- }
- }
- } while (ktory != 0);
- }
- void zapisz(int a, int b, int wynik_NWD)
- {
- fstream raport;
- raport.open("raport.txt", ios::out | ios::app);
- if (raport.good() == true)
- {
- raport << endl << "a = " << a << ", b = " << b << ", wynik_NWD = " << wynik_NWD << ", Wynik binarnie = ";
- int i = 0, tab[31];
- while (wynik_NWD)
- {
- tab[i++] = wynik_NWD % 2;
- wynik_NWD /= 2;
- }
- for (int j = i - 1; j >= 0; j--)
- raport << tab[j];
- cout << "" << endl;
- }
- else
- {
- cout << "Error! Nie udalo otworzyc sie pliku! " << endl;
- }
- }
- void wczytaj::odczyt()
- {
- string linia;
- fstream raport;
- raport.open("raport.txt",ios::in);
- if (raport.good() == true)
- {
- while (!raport.eof())
- {
- getline(raport, linia);
- cout << linia << endl; //wyświetlenie linii
- }
- raport.close();
- }
- else
- {
- cout << "Error! Nie udalo otworzyc sie pliku! " << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement