C++ Simple equation Parser – Code Review Stack Exchange

I am relatively new to C++ coming form languages such as Java and would like tips to make my code more C++ like and doing things in the C++ way.

The header file

#pragma once

#include <string>
#include <memory>

class Expression
{
public:
    std::string symbol;
    std::shared_ptr<Expression> left;
    std::shared_ptr<Expression> right;

    float eval();
    static Expression parse(std::string s);

private:
    Expression(std::string symbol, Expression *left, Expression *right);
    static Expression parseRec(std::string s);
    static float evalRec(const Expression &e);
};

cpp file:

#include "Expression.hpp"
#include <unordered_map>

Expression::Expression(std::string symbol, Expression *left, Expression *right)
    : symbol(symbol), left(left), right(right) {}

float Expression::eval()
{
    return Expression::evalRec(*this);
}

float Expression::evalRec(const Expression &e)
{
    switch (e.symbol(0))
    {
    case '+':
        return evalRec(*e.left) + evalRec(*e.right);
    case '-':
        return evalRec(*e.left) - evalRec(*e.right);
    case '*':
        return evalRec(*e.left) * evalRec(*e.right);
    case "https://codereview.stackexchange.com/":
        return evalRec(*e.left) / evalRec(*e.right);
    default:
        return std::stoi(e.symbol);
    }
}

Expression Expression::parse(std::string s)
{
    //Remove whitespace
    std::string output;
    for (auto &i : s)
    {
        if (i != ' ')
            output += i;
    }
    return parseRec(output);
}

Expression Expression::parseRec(std::string s)
{
    const std::unordered_map<char, int> precedence = {{'+', 1}, {'-', 1}, {'*', 10}, {"https://codereview.stackexchange.com/", 10}};
    int indexOfLowest = -1;
    int i = 0;
    for (auto &&j : s)
    {
        switch (j)
        {
        case '+':
        case '-':
        case '*':
        case "https://codereview.stackexchange.com/":
            if (indexOfLowest == -1)
                indexOfLowest = i;
            else if (precedence.at(j) <= precedence.at(s(indexOfLowest)))
                indexOfLowest = i;
            break;
        default:
            break;
        }
        i++;
    }
    if (indexOfLowest == -1)
    {
        return Expression(s, NULL, NULL);
    }
    else
    {
        return Expression(std::string(1, s(indexOfLowest)),
                          new Expression(parseRec(s.substr(0, indexOfLowest))),
                          new Expression(parseRec(s.substr(indexOfLowest + 1, s.length() - indexOfLowest - 1))));
    }
}

and a simple main:

#include <iostream>
#include "Expression.hpp"

int main(int argc, char const *argv())
{
    //Parsed expression tree
    Expression e = Expression::parse("5 + 10 * 2 + 6 / 3");
    std::cout << e.eval() << std::endl;
    return 0;
}

Many thanks

magento2 – Linking InsertListings – Magento Stack Exchange

I have two database tables, zones and rules. The rules includes a foreign key to the zones table (i.e. zone_id) and I wish to create an admin form to edit these.

The zone edit form includes the various fields of the zone in one fieldset and an insertListings ui component in another. At the moment the rules listings shows all listings, for every single zone, but I want to limit this to the zone that is being editted.

How do I connect the insertListings to only show the rules associated with the id of the form?

Any help will be appreciated.

Render LaTeX Facebook – Web Applications Stack Exchange

How do I render LaTeX in Facebook? The Chrome “Tex all the things” extension does not work.
It does not render, it does not render, it does not render, it does not render. It does not render, it does not render, it does not render, it does not render.

bitcoin feeless transactions – Bitcoin Stack Exchange

The mobile application cashapp specifically says I can send bitcoin to any address anywhere in the world for free.

Coinbase also says they can do off the network transactions instantly and for free as long as both parties have a coinbase address…how does this work ? Does a miner check these transactions ?

Where does the concept of average transaction fee come into place ?
https://ycharts.com/indicators/bitcoin_average_transaction_fee

Is this exchange legitimate?

I was sent a discord message with an invitation to an exchange called www.doxxwallet.com. They offered me 0.21 bitcoin as a joining bonus, and I created the account and according to them do indeed have a wallet with .21 bitcoin. In order to withdraw the bitcoin, I have to transfer to the website 0.006 bitcoin and then I can withdraw the entire balance.

This sounds pretty scammy, but I wanted to see if anyone else had heard of them or had a way to verify that this website is legitimate? I have an image of the message I received below.

enter image description here

SharePoint Prevent Scrolling – SharePoint Stack Exchange

I have created a landing page where all of the elements fit in the window without having to scroll. But inconveniently, there is a bunch of white space at the bottom of the page and it will scroll all the way down for no reason.

I have all of my divs within the body element (pretty much everything is in the body element), so I tried:
body, html { margin: 0; padding: 0; height: 100%; overflow-y: hidden; } and of course it did nothing. I have found several posts about scrolling, but not related to SharePoint. I tried applying these fixes and of course nothing happens in SharePoint, but when I go to JSFiddle… it magically works.

https://stackoverflow.com/questions/2589399/css-overflow-hidden-does-not-work

https://stackoverflow.com/questions/28411499/disable-scrolling-on-body

If my code is needed, please let me know and I will add it. But I do not see why I would need to post it when it works on Fiddle, but not SharePoint. SharePoint is so buggy I hate it.

Microsoft Teams: invalid_resource|AADSTS500014 – Web Applications Stack Exchange

When I am opening the site teams.microsoft.com it showns me the followng window

enter image description here

  1. Text in the middle states: This indicate that a subscription within the tenant has lapsed, or that the administrator for this tenant has disabled the application, preventing tokens from being issued for it.

What this can mean? What is “this tenant”? What is “tenant” and which of them is “this”?

  1. Button means “Enter”. If I press it, the window reappears.

  2. Text below states: if this doesn’t work, then try to exit and then enter again.

What this can mean? What it “Exit”? How to exit? I have only “Enter” button and not “Exit” one? Exit form where? And enter to where?

โ“ASK – What should i need to open my own exchange ! | NewProxyLists

This question is very interesting, 3 years ago I wanted to launch a cryptocurrency exchange, but my partner was not convinced and I did not continue to persevere, now I regret not having done it.
The main thing you should have is a lot of money for hosting, security, programmers, etc.

An amazing site to exchange and profit from cryptocurrencies | NewProxyLists

An amazing site to exchange and profit from cryptocurrencies

Great and reliable cryptocurrency exchange (buy + sell + exchange)
It is also a profit site that you can profit from
Visit the site and check for yourself ๐Ÿ˜๐Ÿ˜๐Ÿ˜

Visiting site

โ€‹

Post automatically merged:

https: //cutt.*us/*NCPYp

Post automatically merged:

Delete the * and enter the site

ย 

Last edited:

probability – Compute $F_V(t)$ – Mathematics Stack Exchange

Given $f_{X,Y}(t)=left{begin{array}{rcl} 1/2& xin(-1,0),-1-xleq yleq1+x\1/2& xin(0,1),x-1leq yleq1-xend{array}right.$
Compute $F_V(t)$ V=X-Y

I’ve tried using $F_V(t)=int_{-infty}^{t}int_{-infty}^{infty}f(x+y,y)dydx$ and got $F_V(t)=left{begin{array}{rcl} frac{t^2+2t+2}{2}& tleq0\
frac{-t^2+2t+2}{2}& tgeq0end{array}right.$

But in the answers the result is $Vsim U(-1,1)$