C :: Shunting-yard Algorithm To Evaluate Expressions?
Sep 16, 2014Can I use Shunting-yard algorithm to evaluate Expressions (arithmetic, relational, and logical) ?
View 8 RepliesCan I use Shunting-yard algorithm to evaluate Expressions (arithmetic, relational, and logical) ?
View 8 RepliesI am very new to programming and would like to know where to even start when evaluating a double integral. I wanted to evaluate this double integral: 6x^3 + y^2 +7x from 0 to 1 (for both).
View 1 Replies View RelatedHow to remake the code that i`ve written to have : a recursive function to evaluate the first n terms in series specified y= 1 - x + x^2/2 - x^3/6 + x^4/24 +....+(-1)^n x^n/n!
And this is my code:
#include <iostream>
using namespace std;
double power(int n, double x) {
double d =1;
for (int i = 1 ; i<=n ; i++)
[Code] ....
The program must evaluate the truth value of the conjunction, disjunction, and implication of each value row. For each logical operator, P is the argument to the left of the operator and Q is to the right.
For conjunction: P ^ Q, disjunction: P _ Q, and implication: P ! Q.
Example prog2 input.txt
P Q
T T
T F
F F
For each value row the program must output a corresponding row, in the following format:
P and Q:<T or F> ntP or Q:<T or F> ntP --> Q:<T or F> For the example input given above
the output is found below.
Example prog2 output.txt
P and Q : T P or Q : T P --> Q : T
P and Q : F P or Q : T P --> Q : F
P and Q : F P or Q : F P --> Q : T
.
This is what I did so far
# include<iostream>
#include<fstream>
using namespace std;
bool charTobool (char c) {
switch (c)
[Code] ....
The question was to evaluate postfix expression (floating point numbers). I had been able to implement stack data structure using one way singly linked list linked list but I am not been able to extract the original input by the user expressions like
ex:
1. 252.124 3453.7 * 46.3 346.2 23.6 ^/$
2.45.23 87.045 * 6.5 ^$
etc,($ELIMETER)
How to take such inputs from the user for proper evaluation . Previously I tried to extract separate digits from integer and decimal fields and computed numbers. The method is very lengthy. Any optimised way for taking such input!
Code:
int main() {
char *arr[] = {"Hello", "World", "Good", "Morning"};
display(arr);
return;
}
[code]....
The code works fine and prints the 4 strings. Where i m riddled is whether "ptr" in display function is a pointer or a string ? If it's a pointer then what is the type of the pointer? If it's an array, then as per my understanding, we cannot use an array name in expressions such as ptr++ (K&R).
Write a program that evaluates postfix expression using array implementation of stack.
The expression [the input] is evaluated from left to right using a stack. When the element read from the expression is an operand, push it into the stack.When the element read from the expression is an operator: Pop two operands from the stack.Evaluate the two operandsPush the result of the evaluation into the stack.
The final result lies on the top of the stack at the end of the calculation. Make sure to display the result before terminating the program.Write a program that evaluates postfix expression using array implementation of stack.
Code:
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define M 20
typedef struct{
[Code] ....
The point of my code is to evaluate a mathematical expression that's already formed in a Binary Search Tree. : ((6+5)-3)*(2/1)=?
I've read other forums and they usually use cout, cin and << >> but I'm still in the learning process so this is basically primitive coding.
Anyway, The recursion is already correct (I think). My problem is how to return char* or should I say an element which has 2 or more digits.
typedef struct cell{
char elem[max];
struct cell *left;
struct cell *right;
}celltype, *node;
node A;
char* evaluate(node *A) //passed as evaluation(&A);
[Code] ....
And the reason that I'm using char is because the operators are also elements in different nodes.
The code above is actually the result when I remembered that you can't return 2-digit char.
The code below is before I remembered that. It works when all results are 1 digit numbers.
typedef struct cell{
char elem;
struct cell *left;
struct cell *right;
}celltype, *node;
node A;
[Code] ....
i'm implementing a templated function callback.
I get this error:
"error C2064: term does not evaluate to a function taking 1 arguments"
I'm not sure why.
Here's the code for the template function in the timer class header:
template<class T>
void TimerEvent(DateAndTime DateTime, std::function<void(T)> Callback);
Now the class body:
template<class T>
void GameTimer::TimerEvent(DateAndTime DateTime, std::function<void(T)> Callback)
{
DateAndTime time;
time.Now(false);
if (time.Compare(DateTime) == 1)
Callback(T);
}
and calling the class in the Engine:
int test1(int a)
{
}
void Main()
{
gameTime.TimerEvent<int>(gh, test1(1));
}
I have this bit of code that I found here: [URL] and at first regex would work, but then when I hit "[]" it wouldn't. Here's the code:
#include <iostream>
#include <string>
#include <regex>
[Code]....
I get the following error:
Cannot convert lambda expression to type system delegate because it's not a delegate type (on invoke).
The Second error is: Client.PrivateChat.txtReceive is inaccessible due to its protection level..
private PrivateChat pChat;
private void client_Received(Client sender, byte[] data) {
this.Invoke(() =>
{
for (int i = 0; i < clientList.Items.Count; i++) {
var client = clientList.Items[i].Tag as Client;
if (client == null || client.Ip != sender.Ip) continue;
[Code] .....
The first call of my function works with empty vectors but fails when dimensions are introduced to the vectors.
When "uncommented, the commented out function call fails with the error above.
These links might be useful for those unfamiliar to QuantLib:
[URL]
QuantLib: GeneralLinearLeastSquares Class Reference
Code:
#include "stdafx.h"
#include "boost/multi_array.hpp"
#include <cassert>
#include <qlmathgenerallinearleastsquares.hpp>
#include <vector>
#include <list>
#include <iostream>
#include "boostlambdalambda.hpp"
[code]....
So I need to use boost/regex for regular expressions. someone told me that it needs to be built. the first problem is boost doesn't tell you how to build it and the second is i did sudo apt-get install libboost something. I don't remember the exact name of the package. it installed but i dont know how i would build it when its installed.
View 2 Replies View Relatedwriting a program for "Validating the e-mail id without using regular expressions in c/c++"?
View 4 Replies View RelatedI am looking for a library to aid me in evaluating Boolean expressions. For example, i have an expression like this:
(1*(5+3)+9*65/5-(354*4565*5643+98) >= 12345) && ( 654*987+123 || (2345 > 23423 && 1 != 2)))
(It can also be much longer!) and would like to evaluate them to a true/false boolean.
There are tons of libraries to calculate the (numerical) result of a mathematical expression, but this is not what i want to do.
In order to parse mathematical expressions I am trying regular expressions and a recursive algorithm, but I have a problem with the four basic operations: +, -, *, /.
Trying to analyze a string like "a+(b+c)", if I use the pattern for a sum "(.+)+(.+)" the program matches it recognizing as subpatterns: "a+(b" and "c". How could I achieve the program to try also the other possibility?
I think that it would be great something like an regex_iterator which worked with regex_match instead of regex_search. I mean, an iterator that iterates over all the possible ways to match a given regular expression and a given string. This way I could loop through all these possibilities until the two subpatterns produced were correct mathematical expressions.
Also, can't use namespace std for this.
#include<iostream>
#include<stack>
#include<fstream>
#include<iomanip>
#include<queue>
#include<cassert>
[Code] ....
/* It will read in a infix expression from a text file.check if the parentheses in the input expression are balanced.convert the infix expression into a postfix expression and evaluate the expression.*/
int main() {
string expression;
string postfixExpression;
double result;
testBalanced();
[Code] ....
1) ask the user to input a mathematical expression in the following format:
NUMBER Operator NUMBER Operator NUMBER
Example: 17 + 15 - 3
Example: 2 * 3 - 4
How to output the answer of the users equation. Is there a function that includes all math operators (+,-,/,*)? Would i need to write each possible scenario using if statements?
i have stuck in a join and i cant figure out where the problem is, i have those tables
public class Themes
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[Code].....
I have two questions that are related to each other. The first one is about overloading the addition operator.
I have defined a struct as the following:
Code:
#include <iostream>
#include <string>
struct Sales_data {
[Code] ....
I then overloaded the I/O operators so I could print to the screen information related Sales_data.
Code:
// overload ostream in order for cout to work
std::ostream& operator << (std::ostream & out,
const Sales_data & cSales_data) {
out << cSales_data.bookNo << ", " << cSales_data.units_sold << ", "
[Code] ....
My first issue is with overloading the addition operator. Everyone works correctly except for std::cout << item << std:endl; will no not output the ISBN number only the units_sold and revenue when added together.
Code:
// addition operator rules
Sales_data Sales_data::operator + (const Sales_data & data2) {
units_sold += data2.units_sold;
revenue += data2.revenue;
return *this;
}
Now here is the code in its entirety
Code:
#include <iostream>
#include <string>
// Sales_data structure
struct Sales_data {
std:: string bookNo;
unsigned units_sold = 0;
[code] .....
After total = total + item;, I would like to print the total for this particular ISBN. However, I only get: blank, total units, total revenue where blank is where the ISBN would go but doesn't print after addition. My second question has to do with comparing the ISBN's of the books entered during the while loop. I would like to do something like
Code:
if (item_i.bookNo == item_i+1.bookNo) {
total = total + item;
} else {
std::cerr << "Books entered must have the same ISBNs" << std::endl;
}
Unfortunately, I cannot figure out how to set up a comparison of the bookNos. If I used #include <casset> in the overload + rule, it will immediately exit since I have no way to compare the ISBNs.
I have the following code to calculate arithmetic expressions :
#include <iostream>
using namespace std;
using namespace std;
const char * expressionToParse = "6.5-2.5*10/5+2*5";
char peek(){
return *expressionToParse;
[code]....
The problem is that it does not work properly with decimal numbers for example it evaluates 6-2*10/5+2*5 = 12 which is correct but for 6.5-2.5*10/5+2*5 it returns 6 instead of 11.5 .
I am writing a simple console-based tic-tac-toe game. I am trying to write a function to check whether someone has won the game.
The board data is saved in an array called board: Code: int board[3][3] with each element corresponding either to an empty spot, an X, or an O, using the numbers 0, 1, and 2, respectively. For clarity:
Code:
#define EMPTY 0
#define X 1
#define O 2 Here is my function: Code: int check_state(int board[3][3]) {
int winner = 0;
[Code].....
A few days ago I got a "bright idea" to see if I could match a string, with an arbitrary length from 1 to 12, to its formulated sequence by using an algorithm to find all possible combinations of the integer combinations from 0 to 9 at each length (1 to 12).
Example: Desired numerical combinations from integers 1 to 3:
At Length 1:
1, 2, 3
At Length 2:
11, 12, 13, 21, 22, 23, 31, 32, 33
At Length 3:
111, 112, 113, 121, 122, 123, 131, 132, 133, 211, 212, 213, 221, 222, 223, 231, 232, 233, 311, 312, 313, 321, 322, 323, 331, 332, 333
And so on until the nth length (in my case a length of 12).
First off, I would like to say that this is not as easy as I thought. I clearly underestimated the problem seeing as I've spent hours attempting to write a working algorithm, but feel like I've made no progress.
Here are a few of my attempts:
Attempt 1:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
[Code]....
I can't exactly explain this one. It works if the length is 2 or less; however, the order of the output is horrendous.
Attempt 3: I tried using recursion, but only found myself getting more and more lost the further I tried developing my function. Cannot find my work for this attempt.
I would really like to figure this out on my own, but I am very stuck as you can see. I also lack time that I can spend working on this since im a full time student.
I wrote a version of find_all() which searches through containers for matches and returns another container that holds iterators pointing to each match. When I compared what I wrote to what the authors of Professional C++ wrote, I found the two find_all() functions to be very different.Here they are:
//Mine
template<typename Iterator, typename Predicate>
std::list<Iterator> find_all
(Iterator front, Iterator back, const Predicate& match) {
std::list<Iterator> toreturn;
for(; front != back; ++front) if(*front == match) toreturn.push_back(front);
[code]...
I have VRP algorithm written in C++, run with command prompt Windows. input (command line) -> VRP.exe -> output (txt file)
Now I want to built a website to run it as SaaS. How to run an exe application(compiled c++) in server used as Saas? What kind of programming do I have to use? Ruby or html5 or others? I don't know how to start.
i was trying to achieve a better way of game looping. so i have a game loop algrithm. but i dont think its quite good. i want it to be better.
here is my algorithm
bool quit = false;
while(quit == false) {
while(blah blah events)//here we hold events {
if(the user want to quits) {
quit = true;
[code]....