Advertisement
Guest User

Untitled

a guest
May 17th, 2017
3,953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. void menu() {
  6.     cout << "1. Bin -> Dec" << endl;
  7.     cout << "2. Dec -> Bin" << endl;
  8.     cout << "3. Potegowanie" << endl;
  9.     cout << "0. Koniec" << endl;
  10.     cout << "Co chcesz zrobic?: ";
  11. }
  12.  
  13. void bintoDec(int bin, int dec, int w, int potega) {
  14.     potega = 1;
  15.     cout << "Podaj liczbe w binarnym: ";
  16.     cin >> bin;
  17.     do {
  18.         w = bin % 10;
  19.         dec = w * potega + dec;
  20.         bin = bin / 10;
  21.         potega = potega * 2;
  22.     } while(bin > 0);
  23.     cout << "Wynik to: " << dec << endl;
  24. }
  25.  
  26. void dectoBin(int bin, int dec, int w, int potega) {
  27.     potega = 1;
  28.     bin = 0;
  29.     cout << "Podaj liczbe w dziesietnym: ";
  30.     cin >> dec;
  31.     do {
  32.         w = dec % 2;
  33.         bin = w * potega + bin;
  34.         potega = potega * 10;
  35.         dec = dec / 2;
  36.     } while(dec > 0);
  37.     cout << "Wynik to: " << bin << endl;
  38. }
  39.  
  40. void obliczPotega(int potega, int podstawa, int wykladnik, int i) {
  41.     potega = 1;
  42.     cout << "Podaj kolejno podstawe i wykladnik: ";
  43.     cin >> podstawa;
  44.     cin >> wykladnik;
  45.     for(i = wykladnik; i > 0; i--) {
  46.         potega = potega * podstawa;
  47.     }
  48.     cout << "Wynik to: " << potega << endl;
  49. }
  50.  
  51. int main(int argc, char** argv) {
  52.  
  53.     int ch, bin, dec, w, i, podstawa, wykladnik;
  54.     int potega = 1;
  55.  
  56.     do {
  57.         menu();
  58.         cin >> ch;
  59.  
  60.         switch(ch) {
  61.             case 1:
  62.                 system("cls");
  63.                 bintoDec(bin, dec, w, potega);
  64.                 break;
  65.             case 2:
  66.                 system("cls");
  67.                 dectoBin(bin, dec, w, potega);
  68.                 break;
  69.             case 3:
  70.                 system("cls");
  71.                 obliczPotega(potega, podstawa, wykladnik, i);
  72.             default:
  73.                 break;
  74.         }
  75.     } while(ch != 0);
  76.  
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement