//вывод в консоль void cnsl_output(NODE* list) { system("cls"); int i = 0; int n = get_n(amt(list), "Введите количество записей, выводимых на одной странице", "out"); while (list) { if (!(i % n)) { if (i && list) { printf_s("\n Далее - нажмите Enter"); rewind(stdin); getchar(); } system("cls"); printf_s("\n-------------------------------------------------------------------------------- \n"); printf_s(" | %3s | %20s | %20s | %6s | %10s, USD |", "№", "Исполнитель", "Альбом", "Год", "Цена"); printf_s("\n-------------------------------------------------------------------------------- \n"); } printf_s(" | %3d | %20s | %20s | %6d | %10.2f |", (i++) + 1, list->data->artist, list->data->album, list->data->year, list->data->price); printf_s("\n-------------------------------------------------------------------------------- \n"); list = list->next; } printf_s("\n Возврат в меню - нажмите Enter"); rewind(stdin); getchar(); }
//меню int menu(NODE* list) { system("cls"); if (list) { printf_s("\n На данный момент записей в списке: %d\n", amt(list)); printf_s("\n МЕНЮ\n\n"); puts(" 1 - Справка"); puts(" 2 - Заполнение списка"); puts(" 3 - Вывести список"); puts(" 4 - Очистить список"); puts(" 0 - Выход"); } else { printf_s("\n На данный момент список пуст\n"); printf_s("\n МЕНЮ\n\n"); puts(" 1 - Справка"); puts(" 2 - Заполнение списка"); puts(" 0 - Выход"); } return(userchoice()); }
void Resource::addToTable(){ // if we haven't logged the resource type yet, do so if ( !this->is_resource_type_logged() ){ Resource::logNewType(); this->type_logged(); } // if we haven't yet, define the table if ( !resource_table->defined() ) Resource::define_table(); // make a row // declare data data an_id( this->ID() ), a_type( (int)this->type() ), an_amt( this->quantity() ), a_creator( this->originatorID() ); // declare entries entry id("ID",an_id), type("Type",a_type), amt("OriginalQuantity", an_amt), creator("OriginatorID",a_creator); // declare row row aRow; aRow.push_back(id), aRow.push_back(type), aRow.push_back(amt), aRow.push_back(creator); // add the row resource_table->addRow(aRow); // record this primary key pkref_.push_back(id); }
void GLWidget::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_F && event->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier)) { if (_fullScreen) { _fullScreen = false; this->showNormal(); } else { _fullScreen = true; this->showFullScreen(); } } else if (event->key() == Qt::Key_Minus || event->key() == Qt::Key_Underscore) { zoom(1.2); } else if (event->key() == Qt::Key_Equal || event->key() == Qt::Key_Plus) { zoom(0.8); } else if (event->key() == Qt::Key_Left) { QPoint amt(width()*0.1, 0); if (event->modifiers() & Qt::ShiftModifier) amt *= 2; moveView(amt); } else if (event->key() == Qt::Key_Right) { QPoint amt(-width()*0.1, 0); if (event->modifiers() & Qt::ShiftModifier) amt *= 2; moveView(amt); } else if (event->key() == Qt::Key_Up) { QPoint amt(0, height()*0.1); if (event->modifiers() & Qt::ShiftModifier) amt *= 2; moveView(amt); } else if (event->key() == Qt::Key_Down) { QPoint amt(0, -height()*0.1); if (event->modifiers() & Qt::ShiftModifier) amt *= 2; moveView(amt); } QGLWidget::keyPressEvent(event); }
/** * Assuming a.type is either the numerator.type or denominator.type in * the price equation, return the number of the other asset type that * could be exchanged at price p. * * ie: p = 3 usd/bts & a = 4 bts then result = 12 usd * ie: p = 3 usd/bts & a = 4 usd then result = 1.333 bts */ asset operator * ( const asset& a, const price& p ) { try { if( a.asset_id == p.base_asset_id ) { fc::bigint ba( a.amount ); // 64.64 fc::bigint r( p.ratio ); // 64.64 auto amnt = ba * r; // 128.128 amnt /= BTS_PRICE_PRECISION; // 128.64 auto lg2 = amnt.log2(); if( lg2 >= 128 ) { FC_THROW_EXCEPTION( addition_overflow, "overflow ${a} * ${p}", ("a",a)("p",p) ); } asset rtn; rtn.amount = amnt.to_int64(); rtn.asset_id = p.quote_asset_id; ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",rtn) ); return rtn; } else if( a.asset_id == p.quote_asset_id ) { fc::bigint amt( a.amount ); // 64.64 amt *= BTS_PRICE_PRECISION; //<<= 64; // 64.128 fc::bigint pri( p.ratio ); // 64.64 auto result = amt / pri; // 64.64 // ilog( "amt: ${amt} / ${pri}", ("amt",string(amt))("pri",string(pri) ) ); // ilog( "${r}", ("r",string(result) ) ); auto lg2 = result.log2(); if( lg2 >= 128 ) { // wlog( "." ); FC_THROW_EXCEPTION( addition_overflow, "overflow ${a} / ${p} = ${r} lg2 = ${l}", ("a",a)("p",p)("r", std::string(result) )("l",lg2) ); } // result += 5000000000; // TODO: evaluate this rounding factor.. asset r; r.amount = result.to_int64(); r.asset_id = p.base_asset_id; ilog( "r.amount = ${r}", ("r",r.amount) ); ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",r) ); return r; } FC_THROW_EXCEPTION( asset_type_mismatch, "type mismatch multiplying asset ${a} by price ${p}", ("a",a)("p",p) ); } FC_RETHROW_EXCEPTIONS( warn, "type mismatch multiplying asset ${a} by price ${p}", ("a",a)("p",p) ); }
/** * Assuming a.type is either the numerator.type or denominator.type in * the price equation, return the number of the other asset type that * could be exchanged at price p. * * ie: p = 3 usd/bts & a = 4 bts then result = 12 usd * ie: p = 3 usd/bts & a = 4 usd then result = 1.333 bts */ asset operator * ( const asset& a, const price& p ) { try { if( a.unit == p.base_unit ) { fc::bigint ba( a.amount ); // 64.64 fc::bigint r( p.ratio ); // 64.64 //fc::uint128 ba_test = ba; auto amnt = ba * r; // 128.128 amnt >>= 64; // 128.64 auto lg2 = amnt.log2(); if( lg2 >= 128 ) { FC_THROW_EXCEPTION( exception, "overflow ${a} * ${p}", ("a",a)("p",p) ); } // amnt += 5000000000; // TODO:evaluate this rounding factor... asset rtn; rtn.amount = amnt; rtn.unit = p.quote_unit; ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",rtn) ); return rtn; } else if( a.unit == p.quote_unit ) { fc::bigint amt( a.amount ); // 64.64 amt <<= 64; // 64.128 fc::bigint pri( p.ratio ); // 64.64 auto result = amt / pri; // 64.64 //auto test_result = result; //ilog( "test result: ${r}", ("r", std::string(test_result >>= 60) ) ); auto lg2 = result.log2(); if( lg2 >= 128 ) { // wlog( "." ); FC_THROW_EXCEPTION( exception, "overflow ${a} / ${p} = ${r} lg2 = ${l}", ("a",a)("p",p)("r", std::string(result) )("l",lg2) ); } // result += 5000000000; // TODO: evaluate this rounding factor.. asset r; r.amount = result; r.unit = p.base_unit; ilog( "${a} * ${p} => ${rtn}", ("a", a)("p",p )("rtn",r) ); return r; } FC_THROW_EXCEPTION( exception, "type mismatch multiplying asset ${a} by price ${p}", ("a",a)("p",p) ); } FC_RETHROW_EXCEPTIONS( warn, "type mismatch multiplying asset ${a} by price ${p}",
Amount AmountFromValue(const UniValue &value) { if (!value.isNum() && !value.isStr()) throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string"); int64_t n; if (!ParseFixedPoint(value.getValStr(), 8, &n)) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); Amount amt(n); if (!MoneyRange(amt)) throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range"); return amt; }
//добавление узла в н-ную позицию NODE* add_n(NODE* list) { if (!list) { system("cls"); printf_s("\n Список пуст, запись будет осуществлена в начало\n\n "); system("pause"); list = add_first(list); } else { int n = get_n(amt(list), "Введите номер позиции, в которую следует добавить запись", "add"); if (n == 1) list = add_first(list); else if (n == amt(list) + 1) list = add_last(list); else { NODE* nta = fill_fields(); NODE *tmp = list; int i; for (i = 1; i < n - 1; i++) tmp = tmp->next; nta->next = tmp->next; tmp->next->prev = nta; nta->prev = tmp; tmp->next = nta; printf_s("\n Новая запись была добавлена в позицию № %d списка\n\n ", n); system("pause"); } } return list; }
// Specific resources void Resource::define_table(){ // declare the table columns column id("ID","INTEGER"); column type("Type","INTEGER"); column amt("OriginalQuantity","REAL"); column creator("OriginatorID","INTEGER"); // declare the table's primary key resource_table->setPrimaryKey(id); // add columns to the table resource_table->addColumn(id); resource_table->addColumn(type); resource_table->addColumn(amt); resource_table->addColumn(creator); // add foreign keys foreign_key_ref *fkref; foreign_key *fk; key myk, theirk; // Resource Types table foreign keys theirk.push_back("Type"); fkref = new foreign_key_ref("ResourceTypes",theirk); // the resource type myk.push_back("Type"); fk = new foreign_key(myk, (*fkref) ); resource_table->addForeignKey( (*fk) ); // type references Resource Types' type myk.clear(), theirk.clear(); // Agents table foreign keys theirk.push_back("ID"); fkref = new foreign_key_ref("Agents",theirk); // the originator id myk.push_back("OriginatorID"); fk = new foreign_key(myk, (*fkref) ); resource_table->addForeignKey( (*fk) ); // originatorid references Agents' id myk.clear(), theirk.clear(); // we've now defined the table resource_table->tableDefined(); }