6

I want to transform a C-string to complex expression and simplify it.

For example for the string:

(3+2i)² + 6-i-3+2i

output should be: 8+13i;

Basilevs
  • 22,440
  • 15
  • 57
  • 102
Stelian B.
  • 81
  • 1
  • 6
    The idea is great, but what is the question? – awesoon Oct 20 '13 at 08:15
  • @soon, the code should be given. :) – Devolus Oct 20 '13 at 08:16
  • 2
    The idea is to code your idea :) – Maroun Oct 20 '13 at 08:17
  • You mean string expression? – Casper Beyer Oct 20 '13 at 08:19
  • I don't have a code because i don't have an idea how to solve this. And the question is: how can i transform a char to a complex expression. I need only an idea. I don't know how to implement the operations and also how to separe a complex number from this expression. – Stelian B. Oct 20 '13 at 08:19
  • Need some help with what exactly? Asking a question fit for the SO format, or one that's code related? – enhzflep Oct 20 '13 at 08:19
  • @enhzflep I don't have a code because i don't know where to start. This problem is confusing for me too. Basicaly I have to transform a char to a complex expression then i have to solve that expression. – Stelian B. Oct 20 '13 at 08:23
  • @MarounMaroun i can't code my idea because i don't know from where i can start. – Stelian B. Oct 20 '13 at 08:24
  • @StelianB., So, if you have a question - ask it. You can edit your post with pressing button `edit`. Please, make the question understandable to other SO users. – awesoon Oct 20 '13 at 08:24
  • 2
    possible duplicate of [What is the best way to evaluate mathematical expression in C++?](http://stackoverflow.com/questions/5115872/what-is-the-best-way-to-evaluate-mathematical-expression-in-c) – Oswald Oct 20 '13 at 08:25
  • @soon you men to post the code, but till now i don't have one. – Stelian B. Oct 20 '13 at 08:26
  • @soon i have to transform a char ((3+2i)2 + 6-i-3+2i) to a complex numbers expression and then to evaluate it. – Stelian B. Oct 20 '13 at 08:27
  • @StelianB. - okay, gotcha. I'd start googling for "c/c++ complex expression evaluator" or "c/c++ evaluate complex expression". The bulk of the problem will be in extracting the individual terms that need to be evaluated. You've got brackets to deal with, the `2` superscript (squared operator), then, finally - you get to add/multiply/subtract the complex numbers. Oddly enough, dealing with complex numbers is the least complex part of this question, methinks. – enhzflep Oct 20 '13 at 08:29
  • Your string already is a complex expression. What you need is a tool to parse it or evaluate it. Your deadline isn't anybody else's problem. – user207421 Oct 20 '13 at 08:53
  • @EJP I am not allowed to use any tool or complicated things to evaluate this string, just only basic things. – Stelian B. Oct 20 '13 at 08:55
  • @StelianB. You are going to use something at least as complex as an expression parser, whether you write it yourself or get it elsewhere. There is nothing 'basic' about this problem. – user207421 Oct 20 '13 at 09:23

1 Answers1

11

You need a library that can parse mathematical expressions. Either write your own or take one of the existing ones (like ExprTk).

Oswald
  • 31,254
  • 3
  • 43
  • 68