Browse Source

intermediate checkin

recurring
adityapk00 6 years ago
committed by Aditya Kulkarni
parent
commit
ed85a4c1e9
  1. 8
      src/main.cpp
  2. 2
      src/precompiled.h
  3. 37
      src/turnstile.cpp
  4. 11
      src/turnstile.h
  5. 2
      zec-qt-wallet.pro

8
src/main.cpp

@ -1,5 +1,7 @@
#include "mainwindow.h"
#include "settings.h"
#include "turnstile.h"
#include "precompiled.h"
int main(int argc, char *argv[])
@ -16,6 +18,8 @@ int main(int argc, char *argv[])
qApp->setFont(QFont("Ubuntu", 11, QFont::Normal, false));
#endif
std::srand(std::time(nullptr));
QCoreApplication::setOrganizationName("zec-qt-wallet-org");
QCoreApplication::setApplicationName("zec-qt-wallet");
@ -24,6 +28,10 @@ int main(int argc, char *argv[])
MainWindow w;
w.setWindowTitle("zec-qt-wallet v" + QString(APP_VERSION));
w.show();
// Temp
Turnstile t;
qDebug() << t.splitAmount(1245.2294371, 3);
return QApplication::exec();
}

2
src/precompiled.h

@ -2,6 +2,8 @@
/* Add C++ includes here */
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <QApplication>
#include <QFontDatabase>

37
src/turnstile.cpp

@ -0,0 +1,37 @@
#include "precompiled.h"
#include "turnstile.h"
Turnstile::Turnstile() {
}
Turnstile::~Turnstile() {
}
QList<QString> Turnstile::splitAmount(double amount, int parts) {
QList<QString> amounts;
fillAmounts(amounts, amount, parts);
// Ensure they all add up!
double sumofparts = 0;
for (auto a : amounts) {
sumofparts += a.toDouble();
}
Q_ASSERT(sumofparts == amount);
return amounts;
}
void Turnstile::fillAmounts(QList<QString>& amounts, double amount, int count) {
if (count == 1 || amount < 1) {
amounts.push_back(QString::number(amount, 'g', 8));
return;
}
// Get a random amount off the amount and call recursively.
auto curAmount = std::rand() % (int)std::floor(amount);
amounts.push_back(QString::number(curAmount, 'g', 8));
fillAmounts(amounts, amount - curAmount, count - 1);
}

11
src/turnstile.h

@ -0,0 +1,11 @@
#pragma once
class Turnstile
{
public:
Turnstile();
~Turnstile();
QList<QString> Turnstile::splitAmount(double amount, int parts);
void fillAmounts(QList<QString>& amounts, double amount, int count);
};

2
zec-qt-wallet.pro

@ -50,6 +50,7 @@ SOURCES += \
src/sendtab.cpp \
src/senttxstore.cpp \
src/txtablemodel.cpp \
src/turnstile.cpp \
src/utils.cpp
HEADERS += \
@ -65,6 +66,7 @@ HEADERS += \
src/settings.h \
src/txtablemodel.h \
src/senttxstore.h \
src/turnstile.h \
src/utils.h
FORMS += \

Loading…
Cancel
Save