kirya_shkolnik

Кристиночке, дорогой

Sep 25th, 2020 (edited)
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "math.h"
  4. #include "string"
  5. #include "bits/stdc++.h"
  6.  
  7. MainWindow::MainWindow(QWidget [id2956970|*parent]) :
  8.  QMainWindow(parent),
  9.  ui(new Ui::MainWindow)
  10. {
  11.  ui->setupUi(this);
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16.  delete ui;
  17. }
  18.  
  19.  
  20. string transformation(int value, int base)
  21. {
  22.     string output;          
  23.     while(value > 0)
  24.     {
  25.         char digit = value % base;
  26.  
  27.         if(digit < 10)
  28.             digit += 48;
  29.         else
  30.             digit += 55;
  31.         output += digit;
  32.         int ost = value % base;
  33.         value /= base;
  34.     }
  35.     reverse(output.begin(), output.end());
  36.     return output;
  37. }
  38.  
  39. void MainWindow::on_pushButton_Result_clicked()
  40. {
  41.  QString str,bases;
  42.  int input, base;
  43.  
  44.  str = ui->lineEdit_Decimal->text(); // input number
  45.  bases = ui->lineEdit_Base->text();  // input base to
  46.  input=str.toInt();
  47.  base=bases.toInt();
  48.  
  49.  QString output;
  50.  output = transformation(input, base);
  51.  ui->label_Binary->setText(output); //output
  52.  
  53. }
Add Comment
Please, Sign In to add comment